[FIX] stock_picking_report_custom_description: avoid dupe product name

By default the sale description is set as
f"{product_name}\n{description". If we pass that string as the
description_picking, when we print the report, the name will be
duplicated. To avoid that effect, we want to trim the product name from
the description passed to the picking by default.

TT52044
This commit is contained in:
David
2024-12-03 13:29:01 +01:00
parent 3bd47d983c
commit 62a9f6b999
2 changed files with 15 additions and 3 deletions

View File

@@ -31,6 +31,15 @@ class StockRule(models.Model):
)
if values.get("sale_line_id"):
line = self.env["sale.order.line"].browse(values["sale_line_id"])
res["description_picking"] = line.name
# Avoid double printing the name in the picking
pattern = f"{line.product_id.display_name}\n"
description_picking = line.name
if description_picking.startswith(pattern):
description_picking = description_picking.replace(pattern, "")
if (
description_picking
and description_picking != line.product_id.display_name
):
res["description_picking"] = description_picking
res["name"] = line.name
return res

View File

@@ -11,13 +11,16 @@ class TestStockPickingReportCustomDescription(common.TransactionCase):
super().setUpClass()
cls.customer = cls.env["res.partner"].create({"name": "Test customer"})
cls.product = cls.env["product.product"].create(
{"name": "Test product", "type": "product"}
{
"name": "Test product",
"type": "product",
"description_sale": "Custom description",
}
)
order_form = common.Form(cls.env["sale.order"])
order_form.partner_id = cls.customer
with order_form.order_line.new() as line_form:
line_form.product_id = cls.product
line_form.name = "Custom description"
cls.order = order_form.save()
def test_so_custom_description_transfer_to_picking(self):