Skip to content

Commit

Permalink
[FIX] sale_purchase: adapt POL description
Browse files Browse the repository at this point in the history
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 #86256

Signed-off-by: Tiffany Chang <tic@odoo.com>
  • Loading branch information
adwid committed Mar 16, 2022
1 parent 1e8982e commit 44284be
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
18 changes: 11 additions & 7 deletions addons/sale_purchase/models/sale_order.py
Expand Up @@ -6,6 +6,7 @@
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):
Expand Down Expand Up @@ -220,22 +221,25 @@ def _purchase_service_prepare_line_values(self, purchase_order, quantity=False):

# 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,
Expand Down
29 changes: 29 additions & 0 deletions addons/sale_purchase/tests/test_sale_purchase.py
Expand Up @@ -256,3 +256,32 @@ def test_update_ordered_sale_quantity(self):
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 comments on commit 44284be

Please sign in to comment.