Skip to content
Snippets Groups Projects
Commit 8e516dcc authored by Walid's avatar Walid
Browse files

[FIX] purchase_mrp: split cost in bom line


Steps to reproduce:
- Create Storable Product "Super Test" with Cost of $1.
- Create Storable Product "Pack of Super Test" with Cost of $10.
- Create a Kit BoM that produces 1 "Pack of Super Test" from 10 "Super Test".
- Ensure product category on both products is set to Automated FIFO Inventory Valuation.
- Create a PO for 20 "Pack of Super Test" and confirm.
- Process the Delivery and look at inventory valuation.
- See that "Super Test" has moved quantity at 200 with Unit Value of 10 each (taken from kit product!).

Bug:
cost isn't split on the qty of the bom line

Fix:
take product quantities of the bom into consideration

opw-3453703

closes odoo/odoo#132186

Signed-off-by: default avatarWilliam Henrotin (whe) <whe@odoo.com>
parent b8fda0bd
Branches
Tags
No related merge requests found
......@@ -32,7 +32,7 @@ class MrpBomLine(models.Model):
def _get_cost_share(self):
self.ensure_one()
if self.cost_share:
return fields.Float.round(self.cost_share / 100, 2)
return self.cost_share / 100
bom = self.bom_id
bom_lines_without_cost_share = bom.bom_line_ids.filtered(lambda bl: not bl.cost_share)
return fields.Float.round(1 / len(bom_lines_without_cost_share), 2)
return 1 / len(bom_lines_without_cost_share)
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from dateutil.relativedelta import relativedelta
from odoo import _, models
from odoo.tools.float_utils import float_is_zero
from odoo.tools.float_utils import float_is_zero, float_round
from odoo.exceptions import UserError
......@@ -22,7 +21,8 @@ class StockMove(models.Model):
line = self.purchase_line_id
kit_price_unit = line._get_gross_price_unit()
cost_share = self.bom_line_id._get_cost_share()
return kit_price_unit * cost_share
price_unit_prec = self.env['decimal.precision'].precision_get('Product Price')
return float_round(kit_price_unit * cost_share * line.product_qty / self.product_qty, precision_digits=price_unit_prec)
def _get_valuation_price_and_qty(self, related_aml, to_curr):
valuation_price_unit_total, valuation_total_qty = super()._get_valuation_price_and_qty(related_aml, to_curr)
......
......@@ -215,6 +215,34 @@ class TestPurchaseMrpFlow(TransactionCase):
move_line.qty_done = qty_to_process[comp][0]
move._action_done()
def test_kit_component_cost(self):
# Set kit and componnet product to automated FIFO
self.kit_1.categ_id.property_cost_method = 'fifo'
self.kit_1.categ_id.property_valuation = 'real_time'
self.kit_1.bom_ids.product_qty = 3
po = Form(self.env['purchase.order'])
po.partner_id = self.env['res.partner'].create({'name': 'Testy'})
with po.order_line.new() as line:
line.product_id = self.kit_1
line.product_qty = 120
line.price_unit = 1260
po = po.save()
po.button_confirm()
po.picking_ids.action_set_quantities_to_reservation()
po.picking_ids.button_validate()
# Unit price equaly dived among bom lines (cost share not set)
# # price further divided by product qty of each component
components = [
self.component_a,
self.component_b,
self.component_c,
]
self.assertEqual(sum([k.standard_price * k.qty_available for k in components]), 120 * 1260)
def test_01_sale_mrp_kit_qty_delivered(self):
""" Test that the quantities delivered are correct when
a kit with subkits is ordered with multiple backorders and returns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment