diff --git a/account_move_template/AUTHORS.txt b/account_move_template/AUTHORS.txt new file mode 100644 index 00000000..f1275149 --- /dev/null +++ b/account_move_template/AUTHORS.txt @@ -0,0 +1,4 @@ +Davide Corio +Lorenzo Battistini +Paolo Chiara +Franco Tampieri diff --git a/account_move_template/__init__.py b/account_move_template/__init__.py new file mode 100644 index 00000000..8e414618 --- /dev/null +++ b/account_move_template/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import account_document_template +import account_move_template +import wizard diff --git a/account_move_template/__openerp__.py b/account_move_template/__openerp__.py new file mode 100644 index 00000000..537137e5 --- /dev/null +++ b/account_move_template/__openerp__.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': "Account Move Template", + 'version': '0.1', + 'category': 'Generic Modules/Accounting', + 'description': """ +Templates for Journal Entries + +User can configure journal entries templates, useful for recurring entries. +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. +The journal entry form allows lo load, through a wizard, the template to use and the amounts to fill. +""", + 'author': 'Agile Business Group & Domsense', + 'website': 'http://www.agilebg.com', + 'license': 'AGPL-3', + "depends" : ['account_accountant', 'analytic'], + "init_xml" : [], + "update_xml" : [ + 'move_template.xml', + 'wizard/select_template.xml', + 'security/ir.model.access.csv', + ], + "demo_xml" : [], + 'test': [ + 'test/generate_move.yml', + ], + "active": False, + "installable": True +} diff --git a/account_move_template/account_document_template.py b/account_move_template/account_document_template.py new file mode 100644 index 00000000..0a035ed7 --- /dev/null +++ b/account_move_template/account_document_template.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields, osv +from tools.translate import _ +import re + +class account_document_template(osv.osv): + + _computed_lines = {} + _current_template_id = 0 + _cr = None + _uid = None + _name = 'account.document.template' + + _columns = { + 'name': fields.char('Name', size=64, required=True), + } + + def _input_lines(self, cr, uid, template): + count = 0 + for line in template.template_line_ids: + if line.type == 'input': + count += 1 + return count + + def _get_template_line(self, cr, uid, template_id, line_number): + for line in self.browse(cr, uid, template_id).template_line_ids: + if line.sequence == line_number: + return line + return False + + def _generate_empty_lines(self, cr, uid, template_id): + lines = {} + for template_line in self.browse(cr, uid, template_id).template_line_ids: + lines[template_line.sequence] = None + return lines + + def lines(self, line_number): + if self._computed_lines[line_number] is not None: + return self._computed_lines[line_number] + line = self._get_template_line(self._cr, self._uid, self._current_template_id, line_number) + if re.match('L\( *'+str(line_number)+' *\)',line.python_code): + raise osv.except_osv(_('Error'), + _('Line %s can\'t refer to itself') % str(line_number)) + try: + self._computed_lines[line_number] = eval(line.python_code.replace('L', 'self.lines')) + except KeyError: + raise osv.except_osv(_('Error'), + _('Code "%s" refers to non existing line') % line.python_code) + return self._computed_lines[line_number] + + def compute_lines(self, cr, uid, template_id, input_lines): + # input_lines: dictionary in the form {line_number: line_amount} + # returns all the lines (included input lines) in the form {line_number: line_amount} + template = self.browse(cr, uid, template_id) + if len(input_lines) != self._input_lines(cr, uid, template): + raise osv.except_osv(_('Error'), + _('Inconsistency between input lines and filled lines for template %s') % template.name) + self._current_template_id = template.id + self._cr = cr + self._uid = uid + self._computed_lines = self._generate_empty_lines(cr, uid, template_id) + self._computed_lines.update(input_lines) + for line_number in self._computed_lines: + self.lines(line_number) + return self._computed_lines + + def check_zero_lines(self, cr, uid, wizard): + if not wizard.line_ids: + return True + for template_line in wizard.line_ids: + if template_line.amount: + return True + return False + +account_document_template() + +class account_document_template_line(osv.osv): + + _name = 'account.document.template.line' + + _columns = { + 'name': fields.char('Name', size=64, required=True), + 'sequence': fields.integer('Sequence', required=True), + 'type': fields.selection([('computed', 'Computed'),('input', 'User input')], 'Type', required=True), + 'python_code':fields.text('Python Code'), + } + +account_document_template_line() diff --git a/account_move_template/account_move_template.py b/account_move_template/account_move_template.py new file mode 100644 index 00000000..fff164f9 --- /dev/null +++ b/account_move_template/account_move_template.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields, osv +from tools.translate import _ + +class account_move_template(osv.osv): + + _inherit = 'account.document.template' + _name = 'account.move.template' + + _columns = { + 'company_id': fields.many2one('res.company', 'Company', required=True, change_default=True), + 'template_line_ids': fields.one2many('account.move.template.line', 'template_id', 'Template Lines'), + 'cross_journals': fields.boolean('Cross-Journals'), + 'transitory_acc_id': fields.many2one('account.account', 'Transitory account', required=False), + } + + _defaults = { + 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.move.template', context=c), + } + + def _check_different_journal(self, cr, uid, ids, context=None): + #Check that the journal on these lines are different/same in the case of cross journals/single journal + journal_ids=[] + all_journal_ids=[] + move_template=self.pool.get('account.move.template').browse(cr,uid,ids)[0] + if not move_template.template_line_ids: + return True + for template_line in move_template.template_line_ids: + all_journal_ids.append(template_line.journal_id.id) + if template_line.journal_id.id not in journal_ids : + journal_ids.append(template_line.journal_id.id) + if move_template.cross_journals: + return len(all_journal_ids)==len(journal_ids) + else: + return len(journal_ids)==1 + + _constraints = [(_check_different_journal,'If the template is "cross-journals", the Journals must be different, if the template does not "cross-journals" the Journals must be the same!',['journal_id'])] + +account_move_template() + +class account_move_template_line(osv.osv): + + _name = 'account.move.template.line' + _inherit = 'account.document.template.line' + + _columns = { + 'journal_id': fields.many2one('account.journal', 'Journal', required=True), + 'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"), + 'move_line_type':fields.selection([ + ('cr','Credit'), + ('dr','Debit'), + ], 'Move Line Type', required=True), + 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"), + 'template_id': fields.many2one('account.move.template', 'Template'), + 'account_tax_id':fields.many2one('account.tax', 'Tax'), + } + + _sql_constraints = [ + ('sequence_template_uniq', 'unique (template_id,sequence)', 'The sequence of the line must be unique per template !') + ] + +account_move_template_line() diff --git a/account_move_template/i18n/account_move_template.pot b/account_move_template/i18n/account_move_template.pot new file mode 100644 index 00000000..c06f59a4 --- /dev/null +++ b/account_move_template/i18n/account_move_template.pot @@ -0,0 +1,282 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_move_template +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.0.3\n" +"Report-Msgid-Bugs-To: support@openerp.com\n" +"POT-Creation-Date: 2011-10-31 08:58+0000\n" +"PO-Revision-Date: 2011-10-31 08:58+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_move_template +#: field:account.move.template.line,move_line_type:0 +#: field:wizard.select.move.template.line,move_line_type:0 +msgid "Move Line Type" +msgstr "" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_move_template_line +msgid "account.move.template.line" +msgstr "" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +#: field:wizard.select.move.template,template_id:0 +msgid "Move Template" +msgstr "" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_wizard_select_template +msgid "Select Move Template" +msgstr "" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_wizard_select_move_template +msgid "wizard.select.move.template" +msgstr "" + +#. module: account_move_template +#: model:ir.module.module,shortdesc:account_move_template.module_meta_information +msgid "Account Move Template" +msgstr "" + +#. module: account_move_template +#: view:account.move.template:0 +msgid "Group By..." +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:87 +#, python-format +msgid "You have to define an analytic journal on the '%s' journal!" +msgstr "" + +#. module: account_move_template +#: field:account.move.template.line,template_id:0 +#: field:wizard.select.move.template.line,template_id:0 +msgid "Template" +msgstr "" + +#. module: account_move_template +#: selection:account.move.template.line,move_line_type:0 +#: selection:wizard.select.move.template.line,move_line_type:0 +msgid "Debit" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:76 +#, python-format +msgid "No period found !" +msgstr "" + +#. module: account_move_template +#: field:account.document.template.line,type:0 +#: field:account.move.template.line,type:0 +msgid "Type" +msgstr "" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_wizard_select_template_by_move +#: model:ir.ui.menu,name:account_move_template.menu_action_wizard_select_template +msgid "Create Move from Template" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:67 +#, python-format +msgid "Error !" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:76 +#, python-format +msgid "Unable to find a valid period !" +msgstr "" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_move_template_form +#: model:ir.ui.menu,name:account_move_template.menu_action_move_template_form +msgid "Move Templates" +msgstr "" + +#. module: account_move_template +#: field:account.move.template,company_id:0 +msgid "Company" +msgstr "" + +#. module: account_move_template +#: model:ir.module.module,description:account_move_template.module_meta_information +msgid "\n" +"=============================\n" +"Templates for Journal Entries\n" +"=============================\n" +"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.\n" +"The journal entry form allows lo load, through a wizard, the template to use and the amounts to fill.\n" +"" +msgstr "" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_move_template +msgid "account.move.template" +msgstr "" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_document_template_line +msgid "account.document.template.line" +msgstr "" + +#. module: account_move_template +#: selection:account.document.template.line,type:0 +#: selection:account.move.template.line,type:0 +msgid "User input" +msgstr "" + +#. module: account_move_template +#: view:account.move.template:0 +msgid "Purchase" +msgstr "" + +#. module: account_move_template +#: field:account.move.template.line,account_id:0 +#: field:wizard.select.move.template.line,account_id:0 +msgid "Account" +msgstr "" + +#. module: account_move_template +#: field:account.document.template,name:0 +#: field:account.document.template.line,name:0 +#: field:account.move.template,name:0 +#: field:account.move.template.line,name:0 +#: field:wizard.select.move.template.line,name:0 +msgid "Name" +msgstr "" + +#. module: account_move_template +#: field:wizard.select.move.template,line_ids:0 +msgid "Lines" +msgstr "" + +#. module: account_move_template +#: view:account.move.template:0 +msgid "Sale" +msgstr "" + +#. module: account_move_template +#: view:account.move.template.line:0 +msgid "Journal Entry Template Line" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:67 +#, python-format +msgid "At least one amount has to be non-zero!" +msgstr "" + +#. module: account_move_template +#: selection:account.move.template.line,move_line_type:0 +#: selection:wizard.select.move.template.line,move_line_type:0 +msgid "Credit" +msgstr "" + +#. module: account_move_template +#: field:wizard.select.move.template.line,amount:0 +msgid "Amount" +msgstr "" + +#. module: account_move_template +#: view:account.move.template:0 +msgid "Journal Entry Template" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/account_document_template.py:69 +#, python-format +msgid "Error" +msgstr "" + +#. module: account_move_template +#: sql_constraint:account.move.template.line:0 +msgid "The sequence of the line must be unique per template !" +msgstr "" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +msgid "Load" +msgstr "" + +#. module: account_move_template +#: view:account.move.template.line:0 +msgid "You can refer to other lines using their sequence number (e.g. 'L(1)' for first line). Examples of code: 'L(1) * 0.2'; 'L(2) - L(1)'; 'L(1) + L(2) + L(3)'; '1250'" +msgstr "" + +#. module: account_move_template +#: selection:account.document.template.line,type:0 +#: selection:account.move.template.line,type:0 +msgid "Computed" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:87 +#, python-format +msgid "No Analytic Journal !" +msgstr "" + +#. module: account_move_template +#: field:account.document.template.line,python_code:0 +#: view:account.move.template.line:0 +#: field:account.move.template.line,python_code:0 +msgid "Python Code" +msgstr "" + +#. module: account_move_template +#: code:addons/account_move_template/account_document_template.py:70 +#, python-format +msgid "Inconsistency between input lines and filled lines for template %s" +msgstr "" + +#. module: account_move_template +#: view:wizard.select.move.template.line:0 +msgid "Move Template Line" +msgstr "" + +#. module: account_move_template +#: field:account.document.template.line,sequence:0 +#: field:account.move.template.line,sequence:0 +#: field:wizard.select.move.template.line,sequence:0 +msgid "Number" +msgstr "" + +#. module: account_move_template +#: field:account.move.template.line,analytic_account_id:0 +msgid "Analytic Account" +msgstr "" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +msgid "Cancel" +msgstr "" + +#. module: account_move_template +#: field:account.move.template,template_line_ids:0 +#: model:ir.model,name:account_move_template.model_wizard_select_move_template_line +msgid "Template Lines" +msgstr "" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_document_template +msgid "account.document.template" +msgstr "" + +#. module: account_move_template +#: view:account.move.template:0 +#: field:account.move.template,journal_id:0 +msgid "Journal" +msgstr "" + diff --git a/account_move_template/i18n/it.po b/account_move_template/i18n/it.po new file mode 100644 index 00000000..1d9e3c4c --- /dev/null +++ b/account_move_template/i18n/it.po @@ -0,0 +1,296 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * account_move_template +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 6.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-04-05 08:19+0000\n" +"PO-Revision-Date: 2012-04-05 10:21+0100\n" +"Last-Translator: eLBati \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" + +#. module: account_move_template +#: field:account.move.template.line,move_line_type:0 +#: field:wizard.select.move.template.line,move_line_type:0 +msgid "Move Line Type" +msgstr "Tipo di movimento" + +#. module: account_move_template +#: selection:wizard.select.move.template,state:0 +msgid "Template selected" +msgstr "Template selezionato" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +#: field:wizard.select.move.template,template_id:0 +msgid "Move Template" +msgstr "Template di registrazione" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_wizard_select_template +msgid "Select Move Template" +msgstr "Scegli template di registrazione" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_wizard_select_move_template +msgid "wizard.select.move.template" +msgstr "wizard.select.move.template" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +msgid "Next" +msgstr "Avanti" + +#. module: account_move_template +#: field:wizard.select.move.template,state:0 +msgid "State" +msgstr "State" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:134 +#: code:addons/account_move_template/wizard/select_template.py:162 +#, python-format +msgid "You have to define an analytic journal on the '%s' journal!" +msgstr "E' necessario definire un giornale analitico sul sezionale '%s'!" + +#. module: account_move_template +#: field:account.move.template.line,template_id:0 +#: field:wizard.select.move.template.line,template_id:0 +msgid "Template" +msgstr "Template" + +#. module: account_move_template +#: selection:account.move.template.line,move_line_type:0 +#: selection:wizard.select.move.template.line,move_line_type:0 +msgid "Debit" +msgstr "Dare" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:91 +#, python-format +msgid "No period found !" +msgstr "Nessun periodo trovato!" + +#. module: account_move_template +#: field:account.document.template.line,type:0 +#: field:account.move.template.line,type:0 +msgid "Type" +msgstr "Tipo" + +#. module: account_move_template +#: field:account.move.template.line,analytic_account_id:0 +msgid "Analytic Account" +msgstr "Conto analitico" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:83 +#, python-format +msgid "Error !" +msgstr "Errore !" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:91 +#, python-format +msgid "Unable to find a valid period !" +msgstr "Impossibile trovare un periodo valido!" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_move_template_form +#: model:ir.ui.menu,name:account_move_template.menu_action_move_template_form +msgid "Move Templates" +msgstr "Template di registrazioni" + +#. module: account_move_template +#: field:account.move.template,company_id:0 +msgid "Company" +msgstr "Azienda" + +#. module: account_move_template +#: view:wizard.select.move.template.line:0 +msgid "Move Template Line" +msgstr "Riga template di registrazione" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_move_template +msgid "account.move.template" +msgstr "account.move.template" + +#. module: account_move_template +#: field:account.move.template,transitory_acc_id:0 +msgid "Transitory account" +msgstr "Transitory account" + +#. module: account_move_template +#: selection:account.document.template.line,type:0 +#: selection:account.move.template.line,type:0 +msgid "User input" +msgstr "Input utente" + +#. module: account_move_template +#: field:account.move.template.line,account_id:0 +#: field:wizard.select.move.template.line,account_id:0 +msgid "Account" +msgstr "Conto" + +#. module: account_move_template +#: field:account.document.template,name:0 +#: field:account.document.template.line,name:0 +#: field:account.move.template,name:0 +#: field:account.move.template.line,name:0 +#: field:wizard.select.move.template.line,name:0 +msgid "Name" +msgstr "Nome" + +#. module: account_move_template +#: field:account.move.template,cross_journals:0 +msgid "Cross-Journals" +msgstr "Cross-Journals" + +#. module: account_move_template +#: field:wizard.select.move.template,line_ids:0 +msgid "Lines" +msgstr "Righe" + +#. module: account_move_template +#: view:account.move.template.line:0 +msgid "Journal Entry Template Line" +msgstr "Riga del template di registrazione" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_move_template_line +msgid "account.move.template.line" +msgstr "account.move.template.line" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:83 +#, python-format +msgid "At least one amount has to be non-zero!" +msgstr "Almeno un importo deve essere diverso da zero!" + +#. module: account_move_template +#: selection:account.move.template.line,move_line_type:0 +#: selection:wizard.select.move.template.line,move_line_type:0 +msgid "Credit" +msgstr "Avere" + +#. module: account_move_template +#: field:wizard.select.move.template.line,amount:0 +msgid "Amount" +msgstr "Importo" + +#. module: account_move_template +#: view:account.move.template:0 +msgid "Journal Entry Template" +msgstr "Template di registrazione contabile" + +#. module: account_move_template +#: code:addons/account_move_template/account_document_template.py:69 +#, python-format +msgid "Error" +msgstr "Errore" + +#. module: account_move_template +#: sql_constraint:account.move.template.line:0 +msgid "The sequence of the line must be unique per template !" +msgstr "Il numero della riga deve essere unico per template!" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +msgid "Load" +msgstr "Carica" + +#. module: account_move_template +#: view:account.move.template.line:0 +msgid "You can refer to other lines using their sequence number (e.g. 'L(1)' for first line). Examples of code: 'L(1) * 0.2'; 'L(2) - L(1)'; 'L(1) + L(2) + L(3)'; '1250'" +msgstr "Si può fare riferimento alle altre righe usando il loro numero di sequenza (ad es. 'L(1)' per la prima riga). Esempi di codice: 'L(1) * 0.2'; 'L(2) - L(1)'; 'L(1) + L(2) + L(3)'; '1250'" + +#. module: account_move_template +#: selection:account.document.template.line,type:0 +#: selection:account.move.template.line,type:0 +msgid "Computed" +msgstr "Calcolato" + +#. module: account_move_template +#: code:addons/account_move_template/wizard/select_template.py:134 +#: code:addons/account_move_template/wizard/select_template.py:162 +#, python-format +msgid "No Analytic Journal !" +msgstr "Nessun giornale analitico!" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_document_template_line +msgid "account.document.template.line" +msgstr "account.document.template.line" + +#. module: account_move_template +#: field:account.document.template.line,python_code:0 +#: view:account.move.template.line:0 +#: field:account.move.template.line,python_code:0 +msgid "Python Code" +msgstr "Codice python" + +#. module: account_move_template +#: code:addons/account_move_template/account_document_template.py:70 +#, python-format +msgid "Inconsistency between input lines and filled lines for template %s" +msgstr "Inconsistenza fra le righe di input previste ed inserite per il template %s" + +#. module: account_move_template +#: field:account.move.template.line,account_tax_id:0 +msgid "Tax" +msgstr "Imposta" + +#. module: account_move_template +#: field:wizard.select.move.template.line,sequence:0 +msgid "Number" +msgstr "Numero" + +#. module: account_move_template +#: model:ir.actions.act_window,name:account_move_template.action_wizard_select_template_by_move +#: model:ir.ui.menu,name:account_move_template.menu_action_wizard_select_template +msgid "Create Move from Template" +msgstr "Crea registrazione da template" + +#. module: account_move_template +#: field:account.document.template.line,sequence:0 +#: field:account.move.template.line,sequence:0 +msgid "Sequence" +msgstr "Numero Sequenza" + +#. module: account_move_template +#: constraint:account.move.template:0 +msgid "If the template is \"cross-journals\", the Journals must be different, if the template does not \"cross-journals\" the Journals must be the same!" +msgstr "If the template is \"cross-journals\", the Journals must be different, if the template does not \"cross-journals\" the Journals must be the same!" + +#. module: account_move_template +#: field:account.move.template,template_line_ids:0 +#: model:ir.model,name:account_move_template.model_wizard_select_move_template_line +msgid "Template Lines" +msgstr "Righe template" + +#. module: account_move_template +#: view:wizard.select.move.template:0 +msgid "Cancel" +msgstr "Annulla" + +#. module: account_move_template +#: field:wizard.select.move.template,partner_id:0 +msgid "Partner" +msgstr "Partner" + +#. module: account_move_template +#: model:ir.model,name:account_move_template.model_account_document_template +msgid "account.document.template" +msgstr "account.document.template" + +#. module: account_move_template +#: field:account.move.template.line,journal_id:0 +msgid "Journal" +msgstr "Sezionale" + diff --git a/account_move_template/move_template.xml b/account_move_template/move_template.xml new file mode 100644 index 00000000..23705a2a --- /dev/null +++ b/account_move_template/move_template.xml @@ -0,0 +1,99 @@ + + + + + + account.move.template.line.tree + account.move.template.line + tree + + + + + + + + + + + + + + + + + + account.move.template.line.form + account.move.template.line + form + +
+ + + + + + + + + + + +
+ + + account.move.template.form + account.move.template + form + +
+ + + + + + + +
+ + + account.move.template.tree + account.move.template + tree + + + + + + + + + + account.move.template.search + account.move.template + search + + + + + + + + + + + + + Move Templates + account.move.template + form + tree,form + + + +
+
diff --git a/account_move_template/security/ir.model.access.csv b/account_move_template/security/ir.model.access.csv new file mode 100644 index 00000000..c52b5cfa --- /dev/null +++ b/account_move_template/security/ir.model.access.csv @@ -0,0 +1,9 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_account_document_template_user","account_document_template_user","model_account_document_template","account.group_account_user","1","1","1","1" +"access_account_document_template_manager","account_document_template_manager","model_account_document_template","account.group_account_manager","1","1","1","1" +"access_account_document_template_line_user","account_document_template_line_user","model_account_document_template_line","account.group_account_user","1","1","1","1" +"access_account_document_template_line_manager","account_document_template_line_manager","model_account_document_template_line","account.group_account_manager","1","1","1","1" +"access_account_move_template_user","account_move_template_user","model_account_move_template","account.group_account_user","1","1","1","1" +"access_account_move_template_manager","account_move_template_manager","model_account_move_template","account.group_account_manager","1","1","1","1" +"access_account_move_template_line_user","account_move_template_line_user","model_account_move_template_line","account.group_account_user","1","1","1","1" +"access_account_move_template_line_manager","account_move_template_line_manager","model_account_move_template_line","account.group_account_manager","1","1","1","1" diff --git a/account_move_template/test/generate_move.yml b/account_move_template/test/generate_move.yml new file mode 100644 index 00000000..f3cac462 --- /dev/null +++ b/account_move_template/test/generate_move.yml @@ -0,0 +1,52 @@ +- + I first create a move template for received bank payment. Two lines, bank and credit +- + !record {model: account.move.template, id: move_template_1}: + company_id: base.main_company + name: "First template" + template_line_ids: + - name: "Bank" + sequence: 1 + journal_id: account.bank_journal + account_id: account.bnk + type: 'input' + move_line_type: 'dr' + - name: "Credit" + sequence: 2 + journal_id: account.bank_journal + account_id: account.a_recv + type: 'computed' + move_line_type: 'cr' + python_code: 'L(1)' + +- + I use "Select Move Template" wizard to generate move +- + !record {model: wizard.select.move.template, id: wizard_select_move_template_1}: + template_id: move_template_1 + +- + I click on Next Button +- + !python {model: wizard.select.move.template}: | + self.load_lines(cr, uid, [ref("wizard_select_move_template_1")]) + +- + I verify that wizard lines are created and write the amount line +- + !python {model: wizard.select.move.template}: | + wizard = self.browse(cr, uid, ref('wizard_select_move_template_1')) + assert(len(wizard.line_ids) == 1), ('Wrong number of wizard lines') + wizard.line_ids[0].write({'amount': 100.0}) + +- + I click on Load Button and check the created move +- + !python {model: wizard.select.move.template}: | + action = self.load_template(cr, uid, [ref("wizard_select_move_template_1")]) + move_obj = self.pool.get('account.move') + domain_list = eval(action['domain']) + for move_id in domain_list[0][2]: + move = move_obj.browse(cr, uid, move_id) + for line in move.line_id: + assert(line.state == 'valid'), ('Move lines must be valid') diff --git a/account_move_template/wizard/__init__.py b/account_move_template/wizard/__init__.py new file mode 100644 index 00000000..4db7f64d --- /dev/null +++ b/account_move_template/wizard/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +import select_template diff --git a/account_move_template/wizard/select_template.py b/account_move_template/wizard/select_template.py new file mode 100644 index 00000000..3e03671b --- /dev/null +++ b/account_move_template/wizard/select_template.py @@ -0,0 +1,199 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2011 Agile Business Group sagl () +# Copyright (C) 2011 Domsense srl () +# All Rights Reserved +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from osv import fields,osv +import time +from tools.translate import _ + +class wizard_select_template(osv.osv_memory): + + _name = "wizard.select.move.template" + _columns = { + 'template_id': fields.many2one('account.move.template', 'Move Template', required=True), + 'partner_id': fields.many2one('res.partner', 'Partner'), + 'line_ids': fields.one2many('wizard.select.move.template.line', 'template_id', 'Lines'), + 'state': fields.selection([ + ('template_selected','Template selected'), + ], 'State'), + } + + def on_change_template_id(self, cr, uid, ids, template_id): + res = {} + if template_id: + res['value'] = {'line_ids': []} + template_pool = self.pool.get('account.move.template') + template = template_pool.browse(cr, uid, template_id) + for line in template.template_line_ids: + if line.type == 'input': + res['value']['line_ids'].append({ + 'sequence': line.sequence, + 'name': line.name, + 'account_id': line.account_id.id, + 'move_line_type': line.move_line_type, + }) + return res + + def load_lines(self, cr, uid, ids, context=None): + wizard = self.browse(cr, uid, ids, context=context)[0] + template_pool = self.pool.get('account.move.template') + wizard_line_pool = self.pool.get('wizard.select.move.template.line') + template = template_pool.browse(cr, uid, wizard.template_id.id) + for line in template.template_line_ids: + if line.type == 'input': + wizard_line_pool.create(cr, uid,{ + 'template_id': wizard.id, + 'sequence': line.sequence, + 'name': line.name, + 'amount': 0.0, + 'account_id': line.account_id.id, + 'move_line_type': line.move_line_type, + }) + if not wizard.line_ids: + return self.load_template(cr, uid, ids) + wizard.write({'state': 'template_selected'}) + return True + + def load_template(self, cr, uid, ids, context=None): + template_obj = self.pool.get('account.move.template') + template_line_obj = self.pool.get('account.move.template.line') + account_period_obj = self.pool.get('account.period') + + + mod_obj = self.pool.get('ir.model.data') + wizard = self.browse(cr, uid, ids, context=context)[0] + if not template_obj.check_zero_lines(cr, uid, wizard): + raise osv.except_osv(_('Error !'), _('At least one amount has to be non-zero!')) + input_lines = {} + + for template_line in wizard.line_ids: + input_lines[template_line.sequence] = template_line.amount + + period_id = account_period_obj.find(cr, uid, context=context) + if not period_id: + raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !')) + period_id = period_id[0] + + computed_lines = template_obj.compute_lines(cr, uid, wizard.template_id.id, input_lines) + + moves={} + for line in wizard.template_id.template_line_ids: + if line.journal_id.id not in moves: + moves[line.journal_id.id]=self._make_move( + cr,uid,wizard.template_id.name,period_id,line.journal_id.id, wizard.partner_id.id) + + id_line=self._make_move_line(cr,uid,line,computed_lines,moves[line.journal_id.id],period_id, + wizard.partner_id.id) + if wizard.template_id.cross_journals : + trans_account_id=wizard.template_id.transitory_acc_id.id + id_trans_line=self._make_transitory_move_line(cr,uid,line,computed_lines, + moves[line.journal_id.id],period_id,trans_account_id, wizard.partner_id.id) + + return { + 'domain': "[('id','in', "+str(moves.values())+")]", + 'name': 'Entries', + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'account.move', + 'type': 'ir.actions.act_window', + 'target': 'current', + } + #'res_id': moves.values() or False, + def _make_move(self, cr, uid,ref,period_id,journal_id, partner_id): + account_move_obj = self.pool.get('account.move') + move_id = account_move_obj.create(cr, uid, { + 'ref': ref, + 'period_id': period_id, + 'journal_id': journal_id, + 'partner_id': partner_id, + }) + return move_id + + def _make_move_line(self,cr,uid,line,computed_lines,move_id,period_id, partner_id): + account_move_line_obj = self.pool.get('account.move.line') + analytic_account_id = False + if line.analytic_account_id: + if not line.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (line.journal_id.name,)) + analytic_account_id = line.analytic_account_id.id + val = { + 'name': line.name, + 'move_id': move_id, + 'journal_id': line.journal_id.id, + 'period_id': period_id, + 'analytic_account_id': analytic_account_id, + 'account_id': line.account_id.id, + 'date': time.strftime('%Y-%m-%d'), + 'account_tax_id': line.account_tax_id.id, + 'credit': 0.0, + 'debit': 0.0, + 'partner_id': partner_id, + } + if line.move_line_type == 'cr': + val['credit'] = computed_lines[line.sequence] + if line.move_line_type == 'dr': + val['debit'] = computed_lines[line.sequence] + id_line = account_move_line_obj.create(cr, uid, val) + return id_line + + def _make_transitory_move_line( + self,cr,uid,line,computed_lines,move_id,period_id,trans_account_id, partner_id): + account_move_line_obj = self.pool.get('account.move.line') + analytic_account_id = False + if line.analytic_account_id: + if not line.journal_id.analytic_journal_id: + raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (wizard.template_id.journal_id.name,)) + analytic_account_id = line.analytic_account_id.id + val = { + 'name': 'transitory', + 'move_id': move_id, + 'journal_id': line.journal_id.id, + 'period_id': period_id, + 'analytic_account_id': analytic_account_id, + 'account_id': trans_account_id, + 'date': time.strftime('%Y-%m-%d'), + 'partner_id': partner_id, + } + if line.move_line_type != 'cr': + val['credit'] = computed_lines[line.sequence] + if line.move_line_type != 'dr': + val['debit'] = computed_lines[line.sequence] + id_line = account_move_line_obj.create(cr, uid, val) + return id_line + +wizard_select_template() + +class wizard_select_template_line(osv.osv_memory): + _description = 'Template Lines' + _name = "wizard.select.move.template.line" + _columns = { + 'template_id': fields.many2one('wizard.select.move.template', 'Template'), + 'sequence': fields.integer('Number', required=True), + 'name': fields.char('Name', size=64, required=True, readonly=True), + 'account_id': fields.many2one('account.account', 'Account', required=True, readonly=True), + 'move_line_type':fields.selection([ + ('cr','Credit'), + ('dr','Debit'), + ], 'Move Line Type', required=True,readonly=True), + 'amount': fields.float('Amount', required=True), + } + +wizard_select_template_line() diff --git a/account_move_template/wizard/select_template.xml b/account_move_template/wizard/select_template.xml new file mode 100644 index 00000000..51bcdfa7 --- /dev/null +++ b/account_move_template/wizard/select_template.xml @@ -0,0 +1,81 @@ + + + + + + Select Move Template + wizard.select.move.template + form + +
+ + + + + + + + + +