Skip to content

Commit

Permalink
[MERGE] forward port branch saas-12.2 up to 27e9c9e
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Mar 27, 2019
2 parents 05e480a + 27e9c9e commit da711b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions addons/mrp/models/mrp_abstract_workorder.py
Expand Up @@ -58,7 +58,7 @@ def _update_workorder_lines(self):
self.production_id.product_uom_id,
round=False
)
qty_todo = float_round(new_qty - sum(move_workorder_lines.mapped('qty_done')), precision_rounding=rounding)
qty_todo = float_round(new_qty - sum(move_workorder_lines.mapped('qty_to_consume')), precision_rounding=rounding)

# Remove or lower quantity on exisiting workorder lines
if float_compare(qty_todo, 0.0, precision_rounding=rounding) < 0:
Expand Down Expand Up @@ -95,7 +95,7 @@ def _update_workorder_lines(self):
if float_compare(qty_reserved_remaining, 0, precision_rounding=rounding) > 0:
qty_to_add = min(qty_reserved_remaining, qty_todo)
line_values['to_update'][workorder_line] = {
'qty_done': workorder_line.qty_done + qty_to_add,
'qty_done': workorder_line.qty_to_consume + qty_to_add,
'qty_to_consume': workorder_line.qty_to_consume + qty_to_add,
'qty_reserved': workorder_line.qty_reserved + qty_to_add,
}
Expand All @@ -104,7 +104,7 @@ def _update_workorder_lines(self):

if not workorder_line.qty_reserved and not workorder_line.lot_id and workorder_line.product_tracking != 'serial':
line_values['to_update'][workorder_line] = {
'qty_done': workorder_line.qty_done + qty_todo,
'qty_done': workorder_line.qty_to_consume + qty_todo,
'qty_to_consume': workorder_line.qty_to_consume + qty_todo,
}
qty_todo = 0
Expand Down
19 changes: 10 additions & 9 deletions addons/mrp/models/mrp_workorder.py
Expand Up @@ -108,15 +108,16 @@ class MrpWorkorder(models.Model):

@api.depends('production_id')
def _compute_final_lot_domain(self):
# check if self is not the first workorder in the list
if self.env['mrp.workorder'].search([('next_work_order_id', '=', self.id)]):
self.final_lot_domain = self.env['stock.production.lot'].search([
('use_next_on_work_order_id', '=', self.id),
]).ids
else:
self.final_lot_domain = self.env['stock.production.lot'].search([
('product_id', '=', self.product_id.id),
]).ids
for wo in self:
# check if self is not the first workorder in the list
if self.env['mrp.workorder'].search([('next_work_order_id', '=', wo.id)]):
wo.final_lot_domain = self.env['stock.production.lot'].search([
('use_next_on_work_order_id', '=', wo.id),
]).ids
else:
wo.final_lot_domain = self.env['stock.production.lot'].search([
('product_id', '=', wo.product_id.id),
]).ids

@api.multi
def name_get(self):
Expand Down
14 changes: 14 additions & 0 deletions addons/mrp/tests/test_order.py
Expand Up @@ -479,6 +479,20 @@ def test_product_produce_1(self):
'active_id': mo.id,
'active_ids': [mo.id],
}))
# change the quantity done in one line
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]
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.')
product_produce.do_produce()
Expand Down
3 changes: 1 addition & 2 deletions addons/mrp/views/stock_move_views.xml
Expand Up @@ -26,7 +26,7 @@
</div>
<label for="quantity_done" attrs="{'invisible': [('parent.state', '=', 'draft')]}"/>
<div class="o_row" attrs="{'invisible': [('parent.state', '=', 'draft')]}">
<span><field name="quantity_done" attrs="{'readonly': ['|', ('is_locked', '=', True), '|', ('finished_lots_exist', '=', True), ('has_tracking', '!=', 'none')]}" nolabel="1"/></span>
<span><field name="quantity_done" attrs="{'readonly': ['|', '|', ('move_line_ids', '!=', False), ('is_locked', '=', True), '|', ('finished_lots_exist', '=', True), ('has_tracking', '!=', 'none')]}" nolabel="1"/></span>
<span> / </span>
<span><field name="reserved_availability" nolabel="1"/></span>
</div>
Expand Down Expand Up @@ -55,7 +55,6 @@
<field name="lot_produced_id" options="{'no_open': True, 'no_create': True}" domain="[('id', 'in', parent.order_finished_lot_ids)]" invisible="not context.get('final_lots')"/>
<field name="product_uom_qty" string="Reserved" readonly="1"/>
<field name="qty_done"/>
<field name="product_qty" invisible="1"/>
<field name="workorder_id" invisible="1"/>
<field name="product_id" invisible="1"/>
<field name="product_uom_id" invisible="1"/>
Expand Down

0 comments on commit da711b9

Please sign in to comment.