Improving the management of planned orders:

* Add menu entry for planned orders
  * Add button to navigate from planned orders to linked manufacturing orders
  * Add action to convert planned orders to fixed
  * When changing the due date in a planned order the release date is recomputed
This commit is contained in:
Jordi Ballester Alomar
2020-03-26 10:52:38 +01:00
committed by JasminSForgeFlow
parent da891f212a
commit 15eee3405f
4 changed files with 170 additions and 1 deletions

View File

@@ -1,8 +1,9 @@
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
# - Lois Rilo Antelo <lois.rilo@forgeflow.com>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from datetime import timedelta
from odoo import fields, models
from odoo import api, fields, models
class MrpPlannedOrder(models.Model):
@@ -70,3 +71,38 @@ class MrpPlannedOrder(models.Model):
comodel_name="mrp.inventory",
ondelete="set null",
)
mrp_production_ids = fields.One2many(
"mrp.production", "planned_order_id", string="Manufacturing Orders"
)
mo_count = fields.Integer(compute="_compute_mrp_production_count")
def _compute_mrp_production_count(self):
for rec in self:
rec.mo_count = len(rec.mrp_production_ids)
@api.onchange("due_date")
def _onchange_due_date(self):
if self.due_date:
if self.product_mrp_area_id.mrp_lead_time:
calendar = self.mrp_area_id.calendar_id
if calendar:
dt = fields.Datetime.from_string(self.due_date)
res = calendar.plan_days(
-1 * (self.product_mrp_area_id.mrp_lead_time + 1), dt
)
self.order_release_date = res.date()
else:
self.order_release_date = fields.Date.from_string(
self.due_date
) - timedelta(days=self.product_mrp_area_id.mrp_lead_time)
def action_toggle_fixed(self):
for rec in self:
rec.fixed = not rec.fixed
def action_open_linked_mrp_production(self):
action = self.env.ref("mrp.mrp_production_action")
result = action.read()[0]
result["context"] = {}
result["domain"] = "[('id','in',%s)]" % self.mrp_production_ids.ids
return result