From 366d0abea868fa01a218da6f66d257ffae366ecb Mon Sep 17 00:00:00 2001 From: "sbh (Open ERP)" Date: Thu, 18 Mar 2010 11:40:48 +0530 Subject: [PATCH] [IMP] auction: remove the defaults value function and used default_get bzr revid: sbh@tinyerp.com-20100318061048-q9mlhmrc1c9wwid6 --- .../wizard/auction_lots_make_invoice.py | 41 +++++++------- .../wizard/auction_lots_make_invoice_buyer.py | 53 ++++++++----------- addons/auction/wizard/auction_pay_buy.py | 51 +++++++++--------- 3 files changed, 71 insertions(+), 74 deletions(-) diff --git a/addons/auction/wizard/auction_lots_make_invoice.py b/addons/auction/wizard/auction_lots_make_invoice.py index ec2fd58bfb0..595bd067f4a 100644 --- a/addons/auction/wizard/auction_lots_make_invoice.py +++ b/addons/auction/wizard/auction_lots_make_invoice.py @@ -28,24 +28,29 @@ import wizard class auction_lots_make_invoice(osv.osv_memory): - def _value_amount(self, cr, uid, context={}): - """ - For Amount default value - @return:default auction lots amount value in amount fields. - """ - lots= self.pool.get('auction.lots').browse(cr, uid, context['active_ids']) - amount_total=0.0 - for lot in lots: - amount_total+=lot.seller_price - return amount_total + + def default_get(self, cr, uid, fields, context): + """ + @summary: To get default values for the object. + + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param fields: List of fields for which we want default values + @param context: A standard dictionary + + @return: A dictionary which of fields with values. - def _value_object(self, cr, uid, context={}): - """ - For object default value. - @return:length of id in Object field. - """ - object = len(context['active_ids']) - return object + """ + res = {} + record_id = context and context.get('active_id',False) + if not record_id: + return res + + lot= self.pool.get('auction.lots').browse(cr, uid, record_id) + res['amount']=lot.buyer_price + res['objects'] = len(context['active_ids']) + return res def makeInvoices(self, cr, uid, ids, context): """ @@ -85,8 +90,6 @@ class auction_lots_make_invoice(osv.osv_memory): } _defaults={ - 'amount':_value_amount, - 'objects':_value_object, 'number':lambda *a: False, } diff --git a/addons/auction/wizard/auction_lots_make_invoice_buyer.py b/addons/auction/wizard/auction_lots_make_invoice_buyer.py index 990318bdf40..e87a1df9865 100644 --- a/addons/auction/wizard/auction_lots_make_invoice_buyer.py +++ b/addons/auction/wizard/auction_lots_make_invoice_buyer.py @@ -28,34 +28,29 @@ import wizard class auction_lots_make_invoice_buyer(osv.osv_memory): - def _value_amount(self, cr, uid, context={}): - """ - For Amount default value - @return:default auction lots amount value in amount fields. - """ - lots= self.pool.get('auction.lots').browse(cr, uid, context['active_ids']) - amount_total=0.0 - for lot in lots: - amount_total+=lot.buyer_price - return amount_total + def default_get(self, cr, uid, fields, context): + """ + @summary: To get default values for the object. + + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param fields: List of fields for which we want default values + @param context: A standard dictionary + + @return: A dictionary which of fields with values. - def _value_object(self, cr, uid, context={}): - """ - For object default value. - @return:length of id in Object field. - """ - object = len(context['active_ids']) - return object - - def _value_buyer_id(self, cr, uid, context={}): - """ - For default buyer id value - @return:auction lots buyer id in buyer id field. - """ - lots= self.pool.get('auction.lots').browse(cr, uid, context['active_ids']) - for lot in lots: - buyer=lot and lot.ach_uid.id or False - return buyer + """ + res = {} + record_id = context and context.get('active_id',False) + if not record_id: + return res + + lot= self.pool.get('auction.lots').browse(cr, uid, record_id) + res['amount']=lot.buyer_price + res['buyer_id']=lot.ach_uid and lot.ach_uid.id or False + res['objects'] = len(context['active_ids']) + return res def makeInvoices(self, cr, uid, ids, context): """ @@ -100,11 +95,7 @@ class auction_lots_make_invoice_buyer(osv.osv_memory): 'buyer_id':fields.many2one('res.partner', 'Buyer', required=True), } _defaults={ - 'amount':_value_amount, - 'objects':_value_object, 'number':lambda *a: False, - 'buyer_id':_value_buyer_id - } auction_lots_make_invoice_buyer() diff --git a/addons/auction/wizard/auction_pay_buy.py b/addons/auction/wizard/auction_pay_buy.py index 511272cec3a..3c36bb24f94 100644 --- a/addons/auction/wizard/auction_pay_buy.py +++ b/addons/auction/wizard/auction_pay_buy.py @@ -29,24 +29,33 @@ import wizard class auction_pay_buy(osv.osv_memory): - def _start(self, cr, uid, context): - rec = self.pool.get('auction.lots').browse(cr, uid, context['active_ids'], context) - amount1 = 0.0 - for r in rec: - amount1+= r.buyer_price - if r.is_ok: - raise osv.except_osv('Error !', 'Some lots of the selection are already paid.') - return amount1 - - def _value_buyer_id(self, cr, uid, context={}): - """ - For default buyer id value - @return:auction lots buyer id in buyer id field. - """ - lots= self.pool.get('auction.lots').browse(cr, uid, context['active_ids']) - for lot in lots: - buyer=lot and lot.ach_uid.id or False - return buyer + def default_get(self, cr, uid, fields, context): + """ + @summary: To get default values for the object. + + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param fields: List of fields for which we want default values + @param context: A standard dictionary + + @return: A dictionary which of fields with values. + + """ + res = {} + record_id = context and context.get('active_id',False) + if not record_id: + return res + + lot= self.pool.get('auction.lots').browse(cr, uid, record_id) + if lot.is_ok : + raise osv.except_osv('Error !', 'Some lots of the selection are already paid.') + + res['amount']=lot.buyer_price + res['total']=lot.buyer_price + res['buyer_id']=lot.ach_uid and lot.ach_uid.id or False + res['objects'] = len(context['active_ids']) + return res def pay_and_reconcile(self, cr, uid, ids, context): """ @@ -103,12 +112,6 @@ class auction_pay_buy(osv.osv_memory): 'statement_id3':fields.many2one('account.bank.statement', 'Statement'), 'total': fields.float('Amount paid', digits = (16, int(tools.config['price_accuracy'])), readonly =True), } - _defaults={ - 'amount' : _start, - 'total' : _start, - 'buyer_id' : _value_buyer_id - } - auction_pay_buy()