From 2d51ad28e4115929fb9727e7e3c8dd554b872203 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 26 Nov 2020 14:57:05 +0100 Subject: [PATCH] [MIG] account_move_template to v14 --- account_move_template/__manifest__.py | 2 +- .../models/account_move_template.py | 16 ++++++----- account_move_template/readme/USAGE.rst | 3 +- .../security/ir.model.access.csv | 2 ++ .../tests/test_account_move_template.py | 3 +- .../wizard/account_move_template_run.py | 28 ++++++++----------- .../wizard/account_move_template_run_view.xml | 19 +++++++++++-- 7 files changed, 42 insertions(+), 31 deletions(-) diff --git a/account_move_template/__manifest__.py b/account_move_template/__manifest__.py index 2631c656..4323026a 100644 --- a/account_move_template/__manifest__.py +++ b/account_move_template/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Account Move Template", - "version": "13.0.1.1.0", + "version": "14.0.1.0.0", "category": "Accounting", "summary": "Templates for recurring Journal Entries", "author": "Agile Business Group, Aurium Technologies, Vauxoo, ForgeFlow, " diff --git a/account_move_template/models/account_move_template.py b/account_move_template/models/account_move_template.py index 78aa888a..5eced3b7 100644 --- a/account_move_template/models/account_move_template.py +++ b/account_move_template/models/account_move_template.py @@ -3,7 +3,6 @@ from odoo import _, api, fields, models from odoo.exceptions import UserError, ValidationError -from odoo.tools import float_round from odoo.tools.safe_eval import safe_eval @@ -36,7 +35,7 @@ class AccountMoveTemplate(models.Model): def copy(self, default=None): self.ensure_one() default = dict(default or {}, name=_("%s (copy)") % self.name) - return super(AccountMoveTemplate, self).copy(default) + return super().copy(default) def eval_computed_line(self, line, sequence2amount): safe_eval_dict = {} @@ -65,7 +64,7 @@ class AccountMoveTemplate(models.Model): ) def compute_lines(self, sequence2amount): - prec = self.company_id.currency_id.rounding + company_cur = self.company_id.currency_id input_sequence2amount = sequence2amount.copy() for line in self.line_ids.filtered(lambda x: x.type == "input"): if line.sequence not in sequence2amount: @@ -87,8 +86,8 @@ class AccountMoveTemplate(models.Model): ) 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 + sequence2amount[line.sequence] = company_cur.round( + sequence2amount[line.sequence] ) return sequence2amount @@ -151,7 +150,10 @@ class AccountMoveTemplateLine(models.Model): string="Payment Terms", help="Used to compute the due date of the journal item.", ) - is_refund = fields.Boolean(default=False, string="Is a refund?",) + is_refund = fields.Boolean( + default=False, + string="Is a refund?", + ) tax_repartition_line_id = fields.Many2one( "account.tax.repartition.line", string="Tax Repartition Line", @@ -163,7 +165,7 @@ class AccountMoveTemplateLine(models.Model): "account.account", string="Account Opt.", domain=[("deprecated", "=", False)], - help="When amount is negative, use this account in stead", + help="When amount is negative, use this account instead", ) @api.depends("is_refund", "account_id", "tax_line_id") diff --git a/account_move_template/readme/USAGE.rst b/account_move_template/readme/USAGE.rst index 96913313..1ea7d726 100644 --- a/account_move_template/readme/USAGE.rst +++ b/account_move_template/readme/USAGE.rst @@ -8,7 +8,6 @@ To create new templates: To use an existing template: -#. Go to *Invoicing / Accounting / Miscellaneous / Create Entry from Template* +#. Go to *Invoicing / Accounting / Actions / Create Entry from Template* #. Select one of the available templates. -#. As option, you can overwrite output lines with dict, i.e., {"L1": {"partner": 1}} #. Complete the entries according to the template and click on the button *Generate Journal Entry*. diff --git a/account_move_template/security/ir.model.access.csv b/account_move_template/security/ir.model.access.csv index 37f0cbdb..e9e043c3 100644 --- a/account_move_template/security/ir.model.access.csv +++ b/account_move_template/security/ir.model.access.csv @@ -1,3 +1,5 @@ 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 +access_account_move_template_run_user,Full access on account.move.template.run to accountant grp,model_account_move_template_run,account.group_account_user,1,1,1,1 +access_account_move_template_line_run_user,Full access on account.move.template.line.run to accountant grp,model_account_move_template_line_run,account.group_account_user,1,1,1,1 diff --git a/account_move_template/tests/test_account_move_template.py b/account_move_template/tests/test_account_move_template.py index bc48fa1e..d5c10c69 100644 --- a/account_move_template/tests/test_account_move_template.py +++ b/account_move_template/tests/test_account_move_template.py @@ -148,8 +148,7 @@ class TestAccountMoveTemplate(TransactionCase): ) def test_create_template(self): - """Test that I can create a template - """ + """Test that I can create a template""" template = ( self.env["account.move.template"] .with_user(self.user) diff --git a/account_move_template/wizard/account_move_template_run.py b/account_move_template/wizard/account_move_template_run.py index f5cd26f8..f66a34b6 100644 --- a/account_move_template/wizard/account_move_template_run.py +++ b/account_move_template/wizard/account_move_template_run.py @@ -4,7 +4,6 @@ from ast import literal_eval from odoo import _, fields, models from odoo.exceptions import UserError, ValidationError -from odoo.tools import float_is_zero class AccountMoveTemplateRun(models.TransientModel): @@ -111,10 +110,10 @@ Valid dictionary to overwrite template lines: return ["partner_id", "amount", "name", "date_maturity"] def _get_overwrite_vals(self): - """ valid_dict = { - 'L1': {'partner_id': 1, 'amount': 10}, - 'L2': {'partner_id': 2, 'amount': 20}, - } + """valid_dict = { + 'L1': {'partner_id': 1, 'amount': 10}, + 'L2': {'partner_id': 2, 'amount': 20}, + } """ self.ensure_one() valid_keys = self._get_valid_keys() @@ -171,19 +170,14 @@ Valid dictionary to overwrite template lines: sequence2amount = {} for wizard_line in self.line_ids: sequence2amount[wizard_line.sequence] = wizard_line.amount - prec = self.company_id.currency_id.rounding + company_cur = self.company_id.currency_id self.template_id.compute_lines(sequence2amount) - if all( - [ - float_is_zero(x, precision_rounding=prec) - for x in sequence2amount.values() - ] - ): + if all([company_cur.is_zero(x) for x in sequence2amount.values()]): raise UserError(_("Debit and credit of all lines are null.")) 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): + if not company_cur.is_zero(amount): move_vals["line_ids"].append( (0, 0, self._prepare_move_line(line, amount)) ) @@ -216,7 +210,7 @@ Valid dictionary to overwrite template lines: date_maturity = False if line.payment_term_id: pterm_list = line.payment_term_id.compute(value=1, date_ref=self.date) - date_maturity = max(l[0] for l in pterm_list) + date_maturity = max(line[0] for line in pterm_list) debit = line.move_line_type == "dr" values = { "name": line.name, @@ -295,7 +289,9 @@ class AccountMoveTemplateLineRun(models.TransientModel): "Amount", required=True, currency_field="company_currency_id" ) note = fields.Char(readonly=True) - is_refund = fields.Boolean(default=False, string="Is a refund?", readonly=True,) + is_refund = fields.Boolean(string="Is a refund?", readonly=True) tax_repartition_line_id = fields.Many2one( - "account.tax.repartition.line", string="Tax Repartition Line", readonly=True, + "account.tax.repartition.line", + string="Tax Repartition Line", + 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 index c8e0d41f..c35613e2 100644 --- a/account_move_template/wizard/account_move_template_run_view.xml +++ b/account_move_template/wizard/account_move_template_run_view.xml @@ -16,9 +16,22 @@ name="overwrite" widget="ace" options="{'mode': 'python'}" - attrs="{'invisible': [('state', '=', 'set_lines')]}" - placeholder="Add an internal note here..." + invisible="1" /> + @@ -91,7 +104,7 @@