Sergi Almacellas Abellana pushed to branch branch/default at Tryton / Tryton


Commits:
1caaaf9f by Sergi Almacellas Abellana at 2023-06-07T09:58:57+02:00
Set date on purchase price context

Closes #12309
- - - - -


4 changed files:

- modules/product_price_list_dates/__init__.py
- + modules/product_price_list_dates/purchase.py
- modules/product_price_list_dates/setup.py
- modules/product_price_list_dates/tests/test_module.py


Changes:

=====================================
modules/product_price_list_dates/__init__.py
=====================================
@@ -3,7 +3,7 @@
 
 from trytond.pool import Pool
 
-from . import product, sale
+from . import product, purchase, sale
 
 __all__ = ['register']
 
@@ -19,3 +19,7 @@
         product.SaleContext,
         module='product_price_list_dates', type_='model',
         depends=['sale_price_list'])
+    Pool.register(
+        purchase.Line,
+        module='product_price_list_dates', type_='model',
+        depends=['purchase_price_list'])


=====================================
modules/product_price_list_dates/purchase.py
=====================================
@@ -0,0 +1,22 @@
+# This file is part of Tryton.  The COPYRIGHT file at the top level of
+# this repository contains the full copyright notices and license terms.
+from trytond.model import fields
+from trytond.pool import PoolMeta
+from trytond.pyson import Eval
+
+
+class Line(metaclass=PoolMeta):
+    __name__ = 'purchase.line'
+
+    @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        cls.product.search_context['date'] = Eval(
+            '_parent_purchase', {}).get('purchase_date')
+
+    @fields.depends('purchase', '_parent_purchase.purchase_date')
+    def _get_context_purchase_price(self):
+        context = super()._get_context_purchase_price()
+        if self.purchase:
+            context.setdefault('date', self.purchase.purchase_date)
+        return context


=====================================
modules/product_price_list_dates/setup.py
=====================================
@@ -47,7 +47,10 @@
         requires.append(get_require_version('trytond_%s' % dep))
 requires.append(get_require_version('trytond'))
 
-tests_require = [get_require_version('trytond_sale_price_list')]
+tests_require = [
+    get_require_version('trytond_purchase_price_list'),
+    get_require_version('trytond_sale_price_list'),
+    ]
 
 setup(name=name,
     version=version,


=====================================
modules/product_price_list_dates/tests/test_module.py
=====================================
@@ -14,7 +14,7 @@
 class ProductPriceListDatesTestCase(CompanyTestMixin, ModuleTestCase):
     'Test Product Price List Dates module'
     module = 'product_price_list_dates'
-    extras = ['sale_price_list']
+    extras = ['sale_price_list', 'purchase_price_list']
 
     def create_price_list(self, field, date):
         pool = Pool()



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/1caaaf9ff7265024f7e3c80298e556fccd9775fa

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/1caaaf9ff7265024f7e3c80298e556fccd9775fa
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to