mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[13.0][MIG] contract_price_revision
This commit is contained in:
@@ -5,13 +5,13 @@
|
||||
{
|
||||
"name": "Contract Price Revision",
|
||||
"summary": "Easy revision of contract prices",
|
||||
"version": "12.0.1.0.1",
|
||||
"version": "13.0.1.0.0",
|
||||
"category": "Contract",
|
||||
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||
"author": "ACSONE SA/NV, Tecnativa, Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
"website": "https://github.com/OCA/contract",
|
||||
"depends": ["contract",],
|
||||
"data": ["views/contract_line.xml", "wizards/contract_price_revision_views.xml",],
|
||||
"depends": ["contract"],
|
||||
"data": ["views/contract_line.xml", "wizards/contract_price_revision_views.xml"],
|
||||
"installable": True,
|
||||
"development_status": "Production/Stable",
|
||||
"maintainers": ["carlosdauden"],
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
# Copyright 2020 Tecnativa - Carlos Dauden
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import logging
|
||||
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@openupgrade.migrate()
|
||||
def migrate(env, version):
|
||||
"""
|
||||
Update values from old previous_revision_id to predecessor_contract_line_id
|
||||
"""
|
||||
if not openupgrade.column_exists(env.cr, "contract_line", "previous_revision_id"):
|
||||
return
|
||||
|
||||
_logger.info("previous_revision_id to predecessor_contract_line_id")
|
||||
openupgrade.logged_query(
|
||||
env.cr,
|
||||
"""
|
||||
UPDATE contract_line
|
||||
SET predecessor_contract_line_id=previous_revision_id
|
||||
WHERE previous_revision_id IS NOT NULL AND (
|
||||
predecessor_contract_line_id IS NULL OR predecessor_contract_line_id=0)
|
||||
""",
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright 2019 Tecnativa - Vicent Cubells
|
||||
# Copyright 2019 Tecnativa - Carlos Dauden
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo.addons.contract.tests.test_contract import TestContractBase
|
||||
@@ -7,8 +8,10 @@ from odoo.addons.contract.tests.test_contract import TestContractBase
|
||||
|
||||
class TestContractPriceRevision(TestContractBase):
|
||||
def execute_wizard(self):
|
||||
# TODO: Limitation here, start date should be on the
|
||||
# beginning of next period (should not have a gap)
|
||||
wizard = self.env["contract.price.revision.wizard"].create(
|
||||
{"date_start": "2018-02-15", "variation_percent": 100.0,}
|
||||
{"date_start": "2018-02-01", "variation_percent": 100.0}
|
||||
)
|
||||
wizard.with_context({"active_ids": [self.contract.id]}).action_apply()
|
||||
|
||||
@@ -27,7 +30,7 @@ class TestContractPriceRevision(TestContractBase):
|
||||
self.acct_line.copy({"automatic_price": True})
|
||||
self.execute_wizard()
|
||||
invoice = self.contract.recurring_create_invoice()
|
||||
invoices = self.env["account.invoice"].search(
|
||||
invoices = self.env["account.move"].search(
|
||||
[
|
||||
(
|
||||
"invoice_line_ids.contract_line_id",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright 2019 Tecnativa - Vicent Cubells
|
||||
# Copyright 2019 Tecnativa - Carlos Dauden
|
||||
# Copyright 2020 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
@@ -21,29 +22,28 @@ class ContractPriceRevisionWizard(models.TransientModel):
|
||||
digits=dp.get_precision("Product Price"), required=True, string="Variation %",
|
||||
)
|
||||
|
||||
def _get_new_line_value(self, line):
|
||||
self.ensure_one()
|
||||
return {
|
||||
"date_start": self.date_start,
|
||||
"last_date_invoiced": False,
|
||||
"date_end": self.date_end,
|
||||
"predecessor_contract_line_id": line.id,
|
||||
"price_unit": line.price_unit * (1.0 + self.variation_percent / 100.0),
|
||||
}
|
||||
|
||||
def action_apply(self):
|
||||
ContractLine = self.env["contract.line"]
|
||||
active_ids = self.env.context.get("active_ids")
|
||||
contracts = self.env["contract.contract"].browse(active_ids)
|
||||
for line in self._get_contract_lines_to_revise(contracts):
|
||||
line.update(
|
||||
{"date_end": self.date_start - relativedelta(days=1),}
|
||||
)
|
||||
new_vals = line.copy_data(
|
||||
{
|
||||
"date_start": self.date_start,
|
||||
"date_end": self.date_end,
|
||||
"predecessor_contract_line_id": line.id,
|
||||
"price_unit": line.price_unit
|
||||
* (1.0 + self.variation_percent / 100.0),
|
||||
}
|
||||
)[0]
|
||||
tmp_line = ContractLine.new(new_vals)
|
||||
tmp_line._onchange_date_start()
|
||||
new_line = ContractLine.create(tmp_line._convert_to_write(tmp_line._cache))
|
||||
line.update(
|
||||
{"successor_contract_line_id": new_line.id,}
|
||||
)
|
||||
line.update({"date_end": self.date_start - relativedelta(days=1)})
|
||||
# As copy or copy_data are trigerring constraints, don't use them
|
||||
new_line = line.new(line._cache)
|
||||
new_line.update(self._get_new_line_value(line))
|
||||
new_line._onchange_date_start()
|
||||
new_line = ContractLine.create(new_line._convert_to_write(new_line._cache))
|
||||
line.update({"successor_contract_line_id": new_line.id})
|
||||
action = self.env["ir.actions.act_window"].for_xml_id(
|
||||
"contract", "action_customer_contract"
|
||||
)
|
||||
|
||||
@@ -31,14 +31,12 @@
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<act_window
|
||||
id="contract_line_duplicate_wizard_action"
|
||||
name="Create revision of contract lines"
|
||||
src_model="contract.contract"
|
||||
res_model="contract.price.revision.wizard"
|
||||
view_type="form"
|
||||
view_mode="form"
|
||||
key2="client_action_multi"
|
||||
target="new"
|
||||
/>
|
||||
<record id="contract_line_duplicate_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Create revision of contract lines</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">contract.price.revision.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="contract.model_contract_contract" />
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user