diff --git a/account_move_template/__manifest__.py b/account_move_template/__manifest__.py index f5b05044c..291f86e74 100644 --- a/account_move_template/__manifest__.py +++ b/account_move_template/__manifest__.py @@ -5,14 +5,14 @@ { "name": "Account Move Template", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "category": "Accounting", "summary": "Templates for recurring Journal Entries", "author": "Agile Business Group, Aurium Technologies, Vauxoo, Eficent, " "Akretion, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-financial-tools", "license": "AGPL-3", - "depends": ["account",], + "depends": ["account"], "data": [ "security/account_move_template_security.xml", "security/ir.model.access.csv", diff --git a/account_move_template/models/account_move_template.py b/account_move_template/models/account_move_template.py index 0a22dd0da..75b34f5ec 100644 --- a/account_move_template/models/account_move_template.py +++ b/account_move_template/models/account_move_template.py @@ -33,8 +33,6 @@ class AccountMoveTemplate(models.Model): ) ] - @api.multi - @api.returns("self", lambda value: value.id) def copy(self, default=None): self.ensure_one() default = dict(default or {}, name=_("%s (copy)") % self.name) @@ -139,7 +137,7 @@ class AccountMoveTemplateLine(models.Model): ) note = fields.Char() type = fields.Selection( - [("computed", "Computed"), ("input", "User input"),], + [("computed", "Computed"), ("input", "User input")], string="Type", required=True, default="input", @@ -153,6 +151,28 @@ 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?",) + tax_repartition_line_id = fields.Many2one( + "account.tax.repartition.line", + string="Tax Repartition Line", + compute="_compute_tax_repartition_line_id", + store=True, + readonly=True, + ) + + @api.depends("is_refund", "account_id", "tax_line_id") + def _compute_tax_repartition_line_id(self): + for record in self.filtered(lambda x: x.account_id and x.tax_line_id): + tax_repartition = "refund_tax_id" if record.is_refund else "invoice_tax_id" + record.tax_repartition_line_id = self.env[ + "account.tax.repartition.line" + ].search( + [ + ("account_id", "=", record.account_id.id), + (tax_repartition, "=", record.tax_line_id.id), + ], + limit=1, + ) _sql_constraints = [ ( diff --git a/account_move_template/readme/CONTRIBUTORS.rst b/account_move_template/readme/CONTRIBUTORS.rst index 3c18f6b05..e7bd2c24f 100644 --- a/account_move_template/readme/CONTRIBUTORS.rst +++ b/account_move_template/readme/CONTRIBUTORS.rst @@ -15,3 +15,7 @@ Module Contributors * Guewen Baconnier * Raf Ven (port to v11) * Jordi Ballester (EFICENT) +* `Sygel `_: + + * Harald Panten + * Valentin Vinagre diff --git a/account_move_template/readme/USAGE.rst b/account_move_template/readme/USAGE.rst index aba820b7b..57f46c969 100644 --- a/account_move_template/readme/USAGE.rst +++ b/account_move_template/readme/USAGE.rst @@ -8,6 +8,6 @@ To create new templates: To use an existing template: -#. Go to *Invoicing / Accounting / Accounting Entries / Create Entry from Template* +#. Go to *Invoicing / Accounting / Miscellaneous / Create Entry from Template* #. Select one of the available templates. #. Complete the entries according to the template and click on the button *Generate Journal Entry*. diff --git a/account_move_template/security/account_move_template_security.xml b/account_move_template/security/account_move_template_security.xml index a64150488..96c7f7db7 100644 --- a/account_move_template/security/account_move_template_security.xml +++ b/account_move_template/security/account_move_template_security.xml @@ -5,6 +5,6 @@ ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + >['|',('company_id','=',False),('company_id','in',company_ids)] diff --git a/account_move_template/tests/test_account_move_template.py b/account_move_template/tests/test_account_move_template.py index 4616c4a76..ac1bd557a 100644 --- a/account_move_template/tests/test_account_move_template.py +++ b/account_move_template/tests/test_account_move_template.py @@ -20,7 +20,7 @@ class TestAccountMoveTemplate(TransactionCase): def _chart_of_accounts_create(self, company, chart): _logger.debug("Creating chart of account") self.env.user.write( - {"company_ids": [(4, company.id)], "company_id": company.id,} + {"company_ids": [(4, company.id)], "company_id": company.id} ) self.with_context(company_id=company.id, force_company=company.id) wizard = self.env["wizard.multi.charts.accounts"].create( @@ -42,16 +42,16 @@ class TestAccountMoveTemplate(TransactionCase): multi_company_group = self.env.ref("base.group_multi_company") account_user_group = self.env.ref("account.group_account_user") account_manager_group = self.env.ref("account.group_account_manager") - self.company = self.env["res.company"].create({"name": "Test company",}) + self.company = self.env["res.company"].create({"name": "Test company"}) self.company_2 = self.env["res.company"].create( - {"name": "Test company 2", "parent_id": self.company.id,} + {"name": "Test company 2", "parent_id": self.company.id} ) self.env.user.company_ids += self.company self.env.user.company_ids += self.company_2 self.user = ( self.env["res.users"] - .sudo(self.env.user) + .with_user(self.env.user) .with_context(no_reset_password=True) .create( { @@ -81,7 +81,7 @@ class TestAccountMoveTemplate(TransactionCase): self.chart = self.env["account.chart.template"].search([], limit=1) self._chart_of_accounts_create(self.company, self.chart) account_template = self.env["account.account.template"].create( - {"name": "Test 1", "code": "Code_test", "user_type_id": self.user_type.id,} + {"name": "Test 1", "code": "Code_test", "user_type_id": self.user_type.id} ) self.env["ir.model.data"].create( { @@ -121,10 +121,10 @@ class TestAccountMoveTemplate(TransactionCase): } ) self.partner = self.env["res.partner"].create( - {"name": "Test partner", "company_id": False,} + {"name": "Test partner", "company_id": False} ) self.partner2 = self.env["res.partner"].create( - {"name": "Test partner 2", "company_id": False,} + {"name": "Test partner 2", "company_id": False} ) self.account_type = self.env["account.account.type"].create( {"name": "Test Tax Account Type"} @@ -152,7 +152,7 @@ class TestAccountMoveTemplate(TransactionCase): """ template = ( self.env["account.move.template"] - .sudo(self.user) + .with_user(self.user) .create( { "name": "Test Move Template", @@ -196,7 +196,7 @@ class TestAccountMoveTemplate(TransactionCase): wiz = ( self.env["wizard.select.move.template"] - .sudo(self.user) + .with_user(self.user) .create( { "company_id": self.company.id, diff --git a/account_move_template/view/account_move_template.xml b/account_move_template/view/account_move_template.xml index f3db6e20b..02b555a29 100644 --- a/account_move_template/view/account_move_template.xml +++ b/account_move_template/view/account_move_template.xml @@ -16,7 +16,7 @@ @@ -60,7 +60,11 @@ name="analytic_account_id" domain="[('company_id','=',company_id)]" /> - + @@ -68,7 +72,12 @@ + + diff --git a/account_move_template/wizard/account_move_template_run.py b/account_move_template/wizard/account_move_template_run.py index e1e148136..b9b6068e1 100644 --- a/account_move_template/wizard/account_move_template_run.py +++ b/account_move_template/wizard/account_move_template_run.py @@ -29,7 +29,7 @@ class AccountMoveTemplateRun(models.TransientModel): "account.move.template.line.run", "wizard_id", string="Lines" ) state = fields.Selection( - [("select_template", "Select Template"), ("set_lines", "Set Lines"),], + [("select_template", "Select Template"), ("set_lines", "Set Lines")], readonly=True, default="select_template", ) @@ -43,12 +43,14 @@ class AccountMoveTemplateRun(models.TransientModel): "account_id": tmpl_line.account_id.id, "partner_id": tmpl_line.partner_id.id or False, "move_line_type": tmpl_line.move_line_type, - "tax_ids": [(6, 0, tmpl_line.tax_ids.ids)], "tax_line_id": tmpl_line.tax_line_id.id, + "tax_ids": [(6, 0, tmpl_line.tax_ids.ids)], "analytic_account_id": tmpl_line.analytic_account_id.id, "analytic_tag_ids": [(6, 0, tmpl_line.analytic_tag_ids.ids)], "note": tmpl_line.note, "payment_term_id": tmpl_line.payment_term_id.id or False, + "is_refund": tmpl_line.is_refund, + "tax_repartition_line_id": tmpl_line.tax_repartition_line_id.id or False, } return vals @@ -83,9 +85,7 @@ class AccountMoveTemplateRun(models.TransientModel): 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,} - ) + result.update({"res_id": self.id, "context": self.env.context}) return result # STEP 2 @@ -95,6 +95,7 @@ class AccountMoveTemplateRun(models.TransientModel): for wizard_line in self.line_ids: sequence2amount[wizard_line.sequence] = wizard_line.amount prec = self.company_id.currency_id.rounding + self.template_id.compute_lines(sequence2amount) if all( [ float_is_zero(x, precision_rounding=prec) @@ -102,7 +103,6 @@ class AccountMoveTemplateRun(models.TransientModel): ] ): 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] @@ -148,13 +148,23 @@ class AccountMoveTemplateRun(models.TransientModel): "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, "date_maturity": date_maturity or self.date, + "tax_repartition_line_id": line.tax_repartition_line_id.id or False, } 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)] + tax_repartition = "refund_tax_id" if line.is_refund else "invoice_tax_id" + atrl_ids = self.env["account.tax.repartition.line"].search( + [ + (tax_repartition, "in", line.tax_ids.ids), + ("repartition_type", "=", "base"), + ] + ) + values["tag_ids"] = [(6, 0, atrl_ids.mapped("tag_ids").ids)] + if line.tax_repartition_line_id: + values["tag_ids"] = [(6, 0, line.tax_repartition_line_id.tag_ids.ids)] return values @@ -192,3 +202,7 @@ 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,) + tax_repartition_line_id = fields.Many2one( + "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 022517b3c..29289882e 100644 --- a/account_move_template/wizard/account_move_template_run_view.xml +++ b/account_move_template/wizard/account_move_template_run_view.xml @@ -36,7 +36,7 @@