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

Proposed by Pedro Manuel Baeza
Status: Merged
Merged at revision: 109
Proposed branch: lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling
Merge into: lp:~account-payment-team/account-payment/6.1
Diff against target: 212 lines (+30/-31)
2 files modified
account_payment_extension/account_move_line.py (+19/-13)
account_payment_extension/wizard/account_payment_order.py (+11/-18)
To merge this branch: bzr merge lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling
Reviewer Review Type Date Requested Status
mikel Approve
Quentin THEURET @Amaris (community) Needs Fixing
Review via email: mp+185239@code.launchpad.net

Description of the change

This MP is for handling correctly context variable, that cannot be initialised as {}, because of side effects, and its initialisation in each method.

To post a comment you must log in.
Revision history for this message
Quentin THEURET @Amaris (qtheuret) wrote :

Hello,

A little error in account_payment_extension/wizard/account_payment_order.py (line 88)

domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type)]#,('amount_to_pay', '<>', 0)]

should be

domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type)]),('amount_to_pay', '<>', 0)]

review: Needs Fixing
Revision history for this message
Quentin THEURET @Amaris (qtheuret) wrote :

Sorry, I also made a mistake :

domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type)]#,('amount_to_pay', '<>', 0)]

should become

domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type),('amount_to_pay', '<>', 0)]

109. By Pedro Manuel Baeza

[FIX] account_payment_extension: domain in invoice search.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Quentin, thank you very much for you review. That it's other question out of this MP, but indeed domain is redundant, because if an invoice has any amount_to_pay, reconcile_id is going to be False, and comes from the problem with the correct handling of the function field, that is not recalculated, but I have already corrected in this MP, and I'm going to handle the other problem in another MP.

Regards.

Revision history for this message
mikel (mikel-martin) wrote :

Thanks Pedro and Quentin

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:23:34 +0000
@@ -32,6 +32,7 @@
32 _inherit = 'account.move.line'32 _inherit = 'account.move.line'
3333
34 def _invoice(self, cursor, user, ids, name, arg, context=None):34 def _invoice(self, cursor, user, ids, name, arg, context=None):
35 context = context or {}
35 invoice_obj = self.pool.get('account.invoice')36 invoice_obj = self.pool.get('account.invoice')
36 res = {}37 res = {}
37 for line_id in ids:38 for line_id in ids:
@@ -56,8 +57,9 @@
56 # return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)57 # return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)
57 #===========================================================================58 #===========================================================================
5859
59 def _invoice_search(self, cr, uid, obj, name, args, context={}):60 def _invoice_search(self, cr, uid, obj, name, args, context=None):
60 """ Redefinition for searching account move lines without any invoice related ('invoice.id','=',False)"""61 """ Redefinition for searching account move lines without any invoice related ('invoice.id','=',False)"""
62 context = context or {}
61 for x in args:63 for x in args:
62 if (x[2] is False) and (x[1] == '=') and (x[0] == 'invoice'):64 if (x[2] is False) and (x[1] == '=') and (x[0] == 'invoice'):
63 cr.execute('SELECT l.id FROM account_move_line l ' \65 cr.execute('SELECT l.id FROM account_move_line l ' \
@@ -69,12 +71,12 @@
69 return [('id', 'in', [x[0] for x in res])]71 return [('id', 'in', [x[0] for x in res])]
70 return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)72 return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)
7173
72 def amount_to_pay(self, cr, uid, ids, name, arg={}, context={}):74 def amount_to_pay(self, cr, uid, ids, name, arg={}, context=None):
73 """75 """
74 Return amount pending to be paid taking into account payment lines and the reconciliation.76 Return amount pending to be paid taking into account payment lines and the reconciliation.
75 Note that the amount to pay can be due to negative supplier refund invoices or customer invoices.77 Note that the amount to pay can be due to negative supplier refund invoices or customer invoices.
76 """78 """
7779 context = context or {}
78 if not ids:80 if not ids:
79 return {}81 return {}
80 cr.execute("""SELECT ml.id,82 cr.execute("""SELECT ml.id,
@@ -125,7 +127,8 @@
125 result[id] = debt127 result[id] = debt
126 return result128 return result
127129
128 def _to_pay_search(self, cr, uid, obj, name, args, context={}):130 def _to_pay_search(self, cr, uid, obj, name, args, context=None):
131 context = context or {}
129 if not len(args):132 if not len(args):
130 return []133 return []
131 currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id134 currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
@@ -142,7 +145,8 @@
142 return [('id','=',False)]145 return [('id','=',False)]
143 return [('id','in',ids)]146 return [('id','in',ids)]
144147
145 def _payment_type_get(self, cr, uid, ids, field_name, arg, context={}):148 def _payment_type_get(self, cr, uid, ids, field_name, arg, context=None):
149 context = context or {}
146 result = {}150 result = {}
147 invoice_obj = self.pool.get('account.invoice')151 invoice_obj = self.pool.get('account.invoice')
148 for rec in self.browse(cr, uid, ids, context):152 for rec in self.browse(cr, uid, ids, context):
@@ -156,14 +160,15 @@
156 result[rec.id] = (0,0)160 result[rec.id] = (0,0)
157 return result161 return result
158162
159 def _payment_type_search(self, cr, uid, obj, name, args, context={}):163 def _payment_type_search(self, cr, uid, obj, name, args, context=None):
164 context = context or {}
160 if not len(args):165 if not len(args):
161 return []166 return []
162 operator = args[0][1]167 operator = args[0][1]
163 value = args[0][2]168 value = args[0][2]
164 if not value:169 if not value:
165 return []170 return []
166 if isinstance(value, int) or isinstance(value, long):171 if isinstance(value, (int, long)):
167 ids = [value]172 ids = [value]
168 elif isinstance(value, list):173 elif isinstance(value, list):
169 ids = value 174 ids = value
@@ -172,7 +177,7 @@
172 if ids:177 if ids:
173 cr.execute('SELECT l.id ' \178 cr.execute('SELECT l.id ' \
174 'FROM account_move_line l, account_invoice i ' \179 'FROM account_move_line l, account_invoice i ' \
175 'WHERE l.move_id = i.move_id AND i.payment_type in (%s)' % (','.join(map(str, ids))))180 'WHERE l.move_id = i.move_id AND i.payment_type in %s', (tuple(ids),))
176 res = cr.fetchall()181 res = cr.fetchall()
177 if len(res):182 if len(res):
178 return [('id', 'in', [x[0] for x in res])]183 return [('id', 'in', [x[0] for x in res])]
@@ -188,12 +193,14 @@
188 }193 }
189194
190 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):195 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
196 context = context or {}
191 for key in vals.keys():197 for key in vals.keys():
192 if key not in ['received_check', 'partner_bank_id', 'date_maturity']:198 if key not in ['received_check', 'partner_bank_id', 'date_maturity']:
193 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)199 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)
194 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check=False)200 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check=False)
195201
196 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):202 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
203 context = context or {}
197 menus = [204 menus = [
198 self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_invoice_payments'),205 self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_invoice_payments'),
199 #self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_done_payments'),206 #self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_done_payments'),
@@ -224,7 +231,7 @@
224 return result231 return result
225 232
226 def pay_move_lines(self, cr, uid, ids, context=None):233 def pay_move_lines(self, cr, uid, ids, context=None):
227 234 context = context or {}
228 #obj_move = self.pool.get('account.move')235 #obj_move = self.pool.get('account.move')
229 amount = 0236 amount = 0
230 name = ''237 name = ''
@@ -258,8 +265,6 @@
258 ttype = 'receipt'265 ttype = 'receipt'
259 invoice_type = 'out_invoice'266 invoice_type = 'out_invoice'
260 267
261 print amount
262
263 return {268 return {
264 'name':_("Pay Moves"),269 'name':_("Pay Moves"),
265 'view_mode': 'form',270 'view_mode': 'form',
@@ -280,8 +285,9 @@
280 'default_type': ttype ,285 'default_type': ttype ,
281 'type': ttype ,286 'type': ttype ,
282 'move_line_ids': ids287 'move_line_ids': ids
283 }288 }
284 }289 }
290
285account_move_line()291account_move_line()
286292
287# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:293# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
288294
=== 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:23:34 +0000
@@ -64,43 +64,36 @@
6464
65 @return : default values of fields.65 @return : default values of fields.
66 """66 """
67 context = context or {}
67 line_obj = self.pool.get('account.move.line')68 line_obj = self.pool.get('account.move.line')
68 res = super(payment_order_create, self).default_get(cr, uid, fields, context=context)69 res = super(payment_order_create, self).default_get(cr, uid, fields, context=context)
69 if 'entries' in fields:70 if 'entries' in fields:
70 if context and 'line_ids' in context and context['line_ids']:71 if context.get('line_ids'):
71 res.update({'entries': context['line_ids']})72 res.update({'entries': context['line_ids']})
7273
73 return res74 return res
7475
75 def search_entries(self, cr, uid, ids, context):76 def search_entries(self, cr, uid, ids, context=None):
77 context = context or {}
76 pool = pooler.get_pool(cr.dbname)78 pool = pooler.get_pool(cr.dbname)
77 order_obj = self.pool.get('payment.order')79 order_obj = self.pool.get('payment.order')
78 line_obj = self.pool.get('account.move.line')80 line_obj = self.pool.get('account.move.line')
79 mod_obj = self.pool.get('ir.model.data')81 mod_obj = self.pool.get('ir.model.data')
80 if context is None:
81 context = {}
82 data = self.browse(cr, uid, ids, context=context)[0]82 data = self.browse(cr, uid, ids, context=context)[0]
83 search_due_date = data.duedate83 search_due_date = data.duedate
84 show_refunds = data.show_refunds84 show_refunds = data.show_refunds
85 amount = data.amount85 amount = data.amount
86
87 payment = order_obj.browse(cr, uid, context.get('active_id'), context=context)86 payment = order_obj.browse(cr, uid, context.get('active_id'), context=context)
88
89 # Search for move line to pay:87 # Search for move line to pay:
90 domain = [('reconcile_id', '=', False),('account_id.type', '=', payment.type),('amount_to_pay', '<>', 0)]88 domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type), ('amount_to_pay', '<>', 0)]
91
92 if payment.type =='payable' and not show_refunds:89 if payment.type =='payable' and not show_refunds:
93 domain += [ ('credit','>',0) ]90 domain += [ ('credit','>',0) ]
94
95 elif not show_refunds:91 elif not show_refunds:
96 domain += [ ('debit','>',0) ]92 domain += [('debit', '>', 0)]
97
98 if payment.mode:93 if payment.mode:
99 domain += [ ('payment_type','=',payment.mode.type.id) ]94 domain += [('payment_type', '=', payment.mode.type.id)]
100
101 domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]95 domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
102 line_ids = line_obj.search(cr, uid, domain, order='date_maturity', context=context)96 line_ids = line_obj.search(cr, uid, domain, order='date_maturity', context=context)
103
104 selected_ids = []97 selected_ids = []
105 if amount > 0.0:98 if amount > 0.0:
106 # If user specified an amount, search what moves match the criteria99 # If user specified an amount, search what moves match the criteria
@@ -111,11 +104,12 @@
111 elif not amount:104 elif not amount:
112 selected_ids = line_ids105 selected_ids = line_ids
113106
114 context.update({'line_ids': selected_ids})107 ctx = context.copy()
108 ctx.update({'line_ids': selected_ids})
115 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)109 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
116 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']110 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
117 return {'name': ('Entrie Lines'),111 return {'name': ('Entrie Lines'),
118 'context': context,112 'context': ctx,
119 'view_type': 'form',113 'view_type': 'form',
120 'view_mode': 'form',114 'view_mode': 'form',
121 'res_model': 'payment.order.create',115 'res_model': 'payment.order.create',
@@ -125,11 +119,10 @@
125 }119 }
126120
127 def create_payment(self, cr, uid, ids, context=None):121 def create_payment(self, cr, uid, ids, context=None):
122 context = context or {}
128 order_obj = self.pool.get('payment.order')123 order_obj = self.pool.get('payment.order')
129 line_obj = self.pool.get('account.move.line')124 line_obj = self.pool.get('account.move.line')
130 payment_obj = self.pool.get('payment.line')125 payment_obj = self.pool.get('payment.line')
131 if context is None:
132 context = {}
133 data = self.browse(cr, uid, ids, context=context)[0]126 data = self.browse(cr, uid, ids, context=context)[0]
134 line_ids = [entry.id for entry in data.entries]127 line_ids = [entry.id for entry in data.entries]
135 if not line_ids:128 if not line_ids:

Subscribers

People subscribed via source and target branches