From 659d7ae8ef2e71ac927225bdde532f7a38e04d1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 8 Aug 2022 22:15:28 +0200 Subject: [PATCH] Use cost method on shipment instead of shipment cost method on sale issue11620 review415401003 --- sale.py | 5 +---- stock.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/sale.py b/sale.py index 6a2737f608..b07d9a0e29 100644 --- a/sale.py +++ b/sale.py @@ -339,13 +339,10 @@ class Line(metaclass=PoolMeta): 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 --git a/stock.py b/stock.py index 4999023c16..f1330906f3 100644 --- a/stock.py +++ b/stock.py @@ -114,7 +114,10 @@ class ShipmentOut(metaclass=PoolMeta): 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 @@ class ShipmentOut(metaclass=PoolMeta): 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