diff --git a/contract_forecast/hooks.py b/contract_forecast/hooks.py index 5119f79e..0faef878 100644 --- a/contract_forecast/hooks.py +++ b/contract_forecast/hooks.py @@ -21,7 +21,7 @@ def post_init_hook(cr, registry): env = api.Environment(cr, SUPERUSER_ID, {}) offset = 0 while True: - contract_lines = env["account.analytic.invoice.line"].search( + contract_lines = env["contract.line"].search( [('is_canceled', '=', False)], limit=100, offset=offset ) contract_lines.with_delay()._generate_forecast_periods() diff --git a/contract_forecast/migrations/12.0.1.0.1/post-migration.py b/contract_forecast/migrations/12.0.1.0.1/post-migration.py index deb6df76..487e537d 100644 --- a/contract_forecast/migrations/12.0.1.0.1/post-migration.py +++ b/contract_forecast/migrations/12.0.1.0.1/post-migration.py @@ -12,7 +12,7 @@ def migrate(cr, version): cr.execute(""" UPDATE contract_line_forecast_period AS forecast SET company_id=contract.company_id - FROM account_analytic_account AS contract + FROM contract_contract AS contract WHERE forecast.contract_id=contract.id AND forecast.contract_id IS NOT NULL """) diff --git a/contract_forecast/models/contract.py b/contract_forecast/models/contract.py index 4a973383..992aa79a 100644 --- a/contract_forecast/models/contract.py +++ b/contract_forecast/models/contract.py @@ -4,9 +4,9 @@ from odoo import _, api, models -class AccountAnalyticAccount(models.Model): +class ContractContract(models.Model): - _inherit = "account.analytic.account" + _inherit = "contract.contract" @api.multi def action_show_contract_forecast(self): @@ -29,7 +29,7 @@ class AccountAnalyticAccount(models.Model): @api.multi def write(self, values): - res = super(AccountAnalyticAccount, self).write(values) + res = super(ContractContract, self).write(values) if any( [ field in values diff --git a/contract_forecast/models/contract_line.py b/contract_forecast/models/contract_line.py index 72a175d0..fcc98852 100644 --- a/contract_forecast/models/contract_line.py +++ b/contract_forecast/models/contract_line.py @@ -8,9 +8,9 @@ from odoo.addons.queue_job.job import job QUEUE_CHANNEL = "root.CONTRACT_FORECAST" -class AccountAnalyticInvoiceLine(models.Model): +class ContractLine(models.Model): - _inherit = "account.analytic.invoice.line" + _inherit = "contract.line" forecast_period_ids = fields.One2many( comodel_name="contract.line.forecast.period", @@ -105,7 +105,7 @@ class AccountAnalyticInvoiceLine(models.Model): @api.model def create(self, values): - contract_lines = super(AccountAnalyticInvoiceLine, self).create(values) + contract_lines = super(ContractLine, self).create(values) for contract_line in contract_lines: contract_line.with_delay()._generate_forecast_periods() return contract_lines @@ -132,7 +132,7 @@ class AccountAnalyticInvoiceLine(models.Model): @api.multi def write(self, values): - res = super(AccountAnalyticInvoiceLine, self).write(values) + res = super(ContractLine, self).write(values) if any( [ field in values diff --git a/contract_forecast/models/contract_line_forecast_period.py b/contract_forecast/models/contract_line_forecast_period.py index 921cd6af..158b85b6 100644 --- a/contract_forecast/models/contract_line_forecast_period.py +++ b/contract_forecast/models/contract_line_forecast_period.py @@ -16,7 +16,7 @@ class ContractLineForecastPeriod(models.Model): string="Sequence", related="contract_line_id.sequence", store=True ) contract_id = fields.Many2one( - comodel_name="account.analytic.account", + comodel_name="contract.contract", string="Contract", required=True, readonly=True, @@ -26,7 +26,7 @@ class ContractLineForecastPeriod(models.Model): index=True, ) contract_line_id = fields.Many2one( - comodel_name="account.analytic.invoice.line", + comodel_name="contract.line", string="Contract Line", required=True, readonly=True, diff --git a/contract_forecast/tests/test_contract_line_forecast_period.py b/contract_forecast/tests/test_contract_line_forecast_period.py index ca4716d0..702c169b 100644 --- a/contract_forecast/tests/test_contract_line_forecast_period.py +++ b/contract_forecast/tests/test_contract_line_forecast_period.py @@ -1,10 +1,10 @@ # 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.addons.contract.tests.test_contract import TestContractBase -from odoo.fields import Date from odoo.tools import mute_logger @@ -15,21 +15,21 @@ class TestContractLineForecastPeriod(TestContractBase): context=dict(self.env.context, test_queue_job_no_delay=True) ) super(TestContractLineForecastPeriod, self).setUp() - self.line_vals["date_start"] = Date.context_today(self.acct_line) - self.line_vals["recurring_next_date"] = Date.context_today( - self.acct_line - ) - self.acct_line = self.env["account.analytic.invoice.line"].create( - self.line_vals - ) + 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") def test_forecast_period_creation(self): self.acct_line.write( { - 'date_start': "2019-01-01", - 'recurring_next_date': "2019-01-01", - 'date_end': "2019-12-31", + 'date_start': "{this_year}-01-01".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-01-01".format( + this_year=self.this_year), + 'date_end': "{this_year}-12-31".format( + this_year=self.this_year), 'recurring_rule_type': "monthly", 'recurring_invoicing_type': 'pre-paid', } @@ -41,9 +41,12 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_1(self): self.acct_line.write( { - 'date_start': "2019-01-01", - 'recurring_next_date': "2019-01-01", - 'date_end': "2019-12-31", + 'date_start': "{this_year}-01-01".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-01-01".format( + this_year=self.this_year), + 'date_end': "{this_year}-12-31".format( + this_year=self.this_year), 'recurring_rule_type': "yearly", 'recurring_invoicing_type': 'pre-paid', } @@ -55,9 +58,12 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_2(self): self.acct_line.write( { - 'date_start': "2019-01-01", - 'recurring_next_date': "2019-01-31", - 'date_end': "2019-6-05", + 'date_start': "{this_year}-01-01".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-01-31".format( + this_year=self.this_year), + 'date_end': "{this_year}-06-05".format( + this_year=self.this_year), 'recurring_rule_type': "monthlylastday", 'recurring_invoicing_type': 'pre-paid', } @@ -92,9 +98,12 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_6(self): self.acct_line.write( { - 'date_start': "2019-01-01", - 'recurring_next_date': "2019-01-01", - 'date_end': "2019-01-28", + 'date_start': "{this_year}-01-01".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-01-01".format( + this_year=self.this_year), + 'date_end': "{this_year}-01-28".format( + this_year=self.this_year), 'recurring_rule_type': "monthly", 'recurring_invoicing_type': 'pre-paid', } @@ -106,9 +115,12 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_6(self): self.acct_line.write( { - 'date_start': "2019-01-01", - 'recurring_next_date': "2019-02-01", - 'date_end': "2019-01-28", + 'date_start': "{this_year}-01-01".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-02-01".format( + this_year=self.this_year), + 'date_end': "{this_year}-01-28".format( + this_year=self.this_year), 'recurring_rule_type': "monthly", 'recurring_invoicing_type': 'post-paid', } @@ -120,7 +132,7 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_7(self): self.acct_line.write( { - 'date_end': "2019-6-05", + 'date_end': date.today() + relativedelta(months=3), 'recurring_rule_type': "monthlylastday", 'recurring_invoicing_type': 'pre-paid', 'is_auto_renew': True, @@ -134,9 +146,12 @@ class TestContractLineForecastPeriod(TestContractBase): def test_forecast_period_on_contract_line_update_8(self): self.acct_line.write( { - 'date_start': "2019-01-14", - 'recurring_next_date': "2019-01-31", - 'date_end': "2019-01-14", + 'date_start': "{this_year}-01-14".format( + this_year=self.this_year), + 'recurring_next_date': "{this_year}-01-31".format( + this_year=self.this_year), + 'date_end': "{this_year}-01-14".format( + this_year=self.this_year), 'recurring_rule_type': "monthlylastday", 'recurring_invoicing_type': 'post-paid', } diff --git a/contract_forecast/views/contract.xml b/contract_forecast/views/contract.xml index aed2940a..387288ad 100644 --- a/contract_forecast/views/contract.xml +++ b/contract_forecast/views/contract.xml @@ -4,13 +4,11 @@ - - account.analytic.account.form (in - contract_forcast) - - account.analytic.account + + contract.contract.form (in contract_forcast) + contract.contract + ref="contract.contract_contract_form_view"/>