[FIX] mrp: list all kit components in delivery slip
When printing a delivery slip, if the delivered product is a kit
composed with a subkit, the products of this subkit won't be listed
To reproduced the issue:
1. Create 5 consumable products: 'Compo 01', 'Compo 02', 'Compo 03',
'Sub Kit', 'Super Kit'
2. Create two phantom-type boms:
- Sub kit:
- 1 x Compo 02
- 1 x Compo 03
- Super Kit:
- 1 x Compo 01
- 1 x Sub Kit
3. Process a delivery with 1 x Super Kit (the picking must be done)
4. Print the delivery slip
Error: The report only contains two lines, i.e. the name of the kit
('Super Kit') and the name of the 'direct' component ('Compo 01)
The issue comes from the SML used to define `kit_move_lines` (XML side).
It uses `has_kits` which only contains the top level kits' SML:
https://github.com/odoo/odoo/blob/1b1067b0cf2a3de2773915ff8205084492b1bbe3/addons/mrp/report/report_deliveryslip.xml#L6-L9
This is the reason why the SML for Compo 02 and Compo 03 are not listed
OPW-2740247
closes odoo/odoo#84735
X-original-commit: 586f900433eb09ee04d0ed073acfdcfa0fc59d58
Signed-off-by: Tiffany Chang <tic@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
</template>
|
||||
|
||||
<template id="stock_report_delivery_kit_sections">
|
||||
<!-- get all kits-related SML, including subkits and excluding the packaged SML -->
|
||||
<t t-set="all_kits_move_lines" t-value="o.move_line_ids.filtered(lambda l: l.move_id.bom_line_id.bom_id.type == 'phantom' and not l.result_package_id)"/>
|
||||
<!-- do another map to get unique top level kits -->
|
||||
<t t-set="kits" t-value="has_kits.mapped('move_id.bom_line_id.bom_id.product_tmpl_id')"/>
|
||||
<t t-foreach="kits" t-as="kit">
|
||||
@@ -35,10 +37,10 @@
|
||||
<span t-esc="kit.display_name"/>
|
||||
</td>
|
||||
</tr>
|
||||
<t t-set="kit_move_lines" t-value="has_kits.filtered(lambda l: l.move_id.name == kit.display_name)"/>
|
||||
<t t-set="kit_move_lines" t-value="all_kits_move_lines.filtered(lambda l: l.move_id.name == kit.display_name)"/>
|
||||
<t t-if="has_serial_number">
|
||||
<tr t-foreach="kit_move_lines" t-as="move_line">
|
||||
<t t-set="description" t-as="move_line.move_id.description_picking"/>
|
||||
<t t-set="description" t-value="move_line.move_id.description_picking"/>
|
||||
<t t-if="description == kit.name">
|
||||
<t t-set="description" t-value=""/>
|
||||
</t>
|
||||
|
||||
@@ -184,3 +184,74 @@ class TestMrpStockReports(TestReportsCommon):
|
||||
self.assertTrue(line['is_matched'], "The corresponding MO line should be matched in the forecast report.")
|
||||
else:
|
||||
self.assertFalse(line['is_matched'], "A line of the forecast report not linked to the MO shoud not be matched.")
|
||||
|
||||
def test_subkit_in_delivery_slip(self):
|
||||
"""
|
||||
Suppose this structure:
|
||||
Super Kit --|- Compo 01 x1
|
||||
|- Sub Kit x1 --|- Compo 02 x1
|
||||
| |- Compo 03 x1
|
||||
|
||||
This test ensures that, when delivering one Super Kit, one Sub Kit, one Compo 01 and one Compo 02,
|
||||
and when putting in pack the third component of the Super Kit, the delivery report is correct.
|
||||
"""
|
||||
compo01, compo02, compo03, subkit, superkit = self.env['product.product'].create([{
|
||||
'name': n,
|
||||
'type': 'consu',
|
||||
} for n in ['Compo 01', 'Compo 02', 'Compo 03', 'Sub Kit', 'Super Kit']])
|
||||
|
||||
self.env['mrp.bom'].create([{
|
||||
'product_tmpl_id': subkit.product_tmpl_id.id,
|
||||
'product_qty': 1,
|
||||
'type': 'phantom',
|
||||
'bom_line_ids': [
|
||||
(0, 0, {'product_id': compo02.id, 'product_qty': 1}),
|
||||
(0, 0, {'product_id': compo03.id, 'product_qty': 1}),
|
||||
],
|
||||
}, {
|
||||
'product_tmpl_id': superkit.product_tmpl_id.id,
|
||||
'product_qty': 1,
|
||||
'type': 'phantom',
|
||||
'bom_line_ids': [
|
||||
(0, 0, {'product_id': compo01.id, 'product_qty': 1}),
|
||||
(0, 0, {'product_id': subkit.id, 'product_qty': 1}),
|
||||
],
|
||||
}])
|
||||
|
||||
picking_form = Form(self.env['stock.picking'])
|
||||
picking_form.picking_type_id = self.picking_type_out
|
||||
picking_form.partner_id = self.partner
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = superkit
|
||||
move.product_uom_qty = 1
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = subkit
|
||||
move.product_uom_qty = 1
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = compo01
|
||||
move.product_uom_qty = 1
|
||||
with picking_form.move_ids_without_package.new() as move:
|
||||
move.product_id = compo02
|
||||
move.product_uom_qty = 1
|
||||
picking = picking_form.save()
|
||||
picking.action_confirm()
|
||||
|
||||
picking.move_ids.quantity_done = 1
|
||||
move = picking.move_ids.filtered(lambda m: m.name == "Super Kit" and m.product_id == compo03)
|
||||
move.move_line_ids.result_package_id = self.env['stock.quant.package'].create({'name': 'Package0001'})
|
||||
picking.button_validate()
|
||||
|
||||
report = self.env['ir.actions.report']._get_report_from_name('stock.report_deliveryslip')
|
||||
html_report = report._render_qweb_html(picking.ids)[0].decode('utf-8').split('\n')
|
||||
keys = [
|
||||
"Package0001", "Compo 03",
|
||||
"Products with no package assigned", "Compo 01", "Compo 02",
|
||||
"Super Kit", "Compo 01", "Compo 02",
|
||||
"Sub Kit", "Compo 02", "Compo 03",
|
||||
]
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user