[IMP] stock: allow product creation in inventory adjustment

Previous to this comment, creating new products during an inventory
adjustment was not possible (within stock app, was possible within
barcode app). Now it is possible to create new products within
stock.inventory form 'product_ids'. Additionally the
stock.inventory.line tree 'product_id' will also allow creation of
new products only when there are no 'product_ids' assigned. By
default these new products will have 'type'='product' (storable).

Specification 2 of inventory onboarding improvements
Task: 2220129
Related ENT PR: odoo/enterprise#10719
This commit is contained in:
Tiffany Chang (tic)
2020-06-18 08:13:01 +00:00
parent eb74c3cf42
commit dccc22293a
2 changed files with 20 additions and 3 deletions
+5 -1
View File
@@ -168,7 +168,6 @@ class Inventory(models.Model):
self.ensure_one()
action = {
'type': 'ir.actions.act_window',
'views': [(self.env.ref('stock.stock_inventory_line_tree').id, 'tree')],
'view_mode': 'tree',
'name': _('Inventory Lines'),
'res_model': 'stock.inventory.line',
@@ -190,8 +189,13 @@ class Inventory(models.Model):
context['readonly_location_id'] = True
if self.product_ids:
# no_create on product_id field
action['view_id'] = self.env.ref('stock.stock_inventory_line_tree_no_product_create').id
if len(self.product_ids) == 1:
context['default_product_id'] = self.product_ids[0].id
else:
# no product_ids => we're allowed to create new products in tree
action['view_id'] = self.env.ref('stock.stock_inventory_line_tree').id
action['context'] = context
action['domain'] = domain
+15 -2
View File
@@ -13,7 +13,8 @@
<field name="product_tracking" invisible="1"/>
<field name="is_editable" invisible="1"/>
<field name="outdated" invisible="1"/>
<field name="product_id" options="{'no_create': True}" width="1.6"
<field name="product_id" width="1.6"
context="{'default_type': 'product'}"
readonly="context.get('default_product_id', False)"
attrs="{'readonly': ['|',
('is_editable', '=', False),
@@ -56,6 +57,17 @@
</field>
</record>
<record id="stock_inventory_line_tree_no_product_create" model="ir.ui.view">
<field name="name">stock.inventory.line.tree2</field>
<field name="model">stock.inventory.line</field>
<field name="inherit_id" ref="stock.stock_inventory_line_tree"/>
<field name="mode">primary</field>
<field name="priority">1000</field>
<field name="arch" type="xml">
<field name="product_id" position="attributes"><attribute name="options">{'no_create': True}</attribute></field>
</field>
</record>
<record id="stock_inventory_line_search" model="ir.ui.view">
<field name="name">stock.inventory.line.search</field>
<field name="model">stock.inventory.line</field>
@@ -180,7 +192,8 @@
widget="many2many_tags"
force_save="1"
groups="stock.group_stock_multi_locations"/>
<field name="product_ids" options="{'no_create': True}"
<field name="product_ids"
context="{'default_type': 'product'}"
widget="many2many_tags"/>
<field name="exhausted"/>
</group>