mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[12.0][IMP] - add new option: create_new_line_at_contract_line_renew
Add a company config option to decide whether to create or to extend contract line at renew action
This commit is contained in:
committed by
Francisco Ivan Anton Prieto
parent
f2de4aafe9
commit
becaad164f
@@ -34,6 +34,7 @@
|
|||||||
'views/contract_template.xml',
|
'views/contract_template.xml',
|
||||||
'views/contract_template_line.xml',
|
'views/contract_template_line.xml',
|
||||||
'views/res_partner_view.xml',
|
'views/res_partner_view.xml',
|
||||||
|
'views/res_config_settings.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
7
contract/migrations/12.0.5.0.1/post-migration.py
Normal file
7
contract/migrations/12.0.5.0.1/post-migration.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
def migrate(cr, version):
|
||||||
|
cr.execute(
|
||||||
|
"""\
|
||||||
|
UPDATE res_company
|
||||||
|
SET create_new_line_at_contract_line_renew = true
|
||||||
|
"""
|
||||||
|
)
|
||||||
@@ -9,3 +9,6 @@ from . import contract_line
|
|||||||
from . import account_invoice
|
from . import account_invoice
|
||||||
from . import account_invoice_line
|
from . import account_invoice_line
|
||||||
from . import res_partner
|
from . import res_partner
|
||||||
|
from . import contract_tag
|
||||||
|
from . import res_company
|
||||||
|
from . import res_config_settings
|
||||||
|
|||||||
@@ -1177,17 +1177,27 @@ class ContractLine(models.Model):
|
|||||||
)
|
)
|
||||||
return date_start, date_end
|
return date_start, date_end
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _renew_create_line(self, date_start, date_end):
|
||||||
|
self.ensure_one()
|
||||||
|
is_auto_renew = self.is_auto_renew
|
||||||
|
self.stop(self.date_end, post_message=False)
|
||||||
|
new_line = self.plan_successor(
|
||||||
|
date_start, date_end, is_auto_renew, post_message=False
|
||||||
|
)
|
||||||
|
new_line._onchange_date_start()
|
||||||
|
return new_line
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def renew(self):
|
def renew(self):
|
||||||
res = self.env['contract.line']
|
res = self.env['contract.line']
|
||||||
for rec in self:
|
for rec in self:
|
||||||
is_auto_renew = rec.is_auto_renew
|
company = rec.contract_id.company_id
|
||||||
rec.stop(rec.date_end, post_message=False)
|
|
||||||
date_start, date_end = rec._get_renewal_dates()
|
date_start, date_end = rec._get_renewal_dates()
|
||||||
new_line = rec.plan_successor(
|
if company.create_new_line_at_contract_line_renew:
|
||||||
date_start, date_end, is_auto_renew, post_message=False
|
new_line = rec._renew_create_line(date_start, date_end)
|
||||||
)
|
else:
|
||||||
new_line._onchange_date_start()
|
raise NotImplementedError
|
||||||
res |= new_line
|
res |= new_line
|
||||||
msg = _(
|
msg = _(
|
||||||
"""Contract line for <strong>{product}</strong>
|
"""Contract line for <strong>{product}</strong>
|
||||||
|
|||||||
17
contract/models/res_company.py
Normal file
17
contract/models/res_company.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# Copyright 2019 ACSONE SA/NV
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResCompany(models.Model):
|
||||||
|
|
||||||
|
_inherit = 'res.company'
|
||||||
|
|
||||||
|
create_new_line_at_contract_line_renew = fields.Boolean(
|
||||||
|
string="Create New Line At Contract Line Renew",
|
||||||
|
help="If checked, a new line will be generated at contract line renew "
|
||||||
|
"and linked to the original one as successor. The default "
|
||||||
|
"behavior is to extend the end date of the contract by a new "
|
||||||
|
"subscription period",
|
||||||
|
)
|
||||||
19
contract/models/res_config_settings.py
Normal file
19
contract/models/res_config_settings.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Copyright 2019 ACSONE SA/NV
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResConfigSettings(models.TransientModel):
|
||||||
|
|
||||||
|
_inherit = 'res.config.settings'
|
||||||
|
|
||||||
|
create_new_line_at_contract_line_renew = fields.Boolean(
|
||||||
|
related="company_id.create_new_line_at_contract_line_renew",
|
||||||
|
readonly=False,
|
||||||
|
string="Create New Line At Contract Line Renew",
|
||||||
|
help="If checked, a new line will be generated at contract line renew "
|
||||||
|
"and linked to the original one as successor. The default "
|
||||||
|
"behavior is to extend the end date of the contract by a new "
|
||||||
|
"subscription period",
|
||||||
|
)
|
||||||
@@ -109,6 +109,7 @@ class TestContractBase(common.SavepointCase):
|
|||||||
cls.line_vals
|
cls.line_vals
|
||||||
)
|
)
|
||||||
cls.acct_line.product_id.is_auto_renew = True
|
cls.acct_line.product_id.is_auto_renew = True
|
||||||
|
cls.contract.company_id.create_new_line_at_contract_line_renew = True
|
||||||
|
|
||||||
|
|
||||||
class TestContract(TestContractBase):
|
class TestContract(TestContractBase):
|
||||||
|
|||||||
28
contract/views/res_config_settings.xml
Normal file
28
contract/views/res_config_settings.xml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright 2019 ACSONE SA/NV
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="res_config_settings_form_view">
|
||||||
|
<field name="model">res.config.settings</field>
|
||||||
|
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//div[@data-key='account']" position="inside">
|
||||||
|
<h2>Contract</h2>
|
||||||
|
<div class="row mt16 o_settings_container">
|
||||||
|
<div class="col-12 col-lg-6 o_setting_box">
|
||||||
|
<div class="o_setting_left_pane">
|
||||||
|
<field name="create_new_line_at_contract_line_renew"/>
|
||||||
|
</div>
|
||||||
|
<div class="o_setting_right_pane">
|
||||||
|
<label for="create_new_line_at_contract_line_renew"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user