[FIX] mrp: multi-companies default location
Before this commit, in a multi-companies when the user can manage
multiple stock locations, there is an error with the default Locations
('default location' and 'default Destination Location' in an Unbuild
Orders; and 'Raw Materials Location' and 'Finished Products Location' in
a Manufacturing Orders). The default gives the stock location of the
first company, if we are working in a different company it will generate
an access error. Also, in an Unbuild Order you could choose location
that there are not internal at the company.
Now, the default location, it's the one of the first Warehouse of the
company. And the form only propose to choose internal locations.
OPW-1919771
closes odoo/odoo#30585
This commit is contained in:
@@ -6,7 +6,7 @@ import math
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons import decimal_precision as dp
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import AccessError, UserError
|
||||
from odoo.tools import float_compare
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
@@ -31,6 +31,10 @@ class MrpProduction(models.Model):
|
||||
location = self.env['stock.picking.type'].browse(self.env.context['default_picking_type_id']).default_location_src_id
|
||||
if not location:
|
||||
location = self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
try:
|
||||
location.check_access_rule('read')
|
||||
except (AttributeError, AccessError):
|
||||
location = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id
|
||||
return location and location.id or False
|
||||
|
||||
@api.model
|
||||
@@ -40,6 +44,10 @@ class MrpProduction(models.Model):
|
||||
location = self.env['stock.picking.type'].browse(self.env.context['default_picking_type_id']).default_location_dest_id
|
||||
if not location:
|
||||
location = self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
try:
|
||||
location.check_access_rule('read')
|
||||
except (AttributeError, AccessError):
|
||||
location = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id
|
||||
return location and location.id or False
|
||||
|
||||
name = fields.Char(
|
||||
@@ -296,6 +304,10 @@ class MrpProduction(models.Model):
|
||||
@api.onchange('picking_type_id')
|
||||
def onchange_picking_type(self):
|
||||
location = self.env.ref('stock.stock_location_stock')
|
||||
try:
|
||||
location.check_access_rule('read')
|
||||
except (AttributeError, AccessError):
|
||||
location = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id
|
||||
self.location_src_id = self.picking_type_id.default_location_src_id.id or location.id
|
||||
self.location_dest_id = self.picking_type_id.default_location_dest_id.id or location.id
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import AccessError, UserError
|
||||
from odoo.tools import float_compare
|
||||
|
||||
|
||||
@@ -13,10 +13,20 @@ class MrpUnbuild(models.Model):
|
||||
_order = 'id desc'
|
||||
|
||||
def _get_default_location_id(self):
|
||||
return self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
stock_location = self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
try:
|
||||
stock_location.check_access_rule('read')
|
||||
return stock_location.id
|
||||
except (AttributeError, AccessError):
|
||||
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id.id
|
||||
|
||||
def _get_default_location_dest_id(self):
|
||||
return self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
stock_location = self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
|
||||
try:
|
||||
stock_location.check_access_rule('read')
|
||||
return stock_location.id
|
||||
except (AttributeError, AccessError):
|
||||
return self.env['stock.warehouse'].search([('company_id', '=', self.env.user.company_id.id)], limit=1).lot_stock_id.id
|
||||
|
||||
name = fields.Char('Reference', copy=False, readonly=True, default=lambda x: _('New'))
|
||||
product_id = fields.Many2one(
|
||||
|
||||
@@ -123,8 +123,8 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="mo_id" domain="[('state','=','done')]"/>
|
||||
<field name="location_id" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="location_dest_id" groups="stock.group_stock_multi_locations"/>
|
||||
<field name="location_id" groups="stock.group_stock_multi_locations" domain="[('usage','=','internal')]"/>
|
||||
<field name="location_dest_id" groups="stock.group_stock_multi_locations" domain="[('usage','=','internal')]"/>
|
||||
<field name="has_tracking" invisible="1"/>
|
||||
<field name="lot_id" attrs="{'invisible': [('has_tracking', '=', 'none')], 'required': [('has_tracking', '!=', 'none')]}" groups="stock.group_production_lot"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user