[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: c7526407ab

opw:1817339
This commit is contained in:
Goffin Simon
2018-10-31 11:51:09 +01:00
parent 9cc8a8d0a4
commit 93d69933ac
+6 -2
View File
@@ -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'),