From 306f6423f32f6811ecf612aba5b67bc6d56e5f93 Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Fri, 10 Apr 2020 12:49:32 +0000 Subject: [PATCH] [FIX] mrp: customize unbuild form via manufacturing order When unbuilding a manufacturing order, there are fields in the default unbuild form that do not make sense to show (i.e. they already correspond to the manufacturing order that is triggering the unbuild). Therefore we make a simplified version of this form that is better suited for a button generated window. This change includes removing the resetting of 'location_id' and 'location_dest_id' when they correspond to the 'company_id' by onchange function since this would overwrite any 'default_location_id' and 'location_dest_id' values when calling the view + this seemed like it would be annoying if someone clicks on the same 'company_id' within the dropdown and their location values changed. closes odoo/odoo#49514 Task: 2234872 X-original-commit: d23341a5b4cb82f4a96b55464dec32dc28ce4351 Signed-off-by: Simon Lejeune (sle) --- addons/mrp/models/mrp_production.py | 10 +++++-- addons/mrp/models/mrp_unbuild.py | 6 ++-- addons/mrp/views/mrp_unbuild_views.xml | 39 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 0ffb2dd4d76..d8b7ee57394 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -1195,11 +1195,15 @@ class MrpProduction(models.Model): def button_unbuild(self): self.ensure_one() return { - 'name': _('Unbuild'), + 'name': _('Unbuild: %s') % self.product_id.display_name, 'view_mode': 'form', 'res_model': 'mrp.unbuild', - 'view_id': self.env.ref('mrp.mrp_unbuild_form_view').id, + 'view_id': self.env.ref('mrp.mrp_unbuild_form_view_simplified').id, 'type': 'ir.actions.act_window', - 'context': {'default_mo_id': self.id, 'create': False, 'edit': False}, + 'context': {'default_mo_id': self.id, + 'default_company_id': self.company_id.id, + 'default_location_id': self.location_dest_id.id, + 'default_location_dest_id': self.location_src_id.id, + 'create': False, 'edit': False}, 'target': 'new', } diff --git a/addons/mrp/models/mrp_unbuild.py b/addons/mrp/models/mrp_unbuild.py index 30d665a36bd..af5c26a8fa4 100644 --- a/addons/mrp/models/mrp_unbuild.py +++ b/addons/mrp/models/mrp_unbuild.py @@ -96,8 +96,10 @@ class MrpUnbuild(models.Model): def _onchange_company_id(self): if self.company_id: warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.company_id.id)], limit=1) - self.location_id = warehouse.lot_stock_id - self.location_dest_id = warehouse.lot_stock_id + if self.location_id.company_id != self.company_id: + self.location_id = warehouse.lot_stock_id + if self.location_dest_id.company_id != self.company_id: + self.location_dest_id = warehouse.lot_stock_id else: self.location_id = False self.location_dest_id = False diff --git a/addons/mrp/views/mrp_unbuild_views.xml b/addons/mrp/views/mrp_unbuild_views.xml index aa95ba19e88..246b807ccd0 100644 --- a/addons/mrp/views/mrp_unbuild_views.xml +++ b/addons/mrp/views/mrp_unbuild_views.xml @@ -130,6 +130,45 @@ + + + mrp.unbuild.form.simplified + mrp.unbuild + +
+ + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + mrp.unbuild.tree mrp.unbuild