Merge lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher into lp:banking-addons/6.1
- 6.1-bank_statement_instant_voucher
- Merge into 6.1
Status: | Merged |
---|---|
Merged at revision: | 143 |
Proposed branch: | lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher |
Merge into: | lp:banking-addons/6.1 |
Diff against target: |
688 lines (+645/-0) 8 files modified
bank_statement_instant_voucher/__init__.py (+1/-0) bank_statement_instant_voucher/__openerp__.py (+56/-0) bank_statement_instant_voucher/i18n/nl.po (+158/-0) bank_statement_instant_voucher/model/__init__.py (+2/-0) bank_statement_instant_voucher/model/account_bank_statement_line.py (+49/-0) bank_statement_instant_voucher/model/account_voucher_instant.py (+306/-0) bank_statement_instant_voucher/view/account_bank_statement_line.xml (+21/-0) bank_statement_instant_voucher/view/account_voucher_instant.xml (+52/-0) |
To merge this branch: | bzr merge lp:~therp-nl/banking-addons/6.1-bank_statement_instant_voucher |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guewen Baconnier @ Camptocamp | no test, review | Approve | |
Review via email:
|
Commit message
Description of the change
This module adds the option of instantly creating a sales or purchase voucher based on a specific statement line.
Although this module is not dependent on account_banking, if this module is installed, upon confirmation of the wizard that created the voucher the statement line will be confirmed and reconciled with the voucher.
Depends on the merge of https:/
- 142. By Stefan Rijnhart (Opener)
-
[FIX] Select view based on voucher type
[FIX] Use different icon than interactive reconcilation wizard from Banking Addons - 143. By Stefan Rijnhart (Opener)
-
[IMP] Take conditional defaults into account when creating voucher
- 144. By Stefan Rijnhart (Opener)
-
[IMP] Take advantage of instantly created import transactions on
manually encoded statements

Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
- 145. By Stefan Rijnhart (Opener)
-
[FIX] Style and optimalizations as per review

Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
Looks fine!
Preview Diff
1 | === added directory 'bank_statement_instant_voucher' |
2 | === added file 'bank_statement_instant_voucher/__init__.py' |
3 | --- bank_statement_instant_voucher/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ bank_statement_instant_voucher/__init__.py 2012-12-05 20:19:21 +0000 |
5 | @@ -0,0 +1,1 @@ |
6 | +import model |
7 | |
8 | === added file 'bank_statement_instant_voucher/__openerp__.py' |
9 | --- bank_statement_instant_voucher/__openerp__.py 1970-01-01 00:00:00 +0000 |
10 | +++ bank_statement_instant_voucher/__openerp__.py 2012-12-05 20:19:21 +0000 |
11 | @@ -0,0 +1,56 @@ |
12 | +# -*- coding: utf-8 -*- |
13 | +############################################################################## |
14 | +# |
15 | +# OpenERP, Open Source Management Solution |
16 | +# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
17 | +# |
18 | +# This program is free software: you can redistribute it and/or modify |
19 | +# it under the terms of the GNU Affero General Public License as |
20 | +# published by the Free Software Foundation, either version 3 of the |
21 | +# License, or (at your option) any later version. |
22 | +# |
23 | +# This program is distributed in the hope that it will be useful, |
24 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | +# GNU Affero General Public License for more details. |
27 | +# |
28 | +# You should have received a copy of the GNU Affero General Public License |
29 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 | +# |
31 | +############################################################################## |
32 | +{ |
33 | + "name": "Bank statement instant voucher", |
34 | + "version": "1.0r028", |
35 | + "author": "Therp BV", |
36 | + "category": 'Base', |
37 | + 'complexity': "normal", |
38 | + "description": """ |
39 | +This module adds a new button on the bank statement line that allows the |
40 | +accountant to instantly create a sales or purchase voucher based on the |
41 | +values of the bank statement line. |
42 | + |
43 | +This module does not depend on account_banking, but if this module is |
44 | +installed, the bank statement line will be reconciled automatically |
45 | +in the confirmation step of the wizard. |
46 | + |
47 | +If account_banking is not installed, the accountant will still have to |
48 | +reconcile the associated move line with the move line from the bank |
49 | +statement line manually. |
50 | + |
51 | +If the wizard is cancelled,the created voucher will be deleted again. |
52 | + |
53 | +Known limitations: |
54 | + |
55 | +Currency conversion and payment difference writeoff are not yet |
56 | +supported. |
57 | + """, |
58 | + 'website': 'http://therp.nl', |
59 | + 'images': [], |
60 | + 'depends': ['account_voucher'], |
61 | + 'data': [ |
62 | + 'view/account_voucher_instant.xml', |
63 | + 'view/account_bank_statement_line.xml', |
64 | + ], |
65 | + "license": 'AGPL-3', |
66 | +} |
67 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
68 | |
69 | === added directory 'bank_statement_instant_voucher/i18n' |
70 | === added file 'bank_statement_instant_voucher/i18n/nl.po' |
71 | --- bank_statement_instant_voucher/i18n/nl.po 1970-01-01 00:00:00 +0000 |
72 | +++ bank_statement_instant_voucher/i18n/nl.po 2012-12-05 20:19:21 +0000 |
73 | @@ -0,0 +1,158 @@ |
74 | +# Translation of OpenERP Server. |
75 | +# This file contains the translation of the following modules: |
76 | +# * bank_statement_instant_voucher |
77 | +# |
78 | +msgid "" |
79 | +msgstr "" |
80 | +"Project-Id-Version: OpenERP Server 6.1\n" |
81 | +"Report-Msgid-Bugs-To: \n" |
82 | +"POT-Creation-Date: 2012-11-12 10:42+0000\n" |
83 | +"PO-Revision-Date: 2012-11-12 10:42+0000\n" |
84 | +"Last-Translator: <>\n" |
85 | +"Language-Team: \n" |
86 | +"MIME-Version: 1.0\n" |
87 | +"Content-Type: text/plain; charset=UTF-8\n" |
88 | +"Content-Transfer-Encoding: \n" |
89 | +"Plural-Forms: \n" |
90 | + |
91 | +#. module: bank_statement_instant_voucher |
92 | +#: view:account.voucher.instant:0 |
93 | +msgid "Confirm" |
94 | +msgstr "Bevestig" |
95 | + |
96 | +#. module: bank_statement_instant_voucher |
97 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:71 |
98 | +#, python-format |
99 | +msgid "Voucher for statement line %s.%s" |
100 | +msgstr "Journaalbon voor bankafschrift %s.%s" |
101 | + |
102 | +#. module: bank_statement_instant_voucher |
103 | +#: field:account.voucher.instant,state:0 |
104 | +msgid "State" |
105 | +msgstr "Status" |
106 | + |
107 | +#. module: bank_statement_instant_voucher |
108 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:201 |
109 | +#, python-format |
110 | +msgid "The voucher could not be posted." |
111 | +msgstr "De journaalbon kon niet worden bevestigd." |
112 | + |
113 | +#. module: bank_statement_instant_voucher |
114 | +#: selection:account.voucher.instant,state:0 |
115 | +msgid "ready" |
116 | +msgstr "ready" |
117 | + |
118 | +#. module: bank_statement_instant_voucher |
119 | +#: model:ir.model,name:bank_statement_instant_voucher.model_account_voucher_instant |
120 | +msgid "Instant Voucher" |
121 | +msgstr "Instant journaalbon" |
122 | + |
123 | +#. module: bank_statement_instant_voucher |
124 | +#: selection:account.voucher.instant,state:0 |
125 | +msgid "confirm" |
126 | +msgstr "confirm" |
127 | + |
128 | +#. module: bank_statement_instant_voucher |
129 | +#: view:account.bank.statement:0 |
130 | +#: model:ir.actions.act_window,name:bank_statement_instant_voucher.act_instant_voucher |
131 | +msgid "Create matching voucher" |
132 | +msgstr "Bijpassende journaalbon aanmaken" |
133 | + |
134 | +#. module: bank_statement_instant_voucher |
135 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:137 |
136 | +#, python-format |
137 | +msgid "Cannot determine statement line" |
138 | +msgstr "Kan de bankafschriftregel niet afleiden" |
139 | + |
140 | +#. module: bank_statement_instant_voucher |
141 | +#: selection:account.voucher.instant,state:0 |
142 | +msgid "init" |
143 | +msgstr "init" |
144 | + |
145 | +#. module: bank_statement_instant_voucher |
146 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:209 |
147 | +#, python-format |
148 | +msgid "The voucher's move line could not be posted." |
149 | +msgstr "De journaalposten van de journaalbon konden niet geboekt worden" |
150 | + |
151 | +#. module: bank_statement_instant_voucher |
152 | +#: model:ir.model,name:bank_statement_instant_voucher.model_account_bank_statement_line |
153 | +msgid "Bank Statement Line" |
154 | +msgstr "Bankafschriftregel" |
155 | + |
156 | +#. module: bank_statement_instant_voucher |
157 | +#: view:account.voucher.instant:0 |
158 | +msgid "Create voucher" |
159 | +msgstr "Journaalbon aanmaken" |
160 | + |
161 | +#. module: bank_statement_instant_voucher |
162 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:214 |
163 | +#, python-format |
164 | +msgid "The amount on the bank statement line needs to be the same as on the voucher. Write-off is not yet supported." |
165 | +msgstr "Het bedrag op het bankafschrift dient gelijk te zijn aan het bedrag op de journaalbon. Afschrijven is nog niet ondersteund." |
166 | + |
167 | +#. module: bank_statement_instant_voucher |
168 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:59 |
169 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:136 |
170 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:190 |
171 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:200 |
172 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:208 |
173 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:213 |
174 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:224 |
175 | +#, python-format |
176 | +msgid "Error" |
177 | +msgstr "Fout" |
178 | + |
179 | +#. module: bank_statement_instant_voucher |
180 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:60 |
181 | +#, python-format |
182 | +msgid "No %s journal defined" |
183 | +msgstr "Geen %s-dagboek ingesteld" |
184 | + |
185 | +#. module: bank_statement_instant_voucher |
186 | +#: constraint:account.bank.statement.line:0 |
187 | +msgid "The amount of the voucher must be the same amount as the one on the statement line" |
188 | +msgstr "Het bedrag op de bon moet hetzelfde bedrag zijn dat vermeld staat op de afschriftregel" |
189 | + |
190 | +#. module: bank_statement_instant_voucher |
191 | +#: field:account.voucher.instant,balance:0 |
192 | +msgid "Balance" |
193 | +msgstr "Balans" |
194 | + |
195 | +#. module: bank_statement_instant_voucher |
196 | +#: field:account.voucher.instant,statement_line_id:0 |
197 | +msgid "Bank statement line" |
198 | +msgstr "Bankafschriftregel" |
199 | + |
200 | +#. module: bank_statement_instant_voucher |
201 | +#: field:account.voucher.instant,ref:0 |
202 | +msgid "Reference" |
203 | +msgstr "Referentie" |
204 | + |
205 | +#. module: bank_statement_instant_voucher |
206 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:191 |
207 | +#, python-format |
208 | +msgid "Currency on the bank statement line needs to be the same as on the voucher. Currency conversion is not yet supported." |
209 | +msgstr "De valuta van de bankafschriftregel dient gelijk te zijn aan die op de journaalbon. Omrekenen tussen valuta is nog niet ondersteund." |
210 | + |
211 | +#. module: bank_statement_instant_voucher |
212 | +#: code:addons/bank_statement_instant_voucher/model/account_voucher_instant.py:225 |
213 | +#, python-format |
214 | +msgid "Cannot match a confirmed statement line" |
215 | +msgstr "Kan een bevestigde bankafschriftregel niet afletteren" |
216 | + |
217 | +#. module: bank_statement_instant_voucher |
218 | +#: field:account.voucher.instant,voucher_id:0 |
219 | +msgid "Voucher" |
220 | +msgstr "Journaalbon" |
221 | + |
222 | +#. module: bank_statement_instant_voucher |
223 | +#: view:account.voucher.instant:0 |
224 | +msgid "Cancel" |
225 | +msgstr "Annuleer" |
226 | + |
227 | +#. module: bank_statement_instant_voucher |
228 | +#: field:account.voucher.instant,partner_id:0 |
229 | +msgid "Partner" |
230 | +msgstr "Relatie" |
231 | + |
232 | |
233 | === added directory 'bank_statement_instant_voucher/model' |
234 | === added file 'bank_statement_instant_voucher/model/__init__.py' |
235 | --- bank_statement_instant_voucher/model/__init__.py 1970-01-01 00:00:00 +0000 |
236 | +++ bank_statement_instant_voucher/model/__init__.py 2012-12-05 20:19:21 +0000 |
237 | @@ -0,0 +1,2 @@ |
238 | +import account_voucher_instant |
239 | +import account_bank_statement_line |
240 | |
241 | === added file 'bank_statement_instant_voucher/model/account_bank_statement_line.py' |
242 | --- bank_statement_instant_voucher/model/account_bank_statement_line.py 1970-01-01 00:00:00 +0000 |
243 | +++ bank_statement_instant_voucher/model/account_bank_statement_line.py 2012-12-05 20:19:21 +0000 |
244 | @@ -0,0 +1,49 @@ |
245 | +# -*- coding: utf-8 -*- |
246 | +############################################################################## |
247 | +# |
248 | +# OpenERP, Open Source Management Solution |
249 | +# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
250 | +# |
251 | +# This program is free software: you can redistribute it and/or modify |
252 | +# it under the terms of the GNU Affero General Public License as |
253 | +# published by the Free Software Foundation, either version 3 of the |
254 | +# License, or (at your option) any later version. |
255 | +# |
256 | +# This program is distributed in the hope that it will be useful, |
257 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
258 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
259 | +# GNU Affero General Public License for more details. |
260 | +# |
261 | +# You should have received a copy of the GNU Affero General Public License |
262 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
263 | +# |
264 | +############################################################################## |
265 | + |
266 | +from openerp.osv import osv, fields |
267 | + |
268 | + |
269 | +class account_bank_statement_line(osv.Model): |
270 | + _inherit = 'account.bank.statement.line' |
271 | + def create_instant_voucher(self, cr, uid, ids, context=None): |
272 | + res = False |
273 | + if ids: |
274 | + if isinstance(ids, (int, float)): |
275 | + ids = [ids] |
276 | + if context is None: |
277 | + context = {} |
278 | + local_context = context.copy() |
279 | + local_context['active_id'] = ids[0] |
280 | + wizard_obj = self.pool.get('account.voucher.instant') |
281 | + res = { |
282 | + 'name': wizard_obj._description, |
283 | + 'view_type': 'form', |
284 | + 'view_mode': 'form', |
285 | + 'res_model': wizard_obj._name, |
286 | + 'domain': [], |
287 | + 'context': local_context, |
288 | + 'type': 'ir.actions.act_window', |
289 | + 'target': 'new', |
290 | + 'res_id': False, |
291 | + 'nodestroy': False, |
292 | + } |
293 | + return res |
294 | |
295 | === added file 'bank_statement_instant_voucher/model/account_voucher_instant.py' |
296 | --- bank_statement_instant_voucher/model/account_voucher_instant.py 1970-01-01 00:00:00 +0000 |
297 | +++ bank_statement_instant_voucher/model/account_voucher_instant.py 2012-12-05 20:19:21 +0000 |
298 | @@ -0,0 +1,306 @@ |
299 | +# -*- coding: utf-8 -*- |
300 | +############################################################################## |
301 | +# |
302 | +# OpenERP, Open Source Management Solution |
303 | +# This module copyright (C) 2012 Therp BV (<http://therp.nl>). |
304 | +# |
305 | +# This program is free software: you can redistribute it and/or modify |
306 | +# it under the terms of the GNU Affero General Public License as |
307 | +# published by the Free Software Foundation, either version 3 of the |
308 | +# License, or (at your option) any later version. |
309 | +# |
310 | +# This program is distributed in the hope that it will be useful, |
311 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
312 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
313 | +# GNU Affero General Public License for more details. |
314 | +# |
315 | +# You should have received a copy of the GNU Affero General Public License |
316 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
317 | +# |
318 | +############################################################################## |
319 | + |
320 | +from openerp.osv import osv, fields |
321 | +from openerp.tools.translate import _ |
322 | +from openerp.addons.decimal_precision import decimal_precision as dp |
323 | + |
324 | + |
325 | +class instant_voucher(osv.TransientModel): |
326 | + _name = 'account.voucher.instant' |
327 | + _description = 'Instant Voucher' |
328 | + |
329 | + def cancel(self, cr, uid, ids, context=None): |
330 | + """ |
331 | + Delete the voucher and close window |
332 | + """ |
333 | + assert len(ids) == 1, "Will only take one resource id" |
334 | + instant = self.browse(cr, uid, ids[0], context=context) |
335 | + if instant.voucher_id: |
336 | + self.pool.get('account.voucher').cancel_voucher( |
337 | + cr, uid, [instant.voucher_id.id], context=context) |
338 | + self.pool.get('account.voucher').unlink( |
339 | + cr, uid, [instant.voucher_id.id], context=context) |
340 | + return {'type': 'ir.actions.act_window_close'} |
341 | + |
342 | + def get_voucher_defaults( |
343 | + self, cr, uid, vals, context=None): |
344 | + """ |
345 | + Gather conditional defaults based on given key, value pairs |
346 | + |
347 | + :param vals: dictionary of key, value pairs |
348 | + :returns: dictionary of default values for fields not in vals |
349 | + """ |
350 | + values_pool = self.pool.get('ir.values') |
351 | + voucher_pool = self.pool.get('account.voucher') |
352 | + res = {} |
353 | + for (key, val) in vals.iteritems(): |
354 | + if val and voucher_pool._all_columns[key].column.change_default: |
355 | + for default in values_pool.get_defaults( |
356 | + cr, uid, 'account.voucher', '%s=%s' % (key, val)): |
357 | + if default[1] not in vals: |
358 | + res[default[1]] = default[2] |
359 | + return res |
360 | + |
361 | + def create_voucher(self, cr, uid, ids, context=None): |
362 | + """ |
363 | + Create a fully fledged voucher counterpart for the |
364 | + statement line. User only needs to process taxes and may |
365 | + adapt cost/income account. |
366 | + """ |
367 | + assert len(ids) == 1, "Will only take one resource id" |
368 | + voucher_pool = self.pool.get('account.voucher') |
369 | + period_pool = self.pool.get('account.period') |
370 | + instant = self.browse(cr, uid, ids[0], context=context) |
371 | + line = instant.statement_line_id |
372 | + voucher_type = line.amount < 0 and 'purchase' or 'sale' |
373 | + journal_ids = self.pool.get('account.journal').search( |
374 | + cr, uid, [('company_id', '=', line.company_id.id), |
375 | + ('type', '=', voucher_type)]) |
376 | + if not journal_ids: |
377 | + osv.exept_osv( |
378 | + _('Error'), |
379 | + _('No %s journal defined') % voucher_type) |
380 | + |
381 | + journal = self.pool.get('account.journal').browse( |
382 | + cr, uid, journal_ids[0], context=context) |
383 | + if journal.type in ('sale', 'sale_refund'): |
384 | + line_account_id = (journal.default_credit_account_id and |
385 | + journal.default_credit_account_id.id or False) |
386 | + elif journal.type in ('purchase', 'expense', 'purchase_refund'): |
387 | + line_account_id = (journal.default_debit_account_id and |
388 | + journal.default_debit_account_id.id or False) |
389 | + vals = { |
390 | + 'name': _('Voucher for statement line %s.%s') % (line.statement_id.name, line.name), |
391 | + 'reference': line.ref or False, |
392 | + 'company_id': line.company_id.id, |
393 | + 'partner_id': instant.partner_id.id, |
394 | + 'date': line.date or res.get('line.date', False), |
395 | + 'account_id': line.account_id.id, |
396 | + 'type': voucher_type, |
397 | + 'line_ids': [(0, 0, {'amount': abs(line.amount), |
398 | + 'account_id': line_account_id, |
399 | + 'type': line.amount < 0 and 'dr' or 'cr', |
400 | + 'name': line.ref or False, |
401 | + })], |
402 | + 'amount': line.amount and abs(line.amount) or res.get('amount', False), |
403 | + 'journal_id': journal_ids[0], |
404 | + } |
405 | + if vals['date']: |
406 | + period_ids = period_pool.find(cr, uid, vals['date'], context=context) |
407 | + if period_ids: |
408 | + vals['period_id'] = period_ids[0] |
409 | + vals.update(self.get_voucher_defaults(cr, uid, vals, context=context)) |
410 | + |
411 | + voucher_id = voucher_pool.create( |
412 | + cr, uid, vals, context=context) |
413 | + self.write( |
414 | + cr, uid, ids[0], |
415 | + {'voucher_id': voucher_id, |
416 | + 'state': 'ready', |
417 | + 'type': voucher_type, |
418 | + }, context=context) |
419 | + return { |
420 | + 'name': self._description, |
421 | + 'view_type': 'form', |
422 | + 'view_mode': 'form', |
423 | + 'res_model': self._name, |
424 | + 'domain': [], |
425 | + 'context': context, |
426 | + 'type': 'ir.actions.act_window', |
427 | + 'target': 'new', |
428 | + 'res_id': ids[0], |
429 | + 'nodestroy': False, |
430 | + } |
431 | + |
432 | + def dummy(self, cr, uid, ids, context=None): |
433 | + return { |
434 | + 'name': self._description, |
435 | + 'view_type': 'form', |
436 | + 'view_mode': 'form', |
437 | + 'res_model': self._name, |
438 | + 'domain': [], |
439 | + 'context': context, |
440 | + 'type': 'ir.actions.act_window', |
441 | + 'target': 'new', |
442 | + 'res_id': ids[0], |
443 | + 'nodestroy': False, |
444 | + } |
445 | + |
446 | + def default_get(self, cr, uid, fields_list, context=None): |
447 | + """ |
448 | + Gather sane default values from the originating statement line |
449 | + """ |
450 | + res = super(instant_voucher, self).default_get( |
451 | + cr, uid, fields_list, context=context) |
452 | + if 'statement_line_id' in fields_list: |
453 | + res['statement_line_id'] = ( |
454 | + context.get('active_id') or |
455 | + context.get('active_ids') and context.get('active_ids')[0]) |
456 | + if not res['statement_line_id']: |
457 | + raise osv.except_osv( |
458 | + _('Error'), |
459 | + _('Cannot determine statement line')) |
460 | + line = self.pool.get('account.bank.statement.line').browse( |
461 | + cr, uid, res['statement_line_id'], context=context) |
462 | + if 'balance' in fields_list: |
463 | + res['balance'] = line.amount |
464 | + if 'ref' in fields_list: |
465 | + res['ref'] = line.ref |
466 | + if 'partner_id' in fields_list: |
467 | + if line.partner_id: |
468 | + res['partner_id'] = line.partner_id.id |
469 | + return res |
470 | + |
471 | + def _get_balance(self, cr, uid, ids, field_name, args, context=None): |
472 | + """ |
473 | + Compute the expected residual |
474 | + TODO: currency conversion |
475 | + """ |
476 | + res = {} |
477 | + for instant in self.browse(cr, uid, ids, context=context): |
478 | + if instant.voucher_id and instant.voucher_id.state == 'posted': |
479 | + amount = instant.statement_line_id.amount |
480 | + counteramount = 0.0 |
481 | + for line in instant.voucher_id.move_ids: |
482 | + if line.account_id.id == instant.statement_line_id.account_id.id: |
483 | + counteramount = line.debit - line.credit |
484 | + for line in instant.voucher_id.move_ids: |
485 | + if line.account_id.id == instant.statement_line_id.account_id.id: |
486 | + counteramount = line.debit - line.credit |
487 | + else: |
488 | + amount = abs(instant.statement_line_id.amount) |
489 | + counteramount = abs(instant.voucher_id and instant.voucher_id.amount or 0.0) |
490 | + res[instant.id] = amount - counteramount |
491 | + return res |
492 | + |
493 | + def confirm(self, cr, uid, ids, context=None): |
494 | + """ |
495 | + Post the voucher if necessary |
496 | + Post the voucher's move lines if necessary |
497 | + Sanity checks on currency and residual = 0.0 |
498 | + |
499 | + If the account_banking module is installed, perform matching |
500 | + and reconciliation. If not, the user is left to manual |
501 | + reconciliation of OpenERP. |
502 | + """ |
503 | + assert len(ids) == 1, "Will only take one resource id" |
504 | + statement_line_obj = self.pool.get('account.bank.statement.line') |
505 | + voucher_obj = self.pool.get('account.voucher') |
506 | + move_obj = self.pool.get('account.move') |
507 | + instant = self.browse(cr, uid, ids[0], context=context) |
508 | + voucher_currency = (instant.voucher_id.currency_id and |
509 | + instant.voucher_id.currency_id or |
510 | + instant.voucher_id.company_id.currency_id) |
511 | + if (instant.statement_line_id.statement_id.currency.id != |
512 | + voucher_currency.id): |
513 | + raise osv.except_osv( |
514 | + _("Error"), |
515 | + _("Currency on the bank statement line needs to be the " |
516 | + "same as on the voucher. Currency conversion is not yet " |
517 | + "supported.")) |
518 | + if instant.voucher_id.state != 'posted': |
519 | + voucher_obj.proforma_voucher( |
520 | + cr, uid, [instant.voucher_id.id], context=context) |
521 | + instant.refresh() |
522 | + if instant.voucher_id.state != 'posted': |
523 | + raise osv.except_osv( |
524 | + _("Error"), |
525 | + _("The voucher could not be posted.")) |
526 | + if instant.voucher_id.move_id.state != 'posted': |
527 | + move_obj.post( |
528 | + cr, uid, [instant.voucher_id.move_id.id], context=context) |
529 | + instant.refresh() |
530 | + if instant.voucher_id.move_id.state != 'posted': |
531 | + raise osv.except_osv( |
532 | + _("Error"), |
533 | + _("The voucher's move line could not be posted.")) |
534 | + if not self.pool.get('res.currency').is_zero( |
535 | + cr, uid, voucher_currency, instant.balance): |
536 | + raise osv.except_osv( |
537 | + _("Error"), |
538 | + _("The amount on the bank statement line needs to be the " |
539 | + "same as on the voucher. Write-off is not yet " |
540 | + "supported.")) |
541 | + # Banking Addons integration: |
542 | + # Gather the info needed to match the bank statement line |
543 | + # and trigger its posting and reconciliation. |
544 | + if 'import_transaction_id' in statement_line_obj._columns: |
545 | + if instant.statement_line_id.state == 'confirmed': |
546 | + raise osv.except_osv( |
547 | + _("Error"), |
548 | + _("Cannot match a confirmed statement line")) |
549 | + if not instant.statement_line_id.import_transaction_id: |
550 | + statement_line_obj.create_instant_transaction( |
551 | + cr, uid, instant.statement_line_id.id, context=context) |
552 | + instant.statement_line_id.refresh() |
553 | + for line in instant.voucher_id.move_ids: |
554 | + if line.account_id.id == instant.statement_line_id.account_id.id: |
555 | + self.pool.get('banking.import.transaction').write( |
556 | + cr, uid, instant.statement_line_id.import_transaction_id.id, |
557 | + { |
558 | + 'move_line_id': line.id, |
559 | + 'move_line_ids': [(6, 0, [line.id])], |
560 | + 'match_type': 'move', |
561 | + 'invoice_id': False, |
562 | + 'invoice_ids': [(6, 0, [])], |
563 | + }, context=context) |
564 | + |
565 | + statement_line_obj.confirm( |
566 | + cr, uid, [instant.statement_line_id.id], context=context) |
567 | + break |
568 | + return {'type': 'ir.actions.act_window_close'} |
569 | + |
570 | + _columns = { |
571 | + 'balance': fields.function( |
572 | + _get_balance, |
573 | + type='float', |
574 | + digits_compute=dp.get_precision('Account'), |
575 | + string="Balance",), |
576 | + 'partner_id': fields.many2one( |
577 | + 'res.partner', |
578 | + 'Partner', |
579 | + required=True), |
580 | + 'statement_line_id': fields.many2one( |
581 | + 'account.bank.statement.line', |
582 | + 'Bank statement line', |
583 | + readonly=True), |
584 | + 'ref': fields.related( |
585 | + 'statement_line_id', 'ref', |
586 | + type="char", size="48", |
587 | + readonly=True, |
588 | + string="Reference"), |
589 | + 'voucher_id': fields.many2one( |
590 | + 'account.voucher', |
591 | + 'Voucher', |
592 | + readonly=True), |
593 | + 'state': fields.selection( |
594 | + [('init', 'init'), |
595 | + ('ready', 'ready'), |
596 | + ('confirm', 'confirm')], |
597 | + 'State'), |
598 | + 'type': fields.selection( |
599 | + [('sale', 'Sale'), |
600 | + ('purchase', 'Purchase')], |
601 | + 'Voucher type'), |
602 | + } |
603 | + |
604 | + _defaults = {'state': 'init'} |
605 | |
606 | === added directory 'bank_statement_instant_voucher/view' |
607 | === added file 'bank_statement_instant_voucher/view/account_bank_statement_line.xml' |
608 | --- bank_statement_instant_voucher/view/account_bank_statement_line.xml 1970-01-01 00:00:00 +0000 |
609 | +++ bank_statement_instant_voucher/view/account_bank_statement_line.xml 2012-12-05 20:19:21 +0000 |
610 | @@ -0,0 +1,21 @@ |
611 | +<?xml version="1.0" encoding="utf-8"?> |
612 | +<openerp> |
613 | + <data> |
614 | + <record id="view_banking_bank_statement_form" model="ir.ui.view"> |
615 | + <field name="name">Add instant voucher button to bank statement line on statement form</field> |
616 | + <field name="inherit_id" ref="account.view_bank_statement_form" /> |
617 | + <field name="model">account.bank.statement</field> |
618 | + <field name="type">form</field> |
619 | + <field name="priority" eval="30"/> |
620 | + <field name="arch" type="xml"> |
621 | + <xpath expr="/form/notebook/page/field[@name='line_ids']/tree/field[@name='voucher_id']" |
622 | + position="before"> |
623 | + <button name="create_instant_voucher" states="draft" |
624 | + string="Create matching voucher" |
625 | + icon="STOCK_COPY" |
626 | + type="object"/> |
627 | + </xpath> |
628 | + </field> |
629 | + </record> |
630 | + </data> |
631 | +</openerp> |
632 | |
633 | === added file 'bank_statement_instant_voucher/view/account_voucher_instant.xml' |
634 | --- bank_statement_instant_voucher/view/account_voucher_instant.xml 1970-01-01 00:00:00 +0000 |
635 | +++ bank_statement_instant_voucher/view/account_voucher_instant.xml 2012-12-05 20:19:21 +0000 |
636 | @@ -0,0 +1,52 @@ |
637 | +<?xml version="1.0" encoding="utf-8"?> |
638 | +<openerp> |
639 | + <data> |
640 | + <record id="instant_voucher_form" model="ir.ui.view"> |
641 | + <field name="name">Instant voucher form view</field> |
642 | + <field name="model">account.voucher.instant</field> |
643 | + <field name="type">form</field> |
644 | + <field name="arch" type="xml"> |
645 | + <form> |
646 | + <field name="state" invisible="1" readonly="1"/> |
647 | + <field name="statement_line_id"/> |
648 | + <field name="ref"/> |
649 | + <newline/> |
650 | + <field name="partner_id"/> |
651 | + <field name="balance"/> |
652 | + <newline/> |
653 | + <field name="type" invisible="1"/> |
654 | + <field name="voucher_id" |
655 | + context="{'statement_line_id': statement_line_id, |
656 | + 'form_view_ref': ( |
657 | + type == 'sale' and 'account_voucher.view_sale_receipt_form' |
658 | + or 'account_voucher.view_purchase_receipt_form') |
659 | + }" |
660 | + /> |
661 | + <newline/> |
662 | + <newline/> |
663 | + <button icon="gtk-cancel" |
664 | + string="Cancel" |
665 | + name="cancel" |
666 | + type="object"/> |
667 | + <button icon="gtk-ok" string="Confirm" |
668 | + states="ready" |
669 | + name="confirm" |
670 | + type="object" |
671 | + /> |
672 | + <button icon="gtk-ok" string="Create voucher" |
673 | + states="init" |
674 | + name="create_voucher" |
675 | + type="object" |
676 | + /> |
677 | + </form> |
678 | + </field> |
679 | + </record> |
680 | + <act_window name="Create matching voucher" |
681 | + res_model="account.voucher.instant" |
682 | + src_model="account.bank.statement.line" |
683 | + view_mode="form" |
684 | + target="new" |
685 | + key2="client_action_multi" |
686 | + id="act_instant_voucher"/> |
687 | + </data> |
688 | +</openerp> |
Hi,
319+from osv import osv, fields tools.translate import _
320+from tools.translate import _
The full import pathes should now be used as per the new Model classes
Example
from openerp.osv import orm, osv, fields
from openerp.
class instant_ voucher( orm.TransientMo del):
277+ context[ 'active_ id'] = ids[0]
285+ 'context': context,
you probably want to use the local_context created just upper (line 276)
332+ instant = self.browse(cr, uid, ids[0], context=context)
361+ instant = self.browse(cr, uid, ids[0], context=context)
496+ instant = self.browse(cr, uid, ids[0], context=context)
As the first item only of the ids argument is used, it would be a good idea
to check that only 1 id have been given. ie. use an assert
345+ for (key, val) in vals.items():
Better have to use vals.iteritems() to avoid the generation of a unnecessary list.
340+ def update_ voucher_ defaults(
It should not return a None value because it is callable from XML/RPC.
I had been mingled by the vals which is a mutable argument and modified in place.
I would have returned only the default vals in this method and updated the vals in the callee method.