Merge lp:~domsense/domsense-agilebg-addons/adding_account_document_template into lp:domsense-agilebg-addons/6.0
- adding_account_document_template
- Merge into 6.0
Proposed by
Lorenzo Battistini
Status: | Merged |
---|---|
Merged at revision: | 50 |
Proposed branch: | lp:~domsense/domsense-agilebg-addons/adding_account_document_template |
Merge into: | lp:domsense-agilebg-addons/6.0 |
Diff against target: |
610 lines (+557/-0) 10 files modified
account_move_template/AUTHORS.txt (+2/-0) account_move_template/__init__.py (+24/-0) account_move_template/__openerp__.py (+46/-0) account_move_template/account_document_template.py (+93/-0) account_move_template/account_move_template.py (+58/-0) account_move_template/move_template.xml (+102/-0) account_move_template/security/ir.model.access.csv (+9/-0) account_move_template/wizard/__init__.py (+22/-0) account_move_template/wizard/select_template.py (+128/-0) account_move_template/wizard/select_template.xml (+73/-0) |
To merge this branch: | bzr merge lp:~domsense/domsense-agilebg-addons/adding_account_document_template |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Agile Business Group | Pending | ||
Review via email: mp+80692@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'account_move_template' |
2 | === added file 'account_move_template/AUTHORS.txt' |
3 | --- account_move_template/AUTHORS.txt 1970-01-01 00:00:00 +0000 |
4 | +++ account_move_template/AUTHORS.txt 2011-10-28 16:15:28 +0000 |
5 | @@ -0,0 +1,2 @@ |
6 | +Davide Corio <davide.corio@agilebg.com> |
7 | +Lorenzo Battistini <lorenzo.battistini@agilebg.com> |
8 | |
9 | === added file 'account_move_template/__init__.py' |
10 | --- account_move_template/__init__.py 1970-01-01 00:00:00 +0000 |
11 | +++ account_move_template/__init__.py 2011-10-28 16:15:28 +0000 |
12 | @@ -0,0 +1,24 @@ |
13 | +# -*- coding: utf-8 -*- |
14 | +############################################################################## |
15 | +# |
16 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
17 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
18 | +# All Rights Reserved |
19 | +# |
20 | +# This program is free software: you can redistribute it and/or modify |
21 | +# it under the terms of the GNU Affero General Public License as published |
22 | +# by the Free Software Foundation, either version 3 of the License, or |
23 | +# (at your option) any later version. |
24 | +# |
25 | +# This program is distributed in the hope that it will be useful, |
26 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
27 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
28 | +# GNU General Public License for more details. |
29 | +# |
30 | +# You should have received a copy of the GNU Affero General Public License |
31 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
32 | +# |
33 | +############################################################################## |
34 | +import account_document_template |
35 | +import account_move_template |
36 | +import wizard |
37 | |
38 | === added file 'account_move_template/__openerp__.py' |
39 | --- account_move_template/__openerp__.py 1970-01-01 00:00:00 +0000 |
40 | +++ account_move_template/__openerp__.py 2011-10-28 16:15:28 +0000 |
41 | @@ -0,0 +1,46 @@ |
42 | +# -*- coding: utf-8 -*- |
43 | +############################################################################## |
44 | +# |
45 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
46 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
47 | +# All Rights Reserved |
48 | +# |
49 | +# This program is free software: you can redistribute it and/or modify |
50 | +# it under the terms of the GNU Affero General Public License as published |
51 | +# by the Free Software Foundation, either version 3 of the License, or |
52 | +# (at your option) any later version. |
53 | +# |
54 | +# This program is distributed in the hope that it will be useful, |
55 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
56 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
57 | +# GNU General Public License for more details. |
58 | +# |
59 | +# You should have received a copy of the GNU Affero General Public License |
60 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
61 | +# |
62 | +############################################################################## |
63 | +{ |
64 | + 'name': "Account Move Template", |
65 | + 'version': '0.1', |
66 | + 'category': 'Generic Modules/Accounting', |
67 | + 'description': """ |
68 | +============================= |
69 | +Templates for Journal Entries |
70 | +============================= |
71 | +User can configure journal entries templates. The amount of each template line can be computed (through python code) or kept as user input. If user input, when using the template, user has to fill the amount of every input lines. |
72 | +The journal entry form allows lo load, through a wizard, the template to use and the amounts to fill. |
73 | +""", |
74 | + 'author': 'Agile Business Group & Domsense', |
75 | + 'website': 'http://www.agilebg.com', |
76 | + 'license': 'AGPL-3', |
77 | + "depends" : ['account'], |
78 | + "init_xml" : [], |
79 | + "update_xml" : [ |
80 | + 'move_template.xml', |
81 | + 'wizard/select_template.xml', |
82 | + 'security/ir.model.access.csv', |
83 | + ], |
84 | + "demo_xml" : [], |
85 | + "active": False, |
86 | + "installable": True |
87 | +} |
88 | |
89 | === added file 'account_move_template/account_document_template.py' |
90 | --- account_move_template/account_document_template.py 1970-01-01 00:00:00 +0000 |
91 | +++ account_move_template/account_document_template.py 2011-10-28 16:15:28 +0000 |
92 | @@ -0,0 +1,93 @@ |
93 | +# -*- coding: utf-8 -*- |
94 | +############################################################################## |
95 | +# |
96 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
97 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
98 | +# All Rights Reserved |
99 | +# |
100 | +# This program is free software: you can redistribute it and/or modify |
101 | +# it under the terms of the GNU Affero General Public License as published |
102 | +# by the Free Software Foundation, either version 3 of the License, or |
103 | +# (at your option) any later version. |
104 | +# |
105 | +# This program is distributed in the hope that it will be useful, |
106 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
107 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
108 | +# GNU General Public License for more details. |
109 | +# |
110 | +# You should have received a copy of the GNU Affero General Public License |
111 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
112 | +# |
113 | +############################################################################## |
114 | + |
115 | +from osv import fields, osv |
116 | +from tools.translate import _ |
117 | + |
118 | +class account_document_template(osv.osv): |
119 | + |
120 | + _computed_lines = {} |
121 | + _current_template_id = 0 |
122 | + _cr = None |
123 | + _uid = None |
124 | + _name = 'account.document.template' |
125 | + |
126 | + _columns = { |
127 | + 'name': fields.char('Name', size=64, required=True), |
128 | + } |
129 | + |
130 | + def _input_lines(self, cr, uid, template): |
131 | + count = 0 |
132 | + for line in template.template_line_ids: |
133 | + if line.type == 'input': |
134 | + count += 1 |
135 | + return count |
136 | + |
137 | + def _get_template_line(self, cr, uid, template_id, line_number): |
138 | + for line in self.browse(cr, uid, template_id).template_line_ids: |
139 | + if line.sequence == line_number: |
140 | + return line |
141 | + return False |
142 | + |
143 | + def _generate_empty_lines(self, cr, uid, template_id): |
144 | + lines = {} |
145 | + for template_line in self.browse(cr, uid, template_id).template_line_ids: |
146 | + lines[template_line.sequence] = None |
147 | + return lines |
148 | + |
149 | + def lines(self, line_number): |
150 | + if self._computed_lines[line_number] is not None: |
151 | + return self._computed_lines[line_number] |
152 | + line = self._get_template_line(self._cr, self._uid, self._current_template_id, line_number) |
153 | + self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines')) |
154 | + return self._computed_lines[line_number] |
155 | + |
156 | + def compute_lines(self, cr, uid, template_id, input_lines): |
157 | + # input_lines: dictionary in the form {line_number: line_amount} |
158 | + # returns all the lines (included input lines) in the form {line_number: line_amount} |
159 | + template = self.browse(cr, uid, template_id) |
160 | + if len(input_lines) != self._input_lines(cr, uid, template): |
161 | + raise osv.except_osv(_('Error'), |
162 | + _('Inconsistency between input lines and filled lines for template %s') % template.name) |
163 | + self._current_template_id = template.id |
164 | + self._cr = cr |
165 | + self._uid = uid |
166 | + self._computed_lines = self._generate_empty_lines(cr, uid, template_id) |
167 | + self._computed_lines.update(input_lines) |
168 | + for line_number in self._computed_lines: |
169 | + self.lines(line_number) |
170 | + return self._computed_lines |
171 | + |
172 | +account_document_template() |
173 | + |
174 | +class account_document_template_line(osv.osv): |
175 | + |
176 | + _name = 'account.document.template.line' |
177 | + |
178 | + _columns = { |
179 | + 'name': fields.char('Name', size=64, required=True), |
180 | + 'sequence': fields.integer('Number', required=True), |
181 | + 'type': fields.selection([('computed', 'Computed'),('input', 'User input')], 'Type', required=True), |
182 | + 'python_code':fields.text('Python Code'), |
183 | + } |
184 | + |
185 | +account_document_template_line() |
186 | |
187 | === added file 'account_move_template/account_move_template.py' |
188 | --- account_move_template/account_move_template.py 1970-01-01 00:00:00 +0000 |
189 | +++ account_move_template/account_move_template.py 2011-10-28 16:15:28 +0000 |
190 | @@ -0,0 +1,58 @@ |
191 | +# -*- coding: utf-8 -*- |
192 | +############################################################################## |
193 | +# |
194 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
195 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
196 | +# All Rights Reserved |
197 | +# |
198 | +# This program is free software: you can redistribute it and/or modify |
199 | +# it under the terms of the GNU Affero General Public License as published |
200 | +# by the Free Software Foundation, either version 3 of the License, or |
201 | +# (at your option) any later version. |
202 | +# |
203 | +# This program is distributed in the hope that it will be useful, |
204 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
205 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
206 | +# GNU General Public License for more details. |
207 | +# |
208 | +# You should have received a copy of the GNU Affero General Public License |
209 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
210 | +# |
211 | +############################################################################## |
212 | + |
213 | +from osv import fields, osv |
214 | +from tools.translate import _ |
215 | + |
216 | +class account_move_template(osv.osv): |
217 | + |
218 | + _inherit = 'account.document.template' |
219 | + _name = 'account.move.template' |
220 | + |
221 | + _columns = { |
222 | + 'journal_id': fields.many2one('account.journal', 'Journal', required=True), |
223 | + 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True), |
224 | + 'template_line_ids': fields.one2many('account.move.template.line', 'template_id', 'Template Lines'), |
225 | + } |
226 | + |
227 | +account_move_template() |
228 | + |
229 | +class account_move_template_line(osv.osv): |
230 | + |
231 | + _name = 'account.move.template.line' |
232 | + _inherit = 'account.document.template.line' |
233 | + |
234 | + _columns = { |
235 | + 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"), |
236 | + 'move_line_type':fields.selection([ |
237 | + ('cr','Credit'), |
238 | + ('dr','Debit'), |
239 | + ], 'Move Line Type', required=True), |
240 | + 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"), |
241 | + 'template_id': fields.many2one('account.move.template', 'Template'), |
242 | + } |
243 | + |
244 | + _sql_constraints = [ |
245 | + ('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !') |
246 | + ] |
247 | + |
248 | +account_move_template_line() |
249 | |
250 | === added directory 'account_move_template/i18n' |
251 | === added file 'account_move_template/move_template.xml' |
252 | --- account_move_template/move_template.xml 1970-01-01 00:00:00 +0000 |
253 | +++ account_move_template/move_template.xml 2011-10-28 16:15:28 +0000 |
254 | @@ -0,0 +1,102 @@ |
255 | +<?xml version="1.0" encoding="utf-8"?> |
256 | +<openerp> |
257 | + <data> |
258 | + |
259 | + <record id="view_move_template_line_tree" model="ir.ui.view"> |
260 | + <field name="name">account.move.template.line.tree</field> |
261 | + <field name="model">account.move.template.line</field> |
262 | + <field name="type">tree</field> |
263 | + <field name="arch" type="xml"> |
264 | + <tree string="Journal Entry Template Line"> |
265 | + <field name="sequence"/> |
266 | + <field name="name"/> |
267 | + <field name="account_id" /> |
268 | + <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/> |
269 | + <field name="type"/> |
270 | + <field name="python_code" /> |
271 | + <field name="move_line_type"/> |
272 | + </tree> |
273 | + </field> |
274 | + </record> |
275 | + |
276 | + |
277 | + <record id="view_move_template_line_form" model="ir.ui.view"> |
278 | + <field name="name">account.move.template.line.form</field> |
279 | + <field name="model">account.move.template.line</field> |
280 | + <field name="type">form</field> |
281 | + <field name="arch" type="xml"> |
282 | + <form string="Journal Entry Template Line"> |
283 | + <field colspan="4" name="name" select="1"/> |
284 | + <field name="sequence"/> |
285 | + <field name="account_id" domain="[('type','<>','view'),('type','<>','consolidation')]"/> |
286 | + <field name="analytic_account_id" groups="analytic.group_analytic_accounting"/> |
287 | + <field name="type"/> |
288 | + <field name="move_line_type"/> |
289 | + <separator string="Python Code" colspan="4"/> |
290 | + <field name="python_code" colspan="4" attrs="{'readonly': [('type', '!=', 'computed')]}" nolabel="1"/> |
291 | + <label string="You can refer to other lines using their sequence number (e.g. 'L(1)' for first line). Example of code: 'L(1) * 0.2'" colspan="4"/> |
292 | + </form> |
293 | + </field> |
294 | + </record> |
295 | + |
296 | + <record id="view_move_template_form" model="ir.ui.view"> |
297 | + <field name="name">account.move.template.form</field> |
298 | + <field name="model">account.move.template</field> |
299 | + <field name="type">form</field> |
300 | + <field name="arch" type="xml"> |
301 | + <form string="Journal Entry Template"> |
302 | + <field name="name"/> |
303 | + <field name="journal_id"/> |
304 | + <field name="company_id" widget='selection' groups="base.group_multi_company"/> |
305 | + <field colspan="4" nolabel="1" name="template_line_ids"/> |
306 | + </form> |
307 | + </field> |
308 | + </record> |
309 | + |
310 | + <record id="view_move_template_tree" model="ir.ui.view"> |
311 | + <field name="name">account.move.template.tree</field> |
312 | + <field name="model">account.move.template</field> |
313 | + <field name="type">tree</field> |
314 | + <field name="arch" type="xml"> |
315 | + <tree string="Journal Entry Template"> |
316 | + <field name="name"/> |
317 | + <field name="journal_id"/> |
318 | + <field name="company_id" groups="base.group_multi_company"/> |
319 | + </tree> |
320 | + </field> |
321 | + </record> |
322 | + |
323 | + <record id="view_move_template_search" model="ir.ui.view"> |
324 | + <field name="name">account.move.template.search</field> |
325 | + <field name="model">account.move.template</field> |
326 | + <field name="type">search</field> |
327 | + <field name="arch" type="xml"> |
328 | + <search string="Journal Entry Template"> |
329 | + <group> |
330 | + <filter string="Sale" icon="terp-camera_test" domain="[('journal_id.type', '=', 'sale')]"/> |
331 | + <filter string="Purchase" icon="terp-purchase" domain="[('journal_id.type', '=', 'purchase')]"/> |
332 | + <separator orientation="vertical"/> |
333 | + <field name="name"/> |
334 | + <field name="journal_id" widget="selection"/> |
335 | + <field name="company_id" widget="selection" groups="base.group_multi_company"/> |
336 | + </group> |
337 | + <newline/> |
338 | + <group expand="0" string="Group By..."> |
339 | + <filter string="Journal" icon="terp-folder-orange" domain="[]" context="{'group_by':'journal_id'}"/> |
340 | + </group> |
341 | + </search> |
342 | + </field> |
343 | + </record> |
344 | + |
345 | + <record id="action_move_template_form" model="ir.actions.act_window"> |
346 | + <field name="name">Move Templates</field> |
347 | + <field name="res_model">account.move.template</field> |
348 | + <field name="view_type">form</field> |
349 | + <field name="view_mode">tree,form</field> |
350 | + <field name="search_view_id" ref="view_move_template_search"/> |
351 | + </record> |
352 | + <menuitem |
353 | + action="action_move_template_form" id="menu_action_move_template_form" sequence="5" |
354 | + parent="account.menu_configuration_misc" groups="base.group_extended"/> |
355 | + </data> |
356 | +</openerp> |
357 | |
358 | === added directory 'account_move_template/security' |
359 | === added file 'account_move_template/security/ir.model.access.csv' |
360 | --- account_move_template/security/ir.model.access.csv 1970-01-01 00:00:00 +0000 |
361 | +++ account_move_template/security/ir.model.access.csv 2011-10-28 16:15:28 +0000 |
362 | @@ -0,0 +1,9 @@ |
363 | +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" |
364 | +"access_account_document_template_user","account_document_template_user","model_account_document_template","account.group_account_user","1","1","1","1" |
365 | +"access_account_document_template_manager","account_document_template_manager","model_account_document_template","account.group_account_manager","1","1","1","1" |
366 | +"access_account_document_template_line_user","account_document_template_line_user","model_account_document_template_line","account.group_account_user","1","1","1","1" |
367 | +"access_account_document_template_line_manager","account_document_template_line_manager","model_account_document_template_line","account.group_account_manager","1","1","1","1" |
368 | +"access_account_move_template_user","account_move_template_user","model_account_move_template","account.group_account_user","1","1","1","1" |
369 | +"access_account_move_template_manager","account_move_template_manager","model_account_move_template","account.group_account_manager","1","1","1","1" |
370 | +"access_account_move_template_line_user","account_move_template_line_user","model_account_move_template_line","account.group_account_user","1","1","1","1" |
371 | +"access_account_move_template_line_manager","account_move_template_line_manager","model_account_move_template_line","account.group_account_manager","1","1","1","1" |
372 | |
373 | === added directory 'account_move_template/wizard' |
374 | === added file 'account_move_template/wizard/__init__.py' |
375 | --- account_move_template/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
376 | +++ account_move_template/wizard/__init__.py 2011-10-28 16:15:28 +0000 |
377 | @@ -0,0 +1,22 @@ |
378 | +# -*- coding: utf-8 -*- |
379 | +############################################################################## |
380 | +# |
381 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
382 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
383 | +# All Rights Reserved |
384 | +# |
385 | +# This program is free software: you can redistribute it and/or modify |
386 | +# it under the terms of the GNU Affero General Public License as published |
387 | +# by the Free Software Foundation, either version 3 of the License, or |
388 | +# (at your option) any later version. |
389 | +# |
390 | +# This program is distributed in the hope that it will be useful, |
391 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
392 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
393 | +# GNU General Public License for more details. |
394 | +# |
395 | +# You should have received a copy of the GNU Affero General Public License |
396 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
397 | +# |
398 | +############################################################################## |
399 | +import select_template |
400 | |
401 | === added file 'account_move_template/wizard/select_template.py' |
402 | --- account_move_template/wizard/select_template.py 1970-01-01 00:00:00 +0000 |
403 | +++ account_move_template/wizard/select_template.py 2011-10-28 16:15:28 +0000 |
404 | @@ -0,0 +1,128 @@ |
405 | +# -*- coding: utf-8 -*- |
406 | +############################################################################## |
407 | +# |
408 | +# Copyright (C) 2011 Agile Business Group sagl (<http://www.agilebg.com>) |
409 | +# Copyright (C) 2011 Domsense srl (<http://www.domsense.com>) |
410 | +# All Rights Reserved |
411 | +# |
412 | +# This program is free software: you can redistribute it and/or modify |
413 | +# it under the terms of the GNU Affero General Public License as published |
414 | +# by the Free Software Foundation, either version 3 of the License, or |
415 | +# (at your option) any later version. |
416 | +# |
417 | +# This program is distributed in the hope that it will be useful, |
418 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
419 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
420 | +# GNU General Public License for more details. |
421 | +# |
422 | +# You should have received a copy of the GNU Affero General Public License |
423 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
424 | +# |
425 | +############################################################################## |
426 | + |
427 | +from osv import fields,osv |
428 | +import time |
429 | + |
430 | +class wizard_select_template(osv.osv_memory): |
431 | + |
432 | + _name = "wizard.select.move.template" |
433 | + _columns = { |
434 | + 'template_id': fields.many2one('account.move.template', 'Move Template', required=True), |
435 | + 'line_ids': fields.one2many('wizard.select.move.template.line', 'template_id', 'Lines'), |
436 | + } |
437 | + |
438 | + def on_change_template_id(self, cr, uid, ids, template_id): |
439 | + res = {} |
440 | + if template_id: |
441 | + res['value'] = {'line_ids': []} |
442 | + template_pool = self.pool.get('account.move.template') |
443 | + template = template_pool.browse(cr, uid, template_id) |
444 | + for line in template.template_line_ids: |
445 | + if line.type == 'input': |
446 | + res['value']['line_ids'].append({ |
447 | + 'sequence': line.sequence, |
448 | + 'name': line.name, |
449 | + 'account_id': line.account_id.id, |
450 | + 'move_line_type': line.move_line_type, |
451 | + }) |
452 | + return res |
453 | + |
454 | + def load_template(self, cr, uid, ids, context=None): |
455 | + template_obj = self.pool.get('account.move.template') |
456 | + template_line_obj = self.pool.get('account.move.template.line') |
457 | + account_period_obj = self.pool.get('account.period') |
458 | + account_move_obj = self.pool.get('account.move') |
459 | + account_move_line_obj = self.pool.get('account.move.line') |
460 | + mod_obj = self.pool.get('ir.model.data') |
461 | + entry = {} |
462 | + |
463 | + wizard = self.browse(cr, uid, ids, context=context)[0] |
464 | + input_lines = {} |
465 | + for template_line in wizard.line_ids: |
466 | + input_lines[template_line.sequence] = template_line.amount |
467 | + |
468 | + computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines) |
469 | + |
470 | + period_id = account_period_obj.find(cr, uid, context=context) |
471 | + if not period_id: |
472 | + raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) |
473 | + period_id = period_id[0] |
474 | + move_id = account_move_obj.create(cr, uid, { |
475 | + 'ref': wizard.template_id.name, |
476 | + 'period_id': period_id, |
477 | + 'journal_id': wizard.template_id.journal_id.id, |
478 | + }) |
479 | + for line in wizard.template_id.template_line_ids: |
480 | + analytic_account_id = False |
481 | + if line.analytic_account_id: |
482 | + if not wizard.template_id.journal_id.analytic_journal_id: |
483 | + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (wizard.template_id.journal_id.name,)) |
484 | + analytic_account_id = line.analytic_account_id.id |
485 | + val = { |
486 | + 'name': line.name, |
487 | + 'move_id': move_id, |
488 | + 'journal_id': wizard.template_id.journal_id.id, |
489 | + 'period_id': period_id, |
490 | + 'analytic_account_id': analytic_account_id, |
491 | + 'account_id': line.account_id.id, |
492 | + 'date': time.strftime('%Y-%m-%d'), |
493 | + } |
494 | + if line.move_line_type == 'cr': |
495 | + val['credit'] = computed_lines[line.sequence] |
496 | + if line.move_line_type == 'dr': |
497 | + val['debit'] = computed_lines[line.sequence] |
498 | + id_line = account_move_line_obj.create(cr, uid, val) |
499 | + |
500 | + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_move_form')], context=context) |
501 | + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
502 | + return { |
503 | + 'domain': "[('id','in', ["+str(move_id)+"])]", |
504 | + 'name': 'Entries', |
505 | + 'view_type': 'form', |
506 | + 'view_mode': 'form', |
507 | + 'res_model': 'account.move', |
508 | + 'views': [(False,'tree'),(resource_id,'form')], |
509 | + 'type': 'ir.actions.act_window', |
510 | + 'target': 'current', |
511 | + } |
512 | + |
513 | +wizard_select_template() |
514 | + |
515 | +class wizard_select_template_line(osv.osv_memory): |
516 | + _description = 'Template Lines' |
517 | + _name = "wizard.select.move.template.line" |
518 | + _columns = { |
519 | + 'template_id': fields.many2one('wizard.select.move.template', 'Template'), |
520 | + 'sequence': fields.integer('Number', required=True), |
521 | + 'name': fields.char('Name', size=64, required=True, readonly=True), |
522 | + 'account_id': fields.many2one('account.account', 'Account', required=True, readonly=True), |
523 | + 'move_line_type':fields.selection([ |
524 | + ('cr','Credit'), |
525 | + ('dr','Debit'), |
526 | + ], 'Move Line Type', required=True,readonly=True), |
527 | + 'amount': fields.float('Amount', required=True), |
528 | + } |
529 | + |
530 | +wizard_select_template_line() |
531 | + |
532 | +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
533 | |
534 | === added file 'account_move_template/wizard/select_template.xml' |
535 | --- account_move_template/wizard/select_template.xml 1970-01-01 00:00:00 +0000 |
536 | +++ account_move_template/wizard/select_template.xml 2011-10-28 16:15:28 +0000 |
537 | @@ -0,0 +1,73 @@ |
538 | +<?xml version="1.0" encoding="utf-8"?> |
539 | +<openerp> |
540 | + <data> |
541 | + |
542 | + <record id="wizard_select_template" model="ir.ui.view"> |
543 | + <field name="name">Select Move Template</field> |
544 | + <field name="model">wizard.select.move.template</field> |
545 | + <field name="type">form</field> |
546 | + <field name="arch" type="xml"> |
547 | + <form string="Move Template" > |
548 | + <group col="2"> |
549 | + <field name="template_id" on_change="on_change_template_id(template_id)"/> |
550 | + <field name="line_ids" colspan="2" nolabel="1" width="600"/> |
551 | + <button icon="gtk-cancel" special="cancel" string="Cancel"/> |
552 | + <button icon="gtk-ok" name="load_template" string="Load" type="object"/> |
553 | + </group> |
554 | + </form> |
555 | + </field> |
556 | + </record> |
557 | + |
558 | + <record id="wizard_select_template_line" model="ir.ui.view"> |
559 | + <field name="name">Select Move Template Line</field> |
560 | + <field name="model">wizard.select.move.template.line</field> |
561 | + <field name="type">form</field> |
562 | + <field name="arch" type="xml"> |
563 | + <form string="Move Template Line"> |
564 | + <group col="2"> |
565 | + <field name="sequence" invisible="1"/> |
566 | + <field name="name" /> |
567 | + <field name="account_id" /> |
568 | + <field name="move_line_type" /> |
569 | + <field name="amount" /> |
570 | + </group> |
571 | + </form> |
572 | + </field> |
573 | + </record> |
574 | + |
575 | + <record id="wizard_select_template_line_tree" model="ir.ui.view"> |
576 | + <field name="name">Select Move Template Line</field> |
577 | + <field name="model">wizard.select.move.template.line</field> |
578 | + <field name="type">tree</field> |
579 | + <field name="arch" type="xml"> |
580 | + <tree string="Move Template Line" editable="bottom"> |
581 | + <field name="sequence" invisible="1"/> |
582 | + <field name="name" /> |
583 | + <field name="account_id" /> |
584 | + <field name="move_line_type" /> |
585 | + <field name="amount" /> |
586 | + </tree> |
587 | + </field> |
588 | + </record> |
589 | + |
590 | + <record id="action_wizard_select_template" model="ir.actions.act_window"> |
591 | + <field name="name">Select Move Template</field> |
592 | + <field name="res_model">wizard.select.move.template</field> |
593 | + <field name="view_type">form</field> |
594 | + <field name="view_mode">form</field> |
595 | + <field name="view_id" ref="wizard_select_template"/> |
596 | + <field name="target">new</field> |
597 | + </record> |
598 | + |
599 | + <act_window name="Create Move from Template" |
600 | + res_model="wizard.select.move.template" |
601 | + src_model="account.move" |
602 | + view_mode="form" |
603 | + target="new" |
604 | + key2="client_action_multi" |
605 | + id="action_wizard_select_template_by_move" |
606 | + view_id="wizard_select_template"/> |
607 | + |
608 | + <menuitem name="Create Move from Template" action="action_wizard_select_template" id="menu_action_wizard_select_template" sequence="10" parent="account.menu_finance_entries"/> |
609 | + </data> |
610 | +</openerp> |