[FIX] stock: add correctly a product in storage categories

Steps to reproduce the bug:
- Connect as Admin and select “My Company (San Francisco)”
- Create a storable product “P1” and select “My Company (San Francisco)” in the `”company”` field
- Go to inventory settings and enable the “Storage Categories” option
- Create a new “Storage Categorie” > select “My Company (San Francisco)” in the `”company”` field > save

BUG1:  Edit and try to add the product “P1” > Edit and try to add the product “P1”
> "P1" is not filtered correctly with domain, because the `”company”` field of the `"stock.storage.category.capacity"` model is not set.
As it's a related field, the “default_company_id” should be in the context so that the “company_id” field will be correctly set with this value

BUG2: Add a new line > create and edit a new product > the product type is “consumable” instead of storable, so we should add the type in the context

BUG3: Add multi-company security rule

opw-2689426

closes odoo/odoo#80061

X-original-commit: f5554fa94d41d7eae62c4a1271e41012178c4d8f
Signed-off-by: Arnold Moyaux <arm@odoo.com>
Signed-off-by: Djamel Touati (otd) <otd@odoo.com>
This commit is contained in:
Touati Djamel (otd)
2021-11-19 08:08:51 +00:00
parent e206b8a80e
commit 4f386b0dec
3 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ class Location(models.Model):
next_inventory_date = fields.Date("Next Expected Inventory", compute="_compute_next_inventory_date", store=True, help="Date for next planned inventory based on cyclic schedule.")
warehouse_view_ids = fields.One2many('stock.warehouse', 'view_location_id', readonly=True)
warehouse_id = fields.Many2one('stock.warehouse', compute='_compute_warehouse_id')
storage_category_id = fields.Many2one('stock.storage.category', string='Storage Category')
storage_category_id = fields.Many2one('stock.storage.category', string='Storage Category', check_company=True)
outgoing_move_line_ids = fields.One2many('stock.move.line', 'location_id', help='Technical: used to compute weight.')
incoming_move_line_ids = fields.One2many('stock.move.line', 'location_dest_id', help='Technical: used to compute weight.')
net_weight = fields.Float('Net Weight', compute="_compute_weight")
+6
View File
@@ -175,5 +175,11 @@
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="stock_storage_category_rule">
<field name="name">stock_storage_category multi-company</field>
<field name="model_id" ref="model_stock_storage_category"/>
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
</data>
</odoo>
@@ -25,7 +25,7 @@
</group>
<notebook>
<page string="Capacity by Package" name="package_capacity" groups="stock.group_tracking_lot">
<field name="package_capacity_ids" context="{'default_storage_category_id': id}">
<field name="package_capacity_ids" context="{'default_storage_category_id': id, 'default_company_id': company_id}">
<tree editable="bottom">
<field name="package_type_id" required="1"/>
<field name="quantity"/>
@@ -34,9 +34,9 @@
</field>
</page>
<page string="Capacity by Product" name="product_capacity">
<field name="product_capacity_ids" context="{'default_storage_category_id': id}">
<field name="product_capacity_ids" context="{'default_storage_category_id': id, 'default_company_id': company_id}">
<tree editable="bottom">
<field name="product_id" required="1"/>
<field name="product_id" required="1" context="{'default_detailed_type': 'product'}"/>
<field name="quantity"/>
<field name="product_uom_id" options="{'no_create': True, 'no_open': True}"/>
<field name="company_id" invisible="1"/>