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

        issue11620
        review415401003
diffstat:

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

diffs (55 lines):

diff -r 7c54613f5d7a -r b1733b905ce3 sale.py
--- a/sale.py   Fri Aug 05 15:07:59 2022 +0200
+++ b/sale.py   Mon Aug 08 22:15:28 2022 +0200
@@ -339,13 +339,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 7c54613f5d7a -r b1733b905ce3 stock.py
--- a/stock.py  Fri Aug 05 15:07:59 2022 +0200
+++ b/stock.py  Mon Aug 08 22:15:28 2022 +0200
@@ -114,7 +114,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
 
@@ -146,18 +149,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