Skip to content

Commit

Permalink
[MIG] account_move_template to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via authored and Abranes committed Jun 5, 2023
1 parent 235bc6e commit 2d51ad2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion account_move_template/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Expand Down
16 changes: 9 additions & 7 deletions account_move_template/models/account_move_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -65,7 +64,7 @@ def eval_computed_line(self, line, sequence2amount):
)

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:
Expand All @@ -87,8 +86,8 @@ def compute_lines(self, sequence2amount):
)
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

Expand Down Expand Up @@ -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",
Expand All @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions account_move_template/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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*.
2 changes: 2 additions & 0 deletions account_move_template/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions account_move_template/tests/test_account_move_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def setUp(self):
)

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)
Expand Down
28 changes: 12 additions & 16 deletions account_move_template/wizard/account_move_template_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from odoo import _, fields, models
from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_is_zero


class AccountMoveTemplateRun(models.TransientModel):
Expand Down Expand Up @@ -111,10 +110,10 @@ def _get_valid_keys(self):
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()
Expand Down Expand Up @@ -171,19 +170,14 @@ def generate_move(self):
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))
)
Expand Down Expand Up @@ -216,7 +210,7 @@ def _prepare_move_line(self, line, amount):
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,
Expand Down Expand Up @@ -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,
)
19 changes: 16 additions & 3 deletions account_move_template/wizard/account_move_template_run_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@
name="overwrite"
widget="ace"
options="{'mode': 'python'}"
attrs="{'invisible': [('state', '=', 'set_lines')]}"
placeholder="Add an internal note here..."
invisible="1"
/>
<!-- 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="date" states="set_lines" />
<field name="journal_id" states="set_lines" />
Expand Down Expand Up @@ -91,7 +104,7 @@
</record>
<menuitem
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"
sequence="10"
/>
Expand Down

0 comments on commit 2d51ad2

Please sign in to comment.