mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_operations_extension: New behaviour added when finishing WO and there are pending movements
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"data": [
|
||||
"data/mrp_operations_extension_data.xml",
|
||||
"wizard/mrp_workorder_produce_view.xml",
|
||||
"wizard/workcerter_line_finish_view.xml",
|
||||
"views/mrp_workcenter_view.xml",
|
||||
"views/mrp_routing_operation_view.xml",
|
||||
"views/mrp_production_view.xml",
|
||||
|
||||
@@ -135,3 +135,25 @@ class MrpProductionWorkcenterLine(models.Model):
|
||||
if workorder.production_id.state in ('confirmed', 'ready'):
|
||||
workorder.production_id.state = 'in_production'
|
||||
return super(MrpProductionWorkcenterLine, self).action_start_working()
|
||||
|
||||
@api.multi
|
||||
def button_done(self):
|
||||
res = {}
|
||||
move_list = self.move_lines.filtered(
|
||||
lambda x: x.state not in('cancel', 'done'))
|
||||
if move_list:
|
||||
idform = self.env.ref(
|
||||
'mrp_operations_extension.finish_wo_form_view')
|
||||
res = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Finish WO'),
|
||||
'res_model': 'workcenter.line.finish',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'views': [(idform.id, 'form')],
|
||||
'target': 'new',
|
||||
'context': self.env.context
|
||||
}
|
||||
else:
|
||||
self.signal_workflow('button_done')
|
||||
return res
|
||||
|
||||
@@ -42,6 +42,7 @@ class TestMrpOperationsExtension(common.TransactionCase):
|
||||
self.produce_line_model = self.env['mrp.product.produce.line']
|
||||
self.production = self.env.ref(
|
||||
'mrp_operations_extension.mrp_production_opeext')
|
||||
self.workcenter_line_finish = self.env['workcenter.line.finish']
|
||||
|
||||
def test_check_do_production_mrp_routing(self):
|
||||
# None of the workcenter lines have the check marked
|
||||
@@ -188,3 +189,44 @@ class TestMrpOperationsExtension(common.TransactionCase):
|
||||
self.assertEqual(
|
||||
line.state, 'done',
|
||||
'Error work center line not in done state')
|
||||
|
||||
def test_operation_button_done(self):
|
||||
self.production.signal_workflow('button_confirm')
|
||||
workorder = self.production.workcenter_lines[0]
|
||||
workorder.action_assign()
|
||||
workorder.force_assign()
|
||||
workorder.signal_workflow('button_start_working')
|
||||
res = workorder.button_done()
|
||||
if res: # check make_them_done
|
||||
lines2move = len(workorder.move_lines.filtered(
|
||||
lambda x: x.state not in ('done')))
|
||||
self.workcenter_line_finish.with_context(
|
||||
active_id=workorder.id,
|
||||
active_model='mrp.production.workcenter.line').make_them_done()
|
||||
lines_done = len(workorder.move_lines.filtered(
|
||||
lambda x: x.state in ('done')))
|
||||
self.assertEqual(lines2move, lines_done,
|
||||
'Error work order moves quantity do not match')
|
||||
self.assertEqual(workorder.state, 'done',
|
||||
'Error work center line not in done state')
|
||||
workorder1 = self.production.workcenter_lines[1]
|
||||
workorder1.signal_workflow('button_start_working')
|
||||
res1 = workorder1.button_done()
|
||||
self.assertFalse(res1, 'Error there are pending movements')
|
||||
workorder2 = self.production.workcenter_lines[2]
|
||||
workorder2.action_assign()
|
||||
workorder2.force_assign()
|
||||
workorder2.signal_workflow('button_start_working')
|
||||
res2 = workorder2.button_done()
|
||||
if res2: # check cancel_all
|
||||
lines2move2 = len(workorder2.move_lines.filtered(
|
||||
lambda x: x.state not in ('cancel')))
|
||||
self.workcenter_line_finish.with_context(
|
||||
active_id=workorder2.id,
|
||||
active_model='mrp.production.workcenter.line').cancel_all()
|
||||
lines_cancel = len(workorder2.move_lines.filtered(
|
||||
lambda x: x.state in ('cancel')))
|
||||
self.assertEqual(lines2move2, lines_cancel,
|
||||
'Error work order moves quantity do not match')
|
||||
self.assertEqual(workorder2.state, 'done',
|
||||
'Error work center line not in done state')
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
<button name="button_done" position="attributes">
|
||||
<attribute name="icon"/>
|
||||
<attribute name="class">oe_highlight</attribute>
|
||||
<attribute name="type">object</attribute>
|
||||
</button>
|
||||
<button name="button_pause" position="attributes">
|
||||
<attribute name="icon"/>
|
||||
@@ -148,12 +149,26 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="mrp_production_form_inherit_view2">
|
||||
<field name="name">mrp.production.form.inherit2</field>
|
||||
<field name="model">mrp.production</field>
|
||||
<field name="inherit_id" ref="mrp_operations.mrp_production_form_inherit_view2" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='workcenter_lines']/tree/button[@name='button_done']" position="attributes">
|
||||
<attribute name="type">object</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="workcenter_line_inh_form_view">
|
||||
<field name="name">Workcenter line inh</field>
|
||||
<field name="model">mrp.production.workcenter.line</field>
|
||||
<field name="inherit_id"
|
||||
ref="mrp_operations.mrp_production_workcenter_form_view_inherit" />
|
||||
<field name="arch" type="xml">
|
||||
<button name="button_done" position="attributes">
|
||||
<attribute name="type">object</attribute>
|
||||
</button>
|
||||
<field name="workcenter_id" position="before">
|
||||
<field name="possible_workcenters" invisible="1"/>
|
||||
</field>
|
||||
|
||||
@@ -3,3 +3,4 @@
|
||||
# For copyright and license notices, see __openerp__.py file in root directory
|
||||
##############################################################################
|
||||
from . import mrp_work_order_produce
|
||||
from . import workcenter_line_finish
|
||||
|
||||
36
mrp_operations_extension/wizard/workcenter_line_finish.py
Normal file
36
mrp_operations_extension/wizard/workcenter_line_finish.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
# For copyright and license notices, see __openerp__.py file in root directory
|
||||
##############################################################################
|
||||
from openerp import models, api
|
||||
|
||||
|
||||
class WorkcenterLineFinish(models.TransientModel):
|
||||
_name = "workcenter.line.finish"
|
||||
|
||||
@api.multi
|
||||
def make_them_done(self):
|
||||
if ('active_id' in self.env.context and
|
||||
(self.env.context['active_model'] ==
|
||||
'mrp.production.workcenter.line')):
|
||||
wc_line_obj = self.env['mrp.production.workcenter.line']
|
||||
wc_line = wc_line_obj.browse(self.env.context['active_id'])
|
||||
wc_line.move_lines.filtered(
|
||||
lambda x: x.state not in ('cancel', 'done')).action_done()
|
||||
wc_line.signal_workflow('button_done')
|
||||
|
||||
@api.multi
|
||||
def cancel_all(self):
|
||||
if ('active_id' in self.env.context and
|
||||
(self.env.context['active_model'] ==
|
||||
'mrp.production.workcenter.line')):
|
||||
wc_line_obj = self.env['mrp.production.workcenter.line']
|
||||
wc_line = wc_line_obj.browse(self.env.context['active_id'])
|
||||
wc_line.move_lines.filtered(
|
||||
lambda x: x.state not in ('cancel', 'done')).action_cancel()
|
||||
if wc_line.do_production:
|
||||
wc_line.production_id.move_created_ids.filtered(
|
||||
lambda x: x.state not in
|
||||
('cancel', 'done')).action_cancel()
|
||||
wc_line.production_id.refresh()
|
||||
wc_line.signal_workflow('button_done')
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="finish_wo_form_view" model="ir.ui.view">
|
||||
<field name="name">finish.wo.form.view</field>
|
||||
<field name="model">workcenter.line.finish</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Finish Work Order">
|
||||
<separator
|
||||
string="There are still some pending moves on WO"
|
||||
colspan="4" />
|
||||
<footer>
|
||||
<button class="oe_highlight" name="make_them_done"
|
||||
string="Do all movements" type="object" />
|
||||
or
|
||||
<button class="oe_highlight" name="cancel_all"
|
||||
string="Cancel all movements" type="object" />
|
||||
or
|
||||
<button class="oe_link" special="cancel"
|
||||
string="Cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user