From 5365e331e8ea64c195928ecb289ad593d40402ef Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Fri, 3 Sep 2010 11:38:12 +0200 Subject: [PATCH] [FIX] purchase: Remove the eval call and replace it with a dict#get bzr revid: stephane@openerp.com-20100903093812-gz0athpfkqyz0iiv --- addons/purchase/purchase.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 2256cffb6f1..51e294200cb 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -145,6 +145,17 @@ class purchase_order(osv.osv): res[purchase.id] = False return res + STATE_SELECTION = [ + ('draft', 'Request for Quotation'), + ('wait', 'Waiting'), + ('confirmed', 'Waiting Supplier Ack'), + ('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, help="unique number of the purchase order,computed automatically when the purchase order is created"), 'origin': fields.char('Source Document', size=64, @@ -164,7 +175,7 @@ class purchase_order(osv.osv): 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}), 'location_id': fields.many2one('stock.location', 'Destination', required=True, domain=[('usage','<>','view')]), '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', 'Waiting Supplier Ack'), ('approved', 'Approved'),('except_picking', 'Shipping Exception'), ('except_invoice', 'Invoice Exception'), ('done', 'Done'), ('cancel', 'Cancelled')], 'State', 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, 'State', 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'), @@ -220,8 +231,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