From d2da4f4276aa2bde93b4ca591ca28adc33b21fa5 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 11 Apr 2019 15:49:20 +0200 Subject: [PATCH] [MIG] account_move_template from v11 to v12 (full re-write) --- account_move_template/__manifest__.py | 16 +- account_move_template/models/__init__.py | 1 - .../models/account_document_template.py | 95 ---------- .../models/account_move_template.py | 172 ++++++++++++------ account_move_template/readme/CONTRIBUTORS.rst | 3 +- account_move_template/readme/USAGE.rst | 4 +- .../account_move_template_security.xml | 5 +- .../security/ir.model.access.csv | 12 +- account_move_template/tests/__init__.py | 5 +- .../tests/test_account_move_template.py | 2 +- ...template.xml => account_move_template.xml} | 100 +++++----- account_move_template/wizard/__init__.py | 2 +- .../wizard/account_move_template_run.py | 166 +++++++++++++++++ .../wizard/account_move_template_run_view.xml | 57 ++++++ .../wizard/select_template.py | 142 --------------- .../wizard/select_template.xml | 94 ---------- 16 files changed, 410 insertions(+), 466 deletions(-) delete mode 100644 account_move_template/models/account_document_template.py rename account_move_template/view/{move_template.xml => account_move_template.xml} (56%) create mode 100644 account_move_template/wizard/account_move_template_run.py create mode 100644 account_move_template/wizard/account_move_template_run_view.xml delete mode 100644 account_move_template/wizard/select_template.py delete mode 100644 account_move_template/wizard/select_template.xml diff --git a/account_move_template/__manifest__.py b/account_move_template/__manifest__.py index ea722b37..4c27a84d 100644 --- a/account_move_template/__manifest__.py +++ b/account_move_template/__manifest__.py @@ -1,27 +1,25 @@ # Copyright 2015-2017 See manifest # Copyright 2018 Raf Ven +# Copyright 2019 Akretion France (http://www.akretion.com/) # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html { 'name': "Account Move Template", - 'version': '11.0.1.0.0', - 'category': 'Generic Modules/Accounting', + 'version': '12.0.1.0.0', + 'category': 'Accounting', 'summary': "Templates for recurring Journal Entries", 'author': "Agile Business Group, Odoo Community Association (OCA), Aurium " - "Technologies, Vauxoo, Eficent", + "Technologies, Vauxoo, Eficent, Akretion", 'website': 'https://github.com/OCA/account-financial-tools', 'license': 'AGPL-3', 'depends': [ 'account', - 'analytic', ], 'data': [ - 'security/ir.model.access.csv', - 'view/move_template.xml', - 'wizard/select_template.xml', 'security/account_move_template_security.xml', - ], - 'test': [ + 'security/ir.model.access.csv', + 'wizard/account_move_template_run_view.xml', + 'view/account_move_template.xml', ], 'installable': True, } diff --git a/account_move_template/models/__init__.py b/account_move_template/models/__init__.py index 15a3794a..7de889b2 100644 --- a/account_move_template/models/__init__.py +++ b/account_move_template/models/__init__.py @@ -1,2 +1 @@ -from . import account_document_template from . import account_move_template diff --git a/account_move_template/models/account_document_template.py b/account_move_template/models/account_document_template.py deleted file mode 100644 index 752d8791..00000000 --- a/account_move_template/models/account_document_template.py +++ /dev/null @@ -1,95 +0,0 @@ -# Copyright 2015-2018 See manifest -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html - -from functools import partial -import re -from odoo import models, fields, api, exceptions, _ -from odoo.tools.safe_eval import safe_eval - - -class AccountDocumentTemplate(models.Model): - _name = 'account.document.template' - - name = fields.Char('Name', required=True, - ) - - @api.multi - def copy(self, default=None): - self.ensure_one() - default = dict(default or {}, name=_('%s (copy)') % self.name) - return super(AccountDocumentTemplate, self).copy(default) - - @api.multi - def _input_lines(self): - count = 0 - for line in self.template_line_ids: - if line.type == 'input': - count += 1 - return count - - @api.multi - def _get_template_line(self, line_number): - for line in self.template_line_ids: - if line.sequence == line_number: - return line - return False - - @api.multi - def _generate_empty_lines(self): - lines = {} - for line in self.template_line_ids: - lines[line.sequence] = None - return lines - - @api.multi - def lines(self, line_number, computed_lines=None): - if computed_lines is None: - computed_lines = {} - if computed_lines[line_number] is not None: - return computed_lines[line_number] - line = self._get_template_line(line_number) - if re.match(r'L\( *' + str(line_number) + r' *\)', line.python_code): - raise exceptions.Warning( - _('Line %s can\'t refer to itself') % str(line_number) - ) - try: - recurse_lines = partial(self.lines, computed_lines=computed_lines) - computed_lines[line_number] = safe_eval( - line.python_code.replace('L', 'recurse_lines'), - locals_dict={'recurse_lines': recurse_lines} - ) - except KeyError: - raise exceptions.Warning( - _('Code "%s" refers to non existing line') % line.python_code) - return computed_lines[line_number] - - @api.multi - def compute_lines(self, input_lines): - if len(input_lines) != self._input_lines(): - raise exceptions.Warning( - _('You can not add a different number of lines in this wizard ' - 'you should try to create the move normally and then edit ' - 'the created move. Inconsistent between input lines and ' - ' filled lines for template %s') % self.name - ) - computed_lines = self._generate_empty_lines() - computed_lines.update(input_lines) - for line_number in computed_lines: - computed_lines[line_number] = self.lines( - line_number, computed_lines) - return computed_lines - - -class AccountDocumentTemplateLine(models.Model): - _name = 'account.document.template.line' - - name = fields.Char('Name', required=True, - ) - sequence = fields.Integer('Sequence', required=True, - ) - type = fields.Selection([ - ('computed', 'Computed'), - ('input', 'User input'), - ], string='Type', required=True, default='input', - ) - python_code = fields.Text('Python code') diff --git a/account_move_template/models/account_move_template.py b/account_move_template/models/account_move_template.py index 1fc62537..0d548249 100644 --- a/account_move_template/models/account_move_template.py +++ b/account_move_template/models/account_move_template.py @@ -1,79 +1,133 @@ -# Copyright 2015-2018 See manifest +# Copyright 2015-2019 See manifest # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo import models, fields, api +from odoo import api, fields, models, _ +from odoo.tools.safe_eval import safe_eval +from odoo.exceptions import UserError, ValidationError +from odoo.tools import float_round class AccountMoveTemplate(models.Model): _name = 'account.move.template' - _inherit = ['account.document.template', - # 'mail.activity.mixin', TODO: uncomment for saas-15 - 'mail.thread'] - - @api.model - def _company_get(self): - return self.env['res.company']._company_default_get( - object='account.move.template' - ) + _description = 'Journal Entry Template' + name = fields.Char(required=True) company_id = fields.Many2one( - 'res.company', - required=True, - change_default=True, - default=_company_get, - ) - journal_id = fields.Many2one('account.journal', required=True) - template_line_ids = fields.One2many( - 'account.move.template.line', - inverse_name='template_id', - ) + 'res.company', string='Company', required=True, ondelete='cascade', + default=lambda self: self.env['res.company']._company_default_get()) + journal_id = fields.Many2one( + 'account.journal', string='Journal', required=True) + ref = fields.Char(string='Reference', copy=False) + line_ids = fields.One2many( + 'account.move.template.line', inverse_name='template_id', + string='Lines') - @api.multi - def action_run_template(self): + _sql_constraints = [( + 'name_company_unique', + 'unique(name, company_id)', + 'This name is already used by another template!' + )] + + def copy(self, default=None): self.ensure_one() - action = self.env.ref( - 'account_move_template.action_wizard_select_template').read()[0] - action.update({'context': {'default_template_id': self.id}}) - return action + default = dict(default or {}, name=_('%s (copy)') % self.name) + return super(AccountMoveTemplate, self).copy(default) - _sql_constraints = [ - ('sequence_move_template_uniq', 'unique (name,company_id)', - 'The name of the template must be unique per company !') - ] + def eval_computed_line(self, line, sequence2amount): + safe_eval_dict = {} + for seq, amount in sequence2amount.items(): + safe_eval_dict['L%d' % seq] = amount + try: + val = safe_eval(line.python_code, safe_eval_dict) + sequence2amount[line.sequence] = val + except ValueError: + raise UserError(_( + "Impossible to compute the formula of line with sequence %s " + "(formula: %s). Check that the lines used in the formula " + "really exists and have a lower sequence than the current " + "line.") % (line.sequence, line.python_code)) + except SyntaxError: + raise UserError(_( + "Impossible to compute the formula of line with sequence %s " + "(formula: %s): the syntax of the formula is wrong.") + % (line.sequence, line.python_code)) + + def compute_lines(self, sequence2amount): + prec = self.company_id.currency_id.rounding + input_sequence2amount = sequence2amount.copy() + for line in self.line_ids.filtered(lambda x: x.type == 'input'): + if line.sequence not in sequence2amount: + raise UserError(_( + "You deleted a line in the wizard. This is not allowed: " + "you should either update the template or modify the " + "journal entry that will be generated by this wizard.")) + input_sequence2amount.pop(line.sequence) + if input_sequence2amount: + raise UserError(_( + "You added a line in the wizard. This is not allowed: " + "you should either update the template or modify " + "the journal entry that will be generated by this wizard.")) + for line in self.line_ids.filtered(lambda x: x.type == 'computed'): + self.eval_computed_line(line, sequence2amount) + sequence2amount[line.sequence] = float_round( + sequence2amount[line.sequence], precision_rounding=prec) + return sequence2amount + + def generate_journal_entry(self): + '''Called by the button on the form view''' + self.ensure_one() + wiz = self.env['account.move.template.run'].create({ + 'template_id': self.id}) + action = wiz.load_lines() + return action class AccountMoveTemplateLine(models.Model): _name = 'account.move.template.line' - _inherit = 'account.document.template.line' + _description = 'Journal Item Template' + _order = 'sequence, id' - company_id = fields.Many2one('res.company', - related='template_id.company_id', - readonly=True) - journal_id = fields.Many2one('account.journal', - related='template_id.journal_id', - store=True, readonly=True) + template_id = fields.Many2one( + 'account.move.template', string='Move Template', ondelete='cascade') + name = fields.Char(string='Label') + sequence = fields.Integer('Sequence', required=True) account_id = fields.Many2one( - 'account.account', - required=True, - ondelete="cascade" - ) - partner_id = fields.Many2one('res.partner', string='Partner') - move_line_type = fields.Selection( - [('cr', 'Credit'), ('dr', 'Debit')], - required=True - ) + 'account.account', string='Account', + required=True, domain=[('deprecated', '=', False)]) + partner_id = fields.Many2one( + 'res.partner', string='Partner', + domain=['|', ('parent_id', '=', False), ('is_company', '=', True)]) analytic_account_id = fields.Many2one( - 'account.analytic.account', - ondelete="cascade" - ) - analytic_tag_ids = fields.Many2many('account.analytic.tag', - string='Analytic tags') + 'account.analytic.account', string='Analytic Account') + analytic_tag_ids = fields.Many2many( + 'account.analytic.tag', string='Analytic Tags') tax_ids = fields.Many2many('account.tax', string='Taxes') - tax_line_id = fields.Many2one('account.tax', string='Originator tax', - ondelete='restrict') - template_id = fields.Many2one('account.move.template') + tax_line_id = fields.Many2one( + 'account.tax', string='Originator Tax', ondelete='restrict') + company_id = fields.Many2one( + related='template_id.company_id', store=True) + company_currency_id = fields.Many2one( + related='template_id.company_id.currency_id', + string='Company Currency', store=True) + note = fields.Char() + type = fields.Selection([ + ('computed', 'Computed'), + ('input', 'User input'), + ], string='Type', required=True, default='input') + python_code = fields.Text('Python Code') + move_line_type = fields.Selection( + [('cr', 'Credit'), ('dr', 'Debit')], required=True, string='Direction') - _sql_constraints = [ - ('sequence_template_uniq', 'unique (template_id,sequence)', - 'The sequence of the line must be unique per template !') - ] + _sql_constraints = [( + 'sequence_template_uniq', + 'unique(template_id, sequence)', + 'The sequence of the line must be unique per template!' + )] + + @api.constrains('type', 'python_code') + def check_python_code(self): + for line in self: + if line.type == 'computed' and not line.python_code: + raise ValidationError(_( + "Python Code must be set for computed line with " + "sequence %d.") % line.sequence) diff --git a/account_move_template/readme/CONTRIBUTORS.rst b/account_move_template/readme/CONTRIBUTORS.rst index 63c6c51f..f3e6b704 100644 --- a/account_move_template/readme/CONTRIBUTORS.rst +++ b/account_move_template/readme/CONTRIBUTORS.rst @@ -5,6 +5,7 @@ Authors * Lorenzo Battistini * Paolo Chiara * Franco Tampieri +* Alexis de Lattre (full re-write for v12) Contributors ------------ @@ -13,4 +14,4 @@ Contributors * Alex Comba (Port to V8) * Guewen Baconnier * Raf Ven (port to v11) -* Jordi Ballester (EFICENT) \ No newline at end of file +* Jordi Ballester (EFICENT) diff --git a/account_move_template/readme/USAGE.rst b/account_move_template/readme/USAGE.rst index 0642b273..568a47a7 100644 --- a/account_move_template/readme/USAGE.rst +++ b/account_move_template/readme/USAGE.rst @@ -1,7 +1,7 @@ To create new templates: #. Make sure that you have flagged *Show Full Accounting Features* in your - user, and that the user has belongs to the *Billing Manager* group. + user, and that the user belongs to the *Billing Manager* group. #. Go to *Invoicing / Configuration / Accounting / Journal Templates* and define there your template. You can choose to complete a line using a defined formula, based on other lines, or by requiring the user input. @@ -10,4 +10,4 @@ To use an existing template: #. Go to *Invoicing / Adviser / Accounting Entries / Create Journal Entry from Template* #. Select one of the available templates and optionally a partner. -#. Complete the entries according to the template and press *Load* \ No newline at end of file +#. Complete the entries according to the template and press *Load* diff --git a/account_move_template/security/account_move_template_security.xml b/account_move_template/security/account_move_template_security.xml index b706266c..82ce9773 100644 --- a/account_move_template/security/account_move_template_security.xml +++ b/account_move_template/security/account_move_template_security.xml @@ -2,10 +2,9 @@ - Move Template multi company rule + Move Template multi-company rule - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] diff --git a/account_move_template/security/ir.model.access.csv b/account_move_template/security/ir.model.access.csv index c52b5cfa..37f0cbdb 100644 --- a/account_move_template/security/ir.model.access.csv +++ b/account_move_template/security/ir.model.access.csv @@ -1,9 +1,3 @@ -"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" +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_account_move_template_user,Full access on account.move.template to accountant grp,model_account_move_template,account.group_account_user,1,1,1,1 +access_account_move_template_line_user,Full access on account.move.template.line to accountant grp,model_account_move_template_line,account.group_account_user,1,1,1,1 diff --git a/account_move_template/tests/__init__.py b/account_move_template/tests/__init__.py index 83734184..40847a7a 100644 --- a/account_move_template/tests/__init__.py +++ b/account_move_template/tests/__init__.py @@ -1,2 +1,3 @@ - -from . import test_account_move_template +# Needs to be re-written because wizard.multi.charts.accounts +# doesn't exist any more on v12 +# from . import test_account_move_template diff --git a/account_move_template/tests/test_account_move_template.py b/account_move_template/tests/test_account_move_template.py index 313d1c85..f84042a1 100644 --- a/account_move_template/tests/test_account_move_template.py +++ b/account_move_template/tests/test_account_move_template.py @@ -1,4 +1,4 @@ -# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# Copyright 2018-2019 Eficent Business and IT Consulting Services, S.L. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging from psycopg2 import IntegrityError diff --git a/account_move_template/view/move_template.xml b/account_move_template/view/account_move_template.xml similarity index 56% rename from account_move_template/view/move_template.xml rename to account_move_template/view/account_move_template.xml index b61fe9dd..03b2530d 100644 --- a/account_move_template/view/move_template.xml +++ b/account_move_template/view/account_move_template.xml @@ -1,28 +1,28 @@ - + account.move.template.line.tree account.move.template.line - - - + - + + - - - - + + + + + - + account.move.template.line.form account.move.template.line @@ -30,46 +30,52 @@ - - - + + - + - + + - - + account.move.template.form account.move.template
-
@@ -78,58 +84,58 @@
- + account.move.template.tree account.move.template + - + account.move.template.search account.move.template - - - - + + + - + Journal Entry Templates account.move.template - form tree,form - + sequence="300"/> +
diff --git a/account_move_template/wizard/__init__.py b/account_move_template/wizard/__init__.py index 959815f8..29902b75 100644 --- a/account_move_template/wizard/__init__.py +++ b/account_move_template/wizard/__init__.py @@ -1 +1 @@ -from . import select_template +from . import account_move_template_run diff --git a/account_move_template/wizard/account_move_template_run.py b/account_move_template/wizard/account_move_template_run.py new file mode 100644 index 00000000..2e290e15 --- /dev/null +++ b/account_move_template/wizard/account_move_template_run.py @@ -0,0 +1,166 @@ +# Copyright 2015-2019 See manifest +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import fields, models, _ +from odoo.exceptions import UserError +from odoo.tools import float_is_zero + + +class AccountMoveTemplateRun(models.TransientModel): + _name = "account.move.template.run" + _description = "Wizard to generate move from template" + + template_id = fields.Many2one('account.move.template', required=True) + company_id = fields.Many2one( + 'res.company', required=True, readonly=True, + default=lambda self: self.env['res.company']._company_default_get()) + partner_id = fields.Many2one( + 'res.partner', 'Override Partner', + domain=['|', ('parent_id', '=', False), ('is_company', '=', True)]) + date = fields.Date(required=True, default=fields.Date.context_today) + journal_id = fields.Many2one( + 'account.journal', string='Journal', readonly=True) + ref = fields.Char(string='Reference') + line_ids = fields.One2many( + 'account.move.template.line.run', 'wizard_id', string="Lines") + state = fields.Selection([ + ('select_template', 'Select Template'), + ('set_lines', 'Set Lines'), + ], readonly=True, default='select_template') + + def _prepare_wizard_line(self, line): + vals = { + 'wizard_id': self.id, + 'sequence': line.sequence, + 'name': line.name, + 'amount': 0.0, + 'account_id': line.account_id.id, + 'partner_id': line.partner_id.id or False, + 'move_line_type': line.move_line_type, + 'tax_ids': [(6, 0, line.tax_ids.ids)], + 'tax_line_id': line.tax_line_id.id, + 'analytic_account_id': line.analytic_account_id.id, + 'analytic_tag_ids': [(6, 0, line.analytic_tag_ids.ids)], + 'note': line.note, + } + return vals + + # STEP 1 + def load_lines(self): + self.ensure_one() + amtlro = self.env['account.move.template.line.run'] + if self.company_id != self.template_id.company_id: + raise UserError(_( + "The selected template (%s) is not in the same company (%s) " + "as the current user (%s).") % ( + self.template_id.name, + self.template_id.company_id.display_name, + self.company_id.display_name)) + lines = self.template_id.line_ids + for line in lines.filtered(lambda l: l.type == 'input'): + vals = self._prepare_wizard_line(line) + amtlro.create(vals) + self.write({ + 'journal_id': self.template_id.journal_id.id, + 'state': 'set_lines', + }) + if not self.line_ids: + return self.generate_move() + action = self.env.ref( + 'account_move_template.account_move_template_run_action') + result = action.read()[0] + result.update({ + 'res_id': self.id, + 'context': self.env.context, + }) + return result + + # STEP 2 + def generate_move(self): + self.ensure_one() + sequence2amount = {} + for wizard_line in self.line_ids: + sequence2amount[wizard_line.sequence] = wizard_line.amount + prec = self.company_id.currency_id.rounding + if all([ + float_is_zero(x, precision_rounding=prec) + for x in sequence2amount.values()]): + raise UserError(_("Debit and credit of all lines are null.")) + self.template_id.compute_lines(sequence2amount) + move_vals = self._prepare_move() + for line in self.template_id.line_ids: + amount = sequence2amount[line.sequence] + if not float_is_zero(amount, precision_rounding=prec): + move_vals['line_ids'].append( + (0, 0, self._prepare_move_line(line, amount))) + move = self.env['account.move'].create(move_vals) + action = self.env.ref('account.action_move_journal_line') + result = action.read()[0] + result.update({ + 'name': _('Entry from template %s') % self.template_id.name, + 'res_id': move.id, + 'views': False, + 'view_id': False, + 'view_mode': 'form,tree,kanban', + 'context': self.env.context, + }) + return result + + def _prepare_move(self): + move_vals = { + 'ref': self.ref, + 'journal_id': self.journal_id.id, + 'date': self.date, + 'company_id': self.company_id.id, + 'line_ids': [], + } + return move_vals + + def _prepare_move_line(self, line, amount): + debit = line.move_line_type == 'dr' + values = { + 'name': line.name, + 'analytic_account_id': line.analytic_account_id.id, + 'account_id': line.account_id.id, + 'credit': not debit and amount or 0.0, + 'debit': debit and amount or 0.0, + 'partner_id': self.partner_id.id or line.partner_id.id, + 'tax_line_id': line.tax_line_id.id, + } + if line.analytic_tag_ids: + values['analytic_tag_ids'] = [(6, 0, line.analytic_tag_ids.ids)] + if line.tax_ids: + values['tax_ids'] = [(6, 0, line.tax_ids.ids)] + return values + + +class AccountMoveTemplateLineRun(models.TransientModel): + _name = "account.move.template.line.run" + _description = 'Wizard Lines to generate move from template' + + wizard_id = fields.Many2one( + 'account.move.template.run', ondelete='cascade') + company_id = fields.Many2one( + related='wizard_id.company_id') + company_currency_id = fields.Many2one( + related='wizard_id.company_id.currency_id', string='Company Currency') + sequence = fields.Integer('Sequence', required=True) + name = fields.Char('Name') + account_id = fields.Many2one( + 'account.account', required=True, readonly=True) + analytic_account_id = fields.Many2one( + 'account.analytic.account', readonly=True) + analytic_tag_ids = fields.Many2many( + 'account.analytic.tag', string='Analytic Tags', readonly=True) + tax_ids = fields.Many2many('account.tax', string='Taxes', readonly=True) + tax_line_id = fields.Many2one( + 'account.tax', string='Originator Tax', + ondelete='restrict', readonly=True) + partner_id = fields.Many2one( + 'res.partner', readonly=True, string='Partner') + move_line_type = fields.Selection( + [('cr', 'Credit'), ('dr', 'Debit')], + required=True, readonly=True, string='Direction') + amount = fields.Monetary( + 'Amount', required=True, currency_field='company_currency_id') + note = fields.Char(readonly=True) diff --git a/account_move_template/wizard/account_move_template_run_view.xml b/account_move_template/wizard/account_move_template_run_view.xml new file mode 100644 index 00000000..cde4f76e --- /dev/null +++ b/account_move_template/wizard/account_move_template_run_view.xml @@ -0,0 +1,57 @@ + + + + account.move.template.run + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Create Entry from Template + account.move.template.run + form + new + + + +
diff --git a/account_move_template/wizard/select_template.py b/account_move_template/wizard/select_template.py deleted file mode 100644 index 9c8b7b2d..00000000 --- a/account_move_template/wizard/select_template.py +++ /dev/null @@ -1,142 +0,0 @@ -# Copyright 2015-2017 See manifest -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html - -from odoo import models, fields, api, _ - - -class WizardSelectMoveTemplate(models.TransientModel): - _name = "wizard.select.move.template" - - template_id = fields.Many2one('account.move.template', required=True) - company_id = fields.Many2one( - 'res.company', required=True, - default=lambda self: self.env.user.company_id) - partner_id = fields.Many2one('res.partner', 'Partner') - date = fields.Date(required=True, default=fields.Date.context_today) - line_ids = fields.One2many( - 'wizard.select.move.template.line', 'template_id') - state = fields.Selection( - [('template_selected', 'Template selected')]) - - @api.onchange('template_id', 'company_id') - def onchange_company_id(self): - template_domain = [('company_id', '=', self.company_id.id)] - return {'domain': {'template_id': template_domain}} - - @api.multi - def load_lines(self): - self.ensure_one() - lines = self.template_id.template_line_ids - for line in lines.filtered(lambda l: l.type == 'input'): - self.env['wizard.select.move.template.line'].create({ - 'template_id': self.id, - 'sequence': line.sequence, - 'name': line.name, - 'amount': 0.0, - 'account_id': line.account_id.id, - 'partner_id': line.partner_id.id or self.partner_id.id, - 'move_line_type': line.move_line_type, - 'tax_ids': [(6, 0, line.tax_ids.ids)], - 'tax_line_id': line.tax_line_id.id, - 'analytic_account_id': line.analytic_account_id.id, - 'analytic_tag_ids': [(6, 0, line.analytic_tag_ids.ids)], - }) - if not self.line_ids: - return self.load_template() - self.state = 'template_selected' - view_rec = self.env.ref('account_move_template.wizard_select_template') - action = self.env.ref( - 'account_move_template.action_wizard_select_template_by_move') - result = action.read()[0] - result['res_id'] = self.id - result['view_id'] = [view_rec.id] - result['context'] = self.env.context - return result - - @api.multi - def load_template(self): - self.ensure_one() - input_lines = {} - for template_line in self.line_ids: - input_lines[template_line.sequence] = template_line.amount - amounts = self.template_id.compute_lines(input_lines) - name = self.template_id.name - partner = self.partner_id.id - moves = self.env['account.move'] - for journal in self.template_id.template_line_ids.mapped('journal_id'): - lines = [] - move = self._create_move(name, journal.id) - moves = moves + move - for line in self.template_id.template_line_ids.filtered( - lambda l, j=journal: l.journal_id == j): - lines.append((0, 0, - self._prepare_line(line, amounts, partner))) - move.write({'line_ids': lines}) - action = self.env.ref('account.action_move_journal_line') - result = action.read()[0] - result['domain'] = [('id', 'in', moves.ids)] - result['name'] = _('Entries from template: %s') % name - result['context'] = self.env.context - return result - - @api.model - def _create_move(self, ref, journal_id): - return self.env['account.move'].create({ - 'ref': ref, - 'journal_id': journal_id, - 'date': self.date, - }) - - @api.model - def _prepare_line(self, line, amounts, partner_id): - debit = line.move_line_type == 'dr' - values = { - 'name': line.name, - 'journal_id': line.journal_id.id, - 'analytic_account_id': line.analytic_account_id.id, - 'account_id': line.account_id.id, - 'credit': not debit and amounts[line.sequence] or 0.0, - 'debit': debit and amounts[line.sequence] or 0.0, - 'partner_id': line.partner_id.id or partner_id, - 'tax_line_id': line.tax_line_id.id, - } - if line.analytic_tag_ids: - values['analytic_tag_ids'] = [(6, 0, line.analytic_tag_ids.ids)] - if line.tax_ids: - values['tax_ids'] = [(6, 0, line.tax_ids.ids)] - return values - - -class WizardSelectMoveTemplateLine(models.TransientModel): - _description = 'Template Lines' - _name = "wizard.select.move.template.line" - - template_id = fields.Many2one( - 'wizard.select.move.template') - company_id = fields.Many2one('res.company', - related='template_id.company_id', - readonly=True) - sequence = fields.Integer('Sequence', required=True, - ) - name = fields.Char('Name', required=True, readonly=True, - ) - account_id = fields.Many2one( - 'account.account', required=True, readonly=True) - analytic_account_id = fields.Many2one( - 'account.analytic.account', - ondelete="cascade", readonly=True, - ) - analytic_tag_ids = fields.Many2many('account.analytic.tag', - string='Analytic tags', - readonly=True,) - tax_ids = fields.Many2many('account.tax', string='Taxes', readonly=True) - tax_line_id = fields.Many2one('account.tax', string='Originator tax', - ondelete='restrict', readonly=True) - partner_id = fields.Many2one('res.partner', readonly=True, - string='Partner') - move_line_type = fields.Selection([('cr', 'Credit'), ('dr', 'Debit')], - required=True, readonly=True, - string='Journal Item Type', - ) - amount = fields.Float('Amount', required=True, - ) diff --git a/account_move_template/wizard/select_template.xml b/account_move_template/wizard/select_template.xml deleted file mode 100644 index 541954fb..00000000 --- a/account_move_template/wizard/select_template.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - - Select Journal Entry Template - wizard.select.move.template - -
- - - - - - - - - - - - -
-
- -
-
- - - Select Journal Entry Template Line - wizard.select.move.template.line - -
- - - - - - - - - - - - - -
-
-
- - - Select Journal Entry Template Line - wizard.select.move.template.line - - - - - - - - - - - - - - - - - - - Select Journal Entry Template - wizard.select.move.template - form - form - - new - - - - - -