[IMP] mrp: Groundwork for the new workorder tablet view
This commit ensures that the prerequisites for the new tablet view (introduced in Enterprise) are met. Aside from a few additional fields and simple view modifications which allow simpler changes via inheritance, the main change it introduces is the capability to take into account consumed quantities of untracked components.
This commit is contained in:
committed by
Simon Lejeune
parent
e73922855d
commit
982834714b
@@ -221,4 +221,3 @@ class MrpWorkcenterProductivity(models.Model):
|
||||
def button_block(self):
|
||||
self.ensure_one()
|
||||
self.workcenter_id.order_ids.end_all()
|
||||
return {'type': 'ir.actions.client', 'tag': 'reload'}
|
||||
|
||||
@@ -50,6 +50,7 @@ class MrpWorkorder(models.Model):
|
||||
'Product Tracking', related='production_id.product_id.tracking',
|
||||
help='Technical: used in views only.')
|
||||
qty_production = fields.Float('Original Production Quantity', readonly=True, related='production_id.product_qty')
|
||||
qty_remaining = fields.Float('Quantity To Be Produced', compute='_compute_qty_remaining', digits=dp.get_precision('Product Unit of Measure'))
|
||||
qty_produced = fields.Float(
|
||||
'Quantity', default=0.0,
|
||||
readonly=True,
|
||||
@@ -111,6 +112,7 @@ class MrpWorkorder(models.Model):
|
||||
final_lot_id = fields.Many2one(
|
||||
'stock.production.lot', 'Lot/Serial Number', domain="[('product_id', '=', product_id)]",
|
||||
states={'done': [('readonly', True)], 'cancel': [('readonly', True)]})
|
||||
tracking = fields.Selection(related='production_id.product_id.tracking')
|
||||
time_ids = fields.One2many(
|
||||
'mrp.workcenter.productivity', 'workorder_id')
|
||||
is_user_working = fields.Boolean(
|
||||
@@ -283,15 +285,18 @@ class MrpWorkorder(models.Model):
|
||||
def record_production(self):
|
||||
self.ensure_one()
|
||||
if self.qty_producing <= 0:
|
||||
raise UserError(_('Please set the quantity you produced in the Current Qty field. It can not be 0!'))
|
||||
raise UserError(_('Please set the quantity you are currently producing. It should be different from zero.'))
|
||||
|
||||
if (self.production_id.product_id.tracking != 'none') and not self.final_lot_id:
|
||||
raise UserError(_('You should provide a lot/serial number for the final product'))
|
||||
|
||||
# Update quantities done on each raw material line
|
||||
# For each untracked component without any 'temporary' move lines,
|
||||
# (the new workorder tablet view allows registering consumed quantities for untracked components)
|
||||
# we assume that only the theoretical quantity was used
|
||||
raw_moves = self.move_raw_ids.filtered(lambda x: (x.has_tracking == 'none') and (x.state not in ('done', 'cancel')) and x.bom_line_id)
|
||||
for move in raw_moves:
|
||||
if move.unit_factor:
|
||||
if move.unit_factor and not move.move_line_ids.filtered(lambda m: not m.done_wo):
|
||||
rounding = move.product_uom.rounding
|
||||
move.quantity_done += float_round(self.qty_producing * move.unit_factor, precision_rounding=rounding)
|
||||
|
||||
@@ -301,10 +306,10 @@ class MrpWorkorder(models.Model):
|
||||
if move_line.qty_done <= 0: # rounding...
|
||||
move_line.sudo().unlink()
|
||||
continue
|
||||
if not move_line.lot_id:
|
||||
if move_line.product_id.tracking != 'none' and not move_line.lot_id:
|
||||
raise UserError(_('You should provide a lot/serial number for a component'))
|
||||
# Search other move_line where it could be added:
|
||||
lots = self.move_line_ids.filtered(lambda x: (x.lot_id.id == move_line.lot_id.id) and (not x.lot_produced_id) and (not x.done_move))
|
||||
lots = self.move_line_ids.filtered(lambda x: (x.lot_id.id == move_line.lot_id.id) and (not x.lot_produced_id) and (not x.done_move) and (x.product_id == move_line.product_id))
|
||||
if lots:
|
||||
lots[0].qty_done += move_line.qty_done
|
||||
lots[0].lot_produced_id = self.final_lot_id.id
|
||||
@@ -486,3 +491,9 @@ class MrpWorkorder(models.Model):
|
||||
action = self.env.ref('stock.action_stock_scrap').read()[0]
|
||||
action['domain'] = [('workorder_id', '=', self.id)]
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
@api.depends('qty_production', 'qty_produced')
|
||||
def _compute_qty_remaining(self):
|
||||
for wo in self:
|
||||
wo.qty_remaining = wo.qty_production - wo.qty_produced
|
||||
|
||||
@@ -91,6 +91,9 @@
|
||||
<field name="model">mrp.workorder</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Production Workcenter" delete="0" create="0">
|
||||
<field name="is_user_working" invisible="1"/>
|
||||
<field name="working_state" invisible="1"/>
|
||||
<field name="production_state" invisible="1"/>
|
||||
<header>
|
||||
<button name="button_finish" type="object" string="Finish Order" attrs="{'invisible': ['|', ('state', '!=', 'progress'), ('is_produced', '=', False)]}" class="btn-info"/>
|
||||
<button name="button_start" type="object" string="Start Working" attrs="{'invisible': ['|', ('working_state', '=', 'blocked'), ('state', '!=', 'pending')]}"/>
|
||||
@@ -103,9 +106,6 @@
|
||||
<button name="button_start" type="object" string="Continue Production" attrs="{'invisible': ['|', '|', ('production_state', '=', 'done'), ('working_state', '=', 'blocked'), ('state', '!=', 'done')]}"/>
|
||||
<button name="button_scrap" type="object" string="Scrap" attrs="{'invisible': [('state', 'in', ('confirmed', 'cancel'))]}"/>
|
||||
<field name="state" widget="statusbar" statusbar_visible="pending,ready,progress,done"/>
|
||||
<field name="is_user_working" invisible="1"/>
|
||||
<field name="working_state" invisible="1"/>
|
||||
<field name="production_state" invisible="1"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
@@ -336,15 +336,13 @@
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="oe_kanban_card oe_kanban_global_click">
|
||||
<div class="oe_kanban_content">
|
||||
<div class="o_kanban_record_top">
|
||||
<span><strong class="o_kanban_record_title"><t t-esc="record.product_id.value"/></strong></span>
|
||||
</div>
|
||||
<strong><span><t t-esc="record.production_id.value"/></span> - <span><t t-esc="record.name.value"/></span></strong>
|
||||
<div class="row">
|
||||
<div class="col-xs-7 o_kanban_primary_left">
|
||||
<span><t t-esc="record.qty_production.value"/> <t t-esc="record.product_uom_id.value"/></span>
|
||||
<span><t t-esc="record.product_id.value"/></span>
|
||||
</div>
|
||||
<div class="col-xs-5 o_kanban_primary_right">
|
||||
<span><t t-esc="record.production_id.value"/></span>
|
||||
<span><t t-esc="record.qty_production.value"/> <t t-esc="record.product_uom_id.value"/></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user