Skip to content
Snippets Groups Projects
Commit e43ff93b authored by anhe-odoo's avatar anhe-odoo
Browse files

[FIX] delivery: use pricelist to compute shipping cost


Expected Behaviour

When adding a shipping cost in a SO, with the shipping method being
associated to a product, the price should be calculated according to
the price of the product in the order's pricelist if available

Observed Behaviour

When adding a shipping cost related to a product, with a fixed price,
the public price of the product is used instead of the price defined
in the SO pricelist

Reproducibility

1. Create a product "Test Shipping" with a public price of 10
2. Create a shipping method "Test Shipping" associated with the
"Test Shipping" product
3. Create a pricelist "Test Pricelist", where the product "Test
Product" has a cost of 15
4. Create a contact "Test Contact" associated with "Test Pricelist"
5. Create a So for the "Test Contact" with "Test Shipping" as shipping
method -> Shipping cost will be 10 instead of 15.

Fix Description

The issue here was that the price computed by the delivery carrier didn't
took into account the selected pricelist. We tried to then change it in
the delivery chooser wizard, but some issue with particular case (i.e.
when the shipping cost should be 0 if the SO total is bigger than X)
appeared, leading us to add the fix directly in the delivery_carrier
classe.

Related Issues/PR

- opw-2754482

closes odoo/odoo#86484

Signed-off-by: default avatarAdrien Widart <awt@odoo.com>
parent 0e627034
Branches
Tags
No related merge requests found
......@@ -265,7 +265,7 @@ class DeliveryCarrier(models.Model):
'price': 0.0,
'error_message': _('Error: this delivery method is not available for this address.'),
'warning_message': False}
price = self.fixed_price
price = order.pricelist_id.get_product_price(self.product_id, 1.0, order.partner_id)
company = self.company_id or order.company_id or self.env.company
if company.currency_id and company.currency_id != order.currency_id:
price = company.currency_id._convert(price, order.currency_id, company, fields.Date.today())
......
......@@ -155,3 +155,44 @@ class TestDeliveryCost(common.TransactionCase):
self.default_delivery_policy = self.SaleConfigSetting.create({})
self.default_delivery_policy.execute()
def test_01_delivery_cost_from_pricelist(self):
""" This test aims to validate the use of a pricelist to compute the delivery cost in the case the associated
product of the shipping method is defined in the pricelist """
# Create pricelist with a custom price for the standard shipping method
my_pricelist = self.env['product.pricelist'].create({
'name': 'shipping_cost_change',
'item_ids': [(0, 0, {
'compute_price': 'fixed',
'fixed_price': 5,
'applied_on': '0_product_variant',
'product_id': self.normal_delivery.product_id.id,
})],
})
# Create sales order with Normal Delivery Charges
sale_pricelist_based_delivery_charges = self.SaleOrder.create({
'partner_id': self.partner_18.id,
'pricelist_id': my_pricelist.id,
'order_line': [(0, 0, {
'name': 'PC Assamble + 2GB RAM',
'product_id': self.product_4.id,
'product_uom_qty': 1,
'product_uom': self.product_uom_unit.id,
'price_unit': 750.00,
})],
})
# Add of delivery cost in Sales order
delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
'default_order_id': sale_pricelist_based_delivery_charges.id,
'default_carrier_id': self.normal_delivery.id
}))
self.assertEqual(delivery_wizard.delivery_price, 5.0, "Delivery cost does not correspond to 5.0 in wizard")
delivery_wizard.save().button_confirm()
line = self.SaleOrderLine.search([('order_id', '=', sale_pricelist_based_delivery_charges.id),
('product_id', '=', self.normal_delivery.product_id.id)])
self.assertEqual(len(line), 1, "Delivery cost hasn't been added to SO")
self.assertEqual(line.price_subtotal, 5.0, "Delivery cost does not correspond to 5.0")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment