Skip to content
Snippets Groups Projects
Commit ca1793d3 authored by Adrien Widart (awt)'s avatar Adrien Widart (awt)
Browse files

[FIX] delivery: add a carrier on a delivery


It is not possible for a user to add a carrier directly on a picking if
the invoicing policy of that carrier is set to "Real Cost"

To reproduce the issue:
1. Enable a carrier C
2. Setup a shipping method SM:
    - Carrier: C
    - Invoicing Policy: Real Cost
3. Create and confirm a SO with a product
4. Edit the related picking P:
    - Carrier: SM
5. Validate P

Error: a Validation error is raised "The operation cannot be completed
[...] Model: Sales Order Line (sale.order.line), Field: Description
(name)"

When validating the delivery, we try to create a new SOL with the
shipping cost. We then update its description with the carrier name.
However, since the carrier has been directly added on the picking, the
sale order does not have that information. We should rather get this
information from the delivery.

OPW-2862306

closes odoo/odoo#103764

Signed-off-by: default avatarTiffany Chang <tic@odoo.com>
parent 14e0abd1
No related branches found
No related tags found
No related merge requests found
......@@ -206,7 +206,7 @@ class StockPicking(models.Model):
delivery_line[0].write({
'price_unit': carrier_price,
# remove the estimated price from the description
'name': sale_order.carrier_id.with_context(lang=self.partner_id.lang).name,
'name': self.carrier_id.with_context(lang=self.partner_id.lang).name,
})
def open_website_url(self):
......
......@@ -299,3 +299,31 @@ class TestDeliveryCost(common.TransactionCase):
])
self.assertRecordValues(line, [{'price_subtotal': 9.09, 'price_total': 10.45}])
def test_add_carrier_on_picking(self):
"""
A user confirms a SO, then adds a carrier on the picking. The invoicing
policy of the carrier is set to "Real Cost". He then confirms the
picking: a line with the carrier cost should be added to the SO
"""
self.normal_delivery.invoice_policy = 'real'
so_form = Form(self.env['sale.order'])
so_form.partner_id = self.partner_4
with so_form.order_line.new() as line:
line.product_id = self.product_2
so = so_form.save()
so.action_confirm()
picking = so.picking_ids
picking.carrier_id = self.normal_delivery
picking.move_lines.quantity_done = 1
picking.button_validate()
so.order_line.invalidate_cache(ids=so.order_line.ids)
self.assertEqual(picking.state, 'done')
self.assertRecordValues(so.order_line, [
{'product_id': self.product_2.id, 'is_delivery': False, 'product_uom_qty': 1, 'qty_delivered': 1},
{'product_id': self.normal_delivery.product_id.id, 'is_delivery': True, 'product_uom_qty': 1, 'qty_delivered': 0},
])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment