← Back to team overview

account-payment-team team mailing list archive

lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling into lp:account-payment

 

Pedro Manuel Baeza has proposed merging lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling into lp:account-payment.

Requested reviews:
  Account Payment (account-payment-team)

For more details, see:
https://code.launchpad.net/~pedro.baeza/account-payment/6.1-payment-extension_context-handling/+merge/185239

This MP is for handling correctly context variable, that cannot be initialised as {}, because of side effects, and its initialisation in each method.
-- 
https://code.launchpad.net/~pedro.baeza/account-payment/6.1-payment-extension_context-handling/+merge/185239
Your team Account Payment is requested to review the proposed merge of lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling into lp:account-payment.
=== modified file 'account_payment_extension/account_move_line.py'
--- account_payment_extension/account_move_line.py	2013-09-02 13:42:26 +0000
+++ account_payment_extension/account_move_line.py	2013-09-12 11:06:33 +0000
@@ -32,6 +32,7 @@
     _inherit = 'account.move.line'
 
     def _invoice(self, cursor, user, ids, name, arg, context=None):
+        context = context or {}
         invoice_obj = self.pool.get('account.invoice')
         res = {}
         for line_id in ids:
@@ -56,8 +57,9 @@
     #    return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)
     #===========================================================================
 
-    def _invoice_search(self, cr, uid, obj, name, args, context={}):
+    def _invoice_search(self, cr, uid, obj, name, args, context=None):
         """ Redefinition for searching account move lines without any invoice related ('invoice.id','=',False)"""
+        context = context or {}
         for x in args:
             if (x[2] is False) and (x[1] == '=') and (x[0] == 'invoice'):
                 cr.execute('SELECT l.id FROM account_move_line l ' \
@@ -69,12 +71,12 @@
                 return [('id', 'in', [x[0] for x in res])]
         return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)
 
-    def amount_to_pay(self, cr, uid, ids, name, arg={}, context={}):
+    def amount_to_pay(self, cr, uid, ids, name, arg={}, context=None):
         """
         Return amount pending to be paid taking into account payment lines and the reconciliation.
         Note that the amount to pay can be due to negative supplier refund invoices or customer invoices.
         """
-
+        context = context or {}
         if not ids:
             return {}
         cr.execute("""SELECT ml.id,
@@ -125,7 +127,8 @@
             result[id] = debt
         return result
 
-    def _to_pay_search(self, cr, uid, obj, name, args, context={}):
+    def _to_pay_search(self, cr, uid, obj, name, args, context=None):
+        context = context or {}
         if not len(args):
             return []
         currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
@@ -142,7 +145,8 @@
             return [('id','=',False)]
         return [('id','in',ids)]
 
-    def _payment_type_get(self, cr, uid, ids, field_name, arg, context={}):
+    def _payment_type_get(self, cr, uid, ids, field_name, arg, context=None):
+        context = context or {}
         result = {}
         invoice_obj = self.pool.get('account.invoice')
         for rec in self.browse(cr, uid, ids, context):
@@ -156,14 +160,15 @@
                 result[rec.id] = (0,0)
         return result
 
-    def _payment_type_search(self, cr, uid, obj, name, args, context={}):
+    def _payment_type_search(self, cr, uid, obj, name, args, context=None):
+        context = context or {}
         if not len(args):
             return []
         operator = args[0][1]
         value = args[0][2]
         if not value:
             return []
-        if isinstance(value, int) or isinstance(value, long):
+        if isinstance(value, (int, long)):
             ids = [value]
         elif isinstance(value, list):
             ids = value 
@@ -172,7 +177,7 @@
         if ids:
             cr.execute('SELECT l.id ' \
                 'FROM account_move_line l, account_invoice i ' \
-                'WHERE l.move_id = i.move_id AND i.payment_type in (%s)' % (','.join(map(str, ids))))
+                'WHERE l.move_id = i.move_id AND i.payment_type in %s', (tuple(ids),))
             res = cr.fetchall()
             if len(res):
                 return [('id', 'in', [x[0] for x in res])]
@@ -188,12 +193,14 @@
     }
 
     def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
+        context = context or {}
         for key in vals.keys():
             if key not in ['received_check', 'partner_bank_id', 'date_maturity']:
                 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)
         return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check=False)
 
-    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
+    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+        context = context or {}
         menus = [
             self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_invoice_payments'),
             #self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_done_payments'),
@@ -224,7 +231,7 @@
         return result
         
     def pay_move_lines(self, cr, uid, ids, context=None):
-        
+        context = context or {}
         #obj_move = self.pool.get('account.move')
         amount = 0
         name = ''
@@ -258,8 +265,6 @@
             ttype = 'receipt'
             invoice_type = 'out_invoice'
             
-        print amount
-            
         return {
             'name':_("Pay Moves"),
             'view_mode': 'form',
@@ -280,8 +285,9 @@
                 'default_type': ttype ,
                 'type':  ttype ,
                 'move_line_ids': ids
-                }
+            }
         }
+
 account_move_line()
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'account_payment_extension/wizard/account_payment_order.py'
--- account_payment_extension/wizard/account_payment_order.py	2013-05-15 15:52:18 +0000
+++ account_payment_extension/wizard/account_payment_order.py	2013-09-12 11:06:33 +0000
@@ -64,43 +64,36 @@
 
         @return : default values of fields.
         """
+        context = context or {}
         line_obj = self.pool.get('account.move.line')
         res = super(payment_order_create, self).default_get(cr, uid, fields, context=context)
         if 'entries' in fields:
-            if context and 'line_ids' in context and context['line_ids']:
+            if context.get('line_ids'):
                 res.update({'entries':  context['line_ids']})
 
         return res
 
-    def search_entries(self, cr, uid, ids, context):
+    def search_entries(self, cr, uid, ids, context=None):
+        context = context or {}
         pool = pooler.get_pool(cr.dbname)
         order_obj = self.pool.get('payment.order')
         line_obj = self.pool.get('account.move.line')
         mod_obj = self.pool.get('ir.model.data')
-        if context is None:
-            context = {}
         data = self.browse(cr, uid, ids, context=context)[0]
         search_due_date = data.duedate
         show_refunds = data.show_refunds
         amount = data.amount
-
         payment = order_obj.browse(cr, uid, context.get('active_id'), context=context)
-
         # Search for move line to pay:
-        domain = [('reconcile_id', '=', False),('account_id.type', '=', payment.type),('amount_to_pay', '<>', 0)]
-
+        domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type)]#,('amount_to_pay', '<>', 0)]
         if payment.type =='payable' and not show_refunds:
             domain += [ ('credit','>',0) ]
-
         elif not show_refunds:
-            domain += [ ('debit','>',0) ]
-
+            domain += [('debit', '>', 0)]
         if payment.mode:
-            domain += [ ('payment_type','=',payment.mode.type.id) ]
-
+            domain += [('payment_type', '=', payment.mode.type.id)]
         domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
         line_ids = line_obj.search(cr, uid, domain, order='date_maturity', context=context)
-
         selected_ids = []
         if amount > 0.0:
             # If user specified an amount, search what moves match the criteria
@@ -111,11 +104,12 @@
         elif not amount:
             selected_ids = line_ids
 
-        context.update({'line_ids': selected_ids})
+        ctx = context.copy()
+        ctx.update({'line_ids': selected_ids})
         model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
         resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
         return {'name': ('Entrie Lines'),
-                'context': context,
+                'context': ctx,
                 'view_type': 'form',
                 'view_mode': 'form',
                 'res_model': 'payment.order.create',
@@ -125,11 +119,10 @@
         }
 
     def create_payment(self, cr, uid, ids, context=None):
+        context = context or {}
         order_obj = self.pool.get('payment.order')
         line_obj = self.pool.get('account.move.line')
         payment_obj = self.pool.get('payment.line')
-        if context is None:
-            context = {}
         data = self.browse(cr, uid, ids, context=context)[0]
         line_ids = [entry.id for entry in data.entries]
         if not line_ids:


Follow ups