2
0

[MIG] account_move_template: Migration to 13.0

This commit is contained in:
Valentin Vinagre Urteaga 2020-04-24 17:30:12 +02:00 committed by Abraham Anes
parent f5b4892d24
commit ff77767af4
9 changed files with 74 additions and 27 deletions

View File

@ -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",

View File

@ -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 = [
(

View File

@ -15,3 +15,7 @@ Module Contributors
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Raf Ven <raf.ven@dynapps.be> (port to v11)
* Jordi Ballester <jordi.ballester@eficent.com> (EFICENT)
* `Sygel <https://www.sygel.es>`_:
* Harald Panten <harald.panten@sygel.es>
* Valentin Vinagre <valentin.vinagre@sygel.es>

View File

@ -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*.

View File

@ -5,6 +5,6 @@
<field name="model_id" ref="model_account_move_template" />
<field
name="domain_force"
>['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])]</field>
>['|',('company_id','=',False),('company_id','in',company_ids)]</field>
</record>
</odoo>

View File

@ -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,

View File

@ -16,7 +16,7 @@
<field
name="analytic_tag_ids"
widget="many2many_tags"
groups="analytic.group_analytic_accounting"
groups="analytic.group_analytic_tags"
/>
<field name="move_line_type" />
<field name="type" />
@ -60,7 +60,11 @@
name="analytic_account_id"
domain="[('company_id','=',company_id)]"
/>
<field name="analytic_tag_ids" widget="many2many_tags" />
<field
name="analytic_tag_ids"
widget="many2many_tags"
groups="analytic.group_analytic_tags"
/>
</group>
<group name="amount" string="Amount">
<field name="move_line_type" />
@ -68,7 +72,12 @@
<field name="note" />
</group>
<group string="Taxes" name="tax">
<field name="is_refund" />
<field name="tax_line_id" />
<field
name="tax_repartition_line_id"
attrs="{'invisible': [('tax_line_id','=',False)]}"
/>
<field name="tax_ids" widget="many2many_tags" />
</group>
</group>

View File

@ -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,
)

View File

@ -36,7 +36,7 @@
<field
name="analytic_tag_ids"
widget="many2many_tags"
groups="analytic.group_analytic_accounting"
groups="analytic.group_analytic_tags"
/>
<field
name="tax_line_id"
@ -84,7 +84,7 @@
</record>
<menuitem
id="account_move_template_run_menu"
parent="account.menu_finance_entries_accounting_entries"
parent="account.menu_finance_entries_accounting_miscellaneous"
action="account_move_template_run_action"
sequence="10"
/>