diff options
| author | William Henrotin <whe@odoo.com> | 2018-11-26 16:00:18 +0000 |
|---|---|---|
| committer | William Henrotin <whe@odoo.com> | 2019-02-11 13:55:55 +0000 |
| commit | 8938afa3f68c879b96e77b960b0dc7efd64a1326 (patch) | |
| tree | 0286ed223bdb2694cba1a762af2ccd23ef795b2b /addons/delivery/models/stock_picking.py | |
| parent | 8b7605c9e5df4a700b0139d1781db24ae5d31626 (diff) | |
[IMP] delivery: invoicing policy of delivery price
The delivery carriers get a new field to specify the invoicing
policy. The two cases are :
- Estimated cost: the delivery price is charged directly on
the sale order based on the estimated fee
- Real cost: the delivery price is estimated from the sale order
but not added in the delivery line (we get a line with quantity=1 and price = 0).
Once the delivery is validated, the delivery price is recomputed.
The new price depends on the integration level. If it's 'rate', the price is
the estimated one (carrier.rate_shipment()). If it's 'rate_and_ship, the price
is the one given by the carrier at the delivery
The bases carriers (fixed_on_rule and base) always use 'Estimated Cost'
as their price should not be changed between the sale order creation
and delivery validation
Task : 1908654
Diffstat (limited to 'addons/delivery/models/stock_picking.py')
| -rw-r--r-- | addons/delivery/models/stock_picking.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/addons/delivery/models/stock_picking.py b/addons/delivery/models/stock_picking.py index accc102c2b7..0b77cb4ca5b 100644 --- a/addons/delivery/models/stock_picking.py +++ b/addons/delivery/models/stock_picking.py @@ -186,12 +186,33 @@ class StockPicking(models.Model): msg = _("Shipment sent to carrier %s for shipping with tracking number %s<br/>Cost: %.2f %s") % (self.carrier_id.name, self.carrier_tracking_ref, self.carrier_price, order_currency.name) self.message_post(body=msg) + def _get_new_delivery_price(self): + if self.carrier_id.integration_level != 'rate_and_ship': + res = self.carrier_id.rate_shipment(self.sale_id) + if res['success']: + self.carrier_price = res['price'] + else: + raise UserError(_("Unable to update the delivery price because of: ") + res['error_message']) + @api.multi def _add_delivery_cost_to_so(self): self.ensure_one() sale_order = self.sale_id + # if there isn't a delivery line on the SO yet if sale_order.invoice_shipping_on_delivery: - sale_order._create_delivery_line(self.carrier_id, self.carrier_price) + self._get_new_delivery_price() # fill `self.carrier_price` if needed + sale_order._create_delivery_line(self.carrier_id, self.carrier_price, price_unit_in_description=False) + else: + # we only want to update the price of the delivery line if the invoice + # policy is 'Real' but we chose not to if the user updated it in the meantime + delivery_line = sale_order.order_line.filtered(lambda line: line.is_delivery) + if self.carrier_id.invoice_policy == 'real' and delivery_line.currency_id.is_zero(delivery_line.price_unit): + self._get_new_delivery_price() + delivery_line.write({ + 'price_unit': self.carrier_price, + # remove the estimated price from the description + 'name': sale_order.carrier_id.with_context(lang=self.partner_id.lang).name, + }) @api.multi def open_website_url(self): |
