2
0

[MIG] account_move_template to v14

This commit is contained in:
Alexis de Lattre 2020-11-26 14:57:05 +01:00 committed by Abraham Anes
parent 235bc6e9c1
commit 2d51ad28e4
7 changed files with 42 additions and 31 deletions

View File

@ -5,7 +5,7 @@
{ {
"name": "Account Move Template", "name": "Account Move Template",
"version": "13.0.1.1.0", "version": "14.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, ForgeFlow, " "author": "Agile Business Group, Aurium Technologies, Vauxoo, ForgeFlow, "

View File

@ -3,7 +3,6 @@
from odoo import _, api, fields, models from odoo import _, api, fields, models
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_round
from odoo.tools.safe_eval import safe_eval from odoo.tools.safe_eval import safe_eval
@ -36,7 +35,7 @@ class AccountMoveTemplate(models.Model):
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)
return super(AccountMoveTemplate, self).copy(default) return super().copy(default)
def eval_computed_line(self, line, sequence2amount): def eval_computed_line(self, line, sequence2amount):
safe_eval_dict = {} safe_eval_dict = {}
@ -65,7 +64,7 @@ class AccountMoveTemplate(models.Model):
) )
def compute_lines(self, sequence2amount): def compute_lines(self, sequence2amount):
prec = self.company_id.currency_id.rounding company_cur = self.company_id.currency_id
input_sequence2amount = sequence2amount.copy() input_sequence2amount = sequence2amount.copy()
for line in self.line_ids.filtered(lambda x: x.type == "input"): for line in self.line_ids.filtered(lambda x: x.type == "input"):
if line.sequence not in sequence2amount: 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"): for line in self.line_ids.filtered(lambda x: x.type == "computed"):
self.eval_computed_line(line, sequence2amount) self.eval_computed_line(line, sequence2amount)
sequence2amount[line.sequence] = float_round( sequence2amount[line.sequence] = company_cur.round(
sequence2amount[line.sequence], precision_rounding=prec sequence2amount[line.sequence]
) )
return sequence2amount return sequence2amount
@ -151,7 +150,10 @@ 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?",) is_refund = fields.Boolean(
default=False,
string="Is a refund?",
)
tax_repartition_line_id = fields.Many2one( tax_repartition_line_id = fields.Many2one(
"account.tax.repartition.line", "account.tax.repartition.line",
string="Tax Repartition Line", string="Tax Repartition Line",
@ -163,7 +165,7 @@ class AccountMoveTemplateLine(models.Model):
"account.account", "account.account",
string="Account Opt.", string="Account Opt.",
domain=[("deprecated", "=", False)], 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") @api.depends("is_refund", "account_id", "tax_line_id")

View File

@ -8,7 +8,6 @@ To create new templates:
To use an existing template: 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. #. 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*. #. Complete the entries according to the template and click on the button *Generate Journal Entry*.

View File

@ -1,3 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink 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_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_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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 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
3 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
4 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
5 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

View File

@ -148,8 +148,7 @@ class TestAccountMoveTemplate(TransactionCase):
) )
def test_create_template(self): def test_create_template(self):
"""Test that I can create a template """Test that I can create a template"""
"""
template = ( template = (
self.env["account.move.template"] self.env["account.move.template"]
.with_user(self.user) .with_user(self.user)

View File

@ -4,7 +4,6 @@ from ast import literal_eval
from odoo import _, fields, models from odoo import _, fields, models
from odoo.exceptions import UserError, ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_is_zero
class AccountMoveTemplateRun(models.TransientModel): class AccountMoveTemplateRun(models.TransientModel):
@ -111,10 +110,10 @@ Valid dictionary to overwrite template lines:
return ["partner_id", "amount", "name", "date_maturity"] return ["partner_id", "amount", "name", "date_maturity"]
def _get_overwrite_vals(self): def _get_overwrite_vals(self):
""" valid_dict = { """valid_dict = {
'L1': {'partner_id': 1, 'amount': 10}, 'L1': {'partner_id': 1, 'amount': 10},
'L2': {'partner_id': 2, 'amount': 20}, 'L2': {'partner_id': 2, 'amount': 20},
} }
""" """
self.ensure_one() self.ensure_one()
valid_keys = self._get_valid_keys() valid_keys = self._get_valid_keys()
@ -171,19 +170,14 @@ Valid dictionary to overwrite template lines:
sequence2amount = {} sequence2amount = {}
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 company_cur = self.company_id.currency_id
self.template_id.compute_lines(sequence2amount) self.template_id.compute_lines(sequence2amount)
if all( if all([company_cur.is_zero(x) for x in sequence2amount.values()]):
[
float_is_zero(x, precision_rounding=prec)
for x in sequence2amount.values()
]
):
raise UserError(_("Debit and credit of all lines are null.")) raise UserError(_("Debit and credit of all lines are null."))
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]
if not float_is_zero(amount, precision_rounding=prec): if not company_cur.is_zero(amount):
move_vals["line_ids"].append( move_vals["line_ids"].append(
(0, 0, self._prepare_move_line(line, amount)) (0, 0, self._prepare_move_line(line, amount))
) )
@ -216,7 +210,7 @@ Valid dictionary to overwrite template lines:
date_maturity = False date_maturity = False
if line.payment_term_id: if line.payment_term_id:
pterm_list = line.payment_term_id.compute(value=1, date_ref=self.date) 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" debit = line.move_line_type == "dr"
values = { values = {
"name": line.name, "name": line.name,
@ -295,7 +289,9 @@ 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,) is_refund = fields.Boolean(string="Is a refund?", readonly=True)
tax_repartition_line_id = fields.Many2one( 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,
) )

View File

@ -16,9 +16,22 @@
name="overwrite" name="overwrite"
widget="ace" widget="ace"
options="{'mode': 'python'}" options="{'mode': 'python'}"
attrs="{'invisible': [('state', '=', 'set_lines')]}" invisible="1"
placeholder="Add an internal note here..."
/> />
<!-- Initial invisibility status of the overwrite field:
attrs="{'invisible': [('state', '=', 'set_lines')]}"
The overwrite option is useful when generating
the move via code, but I think it's not a good idea to display it to
the user. We can't expect users to write a python dict to enter data
via the web interface for their daily usage of Odoo. Of course, most
users will just leave the field empty and use the module as normal, but
it complexifies the interface for everybody, and many users will wonder
what they should enter in this "Overwrite" field and wait for help. So
let's make that field invisible, and you can un-hide it for specific
project where you have an accountant that is good at writing python
dicts and finding IDs of partners!
-->
<field name="company_id" groups="base.group_multi_company" /> <field name="company_id" groups="base.group_multi_company" />
<field name="date" states="set_lines" /> <field name="date" states="set_lines" />
<field name="journal_id" states="set_lines" /> <field name="journal_id" states="set_lines" />
@ -91,7 +104,7 @@
</record> </record>
<menuitem <menuitem
id="account_move_template_run_menu" id="account_move_template_run_menu"
parent="account.menu_finance_entries_accounting_miscellaneous" parent="account.menu_finance_entries_actions"
action="account_move_template_run_action" action="account_move_template_run_action"
sequence="10" sequence="10"
/> />