[FIX] sale_stock, purchase_stock: use product name as stock.move name

Steps to reproduce the bug:
- Create a Kit product "Kit 1":
    - Add a BOM with a component “C1”
    - Add a sales description
- Create another kit product without a sales description "Kit 2":
    - Add a BOM with a component "C2"
- Make sure you have a qty of “C1” and "C2"
- Create a SO:
    - Add "Kit 1" and "Kit 2"
    - Add any other storable product
    - Confirm the SO
- Go to the delivery → validate it
- Print the delivery slip

Problem:
The report doesn’t contain the kit product.

Because in the report, the `stock.move.line` are filtered by checking
the name of their move if it has the same name as the product in
the bill of material, but like the `stock.move` has the name
('description') of the `sale.order.line` instead of the product name,
the lines are filtered and not displayed:
https://github.com/odoo/odoo/blob/14.0/addons/mrp/report/report_deliveryslip.xml#L9

The behavior is the same for purchase orders

opw-2960467

closes odoo/odoo#105158

X-original-commit: be25cea0d882bb03a4873821fdb788a0890ba49a
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2022-11-07 14:52:56 +01:00
parent b2fc9f09f6
commit 4cc2b3bcca
3 changed files with 60 additions and 2 deletions
+1 -1
View File
@@ -522,7 +522,7 @@ class PurchaseOrderLine(models.Model):
return {
# truncate to 2000 to avoid triggering index limit error
# TODO: remove index in master?
'name': (self.name or '')[:2000],
'name': (self.product_id.display_name or '')[:2000],
'product_id': self.product_id.id,
'date': date_planned,
'date_deadline': date_planned,
@@ -396,3 +396,61 @@ class TestSaleMrpKitBom(TransactionCase):
for move_line in ship.move_line_ids:
self.assertEqual(move_line.move_id.product_uom_qty, move_line.qty_done, "Quantity done should be equal to the quantity reserved in the move line")
def test_kit_in_delivery_slip(self):
"""
Suppose this structure:
Sale order:
- Kit 1 with a sales description("test"):
|- Compo 1
- Product 1
This test ensures that, when delivering a Kit product with a sales description,
the delivery report is correctly printed with all the products.
"""
kit_1, component_1, product_1 = self.env['product.product'].create([{
'name': n,
'type': 'product',
} for n in ['Kit 1', 'Compo 1', 'Product 1']])
kit_1.description_sale = "test"
self.env['mrp.bom'].create([{
'product_tmpl_id': kit_1.product_tmpl_id.id,
'product_qty': 1,
'type': 'phantom',
'bom_line_ids': [
(0, 0, {'product_id': component_1.id, 'product_qty': 1}),
],
}])
customer = self.env['res.partner'].create({
'name': 'customer',
})
so = self.env['sale.order'].create({
'partner_id': customer.id,
'order_line': [
(0, 0, {
'product_id': kit_1.id,
'product_uom_qty': 1.0,
}),
(0, 0, {
'product_id': product_1.id,
'product_uom_qty': 1.0,
})],
})
so.action_confirm()
picking = so.picking_ids
self.assertEqual(len(so.picking_ids.move_ids_without_package), 2)
picking.move_ids.quantity_done = 1
picking.button_validate()
self.assertEqual(picking.state, 'done')
html_report = self.env['ir.actions.report']._render_qweb_html('stock.report_deliveryslip', picking.ids)[0].decode('utf-8').split('\n')
keys = [
"Kit 1", "Compo 1",
"Products not associated with a kit", "Product 1",
]
for line in html_report:
if not keys:
break
if keys[0] in line:
keys = keys[1:]
self.assertFalse(keys, "All keys should be in the report with the defined order")
+1 -1
View File
@@ -330,7 +330,7 @@ class SaleOrderLine(models.Model):
procurements.append(self.env['procurement.group'].Procurement(
line.product_id, product_qty, procurement_uom,
line.order_id.partner_shipping_id.property_stock_customer,
line.name, line.order_id.name, line.order_id.company_id, values))
line.product_id.display_name, line.order_id.name, line.order_id.company_id, values))
if procurements:
self.env['procurement.group'].run(procurements)