Skip to content
Permalink
Browse files

m

  • Loading branch information...
amoyaux committed Apr 4, 2019
1 parent 29697ca commit 8eee33082324d98e6b948670362e117cf7493960
@@ -26,10 +26,9 @@ class MrpAbstractWorkorder(models.AbstractModel):
)
use_create_components_lots = fields.Boolean(related="production_id.picking_type_id.use_create_components_lots")

@api.depends('raw_workorder_line_ids', 'finished_workorder_line_ids')
def _compute_workorder_line_ids(self):
for workorder in self:
workorder.workorder_line_ids = workorder.raw_workorder_line_ids | workorder.finished_workorder_line_ids
def _workorder_line_ids(self):
self.ensure_one()
return self.raw_workorder_line_ids | self.finished_workorder_line_ids

@api.onchange('qty_producing')
def _onchange_qty_producing(self):
@@ -61,7 +60,7 @@ def _update_workorder_lines(self):
move_finished_ids = self.move_finished_ids.filtered(lambda move: move.product_id != self.product_id and move.state not in ('done', 'cancel'))
move_raw_ids = self.move_raw_ids.filtered(lambda move: move.state not in ('done', 'cancel'))
for move in move_raw_ids | move_finished_ids:
move_workorder_lines = self.workorder_line_ids.filtered(lambda w: w.move_id == move)
move_workorder_lines = self._workorder_line_ids().filtered(lambda w: w.move_id == move)

# Compute the new quantity for the current component
rounding = move.product_uom.rounding
@@ -176,7 +175,7 @@ def _generate_lines_values(self, move, qty_to_consume):
if move_line.lot_produced_ids or float_compare(move_line.product_uom_qty, move_line.qty_done, precision_rounding=move.product_uom.rounding) <= 0:
continue
# search wo line on which the lot is not fully consumed or other reserved lot
linked_wo_line = self.workorder_line_ids.filtered(
linked_wo_line = self._workorder_line_ids().filtered(
lambda line: line.product_id == move_line.product_id and
line.lot_id == move_line.lot_id
)
@@ -266,7 +265,7 @@ def _update_moves(self):
# Before writting produce quantities, we ensure they respect the bom strictness
self._strict_consumption_check()
vals_list = []
workorder_lines_to_process = self.workorder_line_ids.filtered(lambda line: line.product_id != self.product_id and line.qty_done > 0)
workorder_lines_to_process = self._workorder_line_ids().filtered(lambda line: line.product_id != self.product_id and line.qty_done > 0)
for line in workorder_lines_to_process:
line._update_move_lines()
if float_compare(line.qty_done, 0, precision_rounding=line.product_uom_id.rounding) > 0:
@@ -282,7 +281,7 @@ def _strict_consumption_check(self):
if self.consumption != 'strict':
return True
for move in self.move_raw_ids:
lines = self.workorder_line_ids.filtered(lambda l: l.move_id == move)
lines = self._workorder_line_ids().filtered(lambda l: l.move_id == move)
qty_done = sum(lines.mapped('qty_done'))
qty_to_consume = sum(lines.mapped('qty_to_consume'))
rounding = self.product_uom_id.rounding
@@ -107,8 +107,6 @@ class MrpWorkorder(models.Model):
capacity = fields.Float(
'Capacity', default=1.0,
help="Number of pieces that can be produced in parallel.")
workorder_line_ids = fields.One2many('mrp.workorder.line',
compute='_compute_workorder_line_ids', string='Workorder lines')
raw_workorder_line_ids = fields.One2many('mrp.workorder.line',
'raw_workorder_id', string='Components')
finished_workorder_line_ids = fields.One2many('mrp.workorder.line',
@@ -224,7 +222,7 @@ def _generate_wo_lines(self):
round=False
)
line_values = self._generate_lines_values(move, qty_to_consume)
if move in self.production_id.move_raw_ids:
if move in self.move_raw_ids:
self.raw_workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
else:
self.finished_workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
@@ -238,7 +236,7 @@ def _action_assign(self):
for move in raw_moves:
rounding = move.product_uom.rounding
qty_already_consumed = 0.0
workorder_lines = workorder.workorder_line_ids.filtered(lambda w: w.move_id == move)
workorder_lines = workorder._workorder_line_ids().filtered(lambda w: w.move_id == move)
for wl in workorder_lines:
if not wl.qty_done:
wl_to_unlink |= wl
@@ -254,7 +252,10 @@ def _action_assign(self):
)
if float_compare(qty_to_consume, qty_already_consumed, precision_rounding=rounding) > 0:
line_values = workorder._generate_lines_values(move, qty_to_consume - qty_already_consumed)
workorder.workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
if move in self.move_raw_ids:
self.raw_workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
else:
self.finished_workorder_line_ids |= self.env['mrp.workorder.line'].create(line_values)
wl_to_unlink.unlink()

def _assign_default_final_lot_id(self, reference_lot_lines):
@@ -72,7 +72,7 @@ class StockMove(models.Model):
bom_line_id = fields.Many2one('mrp.bom.line', 'BoM Line')
byproduct_id = fields.Many2one(
'mrp.bom.byproduct', 'Byproduct',
help="Subproduct line that generated the move in a manufacturing order")
help="By-product line that generated the move in a manufacturing order")
unit_factor = fields.Float('Unit Factor', default=1)
is_done = fields.Boolean(
'Done', compute='_compute_is_done',
@@ -306,21 +306,21 @@ def test_product_produce_1(self):
'active_ids': [mo.id],
}))
# change the quantity done in one line
produce_form.workorder_line_ids._records[0]['qty_done'] = 1
produce_form._workorder_line_ids()._records[0]['qty_done'] = 1

# change the quantity producing
produce_form.qty_producing = 3

# check than all quantities are update correctly
line1 = produce_form.workorder_line_ids._records[0]
line2 = produce_form.workorder_line_ids._records[1]
line1 = produce_form._workorder_line_ids()._records[0]
line2 = produce_form._workorder_line_ids()._records[1]
self.assertEqual(line1['qty_to_consume'], 3, "Wrong quantity to consume")
self.assertEqual(line1['qty_done'], 3, "Wrong quantity done")
self.assertEqual(line2['qty_to_consume'], 12, "Wrong quantity to consume")
self.assertEqual(line2['qty_done'], 12, "Wrong quantity done")

product_produce = produce_form.save()
self.assertEqual(len(product_produce.workorder_line_ids), 2, 'You should have produce lines even the consumed products are not tracked.')
self.assertEqual(len(product_produce._workorder_line_ids()), 2, 'You should have produce lines even the consumed products are not tracked.')
product_produce.do_produce()

def test_product_produce_2(self):
@@ -351,12 +351,12 @@ def test_product_produce_2(self):
'active_ids': [mo.id],
}))

self.assertEqual(len(produce_form.workorder_line_ids), 3, 'You should have 3 produce lines. One for each serial to consume and for the untracked product.')
self.assertEqual(len(produce_form._workorder_line_ids()), 3, 'You should have 3 produce lines. One for each serial to consume and for the untracked product.')
produce_form.qty_producing = 1

# get the proposed lot
consumed_lots = self.env['stock.production.lot']
for workorder_line in produce_form.workorder_line_ids._records:
for workorder_line in produce_form._workorder_line_ids()._records:
if workorder_line['product_id'] == p1.id:
consumed_lots |= self.env['stock.production.lot'].browse(workorder_line['lot_id'])
consumed_lots.ensure_one()
@@ -371,8 +371,8 @@ def test_product_produce_2(self):
'active_ids': [mo.id],
}))
product_produce = produce_form.save()
self.assertEqual(len(product_produce.workorder_line_ids), 2, 'You should have 2 produce lines left.')
for line in product_produce.workorder_line_ids.filtered(lambda x: x.lot_id):
self.assertEqual(len(product_produce._workorder_line_ids()), 2, 'You should have 2 produce lines left.')
for line in product_produce._workorder_line_ids().filtered(lambda x: x.lot_id):
self.assertEqual(line.lot_id, remaining_lot, 'Wrong lot proposed.')

def test_product_produce_3(self):
@@ -419,9 +419,9 @@ def test_product_produce_3(self):
# product 1 lot 1 shelf1
# product 1 lot 1 shelf2
# product 1 lot 2
self.assertEqual(len(product_produce.workorder_line_ids), 4, 'You should have 4 produce lines. lot 1 shelf_1, lot 1 shelf_2, lot2 and for product which have tracking None')
self.assertEqual(len(product_produce._workorder_line_ids()), 4, 'You should have 4 produce lines. lot 1 shelf_1, lot 1 shelf_2, lot2 and for product which have tracking None')

for produce_line in product_produce.workorder_line_ids:
for produce_line in product_produce._workorder_line_ids():
produce_line.qty_done = produce_line.qty_to_consume + 1
product_produce.do_produce()

@@ -588,7 +588,7 @@ def test_product_produce_7(self):
produce_form.qty_producing = 1
produce_wizard = produce_form.save()

self.assertEqual(len(produce_wizard.workorder_line_ids), 2)
self.assertEqual(len(produce_wizard._workorder_line_ids()), 2)
produce_wizard.do_produce()

produce_form = Form(self.env['mrp.product.produce'].with_context({
@@ -599,7 +599,7 @@ def test_product_produce_7(self):

produce_wizard = produce_form.save()

self.assertEqual(len(produce_wizard.workorder_line_ids), 2)
self.assertEqual(len(produce_wizard._workorder_line_ids()), 2)
produce_wizard.do_produce()

mo.button_mark_done()
@@ -698,7 +698,7 @@ def test_product_produce_9(self):
with self.assertRaises(UserError):
# try adding another line for a bom product to increase the quantity
produce_form.qty_producing = 1
with produce_form.workorder_line_ids.new() as line:
with produce_form._workorder_line_ids().new() as line:
line.product_id = p1
line.qty_done = 1
product_produce = produce_form.save()
@@ -707,7 +707,7 @@ def test_product_produce_9(self):
with self.assertRaises(UserError):
# Try updating qty_done
product_produce = produce_form.save()
product_produce.workorder_line_ids[0].qty_done += 1
product_produce._workorder_line_ids()[0].qty_done += 1
product_produce.do_produce()

with self.assertRaises(UserError):
@@ -717,7 +717,7 @@ def test_product_produce_9(self):
'active_ids': [mo.id],
}))
produce_form.qty_producing = 1
with produce_form.workorder_line_ids.new() as line:
with produce_form._workorder_line_ids().new() as line:
line.product_id = self.product_4
line.qty_done = 1
product_produce = produce_form.save()
@@ -730,11 +730,11 @@ def test_product_produce_9(self):
}))
produce_form.qty_producing = 1

with produce_form.workorder_line_ids.new() as line:
with produce_form._workorder_line_ids().new() as line:
line.product_id = p1
line.qty_done = 1
product_produce = produce_form.save()
product_produce.workorder_line_ids[1].qty_done -= 1
product_produce._workorder_line_ids()[1].qty_done -= 1
product_produce.do_produce()

def test_product_produce_uom(self):
@@ -840,8 +840,8 @@ def test_product_produce_uom_2(self):
}))
product_produce = produce_form.save()
self.assertEqual(product_produce.qty_producing, 1)
self.assertEqual(len(product_produce.workorder_line_ids), 2, 'Should be 2 lines since the component tracking is serial and quantity 2.')
self.assertEqual(product_produce.workorder_line_ids[0].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
self.assertEqual(product_produce.workorder_line_ids[0].product_uom_id, unit, 'Should be the product uom so "unit"')
self.assertEqual(product_produce.workorder_line_ids[1].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
self.assertEqual(product_produce.workorder_line_ids[1].product_uom_id, unit, 'should be the product uom so "unit"')
self.assertEqual(len(product_produce._workorder_line_ids()), 2, 'Should be 2 lines since the component tracking is serial and quantity 2.')
self.assertEqual(product_produce._workorder_line_ids()[0].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
self.assertEqual(product_produce._workorder_line_ids()[0].product_uom_id, unit, 'Should be the product uom so "unit"')
self.assertEqual(product_produce._workorder_line_ids()[1].qty_to_consume, 1, 'Should be 1 unit since the tracking is serial and quantity 2.')
self.assertEqual(product_produce._workorder_line_ids()[1].product_uom_id, unit, 'should be the product uom so "unit"')
@@ -422,7 +422,7 @@ def test_production_links_with_non_tracked_lots(self):
produce_form.qty_producing = 3.0
produce_form.final_lot_id = lot_finished_1
produce_wizard = produce_form.save()
produce_wizard.workorder_line_ids[0].lot_id = lot_1
produce_wizard._workorder_line_ids()[0].lot_id = lot_1
produce_wizard.do_produce()

lot_2 = self.env['stock.production.lot'].create({
@@ -444,7 +444,7 @@ def test_production_links_with_non_tracked_lots(self):
produce_form.final_lot_id = lot_finished_2

produce_wizard = produce_form.save()
produce_wizard.workorder_line_ids[0].lot_id = lot_2
produce_wizard._workorder_line_ids()[0].lot_id = lot_2
produce_wizard.do_produce()
mo.button_mark_done()
ml = mo.finished_move_line_ids[0].consume_line_ids.filtered(lambda m: m.product_id == p1 and lot_finished_1 in m.lot_produced_ids)
@@ -95,7 +95,7 @@ def test_00_workorder_process(self):
finished_lot =self.env['stock.production.lot'].create({'product_id': production_table.product_id.id})
workorder.write({'final_lot_id': finished_lot.id})
workorder.button_start()
for workorder_line_id in workorder.workorder_line_ids:
for workorder_line_id in workorder._workorder_line_ids():
if workorder_line_id.product_id.id == product_bolt.id:
workorder_line_id.write({'lot_id': lot_bolt.id, 'qty_done': 1})
if workorder_line_id.product_id.id == product_table_sheet.id:
@@ -199,7 +199,7 @@ def test_00b_workorder_process(self):
finished_lot = self.env['stock.production.lot'].create({'product_id': production_table.product_id.id})
workorders[0].write({'final_lot_id': finished_lot.id, 'qty_producing': 1.0})
workorders[0].button_start()
workorders[0].workorder_line_ids[0].write({'lot_id': lot_sheet.id, 'qty_done': 1})
workorders[0]._workorder_line_ids()[0].write({'lot_id': lot_sheet.id, 'qty_done': 1})
self.assertEqual(workorders[0].state, 'progress')
workorders[0].record_production()

@@ -212,7 +212,7 @@ def test_00b_workorder_process(self):
workorders[1].button_start()
workorders[1].qty_producing = 1.0
workorders[1].final_lot_id = finished_lot
workorders[1].workorder_line_ids[0].write({'lot_id': lot_leg.id, 'qty_done': 4})
workorders[1]._workorder_line_ids()[0].write({'lot_id': lot_leg.id, 'qty_done': 4})
workorders[1].record_production()
move_leg = production_table.move_raw_ids.filtered(lambda p: p.product_id == product_table_leg)
#self.assertEqual(workorders[1].state, 'done')
@@ -224,7 +224,7 @@ def test_00b_workorder_process(self):
workorders[2].button_start()
workorders[2].qty_producing = 1.0
workorders[2].final_lot_id = finished_lot
move_lot = workorders[2].workorder_line_ids[0]
move_lot = workorders[2]._workorder_line_ids()[0]
move_lot.write({'lot_id': lot_bolt.id, 'qty_done': 4})
move_table_bolt = production_table.move_raw_ids.filtered(lambda p: p.product_id.id == product_bolt.id)
workorders[2].record_production()
@@ -488,7 +488,7 @@ def test_01_without_workorder(self):
laptop_lot_001 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id})
product_form.final_lot_id = laptop_lot_001
product_consume = product_form.save()
product_consume.workorder_line_ids[0].qty_done = 12
product_consume._workorder_line_ids()[0].qty_done = 12
product_consume.do_produce()

# Check consumed move after produce 6 quantity of customized laptop.
@@ -515,8 +515,8 @@ def test_01_without_workorder(self):
laptop_lot_002 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id})
produce_form.final_lot_id = laptop_lot_002
product_consume = produce_form.save()
self.assertEquals(len(product_consume.workorder_line_ids), 2)
product_consume.workorder_line_ids[0].qty_done = 8
self.assertEquals(len(product_consume._workorder_line_ids()), 2)
product_consume._workorder_line_ids()[0].qty_done = 8
product_consume.do_produce()
charger_move = mo_custom_laptop.move_raw_ids.filtered(lambda x: x.product_id.id == product_charger.id and x.state != 'done')
keybord_move = mo_custom_laptop.move_raw_ids.filtered(lambda x: x.product_id.id == product_keybord.id and x.state !='done')
@@ -654,9 +654,9 @@ def test_02_different_uom_on_bomlines(self):
produce_form.final_lot_id = lot_a
product_consume = produce_form.save()
# laptop_lot_002 = self.env['stock.production.lot'].create({'product_id': custom_laptop.id})
self.assertEquals(len(product_consume.workorder_line_ids), 2)
product_consume.workorder_line_ids.filtered(lambda x: x.product_id == product_C).write({'qty_done': 3000})
product_consume.workorder_line_ids.filtered(lambda x: x.product_id == product_B).write({'qty_done': 20})
self.assertEquals(len(product_consume._workorder_line_ids()), 2)
product_consume._workorder_line_ids().filtered(lambda x: x.product_id == product_C).write({'qty_done': 3000})
product_consume._workorder_line_ids().filtered(lambda x: x.product_id == product_B).write({'qty_done': 20})
product_consume.do_produce()
mo_custom_product.post_inventory()

Oops, something went wrong.

0 comments on commit 8eee330

Please sign in to comment.
You can’t perform that action at this time.