[FIX] pos_mrp: subkits cost
Steps to reproduce:
- Create the following subkits boms
F-> SK1 -> A
-> B
SK2 -> C
-> D
- Set all these products to be available in pos and have AVCO automated
valuation with A,B,C and D having a cost of 5$
- Sell F in pos creaing an invoice
- In accounting check the expense account (cost of goods) wrong cost
Bug:
´comp[1]['product']´ referrs to the kit product of the last children boms
(SK1 and SK2 in this case) which would then each be counted twice
instead use ´comp[0].product_id´ (the components of the child boms)
also fixed total_cost computation for pos lines which would filter out
all the subkits moves
opw-3538285
closes odoo/odoo#150937
X-original-commit: d6a513355ee0ae4b02e38baacdde760cc35fb873
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
@@ -10,7 +10,8 @@ class PosOrderLine(models.Model):
|
||||
bom = product.env['mrp.bom']._bom_find(product, company_id=stock_moves.company_id.id, bom_type='phantom')[product]
|
||||
if not bom:
|
||||
return super()._get_stock_moves_to_consider(stock_moves, product)
|
||||
ml_product_to_consider = (product.bom_ids and bom.bom_line_ids.mapped('product_id').mapped('id')) or [product.id]
|
||||
_dummy, components = bom.explode(product, self.qty)
|
||||
ml_product_to_consider = (product.bom_ids and [comp[0].product_id.id for comp in components]) or [product.id]
|
||||
return stock_moves.filtered(lambda ml: ml.product_id.id in ml_product_to_consider and ml.bom_line_id)
|
||||
|
||||
class PosOrder(models.Model):
|
||||
@@ -21,4 +22,4 @@ class PosOrder(models.Model):
|
||||
if not bom:
|
||||
return super()._get_pos_anglo_saxon_price_unit(product, partner_id, quantity)
|
||||
dummy, components = bom.explode(product, quantity)
|
||||
return sum(super(PosOrder, self)._get_pos_anglo_saxon_price_unit(comp[1]['product'], partner_id, comp[1]['qty']) for comp in components)
|
||||
return sum(super(PosOrder, self)._get_pos_anglo_saxon_price_unit(comp[0].product_id, partner_id, comp[1]['qty']) for comp in components)
|
||||
|
||||
@@ -125,7 +125,15 @@ class TestPosMrp(TestPointOfSaleCommon):
|
||||
self.component_b = self.env['product.product'].create({
|
||||
'name': 'Comp B',
|
||||
'available_in_pos': True,
|
||||
'standard_price': 10.0,
|
||||
'standard_price': 5.0,
|
||||
'categ_id': category.id,
|
||||
'taxes_id': False,
|
||||
})
|
||||
|
||||
self.component_c = self.env['product.product'].create({
|
||||
'name': 'Comp C',
|
||||
'available_in_pos': True,
|
||||
'standard_price': 5.0,
|
||||
'categ_id': category.id,
|
||||
'taxes_id': False,
|
||||
})
|
||||
@@ -148,6 +156,9 @@ class TestPosMrp(TestPointOfSaleCommon):
|
||||
with bom_product_form.bom_line_ids.new() as bom_line:
|
||||
bom_line.product_id = self.component_b
|
||||
bom_line.product_qty = 1.0
|
||||
with bom_product_form.bom_line_ids.new() as bom_line:
|
||||
bom_line.product_id = self.component_c
|
||||
bom_line.product_qty = 1.0
|
||||
self.bom_b = bom_product_form.save()
|
||||
|
||||
bom_product_form = Form(self.env['mrp.bom'])
|
||||
@@ -198,6 +209,7 @@ class TestPosMrp(TestPointOfSaleCommon):
|
||||
}
|
||||
order = self.env['pos.order'].create_from_ui([order_data])
|
||||
order = self.env['pos.order'].browse(order[0]['id'])
|
||||
self.assertEqual(order.lines.total_cost, 15.0)
|
||||
accounts = self.kit.product_tmpl_id.get_product_accounts()
|
||||
debit_interim_account = accounts['stock_output']
|
||||
credit_expense_account = accounts['expense']
|
||||
|
||||
Reference in New Issue
Block a user