Rifakat (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.0-bug-734686-rha into 
lp:openobject-addons/6.0.

Requested reviews:
  Raphael Collet (OpenERP) (rco-openerp)
Related bugs:
  Bug #734686 in OpenERP Addons: "Name of unit of measurements should be unique 
per category"
  https://bugs.launchpad.net/openobject-addons/+bug/734686

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-734686-rha/+merge/78235

Hello,

Added constraint for unique UoM per category. Same UoM can be created for 
different categories but can not be created category within.

Kindly review it.
Best regards,
Rifakat
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-734686-rha/+merge/78235
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.0-bug-734686-rha.
=== modified file 'account/report/account_print_invoice.sxw'
Binary files account/report/account_print_invoice.sxw	2011-01-14 00:11:01 +0000 and account/report/account_print_invoice.sxw	2011-10-05 11:26:24 +0000 differ
=== modified file 'product/product.py'
--- product/product.py	2011-09-05 10:26:44 +0000
+++ product/product.py	2011-10-05 11:26:24 +0000
@@ -92,6 +92,14 @@
                 data['factor'] = self._compute_factor_inv(data['factor_inv'])
             del(data['factor_inv'])
         return super(product_uom, self).create(cr, uid, data, context)
+    
+    def _check_uom_per_categ(self, cr, uid, ids, context=None):
+        uom = self.browse(cr, uid, ids, context=context)[0]
+        all_uoms = self.search(cr, uid, [('category_id','=',uom.category_id.id), ('id','not in', ids)], context=context)
+        for categ_uom in self.browse(cr, uid, all_uoms, context=context):
+            if uom.name == categ_uom.name:
+                return False
+        return True
 
     _columns = {
         'name': fields.char('Name', size=64, required=True, translate=True),
@@ -123,6 +131,10 @@
     _sql_constraints = [
         ('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!'),
     ]
+    
+    _constraints = [
+        (_check_uom_per_categ, 'UoM already exists for this category! ', ['name'])
+    ]
 
     def _compute_qty(self, cr, uid, from_uom_id, qty, to_uom_id=False):
         if not from_uom_id or not qty or not to_uom_id:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to