[REF] mrp: is_planned and is_partially_planned

the `planned` state was removed but still used in a bunch of places
make `is_planned` stored and use it instead

closes odoo/odoo#54845

Related: odoo/upgrade#1710
Signed-off-by: Arnold Moyaux <amoyaux@users.noreply.github.com>
This commit is contained in:
Simon Lejeune
2020-09-02 08:04:18 +00:00
committed by William Henrotin
parent ca815e9a10
commit c065d5b92d
3 changed files with 13 additions and 16 deletions
+5 -7
View File
@@ -229,8 +229,7 @@ class MrpProduction(models.Model):
scrap_ids = fields.One2many('stock.scrap', 'production_id', 'Scraps')
scrap_count = fields.Integer(compute='_compute_scrap_move_count', string='Scrap Move')
is_locked = fields.Boolean('Is Locked', default=_get_default_is_locked, copy=False)
is_planned = fields.Boolean('Its Operations are Planned', compute="_compute_is_planned")
is_partially_planned = fields.Boolean('One operation is Planned', compute="_compute_is_planned")
is_planned = fields.Boolean('Its Operations are Planned', compute="_compute_is_planned", store=True)
show_final_lots = fields.Boolean('Show Final Lots', compute='_compute_show_lots')
production_location_id = fields.Many2one('stock.location', "Production Location", compute="_compute_production_location", store=True)
@@ -317,14 +316,13 @@ class MrpProduction(models.Model):
for production in self:
(self.move_raw_ids | self.move_finished_ids).date_deadline = production.date_deadline
@api.depends("workorder_ids")
def _compute_is_planned(self):
for production in self:
if production.workorder_ids:
production.is_planned = all(wo.date_planned_start and wo.date_planned_finished for wo in production.workorder_ids)
production.is_partially_planned = any(wo.date_planned_start and wo.date_planned_finished for wo in production.workorder_ids if production.state != 'draft')
production.is_planned = any(wo.date_planned_start and wo.date_planned_finished for wo in production.workorder_ids)
else:
production.is_planned = False
production.is_partially_planned = False
@api.depends('move_raw_ids.delay_alert_date')
def _compute_delay_alert_date(self):
@@ -490,7 +488,7 @@ class MrpProduction(models.Model):
any_quantity_done = any(m.quantity_done > 0 for m in order.move_raw_ids)
order.unreserve_visible = not any_quantity_done and already_reserved
order.reserve_visible = (order.is_planned or order.state in ('confirmed', 'progress', 'to_close')) and any(move.product_uom_qty and move.state in ['confirmed', 'partially_available'] for move in order.move_raw_ids)
order.reserve_visible = order.state in ('confirmed', 'progress', 'to_close') and any(move.product_uom_qty and move.state in ['confirmed', 'partially_available'] for move in order.move_raw_ids)
@api.depends('workorder_ids.state', 'move_finished_ids', 'move_finished_ids.quantity_done')
def _get_produced_qty(self):
@@ -699,7 +697,7 @@ class MrpProduction(models.Model):
if 'date_planned_start' in vals and not self.env.context.get('force_date', False):
if production.state in ['done', 'cancel']:
raise UserError(_('You cannot move a manufacturing order once it is cancelled or done.'))
if production.is_partially_planned:
if any(wo.date_planned_start and wo.date_planned_finished for wo in production.workorder_ids):
raise UserError(_('You cannot move a manufacturing order once it has a planned workorder, move related workorder(s) instead.'))
if vals.get('date_planned_start'):
production.move_raw_ids.write({'date': production.date_planned_start})
+1 -1
View File
@@ -31,7 +31,7 @@ class StockPickingType(models.Model):
return
domains = {
'count_mo_waiting': [('reservation_state', '=', 'waiting')],
'count_mo_todo': ['|', ('state', 'in', ('confirmed', 'draft', 'planned', 'progress'))],
'count_mo_todo': ['|', ('state', 'in', ('confirmed', 'draft', 'progress')), ('is_planned', '=', True)],
'count_mo_late': [('date_planned_start', '<', fields.Date.today()), ('state', '=', 'confirmed')],
}
for field in domains:
+7 -8
View File
@@ -79,7 +79,7 @@
<button name="action_confirm" attrs="{'invisible': [('state', '!=', 'draft')]}" string="Confirm" type="object" class="oe_highlight"/>
<button name="action_assign" attrs="{'invisible': ['|', ('state', 'in', ('draft', 'done', 'cancel')), ('reserve_visible', '=', False)]}" string="Check availability" type="object"/>
<button name="button_plan" attrs="{'invisible': ['|', '|', ('state', 'not in', ('confirmed', 'progress', 'to_close')), ('workorder_ids', '=', []), ('is_planned', '=', True)]}" type="object" string="Plan" class="oe_highlight"/>
<button name="button_unplan" type="object" string="Unplan" attrs="{'invisible': ['|', '|', ('state', '!=', 'planned'), ('date_planned_start', '=', False), ('date_planned_finished', '=', False)]}"/>
<button name="button_unplan" type="object" string="Unplan" attrs="{'invisible': ['|', '|', ('is_planned', '!=', 'True'), ('date_planned_start', '=', False), ('date_planned_finished', '=', False)]}"/>
<button name="button_unreserve" type="object" string="Unreserve" attrs="{'invisible': [('unreserve_visible', '=', False)]}"/>
<button name="button_scrap" type="object" string="Scrap" attrs="{'invisible': [('state', 'in', ('cancel', 'draft'))]}"/>
<field name="state" widget="statusbar" statusbar_visible="draft,confirmed,assigned,done"/>
@@ -94,7 +94,6 @@
</header>
<sheet>
<field name="reservation_state" invisible="1"/>
<field name="is_partially_planned" invisible="1"/>
<field name="date_planned_finished" invisible="1"/>
<field name="is_locked" invisible="1"/>
<field name="qty_produced" invisible="1"/>
@@ -177,7 +176,7 @@
<label for="date_planned_start"/>
<div class="o_row">
<field name="date_planned_start"
attrs="{'readonly': ['|', ('is_partially_planned', '=', True), ('state', 'in', ['close', 'cancel'])]}"
attrs="{'readonly': ['|', ('is_planned', '=', True), ('state', 'in', ['close', 'cancel'])]}"
decoration-warning="state not in ('done', 'cancel') and date_planned_start &lt; now"
decoration-danger="state not in ('done', 'cancel') and date_planned_start &lt; current_date"
decoration-bf="state not in ('done', 'cancel') and (date_planned_start &lt; current_date or date_planned_start &lt; now)"/>
@@ -217,7 +216,7 @@
<notebook>
<page string="Components" name="components">
<field name="move_raw_ids"
context="{'default_product_uom_qty': 1.0, 'default_date': date_planned_start, 'default_date_deadline': date_deadline, 'default_location_id': location_src_id, 'default_location_dest_id': production_location_id, 'default_state': 'draft', 'default_raw_material_production_id': id, 'default_picking_type_id': picking_type_id, 'default_company_id': company_id}"
context="{'default_product_uom_qty': 1.0, 'default_date': date_planned_start, 'default_date_deadline': date_deadline, 'default_location_id': location_src_id, 'default_location_dest_id': production_location_id, 'default_state': 'draft', 'default_raw_material_production_id': id, 'default_picking_type_id': picking_type_id, 'default_company_id': company_id}"
attrs="{'readonly': ['|', ('state', '=', 'cancel'), '&amp;', ('state', '=', 'done'), ('is_locked', '=', True)]}" options="{'delete': [('state', '=', 'draft')]}">
<tree default_order="is_done,sequence" editable="bottom">
<field name="product_id" force_save="1" required="1" context="{'default_type': 'product'}" attrs="{'readonly': ['|', '|', ('has_move_lines', '=', True), ('state', '=', 'cancel'), '&amp;', ('state', '!=', 'draft'), ('additional', '=', False) ]}"/>
@@ -261,7 +260,7 @@
<field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]" invisible="1"/>
<field name="state" invisible="1" force_save="1"/>
<field name="should_consume_qty" invisible="1"/>
<field name="product_uom_qty" widget="mrp_should_consume" string="To Consume" attrs="{'readonly': ['&amp;', ('parent.state', '!=', 'draft'), '|', ('parent.state', 'not in', ('confirmed', 'planned', 'progress', 'to_close')), ('parent.is_locked', '=', True)]}" width="1"/>
<field name="product_uom_qty" widget="mrp_should_consume" string="To Consume" attrs="{'readonly': ['&amp;', ('parent.state', '!=', 'draft'), '|', '&amp;', ('parent.state', 'not in', ('confirmed', 'progress', 'to_close')), ('parent.is_planned', '!=', True), ('parent.is_locked', '=', True)]}" width="1"/>
<field name="json_forecast" string="Reserved" attrs="{'column_invisible': [('parent.state', 'in', ['draft', 'done'])]}" widget="forecast_widget"/>
<field name="is_quantity_done_editable" invisible="1"/>
<field name="quantity_done" string="Consumed"
@@ -326,7 +325,7 @@
<field name="has_move_lines" invisible="1"/>
<field name="location_dest_id" domain="[('id', 'child_of', parent.location_dest_id)]" invisible="1"/>
<field name="state" invisible="1" force_save="1"/>
<field name="product_uom_qty" string="To Produce" attrs="{'readonly': ['&amp;', ('parent.state', '!=', 'draft'), '|', ('parent.state', 'not in', ('confirmed', 'planned', 'progress', 'to_close')), ('parent.is_locked', '=', True)]}"/>
<field name="product_uom_qty" string="To Produce" attrs="{'readonly': ['&amp;', ('parent.state', '!=', 'draft'), '|', '&amp;', ('parent.state', 'not in', ('confirmed', 'progress', 'to_close')), ('parent.is_planned', '!=', True), ('parent.is_locked', '=', True)]}"/>
<field name="is_quantity_done_editable" invisible="1"/>
<field name="quantity_done" string="Produced" attrs="{'column_invisible': [('parent.state', '=', 'draft')], 'readonly': [('is_quantity_done_editable', '=', False)]}"/>
<field name="product_uom" groups="uom.group_uom"/>
@@ -463,13 +462,13 @@
<field name="move_raw_ids" string="Component" filter_domain="[('move_raw_ids.product_id', 'ilike', self)]"/>
<field name="name" string="Work Center" filter_domain="[('bom_id.operation_ids.workcenter_id', 'ilike', self)]"/>
<field name="origin"/>
<filter string="To Do" name="todo" domain="[('state', 'in', ('draft', 'confirmed', 'planned','progress', 'to_close'))]"
<filter string="To Do" name="todo" domain="['|', ('state', 'in', ('draft', 'confirmed', 'progress', 'to_close')), ('is_planned', '=', True)]"
help="Manufacturing Orders which are in confirmed state."/>
<filter string="Starred" name="starred" domain="[('priority', '=', '1')]"/>
<separator/>
<filter string="Draft" name="filter_draft" domain="[('state', '=', 'draft')]"/>
<filter string="Confirmed" name="filter_confirmed" domain="[('state', '=', 'confirmed')]"/>
<filter string="Planned" name="filter_planned" domain="[('state', '=', 'planned')]" groups="mrp.group_mrp_routings"/>
<filter string="Planned" name="filter_planned" domain="[('is_planned', '=', True)]" groups="mrp.group_mrp_routings"/>
<filter string="In Progress" name="filter_in_progress" domain="[('state', '=', 'progress')]"/>
<filter string="To Close" name="filter_to_close" domain="[('state', '=', 'to_close')]"/>
<filter string="Done" name="filter_done" domain="[('state', '=', 'done')]"/>