[FIX] purchase: Use .get instead of an eval
authorStephane Wirtel <stephane@openerp.com>
Fri, 3 Sep 2010 10:10:26 +0000 (12:10 +0200)
committerStephane Wirtel <stephane@openerp.com>
Fri, 3 Sep 2010 10:10:26 +0000 (12:10 +0200)
bzr revid: stephane@openerp.com-20100903101026-xkkx4rt0iwv9cmqe

addons/purchase/purchase.py

index 72bbf97..7883da5 100644 (file)
@@ -145,6 +145,14 @@ class purchase_order(osv.osv):
                 res[purchase.id] = False
         return res
 
+    STATE_SELECTION = [('draft', 'Request for Quotation'),
+                       ('wait', 'Waiting'),
+                       ('confirmed', 'Confirmed'),
+                       ('approved', 'Approved'),
+                       ('except_picking', 'Shipping Exception'),
+                       ('except_invoice', 'Invoice Exception'),
+                       ('done', 'Done'),
+                       ('cancel', 'Cancelled')]
     _columns = {
         'name': fields.char('Order Reference', size=64, required=True, select=True),
         'origin': fields.char('Origin', size=64,
@@ -165,7 +173,7 @@ class purchase_order(osv.osv):
 
         'pricelist_id':fields.many2one('product.pricelist', 'Pricelist', required=True, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}, help="The pricelist sets the currency used for this purchase order. It also computes the supplier price for the selected products/quantities."),
 
-        'state': fields.selection([('draft', 'Request for Quotation'), ('wait', 'Waiting'), ('confirmed', 'Confirmed'), ('approved', 'Approved'),('except_picking', 'Shipping Exception'), ('except_invoice', 'Invoice Exception'), ('done', 'Done'), ('cancel', 'Cancelled')], 'Order Status', readonly=True, help="The state of the purchase order or the quotation request. A quotation is a purchase order in a 'Draft' state. Then the order has to be confirmed by the user, the state switch to 'Confirmed'. Then the supplier must confirm the order to change the state to 'Approved'. When the purchase order is paid and received, the state becomes 'Done'. If a cancel action occurs in the invoice or in the reception of goods, the state becomes in exception.", select=True),
+        'state': fields.selection(STATE_SELECTION, 'Order Status', readonly=True, help="The state of the purchase order or the quotation request. A quotation is a purchase order in a 'Draft' state. Then the order has to be confirmed by the user, the state switch to 'Confirmed'. Then the supplier must confirm the order to change the state to 'Approved'. When the purchase order is paid and received, the state becomes 'Done'. If a cancel action occurs in the invoice or in the reception of goods, the state becomes in exception.", select=True),
         'order_line': fields.one2many('purchase.order.line', 'order_id', 'Order Lines', states={'approved':[('readonly',True)],'done':[('readonly',True)]}),
         'validator' : fields.many2one('res.users', 'Validated by', readonly=True),
         'notes': fields.text('Notes'),
@@ -217,8 +225,7 @@ class purchase_order(osv.osv):
             if s['state'] in ['draft','cancel']:
                 unlink_ids.append(s['id'])
             else:
-                state_dict = {'wait':'Waiting','confirmed':'Confirmed','approved':'Approved','except_picking': 'Shipping Exception','except_invoice': 'Invoice Exception','done': 'Done'}
-                raise osv.except_osv(_('Invalid action !'), _('Cannot delete Purchase Order(s) which are in %s State!')  %_(eval(s['state'],state_dict)))
+                raise osv.except_osv(_('Invalid action !'), _('Cannot delete Purchase Order(s) which are in %s State!')  %_(dict(purchase_order.STATE_SELECTION).get(s['state'])))
 
         # TODO: temporary fix in 5.0, to remove in 5.2 when subflows support 
         # automatically sending subflow.delete upon deletion