changeset 55e47bf6790b in modules/sale_product_customer:default
details: 
https://hg.tryton.org/modules/sale_product_customer?cmd=changeset;node=55e47bf6790b
description:
        Add amendment

        issue8494
        review267641002
diffstat:

 __init__.py                         |   4 ++
 sale.py                             |  58 +++++++++++++++++++++++++++++++++++++
 sale.xml                            |   8 +++++
 setup.py                            |   3 +-
 tests/test_sale_product_customer.py |   1 +
 tryton.cfg                          |   2 +
 view/sale_amendment_line_form.xml   |   9 +++++
 7 files changed, 84 insertions(+), 1 deletions(-)

diffs (144 lines):

diff -r 63a795913dd4 -r 55e47bf6790b __init__.py
--- a/__init__.py       Sat Sep 28 23:59:10 2019 +0200
+++ b/__init__.py       Sun Sep 29 18:30:25 2019 +0200
@@ -16,6 +16,10 @@
         sale.Line,
         module='sale_product_customer', type_='model')
     Pool.register(
+        sale.AmendmentLine,
+        module='sale_product_customer', type_='model',
+        depends=['sale_amendment'])
+    Pool.register(
         module='sale_product_customer', type_='wizard')
     Pool.register(
         module='sale_product_customer', type_='report')
diff -r 63a795913dd4 -r 55e47bf6790b sale.py
--- a/sale.py   Sat Sep 28 23:59:10 2019 +0200
+++ b/sale.py   Sun Sep 29 18:30:25 2019 +0200
@@ -60,3 +60,61 @@
                 if len(self.product_customer.template.products) == 1:
                     self.product, = self.product_customer.template.products
         self.on_change_product()
+
+
+class AmendmentLine(metaclass=PoolMeta):
+    __name__ = 'sale.amendment.line'
+
+    product_customer = fields.Many2One(
+        'sale.product_customer', "Customer's Product",
+        domain=[
+            ['OR',
+                [
+                    ('template.products', '=', Eval('product')),
+                    ('product', '=', None),
+                    ],
+                ('product', '=', Eval('product')),
+                ],
+            ('party', '=', Eval('party', -1)),
+            ],
+        states={
+            'invisible': Eval('action') != 'product',
+            },
+        depends=['action', 'product', 'party'])
+
+    @fields.depends('line')
+    def on_change_line(self):
+        super().on_change_line()
+        if self.line:
+            self.product_customer = self.line.product_customer
+
+    @fields.depends('product', 'product_customer', 'line')
+    def on_change_product(self):
+        try:
+            super().on_change_product()
+        except AttributeError:
+            pass
+        if not self.product and not self.line:
+            return
+        product_customers = list(self.product.product_customer_used(
+                **self.line._get_product_customer_pattern()))
+        if len(product_customers) == 1:
+            self.product_customer, = product_customers
+        elif (self.product_customer
+                and self.product_customer not in product_customers):
+            self.product_customer = None
+
+    @fields.depends('product', 'product_customer',
+        methods=['on_change_product'])
+    def on_change_product_customer(self):
+        if self.product_customer:
+            if self.product_customer.product:
+                self.product = self.product_customer.product
+            elif not self.product:
+                if len(self.product_customer.template.products) == 1:
+                    self.product, = self.product_customer.template.products
+        self.on_change_product()
+
+    def _apply_line(self, sale, sale_line):
+        super()._apply_line(sale, sale_line)
+        sale_line.product_customer = self.product_customer
diff -r 63a795913dd4 -r 55e47bf6790b sale.xml
--- a/sale.xml  Sat Sep 28 23:59:10 2019 +0200
+++ b/sale.xml  Sun Sep 29 18:30:25 2019 +0200
@@ -74,4 +74,12 @@
             <field name="perm_delete" eval="True"/>
         </record>
     </data>
+
+    <data depends="sale_amendment">
+        <record model="ir.ui.view" id="sale_amendment_line_view_form">
+            <field name="model">sale.amendment.line</field>
+            <field name="inherit" 
ref="sale_amendment.sale_amendment_line_view_form"/>
+            <field name="name">sale_amendment_line_form</field>
+        </record>
+    </data>
 </tryton>
diff -r 63a795913dd4 -r 55e47bf6790b setup.py
--- a/setup.py  Sat Sep 28 23:59:10 2019 +0200
+++ b/setup.py  Sun Sep 29 18:30:25 2019 +0200
@@ -51,7 +51,8 @@
         requires.append(get_require_version('trytond_%s' % dep))
 requires.append(get_require_version('trytond'))
 
-tests_require = [get_require_version('proteus')]
+tests_require = [get_require_version('proteus'),
+    get_require_version('trytond_sale_amendment')]
 dependency_links = []
 if minor_version % 2:
     dependency_links.append('https://trydevpi.tryton.org/')
diff -r 63a795913dd4 -r 55e47bf6790b tests/test_sale_product_customer.py
--- a/tests/test_sale_product_customer.py       Sat Sep 28 23:59:10 2019 +0200
+++ b/tests/test_sale_product_customer.py       Sun Sep 29 18:30:25 2019 +0200
@@ -14,6 +14,7 @@
 class SaleProductCustomerTestCase(ModuleTestCase):
     'Test Sale Product Customer module'
     module = 'sale_product_customer'
+    extras = ['sale_amendment']
 
 
 def suite():
diff -r 63a795913dd4 -r 55e47bf6790b tryton.cfg
--- a/tryton.cfg        Sat Sep 28 23:59:10 2019 +0200
+++ b/tryton.cfg        Sun Sep 29 18:30:25 2019 +0200
@@ -4,6 +4,8 @@
     ir
     product
     sale
+extras_depend:
+    sale_amendment
 xml:
     product.xml
     sale.xml
diff -r 63a795913dd4 -r 55e47bf6790b view/sale_amendment_line_form.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/sale_amendment_line_form.xml Sun Sep 29 18:30:25 2019 +0200
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<data>
+    <xpath expr="/form/field[@name='product']" position="after">
+        <label name="product_customer"/>
+        <field name="product_customer"/>
+    </xpath>
+</data>

Reply via email to