Merge lp:~pedro.baeza/account-payment/6.1-payment-extension_context-handling into lp:~account-payment-team/account-payment/6.1
- 6.1-payment-extension_context-handling
- Merge into 6.1
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
mikel | Approve | ||
Quentin THEURET @Amaris (community) | Needs Fixing | ||
Review via email: mp+185239@code.launchpad.net |
Commit message
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.
Quentin THEURET @Amaris (qtheuret) wrote : | # |
Sorry, I also made a mistake :
domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.
should become
domain = [('reconcile_id', '=', False), ('account_id.type', '=', payment.
- 109. By Pedro Manuel Baeza
-
[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
Preview Diff
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 | 32 | _inherit = 'account.move.line' | 32 | _inherit = 'account.move.line' |
6 | 33 | 33 | ||
7 | 34 | def _invoice(self, cursor, user, ids, name, arg, context=None): | 34 | def _invoice(self, cursor, user, ids, name, arg, context=None): |
8 | 35 | context = context or {} | ||
9 | 35 | invoice_obj = self.pool.get('account.invoice') | 36 | invoice_obj = self.pool.get('account.invoice') |
10 | 36 | res = {} | 37 | res = {} |
11 | 37 | for line_id in ids: | 38 | for line_id in ids: |
12 | @@ -56,8 +57,9 @@ | |||
13 | 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) |
14 | 57 | #=========================================================================== | 58 | #=========================================================================== |
15 | 58 | 59 | ||
17 | 59 | def _invoice_search(self, cr, uid, obj, name, args, context={}): | 60 | def _invoice_search(self, cr, uid, obj, name, args, context=None): |
18 | 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)""" |
19 | 62 | context = context or {} | ||
20 | 61 | for x in args: | 63 | for x in args: |
21 | 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'): |
22 | 63 | cr.execute('SELECT l.id FROM account_move_line l ' \ | 65 | cr.execute('SELECT l.id FROM account_move_line l ' \ |
23 | @@ -69,12 +71,12 @@ | |||
24 | 69 | return [('id', 'in', [x[0] for x in res])] | 71 | return [('id', 'in', [x[0] for x in res])] |
25 | 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) |
26 | 71 | 73 | ||
28 | 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): |
29 | 73 | """ | 75 | """ |
30 | 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. |
31 | 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. |
32 | 76 | """ | 78 | """ |
34 | 77 | 79 | context = context or {} | |
35 | 78 | if not ids: | 80 | if not ids: |
36 | 79 | return {} | 81 | return {} |
37 | 80 | cr.execute("""SELECT ml.id, | 82 | cr.execute("""SELECT ml.id, |
38 | @@ -125,7 +127,8 @@ | |||
39 | 125 | result[id] = debt | 127 | result[id] = debt |
40 | 126 | return result | 128 | return result |
41 | 127 | 129 | ||
43 | 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): |
44 | 131 | context = context or {} | ||
45 | 129 | if not len(args): | 132 | if not len(args): |
46 | 130 | return [] | 133 | return [] |
47 | 131 | currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id | 134 | currency = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.currency_id |
48 | @@ -142,7 +145,8 @@ | |||
49 | 142 | return [('id','=',False)] | 145 | return [('id','=',False)] |
50 | 143 | return [('id','in',ids)] | 146 | return [('id','in',ids)] |
51 | 144 | 147 | ||
53 | 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): |
54 | 149 | context = context or {} | ||
55 | 146 | result = {} | 150 | result = {} |
56 | 147 | invoice_obj = self.pool.get('account.invoice') | 151 | invoice_obj = self.pool.get('account.invoice') |
57 | 148 | for rec in self.browse(cr, uid, ids, context): | 152 | for rec in self.browse(cr, uid, ids, context): |
58 | @@ -156,14 +160,15 @@ | |||
59 | 156 | result[rec.id] = (0,0) | 160 | result[rec.id] = (0,0) |
60 | 157 | return result | 161 | return result |
61 | 158 | 162 | ||
63 | 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): |
64 | 164 | context = context or {} | ||
65 | 160 | if not len(args): | 165 | if not len(args): |
66 | 161 | return [] | 166 | return [] |
67 | 162 | operator = args[0][1] | 167 | operator = args[0][1] |
68 | 163 | value = args[0][2] | 168 | value = args[0][2] |
69 | 164 | if not value: | 169 | if not value: |
70 | 165 | return [] | 170 | return [] |
72 | 166 | if isinstance(value, int) or isinstance(value, long): | 171 | if isinstance(value, (int, long)): |
73 | 167 | ids = [value] | 172 | ids = [value] |
74 | 168 | elif isinstance(value, list): | 173 | elif isinstance(value, list): |
75 | 169 | ids = value | 174 | ids = value |
76 | @@ -172,7 +177,7 @@ | |||
77 | 172 | if ids: | 177 | if ids: |
78 | 173 | cr.execute('SELECT l.id ' \ | 178 | cr.execute('SELECT l.id ' \ |
79 | 174 | 'FROM account_move_line l, account_invoice i ' \ | 179 | 'FROM account_move_line l, account_invoice i ' \ |
81 | 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),)) |
82 | 176 | res = cr.fetchall() | 181 | res = cr.fetchall() |
83 | 177 | if len(res): | 182 | if len(res): |
84 | 178 | return [('id', 'in', [x[0] for x in res])] | 183 | return [('id', 'in', [x[0] for x in res])] |
85 | @@ -188,12 +193,14 @@ | |||
86 | 188 | } | 193 | } |
87 | 189 | 194 | ||
88 | 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): |
89 | 196 | context = context or {} | ||
90 | 191 | for key in vals.keys(): | 197 | for key in vals.keys(): |
91 | 192 | if key not in ['received_check', 'partner_bank_id', 'date_maturity']: | 198 | if key not in ['received_check', 'partner_bank_id', 'date_maturity']: |
92 | 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) |
93 | 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) |
94 | 195 | 201 | ||
96 | 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): |
97 | 203 | context = context or {} | ||
98 | 197 | menus = [ | 204 | menus = [ |
99 | 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'), |
100 | 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'), |
101 | @@ -224,7 +231,7 @@ | |||
102 | 224 | return result | 231 | return result |
103 | 225 | 232 | ||
104 | 226 | def pay_move_lines(self, cr, uid, ids, context=None): | 233 | def pay_move_lines(self, cr, uid, ids, context=None): |
106 | 227 | 234 | context = context or {} | |
107 | 228 | #obj_move = self.pool.get('account.move') | 235 | #obj_move = self.pool.get('account.move') |
108 | 229 | amount = 0 | 236 | amount = 0 |
109 | 230 | name = '' | 237 | name = '' |
110 | @@ -258,8 +265,6 @@ | |||
111 | 258 | ttype = 'receipt' | 265 | ttype = 'receipt' |
112 | 259 | invoice_type = 'out_invoice' | 266 | invoice_type = 'out_invoice' |
113 | 260 | 267 | ||
114 | 261 | print amount | ||
115 | 262 | |||
116 | 263 | return { | 268 | return { |
117 | 264 | 'name':_("Pay Moves"), | 269 | 'name':_("Pay Moves"), |
118 | 265 | 'view_mode': 'form', | 270 | 'view_mode': 'form', |
119 | @@ -280,8 +285,9 @@ | |||
120 | 280 | 'default_type': ttype , | 285 | 'default_type': ttype , |
121 | 281 | 'type': ttype , | 286 | 'type': ttype , |
122 | 282 | 'move_line_ids': ids | 287 | 'move_line_ids': ids |
124 | 283 | } | 288 | } |
125 | 284 | } | 289 | } |
126 | 290 | |||
127 | 285 | account_move_line() | 291 | account_move_line() |
128 | 286 | 292 | ||
129 | 287 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: | 293 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
130 | 288 | 294 | ||
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 | 64 | 64 | ||
136 | 65 | @return : default values of fields. | 65 | @return : default values of fields. |
137 | 66 | """ | 66 | """ |
138 | 67 | context = context or {} | ||
139 | 67 | line_obj = self.pool.get('account.move.line') | 68 | line_obj = self.pool.get('account.move.line') |
140 | 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) |
141 | 69 | if 'entries' in fields: | 70 | if 'entries' in fields: |
143 | 70 | if context and 'line_ids' in context and context['line_ids']: | 71 | if context.get('line_ids'): |
144 | 71 | res.update({'entries': context['line_ids']}) | 72 | res.update({'entries': context['line_ids']}) |
145 | 72 | 73 | ||
146 | 73 | return res | 74 | return res |
147 | 74 | 75 | ||
149 | 75 | def search_entries(self, cr, uid, ids, context): | 76 | def search_entries(self, cr, uid, ids, context=None): |
150 | 77 | context = context or {} | ||
151 | 76 | pool = pooler.get_pool(cr.dbname) | 78 | pool = pooler.get_pool(cr.dbname) |
152 | 77 | order_obj = self.pool.get('payment.order') | 79 | order_obj = self.pool.get('payment.order') |
153 | 78 | line_obj = self.pool.get('account.move.line') | 80 | line_obj = self.pool.get('account.move.line') |
154 | 79 | mod_obj = self.pool.get('ir.model.data') | 81 | mod_obj = self.pool.get('ir.model.data') |
155 | 80 | if context is None: | ||
156 | 81 | context = {} | ||
157 | 82 | data = self.browse(cr, uid, ids, context=context)[0] | 82 | data = self.browse(cr, uid, ids, context=context)[0] |
158 | 83 | search_due_date = data.duedate | 83 | search_due_date = data.duedate |
159 | 84 | show_refunds = data.show_refunds | 84 | show_refunds = data.show_refunds |
160 | 85 | amount = data.amount | 85 | amount = data.amount |
161 | 86 | |||
162 | 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) |
163 | 88 | |||
164 | 89 | # Search for move line to pay: | 87 | # Search for move line to pay: |
167 | 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)] |
166 | 91 | |||
168 | 92 | if payment.type =='payable' and not show_refunds: | 89 | if payment.type =='payable' and not show_refunds: |
169 | 93 | domain += [ ('credit','>',0) ] | 90 | domain += [ ('credit','>',0) ] |
170 | 94 | |||
171 | 95 | elif not show_refunds: | 91 | elif not show_refunds: |
174 | 96 | domain += [ ('debit','>',0) ] | 92 | domain += [('debit', '>', 0)] |
173 | 97 | |||
175 | 98 | if payment.mode: | 93 | if payment.mode: |
178 | 99 | domain += [ ('payment_type','=',payment.mode.type.id) ] | 94 | domain += [('payment_type', '=', payment.mode.type.id)] |
177 | 100 | |||
179 | 101 | domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)] | 95 | domain += ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)] |
180 | 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) |
181 | 103 | |||
182 | 104 | selected_ids = [] | 97 | selected_ids = [] |
183 | 105 | if amount > 0.0: | 98 | if amount > 0.0: |
184 | 106 | # If user specified an amount, search what moves match the criteria | 99 | # If user specified an amount, search what moves match the criteria |
185 | @@ -111,11 +104,12 @@ | |||
186 | 111 | elif not amount: | 104 | elif not amount: |
187 | 112 | selected_ids = line_ids | 105 | selected_ids = line_ids |
188 | 113 | 106 | ||
190 | 114 | context.update({'line_ids': selected_ids}) | 107 | ctx = context.copy() |
191 | 108 | ctx.update({'line_ids': selected_ids}) | ||
192 | 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) |
193 | 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'] |
194 | 117 | return {'name': ('Entrie Lines'), | 111 | return {'name': ('Entrie Lines'), |
196 | 118 | 'context': context, | 112 | 'context': ctx, |
197 | 119 | 'view_type': 'form', | 113 | 'view_type': 'form', |
198 | 120 | 'view_mode': 'form', | 114 | 'view_mode': 'form', |
199 | 121 | 'res_model': 'payment.order.create', | 115 | 'res_model': 'payment.order.create', |
200 | @@ -125,11 +119,10 @@ | |||
201 | 125 | } | 119 | } |
202 | 126 | 120 | ||
203 | 127 | def create_payment(self, cr, uid, ids, context=None): | 121 | def create_payment(self, cr, uid, ids, context=None): |
204 | 122 | context = context or {} | ||
205 | 128 | order_obj = self.pool.get('payment.order') | 123 | order_obj = self.pool.get('payment.order') |
206 | 129 | line_obj = self.pool.get('account.move.line') | 124 | line_obj = self.pool.get('account.move.line') |
207 | 130 | payment_obj = self.pool.get('payment.line') | 125 | payment_obj = self.pool.get('payment.line') |
208 | 131 | if context is None: | ||
209 | 132 | context = {} | ||
210 | 133 | data = self.browse(cr, uid, ids, context=context)[0] | 126 | data = self.browse(cr, uid, ids, context=context)[0] |
211 | 134 | line_ids = [entry.id for entry in data.entries] | 127 | line_ids = [entry.id for entry in data.entries] |
212 | 135 | if not line_ids: | 128 | if not line_ids: |
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)]