Add purchase_blanket_agreement and sale_blanket_agreement modules

issue10962
review391151002
This commit is contained in:
Cédric Krier committed 2022-10-10 18:35:01 +02:00
1 parent 4b0346110a
commit d255c5d881
7 files changed
+125 -1

No files matched your search

+5
View File
@@ -19,6 +19,11 @@ def register():
sale.AmendmentLine,
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(
+88
View File
@@ -118,3 +118,91 @@ class AmendmentLine(metaclass=PoolMeta):
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
+13
View File
@@ -85,4 +85,17 @@ this repository contains the full copyright notices and license terms. -->
<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>
+1 -1
View File
@@ -7,7 +7,7 @@ from trytond.tests.test_tryton import ModuleTestCase
class SaleProductCustomerTestCase(ModuleTestCase):
'Test Sale Product Customer module'
module = 'sale_product_customer'
extras = ['sale_amendment']
extras = ['sale_amendment', 'sale_blanket_agreement']
del ModuleTestCase
+1
View File
@@ -6,6 +6,7 @@ depends:
sale
extras_depend:
sale_amendment
sale_blanket_agreement
xml:
product.xml
sale.xml
@@ -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>
@@ -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>