Skip to content
Snippets Groups Projects
Commit 44284bee authored by Adrien Widart's avatar Adrien Widart
Browse files

[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

Signed-off-by: default avatarTiffany Chang <tic@odoo.com>
parent 1e8982e4
Branches
Tags
No related merge requests found
......@@ -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 SaleOrder(models.Model):
......@@ -220,22 +221,25 @@ class SaleOrderLine(models.Model):
# compute unit price
price_unit = 0.0
if supplierinfo:
price_unit = self.env['account.tax'].sudo()._fix_tax_included_price_company(supplierinfo.price, self.product_id.supplier_taxes_id, taxes, self.company_id)
if purchase_order.currency_id and supplierinfo.currency_id != purchase_order.currency_id:
price_unit = supplierinfo.currency_id.compute(price_unit, purchase_order.currency_id)
# purchase line description in supplier lang
product_in_supplier_lang = self.product_id.with_context(
lang=supplierinfo.name.lang,
partner_id=supplierinfo.name.id,
)
name = '[%s] %s' % (self.product_id.default_code, product_in_supplier_lang.display_name)
if supplierinfo:
price_unit = self.env['account.tax'].sudo()._fix_tax_included_price_company(supplierinfo.price, self.product_id.supplier_taxes_id, taxes, self.company_id)
if purchase_order.currency_id and supplierinfo.currency_id != purchase_order.currency_id:
price_unit = supplierinfo.currency_id.compute(price_unit, purchase_order.currency_id)
product_in_supplier_lang = product_in_supplier_lang.with_context(seller_id=supplierinfo.id)
else:
product_in_supplier_lang = product_in_supplier_lang.with_context(partner_id=purchase_order.partner_id.id)
name = product_in_supplier_lang.display_name
if product_in_supplier_lang.description_purchase:
name += '\n' + product_in_supplier_lang.description_purchase
return {
'name': '[%s] %s' % (self.product_id.default_code, self.name) if self.product_id.default_code else self.name,
'name': name,
'product_qty': purchase_qty_uom,
'product_id': self.product_id.id,
'product_uom': self.product_id.uom_po_id.id,
......
......@@ -256,3 +256,32 @@ class TestSalePurchase(TestCommonSalePurchaseNoChart):
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, {
'name': 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_customer_usd.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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment