changeset cfe70948bb06 in modules/sale_shipment_cost:default
details:
https://hg.tryton.org/modules/sale_shipment_cost?cmd=changeset;node=cfe70948bb06
description:
Compute shipment cost without creating a line
issue9010
review252971002
diffstat:
CHANGELOG | 2 ++
sale.py | 30 ++++++++++++++----------------
2 files changed, 16 insertions(+), 16 deletions(-)
diffs (57 lines):
diff -r cf84fd8a2a13 -r cfe70948bb06 CHANGELOG
--- a/CHANGELOG Wed Aug 05 00:27:46 2020 +0200
+++ b/CHANGELOG Mon Oct 12 18:07:39 2020 +0200
@@ -1,3 +1,5 @@
+* Compute shipment cost without creating a line
+
Version 5.6.0 - 2020-05-04
* Bug fixes (see mercurial logs for details)
diff -r cf84fd8a2a13 -r cfe70948bb06 sale.py
--- a/sale.py Wed Aug 05 00:27:46 2020 +0200
+++ b/sale.py Mon Oct 12 18:07:39 2020 +0200
@@ -187,30 +187,28 @@
def _get_carrier_context(self):
return {}
- def set_shipment_cost(self):
+ def compute_shipment_cost(self):
pool = Pool()
Date = pool.get('ir.date')
Currency = pool.get('currency.currency')
-
- cost, currency_id = 0, None
- if (self.carrier
- and any(l.quantity >= 0 for l in self.lines
- if l.type == 'line'
- and l.product and l.product.type != 'service')):
+ stockable = any(
+ line.quantity >= 0 for line in self.lines
+ if line.type == 'line'
+ and line.product and line.product.type != 'service')
+ if self.carrier and stockable:
with Transaction().set_context(self._get_carrier_context()):
cost, currency_id = self.carrier.get_sale_price()
-
- cost_line = None
- products = [line.product for line in self.lines or []
- if getattr(line, 'product', None)]
- stockable = any(product.type in ('goods', 'assets')
- for product in products)
- if cost and currency_id and stockable:
today = Date.today()
date = self.sale_date or today
with Transaction().set_context(date=date):
- cost = Currency.compute(Currency(currency_id), cost,
- self.currency, round=False)
+ return Currency.compute(
+ Currency(currency_id), cost, self.currency, round=False)
+ return 0
+
+ def set_shipment_cost(self):
+ cost_line = None
+ cost = self.compute_shipment_cost()
+ if cost:
cost_line = self.get_shipment_cost_line(cost)
removed = []