[IMP] stock: allow importing quants

As the inventory adjustments have been removed in favour of the editable
quants, this commit introduced the possibility to import pre counted
quants like non validated inventories back then.

task : 2555118

Part-of: odoo/odoo#74715
This commit is contained in:
William Henrotin
2021-09-02 12:57:31 +00:00
parent 0624e3f728
commit 04beff906d
4 changed files with 26 additions and 20 deletions
+14 -5
View File
@@ -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
+1 -2
View File
@@ -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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
27 access_product_pricelist_item_stock_manager product.pricelist.item stock_manager product.model_product_pricelist_item stock.group_stock_manager 1 1 1 1
28 access_stock_warehouse_orderpoint stock.warehouse.orderpoint model_stock_warehouse_orderpoint stock.group_stock_user 1 0 0 0
29 access_stock_warehouse_orderpoint_system stock.warehouse.orderpoint system model_stock_warehouse_orderpoint stock.group_stock_manager 1 1 1 1
30 access_stock_quant_manager access_stock_quant_user stock.quant manager stock.quant user model_stock_quant stock.group_stock_manager stock.group_stock_user 1 0 1 0 1 0
access_stock_quant_user stock.quant user model_stock_quant stock.group_stock_user 1 0 0 0
31 access_stock_quant_all stock.quant all users model_stock_quant base.group_user 1 0 0 0
32 access_stock_quant_package_all stock.quant.package all users model_stock_quant_package base.group_user 1 0 0 0
33 access_stock_quant_package_stock_manager stock.quant.package stock manager model_stock_quant_package stock.group_stock_manager 1 1 1 1
+9 -11
View File
@@ -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.
+2 -2
View File
@@ -122,7 +122,7 @@
<field eval="10" name="priority"/>
<field name="arch" type="xml">
<tree editable="bottom"
create="1" edit="1" import="0" js_class="singleton_list"
create="1" edit="1" js_class="singleton_list"
sample="1">
<field name="id" invisible="1"/>
<field name="tracking" invisible="1"/>
@@ -340,7 +340,7 @@
<field name="model">stock.quant</field>
<field eval="10" name="priority"/>
<field name="arch" type="xml">
<tree default_order="location_id, inventory_date, product_id, package_id, lot_id, owner_id" decoration-warning='is_outdated' editable="bottom" create="1" edit="1" import="0" js_class="singleton_list" sample="1">
<tree default_order="location_id, inventory_date, product_id, package_id, lot_id, owner_id" decoration-warning='is_outdated' editable="bottom" create="1" edit="1" import="1" js_class="singleton_list" sample="1">
<header>
<button name="stock.action_stock_inventory_adjustement_name" groups="stock.group_stock_manager" type="action" string="Apply"/>
<button name="action_set_inventory_quantity" type="object" string="Set"/>