changeset 9b041c3782a6 in modules/product_price_list_dates:5.0
details: 
https://hg.tryton.org/modules/product_price_list_dates?cmd=changeset&node=9b041c3782a6
description:
        Use context date as default pattern

        issue11359
        review417411003
        (grafted from 3ca1623dd74c4c1a9aff760d2b43d5dabf82a1ee)
diffstat:

 product.py                             |   9 +++++++++
 tests/test_product_price_list_dates.py |  21 +++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diffs (64 lines):

diff -r 59ef9db0ce19 -r 9b041c3782a6 product.py
--- a/product.py        Thu Jun 17 22:01:18 2021 +0200
+++ b/product.py        Tue Jun 21 10:13:53 2022 +0200
@@ -3,6 +3,7 @@
 from trytond.model import ModelView, fields
 from trytond.pool import PoolMeta, Pool
 from trytond.pyson import Eval, If
+from trytond.transaction import Transaction
 
 __all__ = ['PriceList', 'PriceListLine', 'PriceListLineContext']
 
@@ -23,6 +24,14 @@
     def open_lines(cls, price_lists):
         pass
 
+    def compute(
+            self, party, product, unit_price, quantity, uom, pattern=None):
+        context = Transaction().context
+        pattern = pattern.copy() if pattern is not None else {}
+        pattern.setdefault('date', context.get('date'))
+        return super().compute(
+            party, product, unit_price, quantity, uom, pattern=pattern)
+
 
 class PriceListLine(metaclass=PoolMeta):
     __name__ = 'product.price_list.line'
diff -r 59ef9db0ce19 -r 9b041c3782a6 tests/test_product_price_list_dates.py
--- a/tests/test_product_price_list_dates.py    Thu Jun 17 22:01:18 2021 +0200
+++ b/tests/test_product_price_list_dates.py    Tue Jun 21 10:13:53 2022 +0200
@@ -10,6 +10,7 @@
 from trytond.tests.test_tryton import suite as test_suite
 
 from trytond.modules.company.tests import create_company, set_company
+from trytond.transaction import Transaction
 
 
 class ProductPriceListDatesTestCase(ModuleTestCase):
@@ -73,6 +74,26 @@
                 None, None, Decimal(10), 1, None, pattern={'date': yesterday}),
             Decimal(9))
 
+    @with_transaction()
+    def test_price_list_with_context_date(self):
+        "Test price list with context date"
+        pool = Pool()
+        Date = pool.get('ir.date')
+
+        today = Date.today()
+        tomorrow = today + datetime.timedelta(days=1)
+
+        price_list = self.create_price_list('start_date', tomorrow)
+
+        with Transaction().set_context(date=today):
+            self.assertEqual(
+                price_list.compute(None, None, Decimal(10), 1, None),
+                Decimal(10))
+        with Transaction().set_context(date=tomorrow):
+            self.assertEqual(
+                price_list.compute(None, None, Decimal(10), 1, None),
+                Decimal(9))
+
 
 def suite():
     suite = test_suite()

Reply via email to