Skip to content

Commit

Permalink
fixup! bom explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
HviorForgeFlow committed Mar 26, 2019
1 parent 592c2e8 commit 5ee6c67
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 47 deletions.
96 changes: 61 additions & 35 deletions mrp_bom_current_stock/tests/test_mrp_bom_current_stock.py
Expand Up @@ -14,93 +14,119 @@ def setUpClass(cls):
cls.bom_obj = cls.env['mrp.bom']
cls.bom_line_obj = cls.env['mrp.bom.line']

cls.uom_unit = cls.env.ref('product.product_uom_unit')
cls.uom_dozen = cls.env.ref('product.product_uom_dozen')
cls.uom_meter = cls.env.ref('product.product_uom_meter')
cls.uom_kgm = cls.env.ref('product.product_uom_kgm')
cls.uom_gm = cls.env.ref("product.product_uom_gram")

# Create products:
cls.product_top = cls.product_obj.create({
'name': 'Final Product',
'name': 'FP-01',
'type': 'product',
'standard_price': 300.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_dozen.id,
'uom_po_id': cls.uom_dozen.id
})
cls.product_sub_1 = cls.product_obj.create({
'name': 'L01-01',
'name': 'IP-01',
'type': 'product',
'standard_price': 300.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_dozen.id,
'uom_po_id': cls.uom_dozen.id
})
cls.product_sub_2 = cls.product_obj.create({
'name': 'L01-02',
'name': 'IP-02',
'type': 'product',
'standard_price': 300.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_kgm.id,
'uom_po_id': cls.uom_kgm.id
})
cls.product_sub_3 = cls.product_obj.create({
'name': 'IP-03',
'type': 'product',
'uom_id': cls.uom_unit.id,
'uom_po_id': cls.uom_unit.id
})

cls.component_1 = cls.product_obj.create({
'name': 'RM 01',
'name': 'PP-01',
'type': 'product',
'standard_price': 100.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_unit.id,
'uom_po_id': cls.uom_unit.id
})
cls.component_2 = cls.product_obj.create({
'name': 'RM 01',
'name': 'PP-02',
'type': 'product',
'standard_price': 75.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_kgm.id,
'uom_po_id': cls.uom_kgm.id
})
cls.component_3 = cls.product_obj.create({
'name': 'RM 03',
'name': 'PP-03',
'type': 'product',
'standard_price': 75.0,
'uom_id': cls.env.ref('product.product_uom_unit').id
'uom_id': cls.uom_meter.id,
'uom_po_id': cls.uom_meter.id
})

# Create Bills of Materials:
cls.bom_top = cls.bom_obj.create({
'product_tmpl_id': cls.product_top.product_tmpl_id.id,
'product_qty': 1.0,
'product_uom_id': cls.uom_unit.id

})
cls.line_top_1 = cls.bom_line_obj.create({
'product_id': cls.product_sub_1.id,
'bom_id': cls.bom_top.id,
'product_qty': 2.0,
'product_qty': 1.0,
'product_uom_id': cls.uom_dozen.id
})
cls.line_top_2 = cls.bom_line_obj.create({
'product_id': cls.product_sub_2.id,
'bom_id': cls.bom_top.id,
'product_qty': 5.0,
'product_qty': 200.0,
'product_uom_id': cls.uom_gm.id
})
cls.line_top_3 = cls.bom_line_obj.create({
'product_id': cls.product_sub_3.id,
'bom_id': cls.bom_top.id,
'product_qty': 1.0,
'product_uom_id': cls.uom_dozen.id
})

cls.bom_sub_1 = cls.bom_obj.create({
'product_tmpl_id': cls.product_sub_1.product_tmpl_id.id,

'product_qty': 12.0,
'product_uom_id': cls.uom_unit.id
})
cls.line_sub_1_1 = cls.bom_line_obj.create({
'product_id': cls.component_1.id,
'bom_id': cls.bom_sub_1.id,
'product_qty': 2.0,
'product_uom': cls.uom_meter
})
cls.line_sub_1_2 = cls.bom_line_obj.create({
'product_id': cls.component_2.id,
'bom_id': cls.bom_sub_1.id,
'product_qty': 5.0,
'product_uom': cls.uom_dozen
'product_qty': 1.0,
'product_uom': cls.uom_dozen.id
})

cls.bom_sub_2 = cls.bom_obj.create({
'product_tmpl_id': cls.product_sub_2.product_tmpl_id.id,
'product_qty': 20.0,
'product_uom_id': cls.uom_kgm.id

})
cls.line_sub_2_1 = cls.bom_line_obj.create({
'product_id': cls.component_1.id,
'product_id': cls.component_2.id,
'bom_id': cls.bom_sub_2.id,
'product_qty': 3.0,
'product_qty': 1.0,
'product_uom_id': cls.uom_unit.id
})
cls.line_sub_2_2 = cls.bom_line_obj.create({

cls.bom_sub_3 = cls.bom_obj.create({
'product_tmpl_id': cls.product_sub_3.product_tmpl_id.id,
'product_qty': 10.0,
'product_uom_id': cls.uom_unit.id

})
cls.line_sub_3_1 = cls.bom_line_obj.create({
'product_id': cls.component_3.id,
'bom_id': cls.bom_sub_2.id,
'product_qty': 3.0,
'bom_id': cls.bom_sub_3.id,
'product_qty': 2.0,
'product_uom': cls.uom_meter.id
})

def test_wizard(self):
Expand All @@ -109,7 +135,7 @@ def test_wizard(self):
"bom_id": self.bom_top.id
})
self.wizard.do_explode()
sol = (2, 4, 10, 5, 15, 15)
sol = (1, 1, 200, 0.01, 1, 2.4)
lines = self.wizard.line_ids
for i, line in enumerate(lines):
self.assertEqual(line.product_qty, sol[i])
19 changes: 7 additions & 12 deletions mrp_bom_current_stock/wizard/bom_route_current_stock.py
Expand Up @@ -76,18 +76,13 @@ def _create_lines(bom, location, level=0, factor=1):
vals = self._prepare_line(line, location, level, factor)
line_obj.create(vals)
line_boms = line.product_id.bom_ids
if line_boms:
if line.product_uom_id.category_id == \
bom.product_uom_id.category_id:
line_qty = line.product_uom_id._compute_quantity(
line.product_qty,
bom.product_uom_id,
)
else:
line_qty = line.product_qty
new_factor = factor * line_qty / bom.product_qty
for line_bom in line_boms:
_create_lines(line_bom, location, level, new_factor)
for line_bom in line_boms:
line_qty = line.product_uom_id._compute_quantity(
line.product_qty,
line_bom.product_uom_id,
)
new_factor = factor * line_qty / line_bom.product_qty
_create_lines(line_bom, location, level, new_factor)

_create_lines(self.bom_id, self.location_id)
return {
Expand Down

0 comments on commit 5ee6c67

Please sign in to comment.