diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py index d2b7dda61e5..f5a93130e21 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_flow.py +++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py @@ -2234,6 +2234,57 @@ class TestSaleMrpFlow(ValuationReconciliationTestCommon): self.assertEqual(cogs_aml.debit, 10) self.assertEqual(cogs_aml.credit, 0) + def test_kit_avco_amls_reconciliation(self): + self.stock_account_product_categ.property_cost_method = 'average' + + compo01, compo02, kit = self.env['product.product'].create([{ + 'name': name, + 'type': 'product', + 'standard_price': price, + 'categ_id': self.stock_account_product_categ.id, + 'invoice_policy': 'delivery', + } for name, price in [ + ('Compo 01', 10), + ('Compo 02', 20), + ('Kit', 0), + ]]) + + self.env['stock.quant']._update_available_quantity(compo01, self.company_data['default_warehouse'].lot_stock_id, 1) + self.env['stock.quant']._update_available_quantity(compo02, self.company_data['default_warehouse'].lot_stock_id, 1) + + self.env['mrp.bom'].create({ + 'product_id': kit.id, + 'product_tmpl_id': kit.product_tmpl_id.id, + 'product_uom_id': kit.uom_id.id, + 'product_qty': 1.0, + 'type': 'phantom', + 'bom_line_ids': [ + (0, 0, {'product_id': compo01.id, 'product_qty': 1.0}), + (0, 0, {'product_id': compo02.id, 'product_qty': 1.0}), + ], + }) + + so = self.env['sale.order'].create({ + 'partner_id': self.partner_a.id, + 'order_line': [ + (0, 0, { + 'name': kit.name, + 'product_id': kit.id, + 'product_uom_qty': 1.0, + 'product_uom': kit.uom_id.id, + 'price_unit': 5, + 'tax_id': False, + })], + }) + so.action_confirm() + so.picking_ids.move_line_ids.qty_done = 1 + so.picking_ids.button_validate() + + invoice = so._create_invoices() + invoice.action_post() + + self.assertEqual(len(invoice.line_ids.filtered('reconciled')), 1) + def test_avoid_removing_kit_bom_in_use(self): so = self.env['sale.order'].create({ 'partner_id': self.partner_a.id, diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index 50ad69b5c21..045b60d8085 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -48,6 +48,8 @@ class StockMove(models.Model): subtype_xmlid='mail.mt_note', ) + def _get_all_related_sm(self, product): + return super()._get_all_related_sm(product) | self.filtered(lambda m: m.sale_line_id.product_id == product) class ProcurementGroup(models.Model): _inherit = 'procurement.group'