changeset 805860023023 in modules/account_stock_shipment_cost:6.4
details:
https://hg.tryton.org/modules/account_stock_shipment_cost?cmd=changeset&node=805860023023
description:
Store allocation factors per model name and id
This avoid collision if different shipment models have the same id.
issue11559
review443231004
(grafted from ff1179530c06cd90d96b4a150c6863bcc557b500)
diffstat:
account.py | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diffs (33 lines):
diff -r 2061d0523fa5 -r 805860023023 account.py
--- a/account.py Mon May 02 17:13:01 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)