changeset 0deee5fb6958 in modules/sale_product_customer:default
details: 
https://hg.tryton.org/modules/sale_product_customer?cmd=changeset&node=0deee5fb6958
description:
        Add purchase_blanket_agreement and sale_blanket_agreement modules

        issue10962
        review391151002
diffstat:

 __init__.py                               |   5 +
 sale.py                                   |  88 +++++++++++++++++++++++++++++++
 sale.xml                                  |  13 ++++
 tests/test_module.py                      |   2 +-
 tryton.cfg                                |   1 +
 view/sale_blanket_agreement_line_form.xml |   9 +++
 view/sale_blanket_agreement_line_list.xml |   8 ++
 7 files changed, 125 insertions(+), 1 deletions(-)

diffs (179 lines):

diff -r 3a9d487cdf99 -r 0deee5fb6958 __init__.py
--- a/__init__.py       Fri Sep 16 23:37:38 2022 +0200
+++ b/__init__.py       Mon Oct 10 18:35:01 2022 +0200
@@ -20,6 +20,11 @@
         module='sale_product_customer', type_='model',
         depends=['sale_amendment'])
     Pool.register(
+        sale.LineBlanketAgreement,
+        sale.BlanketAgreementLine,
+        module='sale_product_customer', type_='model',
+        depends=['sale_blanket_agreement'])
+    Pool.register(
         module='sale_product_customer', type_='wizard')
     Pool.register(
         module='sale_product_customer', type_='report')
diff -r 3a9d487cdf99 -r 0deee5fb6958 sale.py
--- a/sale.py   Fri Sep 16 23:37:38 2022 +0200
+++ b/sale.py   Mon Oct 10 18:35:01 2022 +0200
@@ -118,3 +118,91 @@
     def _apply_line(self, sale, sale_line):
         super()._apply_line(sale, sale_line)
         sale_line.product_customer = self.product_customer
+
+
+class LineBlanketAgreement(metaclass=PoolMeta):
+    __name__ = 'sale.line'
+
+    @classmethod
+    def _domain_blanket_agreemnt_line_product(cls):
+        return [
+            super()._domain_blanket_agreemnt_line_product(),
+            If(Eval('product_customer'),
+                ('product_customer', '=', Eval('product_customer')),
+                ()),
+            ]
+
+    @fields.depends(
+        'blanket_agreement_line', 'product_customer',
+        '_parent_blanket_agreement_line.product_customer')
+    def on_change_blanket_agreement_line(self):
+        if self.blanket_agreement_line:
+            line = self.blanket_agreement_line
+            if not self.product_customer:
+                self.product_customer = line.product_customer
+        super().on_change_blanket_agreement_line()
+
+
+class BlanketAgreementLine(metaclass=PoolMeta):
+    __name__ = 'sale.blanket_agreement.line'
+
+    product_customer = fields.Many2One(
+        'sale.product_customer', "Customer's Product", ondelete='RESTRICT',
+        domain=[
+            If(Bool(Eval('product')),
+                ['OR',
+                    [
+                        ('template.products', '=', Eval('product')),
+                        ('product', '=', None),
+                        ],
+                    ('product', '=', Eval('product')),
+                    ],
+                []),
+            ('party', '=', Eval('_parent_blanket_agreement', {}).get(
+                    'customer')),
+            ],
+        states={
+            'readonly': Eval('agreement_state') != 'draft'
+            })
+
+    @fields.depends('blanket_agreement', '_parent_blanket_agreement.customer')
+    def _get_product_customer_pattern(self):
+        return {
+            'party': (
+                self.blanket_agreement.customer.id
+                if self.blanket_agreement and self.blanket_agreement.customer
+                else -1),
+            }
+
+    @fields.depends('product', 'product_customer')
+    def on_change_product(self):
+        try:
+            super().on_change_product()
+        except AttributeError:
+            pass
+        if not self.product:
+            return
+        product_customers = list(self.product.product_customer_used(
+                **self._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 get_sale_line(self, sale):
+        sale_line = super().get_sale_line(sale)
+        if self.product_customer:
+            sale_line.product_customer = self.product_customer
+        return sale_line
diff -r 3a9d487cdf99 -r 0deee5fb6958 sale.xml
--- a/sale.xml  Fri Sep 16 23:37:38 2022 +0200
+++ b/sale.xml  Mon Oct 10 18:35:01 2022 +0200
@@ -85,4 +85,17 @@
             <field name="name">sale_amendment_line_form</field>
         </record>
     </data>
+
+    <data depends="sale_blanket_agreement">
+        <record model="ir.ui.view" id="sale_blanket_agreement_line_view_form">
+            <field name="model">sale.blanket_agreement.line</field>
+            <field name="inherit" 
ref="sale_blanket_agreement.sale_blanket_agreement_line_view_form"/>
+            <field name="name">sale_blanket_agreement_line_form</field>
+        </record>
+        <record model="ir.ui.view" id="sale_blanket_agreement_line_view_list">
+            <field name="model">sale.blanket_agreement.line</field>
+            <field name="inherit" 
ref="sale_blanket_agreement.sale_blanket_agreement_line_view_list"/>
+            <field name="name">sale_blanket_agreement_line_list</field>
+        </record>
+    </data>
 </tryton>
diff -r 3a9d487cdf99 -r 0deee5fb6958 tests/test_module.py
--- a/tests/test_module.py      Fri Sep 16 23:37:38 2022 +0200
+++ b/tests/test_module.py      Mon Oct 10 18:35:01 2022 +0200
@@ -7,7 +7,7 @@
 class SaleProductCustomerTestCase(ModuleTestCase):
     'Test Sale Product Customer module'
     module = 'sale_product_customer'
-    extras = ['sale_amendment']
+    extras = ['sale_amendment', 'sale_blanket_agreement']
 
 
 del ModuleTestCase
diff -r 3a9d487cdf99 -r 0deee5fb6958 tryton.cfg
--- a/tryton.cfg        Fri Sep 16 23:37:38 2022 +0200
+++ b/tryton.cfg        Mon Oct 10 18:35:01 2022 +0200
@@ -6,6 +6,7 @@
     sale
 extras_depend:
     sale_amendment
+    sale_blanket_agreement
 xml:
     product.xml
     sale.xml
diff -r 3a9d487cdf99 -r 0deee5fb6958 view/sale_blanket_agreement_line_form.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/sale_blanket_agreement_line_form.xml Mon Oct 10 18:35:01 2022 +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="//field[@name='product']" position="after">
+        <label name="product_customer"/>
+        <field name="product_customer"/>
+    </xpath>
+</data>
diff -r 3a9d487cdf99 -r 0deee5fb6958 view/sale_blanket_agreement_line_list.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/sale_blanket_agreement_line_list.xml Mon Oct 10 18:35:01 2022 +0200
@@ -0,0 +1,8 @@
+<?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="//field[@name='product']" position="after">
+        <field name="product_customer" expand="1" optional="1"/>
+    </xpath>
+</data>

Reply via email to