diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index cee53282976..c55a5ec7d20 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -53,7 +53,7 @@ class StockQuant(models.Model): product_id = fields.Many2one( 'product.product', 'Product', domain=lambda self: self._domain_product_id(), - ondelete='restrict', readonly=True, required=True, index=True, check_company=True) + ondelete='restrict', required=True, index=True, check_company=True) product_tmpl_id = fields.Many2one( 'product.template', string='Product Template', related='product_id.product_tmpl_id') @@ -64,18 +64,18 @@ class StockQuant(models.Model): location_id = fields.Many2one( 'stock.location', 'Location', domain=lambda self: self._domain_location_id(), - auto_join=True, ondelete='restrict', readonly=True, required=True, index=True, check_company=True) + auto_join=True, ondelete='restrict', required=True, index=True, check_company=True) lot_id = fields.Many2one( 'stock.production.lot', 'Lot/Serial Number', index=True, - ondelete='restrict', readonly=True, check_company=True, + ondelete='restrict', check_company=True, domain=lambda self: self._domain_lot_id()) package_id = fields.Many2one( 'stock.quant.package', 'Package', domain="[('location_id', '=', location_id)]", - help='The package containing this quant', readonly=True, ondelete='restrict', check_company=True) + help='The package containing this quant', ondelete='restrict', check_company=True) owner_id = fields.Many2one( 'res.partner', 'Owner', - help='This is the owner of the quant', readonly=True, check_company=True) + help='This is the owner of the quant', check_company=True) quantity = fields.Float( 'Quantity', help='Quantity of products in this quant, in the default unit of measure of the product', @@ -201,6 +201,15 @@ class StockQuant(models.Model): res._check_company() return res + def _load_records_create(self, values): + """ Add default location if import file did not fill it""" + company_user = self.env.company + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1) + for value in values: + if 'location_id' not in value: + value['location_id'] = warehouse.lot_stock_id.id + return super()._load_records_create(values) + @api.model def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): """ Override to set the `inventory_quantity` field if we're in "inventory mode" as well diff --git a/addons/stock/security/ir.model.access.csv b/addons/stock/security/ir.model.access.csv index ce8729cf0a5..3a081dd3345 100644 --- a/addons/stock/security/ir.model.access.csv +++ b/addons/stock/security/ir.model.access.csv @@ -27,8 +27,7 @@ access_product_group_res_partner_stock_manager,res_partner group_stock_manager,b access_product_pricelist_item_stock_manager,product.pricelist.item stock_manager,product.model_product_pricelist_item,stock.group_stock_manager,1,1,1,1 access_stock_warehouse_orderpoint,stock.warehouse.orderpoint,model_stock_warehouse_orderpoint,stock.group_stock_user,1,0,0,0 access_stock_warehouse_orderpoint_system,stock.warehouse.orderpoint system,model_stock_warehouse_orderpoint,stock.group_stock_manager,1,1,1,1 -access_stock_quant_manager,stock.quant manager,model_stock_quant,stock.group_stock_manager,1,0,0,0 -access_stock_quant_user,stock.quant user,model_stock_quant,stock.group_stock_user,1,0,0,0 +access_stock_quant_user,stock.quant user,model_stock_quant,stock.group_stock_user,1,1,1,0 access_stock_quant_all,stock.quant all users,model_stock_quant,base.group_user,1,0,0,0 access_stock_quant_package_all,stock.quant.package all users,model_stock_quant_package,base.group_user,1,0,0,0 access_stock_quant_package_stock_manager,stock.quant.package stock manager,model_stock_quant_package,stock.group_stock_manager,1,1,1,1 diff --git a/addons/stock/tests/test_quant.py b/addons/stock/tests/test_quant.py index b37de9685bb..cb7b8b5679e 100644 --- a/addons/stock/tests/test_quant.py +++ b/addons/stock/tests/test_quant.py @@ -491,8 +491,8 @@ class StockQuant(TransactionCase): self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product_serial, self.stock_location, lot_id=lot1), 1.0) def test_access_rights_1(self): - """ Directly update the quant with a user with or without stock access rights sould raise - an AccessError. + """ Directly update the quant with a user with or without stock access rights should not raise + an AccessError only deletion will. """ quant = self.env['stock.quant'].create({ 'product_id': self.product.id, @@ -512,16 +512,14 @@ class StockQuant(TransactionCase): quant.with_user(self.demo_user).unlink() self.env = self.env(user=self.stock_user) + self.env['stock.quant'].create({ + 'product_id': self.product.id, + 'location_id': self.stock_location.id, + 'quantity': 1.0, + }) + quant.with_user(self.stock_user).with_context(inventory_mode=True).write({'quantity': 3.0}) with self.assertRaises(AccessError): - self.env['stock.quant'].create({ - 'product_id': self.product.id, - 'location_id': self.stock_location.id, - 'quantity': 1.0, - }) - with self.assertRaises(AccessError): - quant.with_user(self.demo_user).write({'quantity': 2.0}) - with self.assertRaises(AccessError): - quant.with_user(self.demo_user).unlink() + quant.with_user(self.stock_user).unlink() def test_in_date_1(self): """ Check that no incoming date is set when updating the quantity of an untracked quant. diff --git a/addons/stock/views/stock_quant_views.xml b/addons/stock/views/stock_quant_views.xml index 1645b5b0f0e..ccbbf797d2b 100644 --- a/addons/stock/views/stock_quant_views.xml +++ b/addons/stock/views/stock_quant_views.xml @@ -122,7 +122,7 @@ @@ -340,7 +340,7 @@ stock.quant - +