changeset 0ad4520af80a in modules/product_price_list:default
details: 
https://hg.tryton.org/modules/product_price_list?cmd=changeset;node=0ad4520af80a
description:
        Allow using the product list price in the price list formula

        issue9979
        review330061002
diffstat:

 CHANGELOG                        |   2 ++
 price_list.py                    |   8 +++++++-
 tests/test_product_price_list.py |  34 ++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 1 deletions(-)

diffs (84 lines):

diff -r 3e087cc0011a -r 0ad4520af80a CHANGELOG
--- a/CHANGELOG Sat Dec 19 17:08:46 2020 +0100
+++ b/CHANGELOG Sat Feb 27 10:14:46 2021 +0100
@@ -1,3 +1,5 @@
+* Allow using the product list price in the price list formula
+
 Version 5.8.0 - 2020-11-02
 * Bug fixes (see mercurial logs for details)
 * Remove support for Python 3.5
diff -r 3e087cc0011a -r 0ad4520af80a price_list.py
--- a/price_list.py     Sat Dec 19 17:08:46 2020 +0100
+++ b/price_list.py     Sat Feb 27 10:14:46 2021 +0100
@@ -53,12 +53,17 @@
             pattern=None):
         if product:
             cost_price = product.get_multivalue('cost_price') or Decimal('0')
+            list_price = product.list_price_used
+            if list_price is None:
+                list_price = unit_price
         else:
             cost_price = Decimal('0')
+            list_price = unit_price
         return {
             'names': {
                 'unit_price': unit_price,
                 'cost_price': cost_price,
+                'list_price': list_price,
                 },
             }
 
@@ -115,7 +120,8 @@
     formula = fields.Char('Formula', required=True,
         help=('Python expression that will be evaluated with:\n'
             '- unit_price: the original unit_price\n'
-            '- cost_price: the cost price of the product'))
+            '- cost_price: the cost price of the product\n'
+            '- list_price: the list price of the product'))
 
     @staticmethod
     def default_formula():
diff -r 3e087cc0011a -r 0ad4520af80a tests/test_product_price_list.py
--- a/tests/test_product_price_list.py  Sat Dec 19 17:08:46 2020 +0100
+++ b/tests/test_product_price_list.py  Sat Feb 27 10:14:46 2021 +0100
@@ -177,6 +177,40 @@
                 price_list.compute(None, product, product.list_price, 1, unit),
                 Decimal(6))
 
+    @with_transaction()
+    def test_price_list_list_price(self):
+        "Test price list with list_price formula"
+        pool = Pool()
+        Template = pool.get('product.template')
+        Product = pool.get('product.product')
+        Uom = pool.get('product.uom')
+        PriceList = pool.get('product.price_list')
+
+        unit, = Uom.search([('name', '=', 'Unit')])
+
+        company = create_company()
+        with set_company(company):
+            template = Template(
+                name="Template",
+                list_price=Decimal(10),
+                default_uom=unit,
+                products=None,
+                )
+            template.save()
+            product = Product(template=template)
+            product.save()
+
+            price_list, = PriceList.create([{
+                        'name': "Price List",
+                        'lines': [('create', [{
+                                        'formula': 'list_price * 0.8',
+                                        }])],
+                        }])
+
+            self.assertEqual(
+                price_list.compute(None, product, Decimal(0), 1, unit),
+                Decimal(8))
+
 
 def suite():
     suite = trytond.tests.test_tryton.suite()

Reply via email to