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