changeset 1af59832ba84 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=1af59832ba84
description:
        Add company as product context field

        issue9111
        review275031002
diffstat:

 sale.py                               |  19 +++++++++++++------
 tests/scenario_sale_modify_header.rst |   9 ++++++---
 2 files changed, 19 insertions(+), 9 deletions(-)

diffs (89 lines):

diff -r e68216124bb0 -r 1af59832ba84 sale.py
--- a/sale.py   Thu Apr 23 21:44:00 2020 +0200
+++ b/sale.py   Sat Apr 25 09:18:50 2020 +0200
@@ -1069,15 +1069,14 @@
             'stock_date_end': Eval('_parent_sale', {}).get('sale_date'),
             'stock_skip_warehouse': True,
             # From _get_context_sale_price
-            'company': Eval(
-                '_parent_sale', {}).get('company', None),
+            'company': Eval('company', None),
             'currency': Eval('_parent_sale', {}).get('currency'),
             'customer': Eval('_parent_sale', {}).get('party'),
             'sale_date': Eval('_parent_sale', {}).get('sale_date'),
             'uom': Eval('unit'),
             'taxes': Eval('taxes', []),
             'quantity': Eval('quantity'),
-            }, depends=['type', 'sale_state'])
+            }, depends=['type', 'sale_state', 'company'])
     product_uom_category = fields.Function(
         fields.Many2One('product.uom.category', 'Product Uom Category'),
         'on_change_with_product_uom_category')
@@ -1136,6 +1135,9 @@
     sale_state = fields.Function(
         fields.Selection('get_sale_states', "Sale State"),
         'on_change_with_sale_state')
+    company = fields.Function(
+        fields.Many2One('company.company', "Company"),
+        'on_change_with_company')
 
     @classmethod
     def __register__(cls, module_name):
@@ -1199,7 +1201,7 @@
 
     @fields.depends(
         'sale', '_parent_sale.currency', '_parent_sale.party',
-        '_parent_sale.sale_date', '_parent_sale.company',
+        '_parent_sale.sale_date', 'company',
         'unit', 'product', 'taxes')
     def _get_context_sale_price(self):
         context = {}
@@ -1209,8 +1211,8 @@
             if self.sale.party:
                 context['customer'] = self.sale.party.id
             context['sale_date'] = self.sale.sale_date
-            if self.sale.company:
-                context['company'] = self.sale.company.id
+        if self.company:
+            context['company'] = self.company.id
         if self.unit:
             context['uom'] = self.unit.id
         elif self.product:
@@ -1370,6 +1372,11 @@
         if self.sale:
             return self.sale.state
 
+    @fields.depends('sale', '_parent_sale.company')
+    def on_change_with_company(self, name=None):
+        if self.sale and self.sale.company:
+            return self.sale.company.id
+
     def get_invoice_line(self):
         'Return a list of invoice lines for sale line'
         pool = Pool()
diff -r e68216124bb0 -r 1af59832ba84 tests/scenario_sale_modify_header.rst
--- a/tests/scenario_sale_modify_header.rst     Thu Apr 23 21:44:00 2020 +0200
+++ b/tests/scenario_sale_modify_header.rst     Sat Apr 25 09:18:50 2020 +0200
@@ -31,11 +31,14 @@
 
     >>> tax = create_tax(Decimal('.10'))
     >>> tax.save()
+    >>> other_tax = create_tax(Decimal('.05'))
+    >>> other_tax.save()
 
     >>> TaxRule = Model.get('account.tax.rule')
     >>> foreign = TaxRule(name='Foreign Customers', company=company)
-    >>> no_tax = foreign.lines.new()
-    >>> no_tax.origin_tax = tax
+    >>> foreign_tax = foreign.lines.new()
+    >>> foreign_tax.origin_tax = tax
+    >>> foreign_tax.tax = other_tax
     >>> foreign.save()
 
 Create account categories::
@@ -92,4 +95,4 @@
     >>> sale.party.name
     'Another Customer'
     >>> sale.untaxed_amount, sale.tax_amount, sale.total_amount
-    (Decimal('30.00'), Decimal('0'), Decimal('30.00'))
+    (Decimal('30.00'), Decimal('1.50'), Decimal('31.50'))

Reply via email to