[FIX+IMP] mrp_operations_extension

FIX: Fixes #920 Now initiate a WO doesn't force MO material reservation
IMP: Creation of the field "picking_type_id" in mrp.routing.workcenter.
FIX: Closes #921
IMP: Added function to avoid repeat code
FIX: When WO starts the MO state should be 'in_production' not 'ready'
This commit is contained in:
Daniel-CA
2015-07-28 15:45:01 +02:00
committed by Pedro M. Baeza
parent 81632ca353
commit 5e6ced1cd9
5 changed files with 43 additions and 17 deletions

View File

@@ -39,6 +39,7 @@
"hr",
],
"data": [
"data/mrp_operations_extension_data.xml",
"wizard/mrp_workorder_produce_view.xml",
"views/mrp_workcenter_view.xml",
"views/mrp_routing_operation_view.xml",

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="req_link_mrp_workcenter" model="res.request.link">
<field name="name">Work Center</field>
<field name="object">mrp.workcenter</field>
</record>
<record id="req_link_mrp_workcenter" model="res.request.link">
<field name="name">Work Order</field>
<field name="object">mrp.production.workcenter.line</field>
</record>
</data>
</openerp>

View File

@@ -36,34 +36,42 @@ class MrpBom(models.Model):
result2, factor=factor, level=level, routing_id=routing_id)
return result, result2
def _get_routing_line_from_workorder(self, routing_id, seq, workcenter_id,
wo_name):
""" Returns first routing line from a given data if found
@param routing_id: Routing id
@param seq: workorder sequence
@param workcenter_id: Workcenter id
@return: wo_name = Workorder name
"""
routing_line_obj = self.env['mrp.routing.workcenter']
domain = [('routing_id', '=', routing_id), ('sequence', '=', seq),
('workcenter_id', '=', workcenter_id)]
routing_lines = routing_line_obj.search(domain)
for rl in routing_lines:
if rl.name in wo_name:
return rl
return routing_line_obj
def _get_workorder_operations(self, result2, factor, level=0,
routing_id=False):
routing_line_obj = self.env['mrp.routing.workcenter']
for work_order in result2:
if (work_order['sequence'] < level or
work_order.get('routing_wc_line')):
continue
seq = work_order['sequence'] - level
domain = [('routing_id', '=', routing_id),
('sequence', '=', seq),
('workcenter_id', '=', work_order['workcenter_id'])]
routing_lines = routing_line_obj.search(domain)
routing_line = (routing_lines and routing_lines[0] or
routing_line_obj)
for rl in routing_lines:
if rl.name in work_order['name']:
routing_line = rl
break
wc = routing_line
cycle = wc.cycle_nbr and int(math.ceil(factor / wc.cycle_nbr)) or 0
hour = wc.hour_nbr * cycle
default_wc_line = wc.op_wc_lines.filtered(lambda r: r.default)
rl = self._get_routing_line_from_workorder(
routing_id, seq, work_order['workcenter_id'],
work_order['name'])
cycle = rl.cycle_nbr and int(math.ceil(factor / rl.cycle_nbr)) or 0
hour = rl.hour_nbr * cycle
default_wc_line = rl.op_wc_lines.filtered(lambda r: r.default)
work_order['cycle'] = cycle
work_order['hour'] = hour
work_order['time_start'] = default_wc_line.time_start or 0.0
work_order['time_stop'] = default_wc_line.time_stop or 0.0
work_order['routing_wc_line'] = routing_line.id
work_order['do_production'] = wc.do_production
work_order['routing_wc_line'] = rl.id
work_order['do_production'] = rl.do_production
return result2
@api.multi

View File

@@ -154,4 +154,6 @@ class MrpProductionWorkcenterLine(models.Model):
'done']):
raise exceptions.Warning(
_("Missing materials to start the production"))
if self.production_id.state in ('confirmed', 'ready'):
self.production_id.state = 'in_production'
return super(MrpProductionWorkcenterLine, self).action_start_working()

View File

@@ -56,6 +56,8 @@ class MrpRoutingWorkcenter(models.Model):
previous_operations_finished = fields.Boolean(
string='Previous operations finished',
default="get_routing_previous_operations")
picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type',
domain=[('code', '=', 'outgoing')])
@api.constrains('op_wc_lines')
def _check_default_op_wc_lines(self):