changeset 5288b779b6ec in modules/sale_shipment_cost:6.2
details: 
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset&node=5288b779b6ec
description:
        Use cost method on shipment instead of shipment cost method on sale

        issue11620
        review415401003
        (grafted from b1733b905ce33277fcc4bd644d256515cff84d09)
diffstat:

 sale.py  |   5 +----
 stock.py |  15 +++++++--------
 2 files changed, 8 insertions(+), 12 deletions(-)

diffs (55 lines):

diff -r 95b8ff809f6c -r 5288b779b6ec sale.py
--- a/sale.py   Fri Apr 15 23:23:20 2022 +0200
+++ b/sale.py   Mon Aug 08 22:15:28 2022 +0200
@@ -330,13 +330,10 @@
         context = Transaction().context
         shipment_cost_invoiced = context.get('_shipment_cost_invoiced')
         lines = super().get_invoice_line()
-        if (self.sale.shipment_cost_method == 'shipment'
-                and self.shipment_cost
+        if (self.shipment_cost
                 and shipment_cost_invoiced is not None):
             for shipment in self.sale.shipments:
                 if (shipment.state == 'done'
-                        and shipment.carrier
-                        and not shipment.cost_invoice_line
                         and shipment.id not in shipment_cost_invoiced):
                     invoice_line = shipment.get_cost_invoice_line(
                         self.sale._get_invoice_sale())
diff -r 95b8ff809f6c -r 5288b779b6ec stock.py
--- a/stock.py  Fri Apr 15 23:23:20 2022 +0200
+++ b/stock.py  Mon Aug 08 22:15:28 2022 +0200
@@ -134,7 +134,10 @@
         Currency = pool.get('currency.currency')
         InvoiceLine = pool.get('account.invoice.line')
 
-        if not self.cost_sale_used:
+        if (self.cost_method != 'shipment'
+                or not self.carrier
+                or not self.cost_sale_used
+                or self.cost_invoice_line):
             return
         product = self.carrier.carrier_product
 
@@ -166,18 +169,14 @@
         pool = Pool()
         Currency = pool.get('currency.currency')
         cost = super()._get_shipment_cost()
-        methods = {
-            m.sale.shipment_cost_method for m in self.outgoing_moves if m.sale}
-        if 'shipment' in methods:
+        if self.cost_method == 'shipment':
             if self.cost_sale:
                 cost_sale = Currency.compute(
                     self.cost_sale_currency, self.cost_sale,
                     self.company.currency, round=False)
                 cost -= cost_sale
-        if 'order' in methods:
-            sales = {
-                m.sale for m in self.outgoing_moves
-                if m.sale and m.sale.shipment_cost_method == 'order'}
+        elif self.cost_method == 'order':
+            sales = {m.sale for m in self.outgoing_moves if m.sale}
             for sale in sales:
                 shipment_cost = sum(
                     (s.cost_used or 0) for s in sale.shipments

Reply via email to