From 93d69933acc9454a5741fe6eb39edd9cdae9fbf1 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 27 Feb 2018 11:09:02 +0100 Subject: [PATCH] [FIX] stock: Wrong production/scrap/adjustment location used in multicompany - When using perpetual inventory valuation, the accounts used for scrap, manufacturing, and inventory adjustment operations are set on the corresponding locations . - In a multicompany environment, you will have a separate chart of accounts for each company. - Account fields on locations are not property fields. - Therefore, in order to separate the accounting of manufacturing, scrap, and inventory adjustment operations, you must use a location for each operation for each company. - Set up one location for each company for scrap, production, and adjustment locations, setting the company field on each. Bug: - When attempting to create a MO, inventory adjustment, or scrap order while signed in to the second company, you will receive a permissions error on stock.location. Fix: - Now the right location is taken according to the company of the user. Backport of this commit: c7526407ab4cf4c3d338f50a0259ac803e89f91f opw:1817339 --- addons/stock/models/stock_scrap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/stock/models/stock_scrap.py b/addons/stock/models/stock_scrap.py index 7707ea90523..7db6715a5fe 100644 --- a/addons/stock/models/stock_scrap.py +++ b/addons/stock/models/stock_scrap.py @@ -10,10 +10,14 @@ class StockScrap(models.Model): _order = 'id desc' def _get_default_scrap_location_id(self): - return self.env['stock.location'].search([('scrap_location', '=', True)], limit=1).id + return self.env['stock.location'].search([('scrap_location', '=', True), ('company_id', 'in', [self.env.user.company_id.id, False])], limit=1).id def _get_default_location_id(self): - return self.env.ref('stock.stock_location_stock', raise_if_not_found=False) + company_user = self.env.user.company_id + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) + if warehouse: + return warehouse.lot_stock_id.id + return None name = fields.Char( 'Reference', default=lambda self: _('New'),