[FIX] Fix no UoM restriction on Min/Max rules

lp bug: https://launchpad.net/bugs/10003350 fixed

bzr revid: qt@tempo-consulting.fr-20120523110439-zwq3zbq41kty7w8g
This commit is contained in:
Quentin THEURET
2012-05-23 13:04:39 +02:00
parent 742124c840
commit f6b512c686
2 changed files with 35 additions and 2 deletions
+34 -1
View File
@@ -503,6 +503,19 @@ class stock_warehouse_orderpoint(osv.osv):
result[orderpoint.id] = procurement_ids
return result
def _check_product_uom(self, cr, uid, ids, context=None):
'''
Check if the UoM has the same category as the product standard UoM
'''
if not context:
context = {}
for rule in self.browse(cr, uid, ids, context=context):
if rule.product_id.uom_id.category_id.id != rule.product_uom.category_id.id:
return False
return True
_columns = {
'name': fields.char('Name', size=32, required=True),
'active': fields.boolean('Active', help="If the active field is set to False, it will allow you to hide the orderpoint without removing it."),
@@ -535,6 +548,9 @@ class stock_warehouse_orderpoint(osv.osv):
_sql_constraints = [
('qty_multiple_check', 'CHECK( qty_multiple > 0 )', 'Qty Multiple must be greater than zero.'),
]
_constraints = [
(_check_product_uom, 'You have to select a product UOM in the same category than the purchase UOM of the product', ['product_id', 'product_uom']),
]
def default_get(self, cr, uid, fields, context=None):
res = super(stock_warehouse_orderpoint, self).default_get(cr, uid, fields, context)
@@ -565,8 +581,25 @@ class stock_warehouse_orderpoint(osv.osv):
"""
if product_id:
prod = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
d = {'product_uom': [('category_id', '=', prod.uom_id.category_id.id)]}
v = {'product_uom': prod.uom_id.id}
return {'value': v}
return {'value': v, 'domain': d}
return {'domain': {'product_uom': []}}
def onchange_uom(self, cr, uid, ids, product_id, uom_id, context=None):
'''
Check if the UoM is compatible with product standard UoM
'''
if uom_id and product_id:
product_obj = self.pool.get('product.product')
uom_obj = self.pool.get('product.uom')
product = product_obj.browse(cr, uid, product_id, context=context)
uom = uom_obj.browse(cr, uid, uom_id, context=context)
if product.uom_id.category_id.id != uom.category_id.id:
raise osv.except_osv(_('Wrong Product UOM !'), _('You have to select a product UOM in the same category than the purchase UOM of the product'))
return {}
def copy(self, cr, uid, id, default=None, context=None):
+1 -1
View File
@@ -206,7 +206,7 @@
<separator string="General Information" colspan="2" />
<field name="name" />
<field name="product_id" on_change="onchange_product_id(product_id)"/>
<field name="product_uom"/>
<field name="product_uom" on_change="onchange_uom(product_id, product_uom)" />
</group>
<group col="2" colspan="2">
<separator string="Locations" colspan="2" />