Cédric Krier pushed to branch branch/default at Tryton / Tryton


Commits:
f6e6e192 by Cédric Krier at 2023-01-14T17:25:39+01:00
Pass the grouped instance to the grouping methods

This allows more possibilities to implement grouping methods.
- - - - -


2 changed files:

- modules/sale_invoice_grouping/sale.py
- modules/sale_shipment_grouping/sale.py


Changes:

=====================================
modules/sale_invoice_grouping/sale.py
=====================================
@@ -15,10 +15,9 @@
         party = self.invoice_party or self.party
         return party.sale_invoice_grouping_method
 
-    @property
-    def _invoice_grouping_fields(self):
-        return ('state', 'company', 'type', 'journal', 'party',
-            'invoice_address', 'currency', 'account', 'payment_term')
+    def _get_invoice_grouping_fields(self, invoice):
+        return ['state', 'company', 'type', 'journal', 'party',
+            'invoice_address', 'currency', 'account', 'payment_term']
 
     def _get_grouped_invoice_order(self):
         "Returns the order clause used to find invoice that should be grouped"
@@ -30,9 +29,9 @@
         invoice_domain = [
             ('lines.origin', 'like', 'sale.line,%'),
             ]
-        defaults = Invoice.default_get(self._invoice_grouping_fields,
-            with_rec_name=False)
-        for field in self._invoice_grouping_fields:
+        fields = self._get_invoice_grouping_fields(invoice)
+        defaults = Invoice.default_get(fields, with_rec_name=False)
+        for field in fields:
             invoice_domain.append(
                 (field, '=', getattr(invoice, field, defaults.get(field)))
                 )


=====================================
modules/sale_shipment_grouping/sale.py
=====================================
@@ -3,7 +3,7 @@
 
 from itertools import groupby
 
-from trytond.pool import PoolMeta
+from trytond.pool import Pool, PoolMeta
 from trytond.transaction import Transaction
 
 
@@ -18,10 +18,14 @@
     def _shipment_grouping_state(self):
         return ['draft', 'waiting']
 
-    @property
-    def _shipment_grouping_fields(self):
-        return ('customer', 'delivery_address', 'company', 'warehouse')
+    def _get_shipment_grouping_fields(self, shipment):
+        pool = Pool()
+        ShipmentOut = pool.get('stock.shipment.out')
+        fields = ['customer', 'company', 'warehouse']
+        if isinstance(shipment, ShipmentOut):
+            fields.append('delivery_address')
+        return fields
 
     def _get_grouped_shipment_planned_date(self, shipment):
         return [('planned_date', '=', shipment.planned_date)]
 
@@ -24,8 +28,8 @@
 
     def _get_grouped_shipment_planned_date(self, shipment):
         return [('planned_date', '=', shipment.planned_date)]
 
-    def _get_grouped_shipment_order(self):
+    def _get_grouped_shipment_order(self, shipment_type):
         "Returns the order used to find shipments that should be grouped"
         return None
 
@@ -37,8 +41,7 @@
             ('state', 'in', self._shipment_grouping_state),
             ]
         shipment_domain += self._get_grouped_shipment_planned_date(shipment)
-        fields = [
-            f for f in self._shipment_grouping_fields if f in Shipment._fields]
+        fields = self._get_shipment_grouping_fields(shipment)
         defaults = Shipment.default_get(fields, with_rec_name=False)
         for field in fields:
             shipment_domain.append((field, '=',
@@ -55,7 +58,7 @@
                 shipment = self._get_shipment_sale(shipment_type, values)
             Shipment = shipment.__class__
             domain = self._get_grouped_shipment_domain(shipment)
-            order = self._get_grouped_shipment_order()
+            order = self._get_grouped_shipment_order(shipment_type)
             grouped_shipments = Shipment.search(domain, order=order, limit=1)
             if grouped_shipments:
                 shipment, = grouped_shipments



View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/f6e6e1921a5466de7864d7f8502cb2a6494d4394

-- 
View it on Heptapod: 
https://foss.heptapod.net/tryton/tryton/-/commit/f6e6e1921a5466de7864d7f8502cb2a6494d4394
You're receiving this email because of your account on foss.heptapod.net.


Reply via email to