← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/margin-analysis/7.0-product_price_history-price-in-future-1295114 into lp:margin-analysis

 

Guewen Baconnier @ Camptocamp has proposed merging lp:~camptocamp/margin-analysis/7.0-product_price_history-price-in-future-1295114 into lp:margin-analysis.

Requested reviews:
  Margin Analysis Core Editors (margin-analysis-core-editors)
Related bugs:
  Bug #1295114 in Financial controlling and costing: "product_price_history: price inserted in the future displayed as current price"
  https://bugs.launchpad.net/margin-analysis/+bug/1295114

For more details, see:
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-product_price_history-price-in-future-1295114/+merge/211954

lp:1295114

If I insert a price in the future for a product (this is possible using the `to_date` key in the context), then the price is correctly inserted in the product_price_history table, but is also displayed on the product whereas I expect to see the actual price.
-- 
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-product_price_history-price-in-future-1295114/+merge/211954
Your team Margin Analysis Core Editors is requested to review the proposed merge of lp:~camptocamp/margin-analysis/7.0-product_price_history-price-in-future-1295114 into lp:margin-analysis.
=== modified file 'product_price_history/product_price_history.py'
--- product_price_history/product_price_history.py	2014-02-04 10:46:08 +0000
+++ product_price_history/product_price_history.py	2014-03-20 14:49:53 +0000
@@ -80,16 +80,16 @@
             return res
         if field_names is None:
             field_names = PRODUCT_FIELD_HISTORIZE
+        if not datetime:
+            datetime = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         select = ("SELECT DISTINCT ON (product_id, name) "
                   "datetime, product_id, name, amount ")
         table = "FROM product_price_history "
         where = ("WHERE product_id IN %s "
                  "AND company_id = %s "
-                 "AND name IN %s ")
-        args = [tuple(ids), company_id, tuple(field_names)]
-        if datetime:
-            where += "AND datetime <= %s "
-            args.append(datetime)
+                 "AND name IN %s "
+                 "AND datetime <= %s ")
+        args = [tuple(ids), company_id, tuple(field_names), datetime]
         # at end, sort by ID desc if several entries are created
         # on the same datetime
         order = ("ORDER BY product_id, name, datetime DESC, id DESC ")
@@ -257,6 +257,7 @@
             for result in results:
                 dict_value = prod_prices[result['id']]
                 result.update(dict_value)
+
         return results
 
     def write(self, cr, uid, ids, values, context=None):

=== modified file 'product_price_history/test/price_historization.yml'
--- product_price_history/test/price_historization.yml	2013-12-03 10:38:20 +0000
+++ product_price_history/test/price_historization.yml	2014-03-20 14:49:53 +0000
@@ -53,3 +53,35 @@
     product = self.browse(cr, uid, ref('product_product_k_avg_01'),context=ctx)
     assert product.standard_price == 80.0, "The standard_price has not been retrieved correctly for first company"
     assert product.list_price == 100.0, "The list_price has not been retrieved correctly for first company"
+-
+  Modify product K with a price now and one in the future
+-
+  !python {model: product.product}: |
+    from datetime import datetime, timedelta
+    ctx = context.copy()
+    self.write(cr, uid, ref('product_product_k_avg_01'),
+               {'standard_price': 90,'list_price': 110}, context=ctx)
+    the_future = datetime.now() + timedelta(days=30)
+    ctx.update({'to_date': the_future.strftime('%Y-%m-%d %H:%M:%S')})
+    self.write(cr, uid, ref('product_product_k_avg_01'),
+               {'standard_price': 99,'list_price': 120}, context=ctx)
+-
+  Test that the default price is the price for now
+-
+  !python {model: product.product}: |
+    import time
+    ctx = context.copy()
+    product = self.browse(cr, uid, ref('product_product_k_avg_01'),context=ctx)
+    assert product.standard_price == 90.0, "The standard_price has not been retrieved correctly for now"
+    assert product.list_price == 110.0, "The list_price has not been retrieved correctly for now"
+-
+  Test that the price read from the future is the one inserted in the future
+-
+  !python {model: product.product}: |
+    from datetime import datetime, timedelta
+    ctx = context.copy()
+    the_future = datetime.now() + timedelta(days=30)
+    ctx.update({'to_date': the_future.strftime('%Y-%m-%d %H:%M:%S')})
+    product = self.browse(cr, uid, ref('product_product_k_avg_01'),context=ctx)
+    assert product.standard_price == 99.0, "The standard_price has not been retrieved correctly for the future"
+    assert product.list_price == 120.0, "The list_price has not been retrieved correctly for the future"


Follow ups