Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] account_move_cutoff: forward product info + settings improvements #305

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions account_move_cutoff/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dateutil.relativedelta import relativedelta

from odoo import _, api, fields, models
from odoo.tools.misc import str2bool

logger = logging.getLogger(__name__)

Expand All @@ -18,16 +19,6 @@ class AccountMoveLine(models.Model):
"cutoff.period.mixin",
]

@api.model
def _get_default_cutoff_method(self):
return (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"account_move_cutoff.default_cutoff_method", "monthly_prorata_temporis"
)
)

is_deferrable_line = fields.Boolean(
string="Is deferrable line",
compute="_compute_is_deferrable_line",
Expand All @@ -40,7 +31,7 @@ def _get_default_cutoff_method(self):
],
string="Cut-off method",
required=True,
default=lambda self: self._get_default_cutoff_method(),
default="monthly_prorata_temporis",
help=(
"Determine how to split amounts over periods:\n"
" * Equal: same amount is splitted over periods of the service"
Expand Down Expand Up @@ -254,6 +245,14 @@ def _prepare_entry_lines(self, new_move, period, amount, is_cutoff=True):
end_date = self.end_date
else:
start_date, end_date = self._get_period_start_end_dates(period)

link_product = str2bool(
self.env["ir.config_parameter"]
.sudo()
.get_param("account_move_cutoff.link_product", "False"),
False,
)

return self.env["account.move.line"].create(
[
{
Expand All @@ -270,6 +269,7 @@ def _prepare_entry_lines(self, new_move, period, amount, is_cutoff=True):
"partner_id": self.partner_id.id,
"analytic_account_id": self.analytic_account_id.id,
"cutoff_source_id": self.id,
"product_id": self.product_id.id if link_product else False,
},
{
"move_id": new_move.id,
Expand All @@ -287,6 +287,7 @@ def _prepare_entry_lines(self, new_move, period, amount, is_cutoff=True):
"account_id": self.deferred_accrual_account_id.id,
"partner_id": self.partner_id.id,
"analytic_account_id": False,
"product_id": False,
"cutoff_source_id": self.id,
},
]
Expand Down
22 changes: 22 additions & 0 deletions account_move_cutoff/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,25 @@ class ResConfigSettings(models.TransientModel):
readonly=False,
string="Expense cut-off journal",
)
link_product = fields.Boolean(
"Link product",
config_parameter="account_move_cutoff.link_product",
help="Link product on deferred account.move.line.",
)
default_cutoff_method = fields.Selection(
[
("equal", "Equal"),
("monthly_prorata_temporis", "Prorata temporis (by month %)"),
],
string="Default Cutoff method",
default="monthly_prorata_temporis",
default_model="account.move.line",
required=True,
help=(
"Determine how to split amounts over periods:\n"
" * Equal: same amount is splitted over periods of the service"
" (using start and end date on the invoice line).\n"
" * Prorata temporis by month %: amount is splitted over"
" the rate of service days in the month.\n"
),
)
40 changes: 40 additions & 0 deletions account_move_cutoff/tests/test_account_invoice_cutoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,53 @@ def test_action_view_deferred_entries(self):
action = self.invoice.action_view_deferred_entries()
self.assertEqual(action["domain"][0][2], self.invoice.cutoff_entry_ids.ids)

def test_link_product(self):
self.addCleanup(
self.env["ir.config_parameter"].sudo().set_param,
"account_move_cutoff.link_product",
False,
)
self.env["ir.config_parameter"].sudo().set_param(
"account_move_cutoff.link_product", "True"
)
self.invoice.line_ids.cutoff_method = "monthly_prorata_temporis"

with freeze_time("2023-01-15"):
self.invoice.action_post()
self.assertEqual(self.invoice.cutoff_move_count, 4)

self.assertEqual(
len(
self.invoice.cutoff_entry_ids.line_ids.filtered(
lambda ml: ml.product_id
)
),
18,
)

def test_account_invoice_cutoff_monthly_factor_prorata(self):
self.addCleanup(
self.env["ir.config_parameter"].sudo().set_param,
"account_move_cutoff.link_product",
False,
)
self.env["ir.config_parameter"].sudo().set_param(
"account_move_cutoff.link_product", "False"
)
self.invoice.line_ids.cutoff_method = "monthly_prorata_temporis"

with freeze_time("2023-01-15"):
self.invoice.action_post()
self.assertEqual(self.invoice.cutoff_move_count, 4)

self.assertEqual(
len(
self.invoice.cutoff_entry_ids.line_ids.filtered(
lambda ml: ml.product_id
)
),
0,
)
cutoff_move = self.invoice.cutoff_entry_ids.filtered(
lambda move, move_date=date(2023, 1, 15): move.date == move_date
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def test_ensure_refund_without_start_end_date_are_postable(self):
self.assertEqual(self.refund.state, "posted")

def test_account_refund_cutoff_equals(self):
# self.env["ir.config_parameter"].set_param(
# "account_move_cutoff.default_cutoff_method",
# "equal"
# )
self.refund.line_ids.cutoff_method = "equal"
with freeze_time("2023-01-15"):
self.refund.action_post()
Expand Down
9 changes: 8 additions & 1 deletion account_move_cutoff/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@
/>
</field>
<xpath
expr="//notebook/page[@id='aml_tab']/field[@name='line_ids']/tree/field[@name='name']"
expr="//notebook/page[@id='invoice_tab']/field[@name='invoice_line_ids']/tree/field[@name='account_id']"
position="after"
>
<field name="cutoff_method" optional="hide" />
</xpath>
<xpath
expr="//notebook/page[@id='aml_tab']/field[@name='line_ids']/tree/field[@name='account_id']"
position="after"
>
<field name="cutoff_method" optional="hide" />
<field name="cutoff_source_move_id" optional="hide" />
<field name="cutoff_source_id" optional="hide" />
</xpath>
Expand Down
3 changes: 3 additions & 0 deletions account_move_cutoff/views/account_move_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
string="Deferred Revenue/Expense"
attrs="{'invisible': [('cutoff_source_move_id', '=', False)]}"
>
<field name="cutoff_method" />
<field name="cutoff_source_move_id" />
<field name="cutoff_source_id" />
</group>
Expand All @@ -28,6 +29,7 @@
<field name="inherit_id" ref="account.view_move_line_tree" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="cutoff_method" optional="hide" />
<field name="cutoff_source_move_id" optional="hide" />
<field name="cutoff_source_id" optional="hide" />
</field>
Expand All @@ -41,6 +43,7 @@
<field name="inherit_id" ref="account.view_move_line_tree_grouped" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="cutoff_method" optional="hide" />
<field name="cutoff_source_move_id" optional="hide" />
<field name="cutoff_source_id" optional="hide" />
</field>
Expand Down
36 changes: 36 additions & 0 deletions account_move_cutoff/views/res_config_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,42 @@
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="link_product" />
</div>
<div class="o_setting_right_pane">
<label
for="link_product"
string="Link product on deferred entries"
/>
<div class="text-muted">
Link product to deferred entries using automatic cutoff on start/end date.
</div>
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<field
name="default_cutoff_method"
string="Default cutoff method"
/>
<div class="text-muted">
Determine how to split amounts over periods:
<li>
<ul
>Equal: same amount is splitted over periods of the service"
(using start and end date on the invoice line).</ul>
<ul>
Prorata temporis by month %: amount is splitted over"
the rate of service days in the month.\n"
</ul>
</li>
</div>
</div>
</div>
</xpath>

</field>
Expand Down
Loading