changeset 97624cfc324a in modules/purchase:default
details: https://hg.tryton.org/modules/purchase?cmd=changeset;node=97624cfc324a
description:
        Use a fresh product instance to find best product supplier

        This ensure to be able to read all the product suppliers.

        issue8723
        review284231002
diffstat:

 product.py  |  10 ++++++++--
 purchase.py |   5 ++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diffs (45 lines):

diff -r 16cbb3ba462e -r 97624cfc324a product.py
--- a/product.py        Wed Oct 16 21:20:29 2019 +0200
+++ b/product.py        Thu Oct 24 19:08:07 2019 +0200
@@ -62,7 +62,10 @@
                     })]
 
     def product_suppliers_used(self, **pattern):
-        for product_supplier in self.product_suppliers:
+        # Skip rules to test pattern on all records
+        with Transaction().set_user(0):
+            template = self.__class__(self)
+        for product_supplier in template.product_suppliers:
             if product_supplier.match(pattern):
                 yield product_supplier
 
@@ -112,7 +115,10 @@
         return cls.get_purchase_price(products, quantity=quantity)
 
     def product_suppliers_used(self, **pattern):
-        for product_supplier in self.product_suppliers:
+        # Skip rules to test pattern on all records
+        with Transaction().set_user(0):
+            product = self.__class__(self)
+        for product_supplier in product.product_suppliers:
             if product_supplier.match(pattern):
                 yield product_supplier
         pattern['product'] = None
diff -r 16cbb3ba462e -r 97624cfc324a purchase.py
--- a/purchase.py       Wed Oct 16 21:20:29 2019 +0200
+++ b/purchase.py       Thu Oct 24 19:08:07 2019 +0200
@@ -1165,10 +1165,13 @@
         context['taxes'] = [t.id for t in self.taxes or []]
         return context
 
-    @fields.depends('purchase', '_parent_purchase.party')
+    @fields.depends('purchase',
+        '_parent_purchase.party', '_parent_purchase.company')
     def _get_product_supplier_pattern(self):
         return {
             'party': self.purchase.party.id if self.purchase.party else -1,
+            'company': (
+                self.purchase.company.id if self.purchase.company else -1),
             }
 
     @fields.depends('product', 'unit', 'purchase', '_parent_purchase.party',

Reply via email to