[MIG] account_move_template: Migration to 13.0
This commit is contained in:
parent
f5b4892d24
commit
ff77767af4
@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
"name": "Account Move Template",
|
"name": "Account Move Template",
|
||||||
"version": "12.0.1.0.0",
|
"version": "13.0.1.0.0",
|
||||||
"category": "Accounting",
|
"category": "Accounting",
|
||||||
"summary": "Templates for recurring Journal Entries",
|
"summary": "Templates for recurring Journal Entries",
|
||||||
"author": "Agile Business Group, Aurium Technologies, Vauxoo, Eficent, "
|
"author": "Agile Business Group, Aurium Technologies, Vauxoo, Eficent, "
|
||||||
"Akretion, Odoo Community Association (OCA)",
|
"Akretion, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/account-financial-tools",
|
"website": "https://github.com/OCA/account-financial-tools",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"depends": ["account",],
|
"depends": ["account"],
|
||||||
"data": [
|
"data": [
|
||||||
"security/account_move_template_security.xml",
|
"security/account_move_template_security.xml",
|
||||||
"security/ir.model.access.csv",
|
"security/ir.model.access.csv",
|
||||||
|
@ -33,8 +33,6 @@ class AccountMoveTemplate(models.Model):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
||||||
@api.multi
|
|
||||||
@api.returns("self", lambda value: value.id)
|
|
||||||
def copy(self, default=None):
|
def copy(self, default=None):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
default = dict(default or {}, name=_("%s (copy)") % self.name)
|
default = dict(default or {}, name=_("%s (copy)") % self.name)
|
||||||
@ -139,7 +137,7 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
)
|
)
|
||||||
note = fields.Char()
|
note = fields.Char()
|
||||||
type = fields.Selection(
|
type = fields.Selection(
|
||||||
[("computed", "Computed"), ("input", "User input"),],
|
[("computed", "Computed"), ("input", "User input")],
|
||||||
string="Type",
|
string="Type",
|
||||||
required=True,
|
required=True,
|
||||||
default="input",
|
default="input",
|
||||||
@ -153,6 +151,28 @@ class AccountMoveTemplateLine(models.Model):
|
|||||||
string="Payment Terms",
|
string="Payment Terms",
|
||||||
help="Used to compute the due date of the journal item.",
|
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 = [
|
_sql_constraints = [
|
||||||
(
|
(
|
||||||
|
@ -15,3 +15,7 @@ Module Contributors
|
|||||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||||
* Raf Ven <raf.ven@dynapps.be> (port to v11)
|
* Raf Ven <raf.ven@dynapps.be> (port to v11)
|
||||||
* Jordi Ballester <jordi.ballester@eficent.com> (EFICENT)
|
* Jordi Ballester <jordi.ballester@eficent.com> (EFICENT)
|
||||||
|
* `Sygel <https://www.sygel.es>`_:
|
||||||
|
|
||||||
|
* Harald Panten <harald.panten@sygel.es>
|
||||||
|
* Valentin Vinagre <valentin.vinagre@sygel.es>
|
||||||
|
@ -8,6 +8,6 @@ To create new templates:
|
|||||||
|
|
||||||
To use an existing template:
|
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.
|
#. Select one of the available templates.
|
||||||
#. Complete the entries according to the template and click on the button *Generate Journal Entry*.
|
#. Complete the entries according to the template and click on the button *Generate Journal Entry*.
|
||||||
|
@ -5,6 +5,6 @@
|
|||||||
<field name="model_id" ref="model_account_move_template" />
|
<field name="model_id" ref="model_account_move_template" />
|
||||||
<field
|
<field
|
||||||
name="domain_force"
|
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>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
@ -20,7 +20,7 @@ class TestAccountMoveTemplate(TransactionCase):
|
|||||||
def _chart_of_accounts_create(self, company, chart):
|
def _chart_of_accounts_create(self, company, chart):
|
||||||
_logger.debug("Creating chart of account")
|
_logger.debug("Creating chart of account")
|
||||||
self.env.user.write(
|
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)
|
self.with_context(company_id=company.id, force_company=company.id)
|
||||||
wizard = self.env["wizard.multi.charts.accounts"].create(
|
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")
|
multi_company_group = self.env.ref("base.group_multi_company")
|
||||||
account_user_group = self.env.ref("account.group_account_user")
|
account_user_group = self.env.ref("account.group_account_user")
|
||||||
account_manager_group = self.env.ref("account.group_account_manager")
|
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(
|
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
|
||||||
self.env.user.company_ids += self.company_2
|
self.env.user.company_ids += self.company_2
|
||||||
|
|
||||||
self.user = (
|
self.user = (
|
||||||
self.env["res.users"]
|
self.env["res.users"]
|
||||||
.sudo(self.env.user)
|
.with_user(self.env.user)
|
||||||
.with_context(no_reset_password=True)
|
.with_context(no_reset_password=True)
|
||||||
.create(
|
.create(
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ class TestAccountMoveTemplate(TransactionCase):
|
|||||||
self.chart = self.env["account.chart.template"].search([], limit=1)
|
self.chart = self.env["account.chart.template"].search([], limit=1)
|
||||||
self._chart_of_accounts_create(self.company, self.chart)
|
self._chart_of_accounts_create(self.company, self.chart)
|
||||||
account_template = self.env["account.account.template"].create(
|
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(
|
self.env["ir.model.data"].create(
|
||||||
{
|
{
|
||||||
@ -121,10 +121,10 @@ class TestAccountMoveTemplate(TransactionCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.partner = self.env["res.partner"].create(
|
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(
|
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(
|
self.account_type = self.env["account.account.type"].create(
|
||||||
{"name": "Test Tax Account Type"}
|
{"name": "Test Tax Account Type"}
|
||||||
@ -152,7 +152,7 @@ class TestAccountMoveTemplate(TransactionCase):
|
|||||||
"""
|
"""
|
||||||
template = (
|
template = (
|
||||||
self.env["account.move.template"]
|
self.env["account.move.template"]
|
||||||
.sudo(self.user)
|
.with_user(self.user)
|
||||||
.create(
|
.create(
|
||||||
{
|
{
|
||||||
"name": "Test Move Template",
|
"name": "Test Move Template",
|
||||||
@ -196,7 +196,7 @@ class TestAccountMoveTemplate(TransactionCase):
|
|||||||
|
|
||||||
wiz = (
|
wiz = (
|
||||||
self.env["wizard.select.move.template"]
|
self.env["wizard.select.move.template"]
|
||||||
.sudo(self.user)
|
.with_user(self.user)
|
||||||
.create(
|
.create(
|
||||||
{
|
{
|
||||||
"company_id": self.company.id,
|
"company_id": self.company.id,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<field
|
<field
|
||||||
name="analytic_tag_ids"
|
name="analytic_tag_ids"
|
||||||
widget="many2many_tags"
|
widget="many2many_tags"
|
||||||
groups="analytic.group_analytic_accounting"
|
groups="analytic.group_analytic_tags"
|
||||||
/>
|
/>
|
||||||
<field name="move_line_type" />
|
<field name="move_line_type" />
|
||||||
<field name="type" />
|
<field name="type" />
|
||||||
@ -60,7 +60,11 @@
|
|||||||
name="analytic_account_id"
|
name="analytic_account_id"
|
||||||
domain="[('company_id','=',company_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>
|
||||||
<group name="amount" string="Amount">
|
<group name="amount" string="Amount">
|
||||||
<field name="move_line_type" />
|
<field name="move_line_type" />
|
||||||
@ -68,7 +72,12 @@
|
|||||||
<field name="note" />
|
<field name="note" />
|
||||||
</group>
|
</group>
|
||||||
<group string="Taxes" name="tax">
|
<group string="Taxes" name="tax">
|
||||||
|
<field name="is_refund" />
|
||||||
<field name="tax_line_id" />
|
<field name="tax_line_id" />
|
||||||
|
<field
|
||||||
|
name="tax_repartition_line_id"
|
||||||
|
attrs="{'invisible': [('tax_line_id','=',False)]}"
|
||||||
|
/>
|
||||||
<field name="tax_ids" widget="many2many_tags" />
|
<field name="tax_ids" widget="many2many_tags" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
@ -29,7 +29,7 @@ class AccountMoveTemplateRun(models.TransientModel):
|
|||||||
"account.move.template.line.run", "wizard_id", string="Lines"
|
"account.move.template.line.run", "wizard_id", string="Lines"
|
||||||
)
|
)
|
||||||
state = fields.Selection(
|
state = fields.Selection(
|
||||||
[("select_template", "Select Template"), ("set_lines", "Set Lines"),],
|
[("select_template", "Select Template"), ("set_lines", "Set Lines")],
|
||||||
readonly=True,
|
readonly=True,
|
||||||
default="select_template",
|
default="select_template",
|
||||||
)
|
)
|
||||||
@ -43,12 +43,14 @@ class AccountMoveTemplateRun(models.TransientModel):
|
|||||||
"account_id": tmpl_line.account_id.id,
|
"account_id": tmpl_line.account_id.id,
|
||||||
"partner_id": tmpl_line.partner_id.id or False,
|
"partner_id": tmpl_line.partner_id.id or False,
|
||||||
"move_line_type": tmpl_line.move_line_type,
|
"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_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_account_id": tmpl_line.analytic_account_id.id,
|
||||||
"analytic_tag_ids": [(6, 0, tmpl_line.analytic_tag_ids.ids)],
|
"analytic_tag_ids": [(6, 0, tmpl_line.analytic_tag_ids.ids)],
|
||||||
"note": tmpl_line.note,
|
"note": tmpl_line.note,
|
||||||
"payment_term_id": tmpl_line.payment_term_id.id or False,
|
"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
|
return vals
|
||||||
|
|
||||||
@ -83,9 +85,7 @@ class AccountMoveTemplateRun(models.TransientModel):
|
|||||||
return self.generate_move()
|
return self.generate_move()
|
||||||
action = self.env.ref("account_move_template.account_move_template_run_action")
|
action = self.env.ref("account_move_template.account_move_template_run_action")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
result.update(
|
result.update({"res_id": self.id, "context": self.env.context})
|
||||||
{"res_id": self.id, "context": self.env.context,}
|
|
||||||
)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# STEP 2
|
# STEP 2
|
||||||
@ -95,6 +95,7 @@ class AccountMoveTemplateRun(models.TransientModel):
|
|||||||
for wizard_line in self.line_ids:
|
for wizard_line in self.line_ids:
|
||||||
sequence2amount[wizard_line.sequence] = wizard_line.amount
|
sequence2amount[wizard_line.sequence] = wizard_line.amount
|
||||||
prec = self.company_id.currency_id.rounding
|
prec = self.company_id.currency_id.rounding
|
||||||
|
self.template_id.compute_lines(sequence2amount)
|
||||||
if all(
|
if all(
|
||||||
[
|
[
|
||||||
float_is_zero(x, precision_rounding=prec)
|
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."))
|
raise UserError(_("Debit and credit of all lines are null."))
|
||||||
self.template_id.compute_lines(sequence2amount)
|
|
||||||
move_vals = self._prepare_move()
|
move_vals = self._prepare_move()
|
||||||
for line in self.template_id.line_ids:
|
for line in self.template_id.line_ids:
|
||||||
amount = sequence2amount[line.sequence]
|
amount = sequence2amount[line.sequence]
|
||||||
@ -148,13 +148,23 @@ class AccountMoveTemplateRun(models.TransientModel):
|
|||||||
"credit": not debit and amount or 0.0,
|
"credit": not debit and amount or 0.0,
|
||||||
"debit": debit and amount or 0.0,
|
"debit": debit and amount or 0.0,
|
||||||
"partner_id": self.partner_id.id or line.partner_id.id,
|
"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,
|
"date_maturity": date_maturity or self.date,
|
||||||
|
"tax_repartition_line_id": line.tax_repartition_line_id.id or False,
|
||||||
}
|
}
|
||||||
if line.analytic_tag_ids:
|
if line.analytic_tag_ids:
|
||||||
values["analytic_tag_ids"] = [(6, 0, line.analytic_tag_ids.ids)]
|
values["analytic_tag_ids"] = [(6, 0, line.analytic_tag_ids.ids)]
|
||||||
if line.tax_ids:
|
if line.tax_ids:
|
||||||
values["tax_ids"] = [(6, 0, line.tax_ids.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
|
return values
|
||||||
|
|
||||||
|
|
||||||
@ -192,3 +202,7 @@ class AccountMoveTemplateLineRun(models.TransientModel):
|
|||||||
"Amount", required=True, currency_field="company_currency_id"
|
"Amount", required=True, currency_field="company_currency_id"
|
||||||
)
|
)
|
||||||
note = fields.Char(readonly=True)
|
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,
|
||||||
|
)
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<field
|
<field
|
||||||
name="analytic_tag_ids"
|
name="analytic_tag_ids"
|
||||||
widget="many2many_tags"
|
widget="many2many_tags"
|
||||||
groups="analytic.group_analytic_accounting"
|
groups="analytic.group_analytic_tags"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
name="tax_line_id"
|
name="tax_line_id"
|
||||||
@ -84,7 +84,7 @@
|
|||||||
</record>
|
</record>
|
||||||
<menuitem
|
<menuitem
|
||||||
id="account_move_template_run_menu"
|
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"
|
action="account_move_template_run_action"
|
||||||
sequence="10"
|
sequence="10"
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user