Browse Source

[REF] Contract Forecast: split from analytic account

pull/283/head
Thomas Binsfeld 5 years ago
committed by sbejaoui
parent
commit
0e4daa70d1
  1. 2
      contract_forecast/hooks.py
  2. 2
      contract_forecast/migrations/12.0.1.0.1/post-migration.py
  3. 6
      contract_forecast/models/contract.py
  4. 8
      contract_forecast/models/contract_line.py
  5. 4
      contract_forecast/models/contract_line_forecast_period.py
  6. 69
      contract_forecast/tests/test_contract_line_forecast_period.py
  7. 10
      contract_forecast/views/contract.xml

2
contract_forecast/hooks.py

@ -21,7 +21,7 @@ def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {}) env = api.Environment(cr, SUPERUSER_ID, {})
offset = 0 offset = 0
while True: while True:
contract_lines = env["account.analytic.invoice.line"].search(
contract_lines = env["contract.line"].search(
[('is_canceled', '=', False)], limit=100, offset=offset [('is_canceled', '=', False)], limit=100, offset=offset
) )
contract_lines.with_delay()._generate_forecast_periods() contract_lines.with_delay()._generate_forecast_periods()

2
contract_forecast/migrations/12.0.1.0.1/post-migration.py

@ -12,7 +12,7 @@ def migrate(cr, version):
cr.execute(""" cr.execute("""
UPDATE contract_line_forecast_period AS forecast UPDATE contract_line_forecast_period AS forecast
SET company_id=contract.company_id SET company_id=contract.company_id
FROM account_analytic_account AS contract
FROM contract_contract AS contract
WHERE forecast.contract_id=contract.id WHERE forecast.contract_id=contract.id
AND forecast.contract_id IS NOT NULL AND forecast.contract_id IS NOT NULL
""") """)

6
contract_forecast/models/contract.py

@ -4,9 +4,9 @@
from odoo import _, api, models from odoo import _, api, models
class AccountAnalyticAccount(models.Model):
class ContractContract(models.Model):
_inherit = "account.analytic.account"
_inherit = "contract.contract"
@api.multi @api.multi
def action_show_contract_forecast(self): def action_show_contract_forecast(self):
@ -29,7 +29,7 @@ class AccountAnalyticAccount(models.Model):
@api.multi @api.multi
def write(self, values): def write(self, values):
res = super(AccountAnalyticAccount, self).write(values)
res = super(ContractContract, self).write(values)
if any( if any(
[ [
field in values field in values

8
contract_forecast/models/contract_line.py

@ -8,9 +8,9 @@ from odoo.addons.queue_job.job import job
QUEUE_CHANNEL = "root.CONTRACT_FORECAST" 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( forecast_period_ids = fields.One2many(
comodel_name="contract.line.forecast.period", comodel_name="contract.line.forecast.period",
@ -105,7 +105,7 @@ class AccountAnalyticInvoiceLine(models.Model):
@api.model @api.model
def create(self, values): def create(self, values):
contract_lines = super(AccountAnalyticInvoiceLine, self).create(values)
contract_lines = super(ContractLine, self).create(values)
for contract_line in contract_lines: for contract_line in contract_lines:
contract_line.with_delay()._generate_forecast_periods() contract_line.with_delay()._generate_forecast_periods()
return contract_lines return contract_lines
@ -132,7 +132,7 @@ class AccountAnalyticInvoiceLine(models.Model):
@api.multi @api.multi
def write(self, values): def write(self, values):
res = super(AccountAnalyticInvoiceLine, self).write(values)
res = super(ContractLine, self).write(values)
if any( if any(
[ [
field in values field in values

4
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 string="Sequence", related="contract_line_id.sequence", store=True
) )
contract_id = fields.Many2one( contract_id = fields.Many2one(
comodel_name="account.analytic.account",
comodel_name="contract.contract",
string="Contract", string="Contract",
required=True, required=True,
readonly=True, readonly=True,
@ -26,7 +26,7 @@ class ContractLineForecastPeriod(models.Model):
index=True, index=True,
) )
contract_line_id = fields.Many2one( contract_line_id = fields.Many2one(
comodel_name="account.analytic.invoice.line",
comodel_name="contract.line",
string="Contract Line", string="Contract Line",
required=True, required=True,
readonly=True, readonly=True,

69
contract_forecast/tests/test_contract_line_forecast_period.py

@ -1,10 +1,10 @@
# Copyright 2019 ACSONE SA/NV # Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from datetime import date
from dateutil.relativedelta import relativedelta from dateutil.relativedelta import relativedelta
from odoo.addons.contract.tests.test_contract import TestContractBase from odoo.addons.contract.tests.test_contract import TestContractBase
from odoo.fields import Date
from odoo.tools import mute_logger from odoo.tools import mute_logger
@ -15,21 +15,21 @@ class TestContractLineForecastPeriod(TestContractBase):
context=dict(self.env.context, test_queue_job_no_delay=True) context=dict(self.env.context, test_queue_job_no_delay=True)
) )
super(TestContractLineForecastPeriod, self).setUp() 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") @mute_logger("odoo.addons.queue_job.models.base")
def test_forecast_period_creation(self): def test_forecast_period_creation(self):
self.acct_line.write( 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_rule_type': "monthly",
'recurring_invoicing_type': 'pre-paid', 'recurring_invoicing_type': 'pre-paid',
} }
@ -41,9 +41,12 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_1(self): def test_forecast_period_on_contract_line_update_1(self):
self.acct_line.write( 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_rule_type': "yearly",
'recurring_invoicing_type': 'pre-paid', 'recurring_invoicing_type': 'pre-paid',
} }
@ -55,9 +58,12 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_2(self): def test_forecast_period_on_contract_line_update_2(self):
self.acct_line.write( 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_rule_type': "monthlylastday",
'recurring_invoicing_type': 'pre-paid', 'recurring_invoicing_type': 'pre-paid',
} }
@ -92,9 +98,12 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_6(self): def test_forecast_period_on_contract_line_update_6(self):
self.acct_line.write( 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_rule_type': "monthly",
'recurring_invoicing_type': 'pre-paid', 'recurring_invoicing_type': 'pre-paid',
} }
@ -106,9 +115,12 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_6(self): def test_forecast_period_on_contract_line_update_6(self):
self.acct_line.write( 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_rule_type': "monthly",
'recurring_invoicing_type': 'post-paid', 'recurring_invoicing_type': 'post-paid',
} }
@ -120,7 +132,7 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_7(self): def test_forecast_period_on_contract_line_update_7(self):
self.acct_line.write( self.acct_line.write(
{ {
'date_end': "2019-6-05",
'date_end': date.today() + relativedelta(months=3),
'recurring_rule_type': "monthlylastday", 'recurring_rule_type': "monthlylastday",
'recurring_invoicing_type': 'pre-paid', 'recurring_invoicing_type': 'pre-paid',
'is_auto_renew': True, 'is_auto_renew': True,
@ -134,9 +146,12 @@ class TestContractLineForecastPeriod(TestContractBase):
def test_forecast_period_on_contract_line_update_8(self): def test_forecast_period_on_contract_line_update_8(self):
self.acct_line.write( 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_rule_type': "monthlylastday",
'recurring_invoicing_type': 'post-paid', 'recurring_invoicing_type': 'post-paid',
} }

10
contract_forecast/views/contract.xml

@ -4,13 +4,11 @@
<odoo> <odoo>
<record model="ir.ui.view" id="account_analytic_account_form_view">
<field name="name">account.analytic.account.form (in
contract_forcast)
</field>
<field name="model">account.analytic.account</field>
<record model="ir.ui.view" id="contract_contract_form_view">
<field name="name">contract.contract.form (in contract_forcast)</field>
<field name="model">contract.contract</field>
<field name="inherit_id" <field name="inherit_id"
ref="contract.account_analytic_account_recurring_form_form"/>
ref="contract.contract_contract_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside"> <xpath expr="//div[@name='button_box']" position="inside">
<button class="oe_stat_button" type="object" <button class="oe_stat_button" type="object"

Loading…
Cancel
Save