mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
Fixes, and add migration script
This commit is contained in:
committed by
JasminSForgeFlow
parent
93204c0fc2
commit
35ec623834
@@ -1,7 +1,7 @@
|
||||
# Copyright 2016 Ucamco - Wim Audenaert <wim.audenaert@ucamco.com>
|
||||
# Copyright 2016-18 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import ast
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
@@ -41,11 +41,19 @@ class Product(models.Model):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
ctx = ast.literal_eval(result.get('context'))
|
||||
if not ctx:
|
||||
ctx = {}
|
||||
mrp_areas = self.env['mrp.area'].search([])
|
||||
if len(mrp_areas) == 1:
|
||||
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
|
||||
area_ids = self.mrp_area_ids.ids
|
||||
ctx.update({'default_product_id': self.id})
|
||||
if self.mrp_area_count != 1:
|
||||
result['domain'] = [('id', 'in', area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = area_ids[0]
|
||||
result['context'] = ctx
|
||||
return result
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import ast
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
@@ -28,12 +28,22 @@ class ProductTemplate(models.Model):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('mrp_multi_level.product_mrp_area_action')
|
||||
result = action.read()[0]
|
||||
ctx = ast.literal_eval(result.get('context'))
|
||||
mrp_areas = self.env['mrp.area'].search([])
|
||||
if 'context' not in result:
|
||||
result['context'] = {}
|
||||
if len(mrp_areas) == 1:
|
||||
ctx.update({'default_mrp_area_id': mrp_areas[0].id})
|
||||
mrp_area_ids = self.with_context(
|
||||
active_test=False).mrp_area_ids.ids
|
||||
if len(self.product_variant_ids) == 1:
|
||||
variant = self.product_variant_ids[0]
|
||||
ctx.update({'default_product_id': variant.id})
|
||||
if len(mrp_area_ids) != 1:
|
||||
result['domain'] = [('id', 'in', mrp_area_ids)]
|
||||
else:
|
||||
res = self.env.ref('mrp_multi_level.product_mrp_area_form', False)
|
||||
result['views'] = [(res and res.id or False, 'form')]
|
||||
result['res_id'] = mrp_area_ids[0]
|
||||
result['context'] = ctx
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user