[FIX] stock: Inventory adjustments in multi company

When making an inventory adjustment in multi company,
the default location_id was all the time taken from
'stock.warehouse0' even if the user was not allowed to read
the warehouse. Inspired from _get_default_location in pos_config.py

Backport of 8955d15e9d

opw:706704
This commit is contained in:
Goffin Simon
2017-02-08 16:49:33 +01:00
parent 7b2bc90d27
commit bd01714388
2 changed files with 16 additions and 1 deletions
+6
View File
@@ -6464,6 +6464,12 @@ msgstr ""
msgid "You may only return Done pickings"
msgstr ""
#. module: stock
#: code:addons/stock/models/stock_inventory.py:21
#, python-format
msgid "You must define a warehouse for the company: %s."
msgstr ""
#. module: stock
#: code:addons/stock/models/stock_move.py:546
#: code:addons/stock/models/stock_pack_operation.py:235
+10 -1
View File
@@ -11,6 +11,15 @@ class Inventory(models.Model):
_name = "stock.inventory"
_description = "Inventory"
@api.model
def _default_location_id(self):
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
else:
raise UserError(_('You must define a warehouse for the company: %s.') % (company_user.name,))
name = fields.Char(
'Inventory Reference',
readonly=True, required=True,
@@ -43,7 +52,7 @@ class Inventory(models.Model):
'stock.location', 'Inventoried Location',
readonly=True, required=True,
states={'draft': [('readonly', False)]},
default=lambda self: getattr(self.env.ref('stock.warehouse0', raise_if_not_found=False) or self.env['stock.warehouse'], 'lot_stock_id').id)
default=_default_location_id)
product_id = fields.Many2one(
'product.product', 'Inventoried Product',
readonly=True,