changeset ff1179530c06 in modules/account_stock_shipment_cost:default details: https://hg.tryton.org/modules/account_stock_shipment_cost?cmd=changeset&node=ff1179530c06 description: Store allocation factors per model name and id
This avoid collision if different shipment models have the same id. issue11559 review443231004 diffstat: account.py | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diffs (33 lines): diff -r 6cd583db02bf -r ff1179530c06 account.py --- a/account.py Mon May 02 17:13:02 2022 +0200 +++ b/account.py Wed Jun 15 22:05:41 2022 +0200 @@ -210,7 +210,7 @@ shipments = self.all_shipments length = Decimal(len(shipments)) factor = 1 / length - return {str(shipment.id): factor for shipment in shipments} + return {str(shipment): factor for shipment in shipments} def _allocate_cost(self, factors, sign=1): "Allocate cost on shipments using factors" @@ -225,13 +225,16 @@ (list(self.shipment_returns), ShipmentReturn), ]: for shipment in shipments: + try: + factor = factors[str(shipment)] + except KeyError: + # Try with just id for backward compatibility + factor = factors[str(shipment.id)] if (any(c.state == 'posted' for c in shipment.shipment_costs) and shipment.cost): - shipment.cost += round_price( - cost * factors[str(shipment.id)]) + shipment.cost += round_price(cost * factor) else: - shipment.cost = round_price( - cost * factors[str(shipment.id)]) + shipment.cost = round_price(cost * factor) klass.save(shipments) klass.set_shipment_cost(shipments)