[FIX] stock: forbids possibility to make inventory of all products when a given product is chosen

opw-634388
Fixes #6512
This commit is contained in:
Nicolas Martinelli 2015-05-05 14:26:17 +02:00
parent 0e5e8d2873
commit 561346db9e
3 changed files with 15 additions and 1 deletions

View File

@ -2744,6 +2744,18 @@ class stock_inventory(osv.osv):
vals.append(product_line)
return vals
def _check_filter_product(self, cr, uid, ids, context=None):
for inventory in self.browse(cr, uid, ids, context=context):
if inventory.filter not in ('product', 'product_owner') and inventory.product_id:
return False
return True
def onchange_filter(self, cr, uid, ids, filter):
return {'value': {'product_id': False} if filter not in ('product', 'product_owner') else {}}
_constraints = [
(_check_filter_product, 'A specific product is chosen while the filter "One product only" is not selected', ['product_id', 'filter']),
]
class stock_inventory_line(osv.osv):
_name = "stock.inventory.line"

View File

@ -102,7 +102,7 @@
<group>
<group>
<field name="location_id" domain="[('usage','not in', ['supplier','production'])]"/>
<field name="filter" string="Inventory of" widget='radio' attrs="{'readonly': [('state', '!=', 'draft')]}"/>
<field name="filter" string="Inventory of" widget='radio' attrs="{'readonly': [('state', '!=', 'draft')]}" on_change="onchange_filter(filter)"/>
</group>
<group>
<field name="date"/>

View File

@ -9,6 +9,7 @@
-
!record {model: stock.inventory, id: inventory_test0}:
name: Test
filter: product
product_id: inventory_product
-
I confirm the inventory and check that my inventory has no line, as the product is a new one.
@ -60,6 +61,7 @@
-
!record {model: stock.inventory, id: inventory_test1}:
name: second test inventory
filter: product
product_id: inventory_product
-
I confirm the inventory and check that my inventory has one line, with a quantity of 10.