From dce84057202497798b1111dfe2ab5162fc2ae6c8 Mon Sep 17 00:00:00 2001 From: cubells Date: Fri, 1 Mar 2019 09:23:23 +0100 Subject: [PATCH] [ADD] contract_price_revision: new module to update contract prices easily --- contract_price_revision/README.rst | 93 ++++ contract_price_revision/__init__.py | 2 + contract_price_revision/__manifest__.py | 21 + .../i18n/contract_price_revision.pot | 152 ++++++ contract_price_revision/i18n/es.po | 157 +++++++ contract_price_revision/models/__init__.py | 2 + .../models/account_analytic_account.py | 17 + .../models/account_analytic_invoice_line.py | 39 ++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + contract_price_revision/readme/USAGE.rst | 14 + .../static/description/index.html | 441 ++++++++++++++++++ contract_price_revision/tests/__init__.py | 1 + .../tests/test_contract_price_revision.py | 71 +++ .../views/account_analytic_account_views.xml | 43 ++ contract_price_revision/wizards/__init__.py | 1 + .../wizards/create_revision_line.py | 50 ++ .../wizards/create_revision_line_views.xml | 41 ++ 18 files changed, 1149 insertions(+) create mode 100644 contract_price_revision/README.rst create mode 100644 contract_price_revision/__init__.py create mode 100644 contract_price_revision/__manifest__.py create mode 100644 contract_price_revision/i18n/contract_price_revision.pot create mode 100644 contract_price_revision/i18n/es.po create mode 100644 contract_price_revision/models/__init__.py create mode 100644 contract_price_revision/models/account_analytic_account.py create mode 100644 contract_price_revision/models/account_analytic_invoice_line.py create mode 100644 contract_price_revision/readme/CONTRIBUTORS.rst create mode 100644 contract_price_revision/readme/DESCRIPTION.rst create mode 100644 contract_price_revision/readme/USAGE.rst create mode 100644 contract_price_revision/static/description/index.html create mode 100644 contract_price_revision/tests/__init__.py create mode 100644 contract_price_revision/tests/test_contract_price_revision.py create mode 100644 contract_price_revision/views/account_analytic_account_views.xml create mode 100644 contract_price_revision/wizards/__init__.py create mode 100644 contract_price_revision/wizards/create_revision_line.py create mode 100644 contract_price_revision/wizards/create_revision_line_views.xml diff --git a/contract_price_revision/README.rst b/contract_price_revision/README.rst new file mode 100644 index 00000000..8398a98d --- /dev/null +++ b/contract_price_revision/README.rst @@ -0,0 +1,93 @@ +======================= +Contract Price Revision +======================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github + :target: https://github.com/OCA/contract/tree/11.0/contract_price_revision + :alt: OCA/contract +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-11-0/contract-11-0-contract_price_revision + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/110/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to create revisions of contract line prices. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module: + +#. Go to **Invoicing > Documents > Customer Contracts** if you are a billing + user. +#. Select as many contracts as you want to update line prices. +#. Click on Action button and execute the wizard **Create revision of contract + lines**. +#. Enter date start from which the new price will be valid and enter date + end and percentage to increase old contract lines. +#. By clicking on Apply button, a new contract line will be created with + a price increased accordingly to the percent entered. Old contract lines + will have as ending date the day before the entered date. +#. When create invoices related to contracts selected, prices will be update + with the prices that are not out of date. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * Vicent Cubells + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/contract `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/contract_price_revision/__init__.py b/contract_price_revision/__init__.py new file mode 100644 index 00000000..aee8895e --- /dev/null +++ b/contract_price_revision/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/contract_price_revision/__manifest__.py b/contract_price_revision/__manifest__.py new file mode 100644 index 00000000..561c09bd --- /dev/null +++ b/contract_price_revision/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Contract Price Revision', + 'summary': 'Easy revision of contract prices', + 'version': '11.0.1.0.0', + 'category': 'Contract', + 'author': 'Tecnativa, ' + 'Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'website': 'https://github.com/OCA/contract', + 'depends': [ + 'contract', + ], + 'data': [ + 'wizards/create_revision_line_views.xml', + 'views/account_analytic_account_views.xml', + ], + 'installable': True, +} diff --git a/contract_price_revision/i18n/contract_price_revision.pot b/contract_price_revision/i18n/contract_price_revision.pot new file mode 100644 index 00000000..cbca8b4d --- /dev/null +++ b/contract_price_revision/i18n/contract_price_revision.pot @@ -0,0 +1,152 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_price_revision +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-01 07:58+0000\n" +"PO-Revision-Date: 2019-03-01 07:58+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_account_analytic_account +msgid "Analytic Account" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Apply" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Cancel" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_create_uid +msgid "Created by" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_create_date +msgid "Created on" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_date_end +msgid "Date End" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_date_start +msgid "Date Start" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_display_name +msgid "Display Name" +msgstr "" + +#. module: contract_price_revision +#: model:ir.actions.act_window,name:contract_price_revision.contract_line_duplicate_wizard_action +msgid "Create revision of contract lines" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_date_end +msgid "End Date" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_id +msgid "ID" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard___last_update +msgid "Last Modified on" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_write_uid +msgid "Last Updated by" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_write_date +msgid "Last Updated on" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "Line Information" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_previous_revision_id +msgid "Previous revision" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,help:contract_price_revision.field_account_analytic_invoice_line_previous_revision_id +msgid "Relation with previous info" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Set new start date and variation percent to duplicate.\n" +" This process set start date previous day as end date of\n" +" origin record.\n" +"
\n" +"
" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_date_start +msgid "Start Date" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_previous_price +msgid "Unit Price" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "Validity" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_variation_percent +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_variation_percent +msgid "Variation %" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_account_analytic_invoice_line +msgid "account.analytic.invoice.line" +msgstr "" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_create_revision_line_wizard +msgid "create.revision.line.wizard" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "or" +msgstr "" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "to" +msgstr "" + diff --git a/contract_price_revision/i18n/es.po b/contract_price_revision/i18n/es.po new file mode 100644 index 00000000..3339fea5 --- /dev/null +++ b/contract_price_revision/i18n/es.po @@ -0,0 +1,157 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * contract_price_revision +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-03-01 07:58+0000\n" +"PO-Revision-Date: 2019-03-01 07:58+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_account_analytic_account +msgid "Analytic Account" +msgstr "Cuenta analítica" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Apply" +msgstr "Aplicar" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Cancel" +msgstr "Cancelar" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_create_date +msgid "Created on" +msgstr "Creado el" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_date_end +msgid "Date End" +msgstr "Fecha fin" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_date_start +msgid "Date Start" +msgstr "Fecha inicio" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: contract_price_revision +#: model:ir.actions.act_window,name:contract_price_revision.contract_line_duplicate_wizard_action +msgid "Create revision of contract lines" +msgstr "Crear revisión de las líneas de contrato" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_date_end +msgid "End Date" +msgstr "Fecha fin" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_id +msgid "ID" +msgstr "Id" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard___last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_write_uid +msgid "Last Updated by" +msgstr "Última modificación de" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_write_date +msgid "Last Updated on" +msgstr "Última actualización en" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "Line Information" +msgstr "Información de la línea" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_previous_revision_id +msgid "Previous revision" +msgstr "Revisión previa" + +#. module: contract_price_revision +#: model:ir.model.fields,help:contract_price_revision.field_account_analytic_invoice_line_previous_revision_id +msgid "Relation with previous info" +msgstr "Relación con la información previa" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Set new start date and variation percent to duplicate.\n" +" This process set start date previous day as end date of\n" +" origin record.\n" +"
\n" +"
" +msgstr "" +"Establezca nueva fecha y porcentaje de variación para duplicar.\n" +" Este proceso establece la fecha de inicio anterior " +"como fecha de finalización de registro de origen.\n" +"
\n" +"
" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_date_start +msgid "Start Date" +msgstr "Fecha de inicio" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_previous_price +msgid "Unit Price" +msgstr "Precio unidad" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "Validity" +msgstr "Validez" + +#. module: contract_price_revision +#: model:ir.model.fields,field_description:contract_price_revision.field_account_analytic_invoice_line_variation_percent +#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_variation_percent +msgid "Variation %" +msgstr "Varicación %" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_account_analytic_invoice_line +msgid "account.analytic.invoice.line" +msgstr "account.analytic.invoice.line" + +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_create_revision_line_wizard +msgid "create.revision.line.wizard" +msgstr "create.revision.line.wizard" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "or" +msgstr "o" + +#. module: contract_price_revision +#: model:ir.ui.view,arch_db:contract_price_revision.account_analytic_invoice_line_form_view +msgid "to" +msgstr "hasta" + diff --git a/contract_price_revision/models/__init__.py b/contract_price_revision/models/__init__.py new file mode 100644 index 00000000..6542a7bc --- /dev/null +++ b/contract_price_revision/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_analytic_account +from . import account_analytic_invoice_line diff --git a/contract_price_revision/models/account_analytic_account.py b/contract_price_revision/models/account_analytic_account.py new file mode 100644 index 00000000..515d80f8 --- /dev/null +++ b/contract_price_revision/models/account_analytic_account.py @@ -0,0 +1,17 @@ +# Copyright 2019 Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, models + + +class AccountAnalyticAccount(models.Model): + _inherit = "account.analytic.account" + + @api.model + def _prepare_invoice_line(self, line, invoice_id): + line_obj = self.env['account.invoice.line'] + invoice = self.env['account.invoice'].browse(invoice_id) + # Line with automatic price are not taken into account + if (line.date_start and invoice.date_invoice < line.date_start) or \ + (line.date_end and invoice.date_invoice > line.date_end): + return line_obj + return super()._prepare_invoice_line(line, invoice_id) diff --git a/contract_price_revision/models/account_analytic_invoice_line.py b/contract_price_revision/models/account_analytic_invoice_line.py new file mode 100644 index 00000000..73ba2548 --- /dev/null +++ b/contract_price_revision/models/account_analytic_invoice_line.py @@ -0,0 +1,39 @@ +# Copyright 2019 Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +import odoo.addons.decimal_precision as dp + + +class AccountAnalyticINvoiceLine(models.Model): + _inherit = "account.analytic.invoice.line" + + date_start = fields.Date( + string='Start Date', + ) + date_end = fields.Date( + string='End Date', + ) + previous_revision_id = fields.Many2one( + comodel_name='account.analytic.invoice.line', + string='Previous revision', + help='Relation with previous revision', + ) + previous_price = fields.Float( + related='previous_revision_id.price_unit', + readonly=True, + ) + variation_percent = fields.Float( + compute='_compute_variation_percent', + store=True, + digits=dp.get_precision('Product Price'), + string='Variation %', + ) + + @api.multi + @api.depends('price_unit', 'previous_revision_id.price_unit') + def _compute_variation_percent(self): + for line in self: + if not (line.price_unit and line.previous_price): + continue + line.variation_percent = ( + (line.price_unit / line.previous_price - 1) * 100) diff --git a/contract_price_revision/readme/CONTRIBUTORS.rst b/contract_price_revision/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..8cd500d6 --- /dev/null +++ b/contract_price_revision/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * Vicent Cubells diff --git a/contract_price_revision/readme/DESCRIPTION.rst b/contract_price_revision/readme/DESCRIPTION.rst new file mode 100644 index 00000000..812aadab --- /dev/null +++ b/contract_price_revision/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows to create revisions of contract line prices. diff --git a/contract_price_revision/readme/USAGE.rst b/contract_price_revision/readme/USAGE.rst new file mode 100644 index 00000000..c0232d24 --- /dev/null +++ b/contract_price_revision/readme/USAGE.rst @@ -0,0 +1,14 @@ +To use this module: + +#. Go to **Invoicing > Documents > Customer Contracts** if you are a billing + user. +#. Select as many contracts as you want to update line prices. +#. Click on Action button and execute the wizard **Create revision of contract + lines**. +#. Enter date start from which the new price will be valid and enter date + end and percentage to increase old contract lines. +#. By clicking on Apply button, a new contract line will be created with + a price increased accordingly to the percent entered. Old contract lines + will have as ending date the day before the entered date. +#. When create invoices related to contracts selected, prices will be update + with the prices that are not out of date. diff --git a/contract_price_revision/static/description/index.html b/contract_price_revision/static/description/index.html new file mode 100644 index 00000000..191f393b --- /dev/null +++ b/contract_price_revision/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Contract Price Revision + + + +
+

Contract Price Revision

+ + +

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

+

This module allows to create revisions of contract line prices.

+

Table of contents

+ +
+

Usage

+

To use this module:

+
    +
  1. Go to Invoicing > Documents > Customer Contracts if you are a billing +user.
  2. +
  3. Select as many contracts as you want to update line prices.
  4. +
  5. Click on Action button and execute the wizard Create revision of contract +lines.
  6. +
  7. Enter date start from which the new price will be valid and enter date +end and percentage to increase old contract lines.
  8. +
  9. By clicking on Apply button, a new contract line will be created with +a price increased accordingly to the percent entered. Old contract lines +will have as ending date the day before the entered date.
  10. +
  11. When create invoices related to contracts selected, prices will be update +with the prices that are not out of date.
  12. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/contract project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/contract_price_revision/tests/__init__.py b/contract_price_revision/tests/__init__.py new file mode 100644 index 00000000..2cc4cb0c --- /dev/null +++ b/contract_price_revision/tests/__init__.py @@ -0,0 +1 @@ +from . import test_contract_price_revision diff --git a/contract_price_revision/tests/test_contract_price_revision.py b/contract_price_revision/tests/test_contract_price_revision.py new file mode 100644 index 00000000..154be5ba --- /dev/null +++ b/contract_price_revision/tests/test_contract_price_revision.py @@ -0,0 +1,71 @@ +# Copyright 2019 Tecnativa - Vicent Cubells +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from dateutil.relativedelta import relativedelta + +from odoo.tests import common +from odoo import fields + + +class TestContractPriceRevision(common.SavepointCase): + @classmethod + def setUpClass(cls): + super(TestContractPriceRevision, cls).setUpClass() + partner = cls.env['res.partner'].create({ + 'name': 'Partner test', + }) + product = cls.env['product.product'].create({ + 'name': 'Test Product', + }) + cls.contract = cls.env['account.analytic.account'].create({ + 'name': 'Contract test', + 'partner_id': partner.id, + 'date_start': fields.Date.today(), + 'recurring_next_date': fields.Date.to_string( + fields.date.today() + relativedelta(days=7)), + 'recurring_rule_type': 'monthly', + 'recurring_invoice_line_ids': [(0, 0, { + 'product_id': product.id, + 'quantity': 1.0, + 'uom_id': product.uom_id.id, + 'name': product.name, + 'price_unit': 33.0, + 'automatic_price': True, + }), (0, 0, { + 'product_id': product.id, + 'quantity': 1.0, + 'uom_id': product.uom_id.id, + 'name': product.name, + 'price_unit': 25.0, + 'automatic_price': False, + })] + }) + + def execute_wizard(self): + wizard = self.env['create.revision.line.wizard'].create({ + 'date_start': fields.Date.today(), + 'date_end': fields.Date.to_string( + fields.date.today() + relativedelta(years=1)), + 'variation_percent': 100.0, + }) + wizard.with_context( + {'active_ids': [self.contract.id]}).action_apply() + + def test_contract_price_revision_wizard(self): + self.assertEqual(len(self.contract.recurring_invoice_line_ids.ids), 2) + self.execute_wizard() + self.assertEqual(len(self.contract.recurring_invoice_line_ids.ids), 3) + lines = self.contract.mapped('recurring_invoice_line_ids').filtered( + lambda x: x.price_unit == 50.0) + self.assertEqual(len(lines), 1) + + def test_contract_price_revision_invoicing(self): + self.execute_wizard() + self.contract.recurring_create_invoice() + invoices = self.env['account.invoice'].search([ + ('contract_id', '=', self.contract.id)]) + self.assertEqual(len(invoices), 1) + lines = invoices.mapped('invoice_line_ids') + self.assertEqual(len(lines), 2) + lines = lines.filtered(lambda x: x.price_unit == 50.0) + self.assertEqual(len(lines), 1) diff --git a/contract_price_revision/views/account_analytic_account_views.xml b/contract_price_revision/views/account_analytic_account_views.xml new file mode 100644 index 00000000..e25fce65 --- /dev/null +++ b/contract_price_revision/views/account_analytic_account_views.xml @@ -0,0 +1,43 @@ + + + + + account.analytic.invoice.line.view + account.analytic.invoice.line + +
+ + + + + + + + + + + + + + +
+
+
+ + Contract form price revision + account.analytic.account + + + + + + + + + + +
diff --git a/contract_price_revision/wizards/__init__.py b/contract_price_revision/wizards/__init__.py new file mode 100644 index 00000000..f215b5a5 --- /dev/null +++ b/contract_price_revision/wizards/__init__.py @@ -0,0 +1 @@ +from . import create_revision_line diff --git a/contract_price_revision/wizards/create_revision_line.py b/contract_price_revision/wizards/create_revision_line.py new file mode 100644 index 00000000..8aca4b84 --- /dev/null +++ b/contract_price_revision/wizards/create_revision_line.py @@ -0,0 +1,50 @@ +# Copyright 2019 Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from dateutil.relativedelta import relativedelta + +from odoo import api, fields, models +import odoo.addons.decimal_precision as dp + + +class CreateRevisionLineWizard(models.TransientModel): + _name = 'create.revision.line.wizard' + + date_start = fields.Date( + required=True, + ) + date_end = fields.Date() + variation_percent = fields.Float( + digits=dp.get_precision('Product Price'), + required=True, + string='Variation %', + ) + + @api.multi + def action_apply(self): + contract_obj = self.env['account.analytic.account'] + line_obj = self.env['account.analytic.invoice.line'] + active_ids = self.env.context['active_ids'] + line_news = line_obj + for item in contract_obj.browse(active_ids).mapped( + 'recurring_invoice_line_ids').filtered( + lambda x: not x.automatic_price): + line_news |= item.copy({ + 'date_start': self.date_start, + 'date_end': self.date_end, + 'previous_revision_id': item.id, + 'price_unit': item.price_unit * ( + 1.0 + self.variation_percent / 100.0), + }) + item.date_end = (fields.Date.from_string(self.date_start) - + relativedelta(days=1)) + action = self.env.ref( + 'contract.action_account_analytic_sale_overdue_all').read()[0] + if len(active_ids) > 1: # pragma: no cover + action['domain'] = [('id', 'in', active_ids)] + elif active_ids: + action['views'] = [( + self.env.ref('contract.account_analytic_account_sale_form').id, + 'form')] + action['res_id'] = active_ids[0] + return action diff --git a/contract_price_revision/wizards/create_revision_line_views.xml b/contract_price_revision/wizards/create_revision_line_views.xml new file mode 100644 index 00000000..9c249ec5 --- /dev/null +++ b/contract_price_revision/wizards/create_revision_line_views.xml @@ -0,0 +1,41 @@ + + + + + Create Revision Line + create.revision.line.wizard + +
+
+ Set new start date and variation percent to duplicate. + This process set start date previous day as end date of + origin record. +
+
+
+ + + + + + + +
+
+
+
+
+ + + +