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 on 2013-09-12
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 2013-09-12 Approve on 2013-09-16
Quentin THEURET @Amaris (community) Needs Fixing on 2013-09-12
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.
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
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 on 2013-09-12

[FIX] account_payment_extension: domain in invoice search.

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.

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
1=== modified file 'account_payment_extension/account_move_line.py'
2--- account_payment_extension/account_move_line.py 2013-09-02 13:42:26 +0000
3+++ account_payment_extension/account_move_line.py 2013-09-12 11:23:34 +0000
4@@ -32,6 +32,7 @@
5 _inherit = 'account.move.line'
6
7 def _invoice(self, cursor, user, ids, name, arg, context=None):
8+ context = context or {}
9 invoice_obj = self.pool.get('account.invoice')
10 res = {}
11 for line_id in ids:
12@@ -56,8 +57,9 @@
13 # return super(account_move_line, self)._invoice(cr, uid, ids, name, arg, context)
14 #===========================================================================
15
16- def _invoice_search(self, cr, uid, obj, name, args, context={}):
17+ def _invoice_search(self, cr, uid, obj, name, args, context=None):
18 """ Redefinition for searching account move lines without any invoice related ('invoice.id','=',False)"""
19+ context = context or {}
20 for x in args:
21 if (x[2] is False) and (x[1] == '=') and (x[0] == 'invoice'):
22 cr.execute('SELECT l.id FROM account_move_line l ' \
23@@ -69,12 +71,12 @@
24 return [('id', 'in', [x[0] for x in res])]
25 return super(account_move_line, self)._invoice_search(cr, uid, obj, name, args, context=context)
26
27- def amount_to_pay(self, cr, uid, ids, name, arg={}, context={}):
28+ def amount_to_pay(self, cr, uid, ids, name, arg={}, context=None):
29 """
30 Return amount pending to be paid taking into account payment lines and the reconciliation.
31 Note that the amount to pay can be due to negative supplier refund invoices or customer invoices.
32 """
33-
34+ context = context or {}
35 if not ids:
36 return {}
37 cr.execute("""SELECT ml.id,
38@@ -125,7 +127,8 @@
39 result[id] = debt
40 return result
41
42- def _to_pay_search(self, cr, uid, obj, name, args, context={}):
43+ def _to_pay_search(self, cr, uid, obj, name, args, context=None):
44+ context = context or {}
45 if not len(args):
46 return []
47 currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id
48@@ -142,7 +145,8 @@
49 return [('id','=',False)]
50 return [('id','in',ids)]
51
52- def _payment_type_get(self, cr, uid, ids, field_name, arg, context={}):
53+ def _payment_type_get(self, cr, uid, ids, field_name, arg, context=None):
54+ context = context or {}
55 result = {}
56 invoice_obj = self.pool.get('account.invoice')
57 for rec in self.browse(cr, uid, ids, context):
58@@ -156,14 +160,15 @@
59 result[rec.id] = (0,0)
60 return result
61
62- def _payment_type_search(self, cr, uid, obj, name, args, context={}):
63+ def _payment_type_search(self, cr, uid, obj, name, args, context=None):
64+ context = context or {}
65 if not len(args):
66 return []
67 operator = args[0][1]
68 value = args[0][2]
69 if not value:
70 return []
71- if isinstance(value, int) or isinstance(value, long):
72+ if isinstance(value, (int, long)):
73 ids = [value]
74 elif isinstance(value, list):
75 ids = value
76@@ -172,7 +177,7 @@
77 if ids:
78 cr.execute('SELECT l.id ' \
79 'FROM account_move_line l, account_invoice i ' \
80- 'WHERE l.move_id = i.move_id AND i.payment_type in (%s)' % (','.join(map(str, ids))))
81+ 'WHERE l.move_id = i.move_id AND i.payment_type in %s', (tuple(ids),))
82 res = cr.fetchall()
83 if len(res):
84 return [('id', 'in', [x[0] for x in res])]
85@@ -188,12 +193,14 @@
86 }
87
88 def write(self, cr, uid, ids, vals, context=None, check=True, update_check=True):
89+ context = context or {}
90 for key in vals.keys():
91 if key not in ['received_check', 'partner_bank_id', 'date_maturity']:
92 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check)
93 return super(account_move_line, self).write(cr, uid, ids, vals, context, check, update_check=False)
94
95- def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
96+ def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
97+ context = context or {}
98 menus = [
99 self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_invoice_payments'),
100 #self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_payment_extension', 'menu_action_done_payments'),
101@@ -224,7 +231,7 @@
102 return result
103
104 def pay_move_lines(self, cr, uid, ids, context=None):
105-
106+ context = context or {}
107 #obj_move = self.pool.get('account.move')
108 amount = 0
109 name = ''
110@@ -258,8 +265,6 @@
111 ttype = 'receipt'
112 invoice_type = 'out_invoice'
113
114- print amount
115-
116 return {
117 'name':_("Pay Moves"),
118 'view_mode': 'form',
119@@ -280,8 +285,9 @@
120 'default_type': ttype ,
121 'type': ttype ,
122 'move_line_ids': ids
123- }
124+ }
125 }
126+
127 account_move_line()
128
129 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
130
131=== modified file 'account_payment_extension/wizard/account_payment_order.py'
132--- account_payment_extension/wizard/account_payment_order.py 2013-05-15 15:52:18 +0000
133+++ account_payment_extension/wizard/account_payment_order.py 2013-09-12 11:23:34 +0000
134@@ -64,43 +64,36 @@
135
136 @return : default values of fields.
137 """
138+ context = context or {}
139 line_obj = self.pool.get('account.move.line')
140 res = super(payment_order_create, self).default_get(cr, uid, fields, context=context)
141 if 'entries' in fields:
142- if context and 'line_ids' in context and context['line_ids']:
143+ if context.get('line_ids'):
144 res.update({'entries': context['line_ids']})
145
146 return res
147
148- def search_entries(self, cr, uid, ids, context):
149+ def search_entries(self, cr, uid, ids, context=None):
150+ context = context or {}
151 pool = pooler.get_pool(cr.dbname)
152 order_obj = self.pool.get('payment.order')
153 line_obj = self.pool.get('account.move.line')
154 mod_obj = self.pool.get('ir.model.data')
155- if context is None:
156- context = {}
157 data = self.browse(cr, uid, ids, context=context)[0]
158 search_due_date = data.duedate
159 show_refunds = data.show_refunds
160 amount = data.amount
161-
162 payment = order_obj.browse(cr, uid, context.get('active_id'), context=context)
163-
164 # Search for move line to pay:
165- domain = [('reconcile_id', '=', False),('account_id.type', '=', payment.type),('amount_to_pay', '<>', 0)]
166-
167+ domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.type), ('amount_to_pay', '<>', 0)]
168 if payment.type =='payable' and not show_refunds:
169 domain += [ ('credit','>',0) ]
170-
171 elif not show_refunds:
172- domain += [ ('debit','>',0) ]
173-
174+ domain += [('debit', '>', 0)]
175 if payment.mode:
176- domain += [ ('payment_type','=',payment.mode.type.id) ]
177-
178+ domain += [('payment_type', '=', payment.mode.type.id)]
179 domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
180 line_ids = line_obj.search(cr, uid, domain, order='date_maturity', context=context)
181-
182 selected_ids = []
183 if amount > 0.0:
184 # If user specified an amount, search what moves match the criteria
185@@ -111,11 +104,12 @@
186 elif not amount:
187 selected_ids = line_ids
188
189- context.update({'line_ids': selected_ids})
190+ ctx = context.copy()
191+ ctx.update({'line_ids': selected_ids})
192 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
193 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
194 return {'name': ('Entrie Lines'),
195- 'context': context,
196+ 'context': ctx,
197 'view_type': 'form',
198 'view_mode': 'form',
199 'res_model': 'payment.order.create',
200@@ -125,11 +119,10 @@
201 }
202
203 def create_payment(self, cr, uid, ids, context=None):
204+ context = context or {}
205 order_obj = self.pool.get('payment.order')
206 line_obj = self.pool.get('account.move.line')
207 payment_obj = self.pool.get('payment.line')
208- if context is None:
209- context = {}
210 data = self.browse(cr, uid, ids, context=context)[0]
211 line_ids = [entry.id for entry in data.entries]
212 if not line_ids:

Subscribers

People subscribed via source and target branches