[FIX] sale_purchase: adapt POL description

When confirming a sale order, if a purchase order is generated, the
descriptions of the PO's lines won't be adapted to the vendor

To reproduce the issue:
1. Create a vendor V
2. Create a product P:
    - Type: Service
    - In Purchase, add a line L01:
        - Vendor: V
        - Vendor Product Name: Name01
        - Vendor Product Code: C01
    - Purchase Automatically: True
3. Create and Confirm a SO with 1 x P
4. Open the generated PO

Error: The description is incorrect (it's the standard name of P instead
of "[C01] Name01")

OPW-2777702

closes odoo/odoo#86256

closes odoo/odoo#86679

X-original-commit: 77a2ad4b81c54fe6a91f2be242345c9d2af10dc0
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
Adrien Widart
2022-03-21 12:11:51 +01:00
parent acd5c98c6e
commit 0e7f90529e
2 changed files with 39 additions and 1 deletions
@@ -6,6 +6,7 @@ from dateutil.relativedelta import relativedelta
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import float_compare
from odoo.tools.misc import get_lang
class SaleOrderLine(models.Model):
@@ -163,14 +164,21 @@ class SaleOrderLine(models.Model):
# compute unit price
price_unit = 0.0
product_ctx = {
'lang': get_lang(self.env, purchase_order.partner_id.lang).code,
'company_id': purchase_order.company_id,
}
if supplierinfo:
price_unit = self.env['account.tax'].sudo()._fix_tax_included_price_company(
supplierinfo.price, supplier_taxes, taxes, self.company_id)
if purchase_order.currency_id and supplierinfo.currency_id != purchase_order.currency_id:
price_unit = supplierinfo.currency_id._convert(price_unit, purchase_order.currency_id, purchase_order.company_id, fields.datetime.today())
product_ctx.update({'seller_id': supplierinfo.id})
else:
product_ctx.update({'partner_id': purchase_order.partner_id.id})
return {
'name': '[%s] %s' % (self.product_id.default_code, self.name) if self.product_id.default_code else self.name,
'name': self.product_id.with_context(**product_ctx).display_name,
'product_qty': purchase_qty_uom,
'product_id': self.product_id.id,
'product_uom': self.product_id.uom_po_id.id,
@@ -225,3 +225,33 @@ class TestSalePurchase(TestCommonSalePurchaseNoChart):
self.assertEqual(len(purchase_order2.order_line), 1, "The 2nd PO has only one line")
self.assertEqual(purchase_line2.sale_line_id, self.sol1_service_purchase_1, "The 2nd PO line came from the SO line sol1_service_purchase_1")
self.assertEqual(purchase_line2.product_qty, delta, "The quantity of the new PO line is the quantity added on the Sale Line, after first PO confirmation")
def test_pol_description(self):
service = self.env['product.product'].create({
'name': 'Super Product',
'type': 'service',
'service_to_purchase': True,
'seller_ids': [(0, 0, {
'partner_id': self.partner_vendor_service.id,
'min_qty': 1,
'price': 10,
'product_code': 'C01',
'product_name': 'Name01',
'sequence': 1,
})]
})
so = self.env['sale.order'].create({
'partner_id': self.partner_a.id,
'order_line': [
(0, 0, {
'name': service.name,
'product_id': service.id,
'product_uom_qty': 1,
})
],
})
so.action_confirm()
po = self.env['purchase.order'].search([('partner_id', '=', self.partner_vendor_service.id)], order='id desc', limit=1)
self.assertEqual(po.order_line.name, "[C01] Name01")