Browse Source

Merge PR #439 into 12.0

Signed-off-by sbejaoui
pull/444/head
OCA-git-bot 5 years ago
parent
commit
bc99f2c2d2
  1. 37
      contract_forecast/models/contract_line.py
  2. 114
      contract_forecast/tests/test_contract_line_forecast_period.py

37
contract_forecast/models/contract_line.py

@ -69,24 +69,33 @@ class ContractLine(models.Model):
for rec in self:
rec.forecast_period_ids.unlink()
if rec.recurring_next_date:
last_date_invoiced = (
period_date_end = (
rec.last_date_invoiced
if rec.last_date_invoiced
else rec.date_start - relativedelta(days=1)
)
period_date_end = last_date_invoiced
recurring_next_date = rec.recurring_next_date
while rec._get_generate_forecast_periods_criteria(
while (
period_date_end
and rec._get_generate_forecast_periods_criteria(
period_date_end
)
):
period_dates = rec._get_period_to_invoice(
last_date_invoiced,
recurring_next_date,
stop_at_date_end=not rec.is_auto_renew,
period_date_start = period_date_end + relativedelta(days=1)
period_date_end = self.get_next_period_date_end(
period_date_start,
rec.recurring_rule_type,
rec.recurring_interval,
max_date_end=rec.date_end,
)
period_date_start, period_date_end, recurring_next_date = (
period_dates
recurring_next_date = rec.get_next_invoice_date(
period_date_start,
rec.recurring_invoicing_type,
rec.recurring_invoicing_offset,
rec.recurring_rule_type,
rec.recurring_interval,
rec.date_end,
)
if period_date_end and recurring_next_date:
values.append(
rec._prepare_contract_line_forecast_period(
period_date_start,
@ -94,13 +103,7 @@ class ContractLine(models.Model):
recurring_next_date,
)
)
last_date_invoiced = period_date_end
recurring_next_date = (
recurring_next_date
+ self.get_relative_delta(
rec.recurring_rule_type, rec.recurring_interval
)
)
return self.env["contract.line.forecast.period"].create(values)
@api.model

114
contract_forecast/tests/test_contract_line_forecast_period.py

@ -1,9 +1,9 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo.fields import Date
from odoo.addons.contract.tests.test_contract import TestContractBase
from odoo.tools import mute_logger
@ -15,9 +15,9 @@ class TestContractLineForecastPeriod(TestContractBase):
context=dict(self.env.context, test_queue_job_no_delay=True)
)
super(TestContractLineForecastPeriod, self).setUp()
self.this_year = date.today().year
self.line_vals["date_start"] = date.today()
self.line_vals["recurring_next_date"] = date.today()
self.this_year = Date.today().year
self.line_vals["date_start"] = Date.today()
self.line_vals["recurring_next_date"] = Date.today()
self.acct_line = self.env["contract.line"].create(self.line_vals)
@mute_logger("odoo.addons.queue_job.models.base")
@ -132,7 +132,7 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_7(self):
self.acct_line.write(
{
'date_end': date.today() + relativedelta(months=3),
'date_end': Date.today() + relativedelta(months=3),
'recurring_rule_type': "monthlylastday",
'recurring_invoicing_type': 'pre-paid',
'is_auto_renew': True,
@ -140,7 +140,7 @@ class TestContractLineForecastPeriod(TestContractBase):
)
self.acct_line._onchange_date_start()
self.assertTrue(self.acct_line.forecast_period_ids)
self.assertEqual(len(self.acct_line.forecast_period_ids), 13)
self.assertEqual(len(self.acct_line.forecast_period_ids), 4)
@mute_logger("odoo.addons.queue_job.models.base")
def test_forecast_period_on_contract_line_update_8(self):
@ -158,3 +158,105 @@ class TestContractLineForecastPeriod(TestContractBase):
)
self.assertTrue(self.acct_line.forecast_period_ids)
self.assertEqual(len(self.acct_line.forecast_period_ids), 1)
@mute_logger("odoo.addons.queue_job.models.base")
def test_forecast_period_on_contract_line_update_9(self):
self.acct_line.write(
{
'date_start': "2019-01-14",
'recurring_next_date': "2019-01-31",
'date_end': "2020-01-14",
'recurring_rule_type': "monthlylastday",
'last_date_invoiced': False,
'recurring_invoicing_type': 'post-paid',
}
)
self.assertTrue(self.acct_line.forecast_period_ids)
self.assertEqual(len(self.acct_line.forecast_period_ids), 13)
self.assertEqual(
(
self.acct_line.forecast_period_ids[0].date_start,
self.acct_line.forecast_period_ids[0].date_end,
self.acct_line.forecast_period_ids[0].date_invoice,
),
(
Date.to_date("2019-01-14"),
Date.to_date("2019-01-31"),
Date.to_date("2019-01-31"),
),
)
self.assertEqual(
(
self.acct_line.forecast_period_ids[1].date_start,
self.acct_line.forecast_period_ids[1].date_end,
self.acct_line.forecast_period_ids[1].date_invoice,
),
(
Date.to_date("2019-02-01"),
Date.to_date("2019-02-28"),
Date.to_date("2019-02-28"),
),
)
self.assertEqual(
(
self.acct_line.forecast_period_ids[-1].date_start,
self.acct_line.forecast_period_ids[-1].date_end,
self.acct_line.forecast_period_ids[-1].date_invoice,
),
(
Date.to_date("2020-01-01"),
Date.to_date("2020-01-14"),
Date.to_date("2020-01-14"),
),
)
@mute_logger("odoo.addons.queue_job.models.base")
def test_forecast_period_on_contract_line_update_10(self):
self.acct_line.write(
{
'date_start': "2019-01-14",
'recurring_next_date': "2019-01-14",
'date_end': "2020-01-14",
'recurring_rule_type': "monthlylastday",
'last_date_invoiced': False,
'recurring_invoicing_type': 'pre-paid',
}
)
self.assertTrue(self.acct_line.forecast_period_ids)
self.assertEqual(len(self.acct_line.forecast_period_ids), 13)
self.assertEqual(
(
self.acct_line.forecast_period_ids[0].date_start,
self.acct_line.forecast_period_ids[0].date_end,
self.acct_line.forecast_period_ids[0].date_invoice,
),
(
Date.to_date("2019-01-14"),
Date.to_date("2019-01-31"),
Date.to_date("2019-01-14"),
),
)
self.assertEqual(
(
self.acct_line.forecast_period_ids[1].date_start,
self.acct_line.forecast_period_ids[1].date_end,
self.acct_line.forecast_period_ids[1].date_invoice,
),
(
Date.to_date("2019-02-01"),
Date.to_date("2019-02-28"),
Date.to_date("2019-02-01"),
),
)
self.assertEqual(
(
self.acct_line.forecast_period_ids[-1].date_start,
self.acct_line.forecast_period_ids[-1].date_end,
self.acct_line.forecast_period_ids[-1].date_invoice,
),
(
Date.to_date("2020-01-01"),
Date.to_date("2020-01-14"),
Date.to_date("2020-01-01"),
),
)
Loading…
Cancel
Save