Skip to content

Commit

Permalink
[IMP] account_move_cutoff: add forward product on defferred revenue/e…
Browse files Browse the repository at this point in the history
…xpenses
  • Loading branch information
petrus-v committed Sep 23, 2024
1 parent 22b5101 commit ec6e843
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
11 changes: 11 additions & 0 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 Down Expand Up @@ -254,6 +255,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 +279,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 +297,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
5 changes: 5 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,8 @@ 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.",
)
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
14 changes: 14 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,20 @@
</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>
</xpath>

</field>
Expand Down

0 comments on commit ec6e843

Please sign in to comment.