[IMP] mrp: Plan WO in the future
Add possibility to set a Start Date on Manufacturing Orders. Once the user clicks on Plan, the Work Order are planned at the first time available from this date. When clicking 'Unplan', Work orders are now completely deleted TaskID: 1889399 closes odoo/odoo#30184
This commit is contained in:
@@ -99,6 +99,11 @@ class MrpProduction(models.Model):
|
||||
states={'done': [('readonly', True)], 'cancel': [('readonly', True)]})
|
||||
date_start = fields.Datetime('Start Date', copy=False, index=True, readonly=True)
|
||||
date_finished = fields.Datetime('End Date', copy=False, index=True, readonly=True)
|
||||
date_start_wo = fields.Datetime(
|
||||
'Planning Start Date', copy=False, readonly=True,
|
||||
states={'draft': [('readonly', False)], 'confirmed': [('readonly', False)]},
|
||||
help="The work orders will be planned based on the availability of the work centers starting from "
|
||||
"this date. If emtpy, the work orders are planned as soon as possible.")
|
||||
bom_id = fields.Many2one(
|
||||
'mrp.bom', 'Bill of Material',
|
||||
readonly=True, states={'draft': [('readonly', False)]},
|
||||
@@ -615,7 +620,7 @@ class MrpProduction(models.Model):
|
||||
return True
|
||||
|
||||
def _get_start_date(self):
|
||||
return datetime.now()
|
||||
return self.date_start_wo or datetime.now()
|
||||
|
||||
def plan_workorders(self):
|
||||
WorkOrder = self.env['mrp.workorder']
|
||||
@@ -661,7 +666,11 @@ class MrpProduction(models.Model):
|
||||
start_date = from_date + relativedelta(minutes=duration)
|
||||
|
||||
def button_unplan(self):
|
||||
self.mapped('workorder_ids').write({'date_planned_start': False, 'date_planned_finished': False})
|
||||
if any(wo.state == 'done' for wo in self.workorder_ids):
|
||||
raise UserError(_("Some work orders are already done, you cannot unplan this manufacturing order."))
|
||||
elif any(wo.state == 'progress' for wo in self.workorder_ids):
|
||||
raise UserError(_("Some work orders have already started, you cannot unplan this manufacturing order."))
|
||||
self.workorder_ids.unlink()
|
||||
|
||||
@api.multi
|
||||
def _generate_workorders(self, exploded_boms):
|
||||
|
||||
@@ -598,3 +598,29 @@ class TestWorkOrderProcess(common.TransactionCase):
|
||||
# Check that the workorder is planned now and that it lasts one hour
|
||||
self.assertAlmostEqual(workorder.date_planned_start, datetime.now(), delta=timedelta(seconds=10), msg="Workorder should be planned now.")
|
||||
self.assertAlmostEqual(workorder.date_planned_finished, datetime.now() + timedelta(hours=1), delta=timedelta(seconds=10), msg="Workorder should be done in an hour.")
|
||||
|
||||
def test_04b_test_planning_date(self):
|
||||
""" Test that workorder are planned at the correct time when setting a start date """
|
||||
# Remove attendances linked to the calendar, this means that the workcenter is working 24/7
|
||||
self.env['resource.calendar'].search([]).write({'attendance_ids': [(5, False, False)]})
|
||||
|
||||
dining_table = self.env.ref("mrp.product_product_computer_desk")
|
||||
|
||||
date_start = datetime.now() + timedelta(days=1)
|
||||
|
||||
production_table_form = Form(self.env['mrp.production'])
|
||||
production_table_form.product_id = dining_table
|
||||
production_table_form.bom_id = self.env.ref("mrp.mrp_bom_desk")
|
||||
production_table_form.product_qty = 1.0
|
||||
production_table_form.product_uom_id = dining_table.uom_id
|
||||
production_table_form.date_start_wo = date_start
|
||||
production_table = production_table_form.save()
|
||||
production_table.action_confirm()
|
||||
|
||||
# Create work order
|
||||
production_table.button_plan()
|
||||
workorder = production_table.workorder_ids[0]
|
||||
|
||||
# Check that the workorder is planned now and that it lasts one hour
|
||||
self.assertEqual(workorder.date_planned_start, date_start, msg="Workorder should be planned tomorrow.")
|
||||
self.assertEqual(workorder.date_planned_finished, date_start + timedelta(hours=1), msg="Workorder should be done one hour later.")
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
<group>
|
||||
<field name="date_planned_start"/>
|
||||
<field name="date_planned_finished" invisible="1"/>
|
||||
<field name="date_start_wo" attrs="{'invisible': ['|', ('routing_id', '=', False), ('state', 'not in', ['draft', 'confirmed'])]}"/>
|
||||
<label for="date_planned_start_wo" string="Scheduled Date" attrs="{'invisible': [('date_planned_start_wo', '=', False)]}"/>
|
||||
<div class="o_row" attrs="{'invisible': [('date_planned_start_wo', '=', False)]}">
|
||||
<field name="date_planned_start_wo" attrs="{'readonly': [('move_raw_ids', '!=', [])]}"/>
|
||||
|
||||
Reference in New Issue
Block a user