From 23bf138fdd405c4bf0bd601083cd7d62538566c7 Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Tue, 17 Dec 2019 12:27:41 +0100 Subject: [PATCH] [MIG] contract_price_revision: Migration to 12.0 --- contract_price_revision/README.rst | 34 +++--- contract_price_revision/__manifest__.py | 13 +- .../i18n/contract_price_revision.pot | 88 ++++---------- contract_price_revision/i18n/es.po | 111 ++++++------------ contract_price_revision/models/__init__.py | 3 +- .../models/account_analytic_account.py | 19 --- .../models/account_analytic_invoice_line.py | 39 ------ .../models/contract_line.py | 31 +++++ .../readme/CONTRIBUTORS.rst | 1 + contract_price_revision/readme/USAGE.rst | 2 +- .../static/description/index.html | 11 +- .../tests/test_contract_price_revision.py | 74 ++++-------- .../views/account_analytic_account_views.xml | 43 ------- .../views/contract_line.xml | 26 ++++ contract_price_revision/wizards/__init__.py | 2 +- .../wizards/contract_price_revision.py | 54 +++++++++ ....xml => contract_price_revision_views.xml} | 6 +- .../wizards/create_revision_line.py | 50 -------- 18 files changed, 234 insertions(+), 373 deletions(-) delete mode 100644 contract_price_revision/models/account_analytic_account.py delete mode 100644 contract_price_revision/models/account_analytic_invoice_line.py create mode 100644 contract_price_revision/models/contract_line.py delete mode 100644 contract_price_revision/views/account_analytic_account_views.xml create mode 100644 contract_price_revision/views/contract_line.xml create mode 100644 contract_price_revision/wizards/contract_price_revision.py rename contract_price_revision/wizards/{create_revision_line_views.xml => contract_price_revision_views.xml} (89%) delete mode 100644 contract_price_revision/wizards/create_revision_line.py diff --git a/contract_price_revision/README.rst b/contract_price_revision/README.rst index 8398a98d..477c0782 100644 --- a/contract_price_revision/README.rst +++ b/contract_price_revision/README.rst @@ -7,23 +7,20 @@ Contract Price Revision !! 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 +.. |badge1| 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 +.. |badge2| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github + :target: https://github.com/OCA/contract/tree/12.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 +.. |badge3| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-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 +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/110/12.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| This module allows to create revisions of contract line prices. @@ -37,7 +34,7 @@ Usage To use this module: -#. Go to **Invoicing > Documents > Customer Contracts** if you are a billing +#. Go to **Invoicing > Customers > 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 @@ -56,7 +53,7 @@ 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -74,6 +71,7 @@ Contributors * `Tecnativa `_: * Vicent Cubells + * Carlos Dauden Maintainers ~~~~~~~~~~~ @@ -88,6 +86,14 @@ 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. +.. |maintainer-carlosdauden| image:: https://github.com/carlosdauden.png?size=40px + :target: https://github.com/carlosdauden + :alt: carlosdauden + +Current `maintainer `__: + +|maintainer-carlosdauden| + +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/__manifest__.py b/contract_price_revision/__manifest__.py index 561c09bd..05b6d836 100644 --- a/contract_price_revision/__manifest__.py +++ b/contract_price_revision/__manifest__.py @@ -1,10 +1,11 @@ -# Copyright 2019 Tecnativa -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +# Copyright 2019 Tecnativa - Vicent Cubells +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { 'name': 'Contract Price Revision', 'summary': 'Easy revision of contract prices', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Contract', 'author': 'Tecnativa, ' 'Odoo Community Association (OCA)', @@ -14,8 +15,10 @@ 'contract', ], 'data': [ - 'wizards/create_revision_line_views.xml', - 'views/account_analytic_account_views.xml', + 'views/contract_line.xml', + 'wizards/contract_price_revision_views.xml', ], 'installable': True, + 'development_status': 'Stable', + 'maintainers': ['carlosdauden'], } diff --git a/contract_price_revision/i18n/contract_price_revision.pot b/contract_price_revision/i18n/contract_price_revision.pot index ffd35e26..eb66b53c 100644 --- a/contract_price_revision/i18n/contract_price_revision.pot +++ b/contract_price_revision/i18n/contract_price_revision.pot @@ -4,8 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-12-17 11:19+0000\n" +"PO-Revision-Date: 2019-12-17 11:19+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -14,18 +16,18 @@ msgstr "" "Plural-Forms: \n" #. module: contract_price_revision -#: model:ir.model,name:contract_price_revision.model_account_analytic_account -msgid "Analytic Account" +#: model_terms: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 "Apply" +#: model_terms:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +msgid "Cancel" msgstr "" #. module: contract_price_revision -#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view -msgid "Cancel" +#: model:ir.model,name:contract_price_revision.model_contract_line +msgid "Contract Line" msgstr "" #. module: contract_price_revision @@ -34,72 +36,57 @@ msgid "Create revision of contract lines" msgstr "" #. module: contract_price_revision -#: model:ir.model.fields,field_description:contract_price_revision.field_create_revision_line_wizard_create_uid +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_wizard__display_name msgid "Display Name" 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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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" +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_line__previous_price +msgid "Previous price" 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 revision" -msgstr "" - -#. module: contract_price_revision -#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +#: model_terms: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" @@ -108,38 +95,13 @@ msgid "Set new start date and variation percent to duplicate.\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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_line__variation_percent +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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.account_analytic_invoice_line_form_view -msgid "to" +#: model:ir.model,name:contract_price_revision.model_contract_price_revision_wizard +msgid "Wizard to update price based on percentage variation" msgstr "" diff --git a/contract_price_revision/i18n/es.po b/contract_price_revision/i18n/es.po index b2878599..f86c58f0 100644 --- a/contract_price_revision/i18n/es.po +++ b/contract_price_revision/i18n/es.po @@ -6,105 +6,89 @@ 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" +"POT-Creation-Date: 2019-12-17 12:20+0100\n" +"PO-Revision-Date: 2019-12-17 12:22+0100\n" +"Last-Translator: Carlos Dauden \n" "Language-Team: \n" -"Language: \n" +"Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: \n" +"X-Generator: Poedit 1.8.7.1\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 +#: model_terms: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 +#: model_terms:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view msgid "Cancel" msgstr "Cancelar" +#. module: contract_price_revision +#: model:ir.model,name:contract_price_revision.model_contract_line +msgid "Contract Line" +msgstr "Línea de contrato" + #. 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_create_revision_line_wizard_create_uid +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_wizard__display_name msgid "Display Name" msgstr "Nombre mostrado" #. 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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_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 -#, fuzzy -#| msgid "Relation with previous info" -msgid "Relation with previous revision" -msgstr "Relación con la información previa" +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_line__previous_price +msgid "Previous price" +msgstr "Precio anterior" #. module: contract_price_revision -#: model:ir.ui.view,arch_db:contract_price_revision.contract_line_duplicate_wizard_view +#: model_terms: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" @@ -113,46 +97,17 @@ msgid "" "
" 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" +" 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 +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_line__variation_percent +#: model:ir.model.fields,field_description:contract_price_revision.field_contract_price_revision_wizard__variation_percent msgid "Variation %" -msgstr "Varicación %" +msgstr "Variació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.account_analytic_invoice_line_form_view -msgid "to" -msgstr "hasta" - -#~ msgid "or" -#~ msgstr "o" +#: model:ir.model,name:contract_price_revision.model_contract_price_revision_wizard +msgid "Wizard to update price based on percentage variation" +msgstr "Asistente para actualizar el precio basado en un porcentaje de variación" diff --git a/contract_price_revision/models/__init__.py b/contract_price_revision/models/__init__.py index 6542a7bc..6143a365 100644 --- a/contract_price_revision/models/__init__.py +++ b/contract_price_revision/models/__init__.py @@ -1,2 +1 @@ -from . import account_analytic_account -from . import account_analytic_invoice_line +from . import contract_line diff --git a/contract_price_revision/models/account_analytic_account.py b/contract_price_revision/models/account_analytic_account.py deleted file mode 100644 index 9c5899cc..00000000 --- a/contract_price_revision/models/account_analytic_account.py +++ /dev/null @@ -1,19 +0,0 @@ -# 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, prefetch=self._prefetch, - ) - # 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 deleted file mode 100644 index 73ba2548..00000000 --- a/contract_price_revision/models/account_analytic_invoice_line.py +++ /dev/null @@ -1,39 +0,0 @@ -# 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/models/contract_line.py b/contract_price_revision/models/contract_line.py new file mode 100644 index 00000000..62c06627 --- /dev/null +++ b/contract_price_revision/models/contract_line.py @@ -0,0 +1,31 @@ +# Copyright 2019 Tecnativa - Vicent Cubells +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models +import odoo.addons.decimal_precision as dp + + +class ContractLine(models.Model): + _inherit = 'contract.line' + + previous_price = fields.Float( + string='Previous price', + related='predecessor_contract_line_id.price_unit', + readonly=True, + ) + variation_percent = fields.Float( + compute='_compute_variation_percent', + store=True, + digits=dp.get_precision('Product Price'), + string='Variation %', + ) + + @api.depends('price_unit', 'predecessor_contract_line_id.price_unit') + def _compute_variation_percent(self): + for line in self: + if line.price_unit and line.previous_price: + line.variation_percent = ( + (line.price_unit / line.previous_price - 1) * 100) + else: + line.variation_percent = 0.0 diff --git a/contract_price_revision/readme/CONTRIBUTORS.rst b/contract_price_revision/readme/CONTRIBUTORS.rst index 8cd500d6..1441c994 100644 --- a/contract_price_revision/readme/CONTRIBUTORS.rst +++ b/contract_price_revision/readme/CONTRIBUTORS.rst @@ -1,3 +1,4 @@ * `Tecnativa `_: * Vicent Cubells + * Carlos Dauden diff --git a/contract_price_revision/readme/USAGE.rst b/contract_price_revision/readme/USAGE.rst index c0232d24..b256f9a5 100644 --- a/contract_price_revision/readme/USAGE.rst +++ b/contract_price_revision/readme/USAGE.rst @@ -1,6 +1,6 @@ To use this module: -#. Go to **Invoicing > Documents > Customer Contracts** if you are a billing +#. Go to **Invoicing > Customers > 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 diff --git a/contract_price_revision/static/description/index.html b/contract_price_revision/static/description/index.html index 6b609992..4a29818d 100644 --- a/contract_price_revision/static/description/index.html +++ b/contract_price_revision/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

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

@@ -386,7 +386,7 @@ ul.auto-toc {

Usage

To use this module:

    -
  1. Go to Invoicing > Documents > Customer Contracts if you are a billing +
  2. Go to Invoicing > Customers > Customer Contracts if you are a billing user.
  3. Select as many contracts as you want to update line prices.
  4. Click on Action button and execute the wizard Create revision of contract @@ -405,7 +405,7 @@ with the prices that are not out of date.
  5. 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.

    +feedback.

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

@@ -421,6 +421,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome @@ -432,7 +433,9 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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.

+

Current maintainer:

+

carlosdauden

+

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/test_contract_price_revision.py b/contract_price_revision/tests/test_contract_price_revision.py index 154be5ba..81e9683f 100644 --- a/contract_price_revision/tests/test_contract_price_revision.py +++ b/contract_price_revision/tests/test_contract_price_revision.py @@ -1,71 +1,43 @@ -# Copyright 2019 Tecnativa - Vicent Cubells -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +# Copyright 2019 Tecnativa - Vicent Cubells +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from dateutil.relativedelta import relativedelta +from odoo.addons.contract.tests.test_contract import TestContractBase -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, - })] - }) +class TestContractPriceRevision(TestContractBase): 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)), + wizard = self.env['contract.price.revision.wizard'].create({ + 'date_start': '2018-02-15', '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.acct_line.copy({'automatic_price': True}) + self.assertEqual(len(self.contract.contract_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(self.contract.contract_line_ids.ids), 3) + lines = self.contract.contract_line_ids.filtered( + lambda x: x.price_unit == 200.0) self.assertEqual(len(lines), 1) def test_contract_price_revision_invoicing(self): + self.acct_line.copy({'automatic_price': True}) self.execute_wizard() - self.contract.recurring_create_invoice() + invoice = self.contract.recurring_create_invoice() invoices = self.env['account.invoice'].search([ - ('contract_id', '=', self.contract.id)]) + ('invoice_line_ids.contract_line_id', 'in', + self.contract.contract_line_ids.ids)]) self.assertEqual(len(invoices), 1) - lines = invoices.mapped('invoice_line_ids') + lines = invoice.invoice_line_ids + self.assertEqual(len(lines), 2) + lines = lines.filtered(lambda x: x.price_unit == 100.0) + self.assertEqual(len(lines), 1) + invoice = self.contract.recurring_create_invoice() + lines = invoice.invoice_line_ids self.assertEqual(len(lines), 2) - lines = lines.filtered(lambda x: x.price_unit == 50.0) + lines = lines.filtered(lambda x: x.price_unit == 200.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 deleted file mode 100644 index e25fce65..00000000 --- a/contract_price_revision/views/account_analytic_account_views.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - account.analytic.invoice.line.view - account.analytic.invoice.line - -
- - - - - - - - - - - - - - -
-
-
- - Contract form price revision - account.analytic.account - - - - - - - - - - -
diff --git a/contract_price_revision/views/contract_line.xml b/contract_price_revision/views/contract_line.xml new file mode 100644 index 00000000..af6bd2f0 --- /dev/null +++ b/contract_price_revision/views/contract_line.xml @@ -0,0 +1,26 @@ + + + + + contract.line + + + + + + + + + + contract.line + + + + + + + + + diff --git a/contract_price_revision/wizards/__init__.py b/contract_price_revision/wizards/__init__.py index f215b5a5..f56726dc 100644 --- a/contract_price_revision/wizards/__init__.py +++ b/contract_price_revision/wizards/__init__.py @@ -1 +1 @@ -from . import create_revision_line +from . import contract_price_revision diff --git a/contract_price_revision/wizards/contract_price_revision.py b/contract_price_revision/wizards/contract_price_revision.py new file mode 100644 index 00000000..2260eb0d --- /dev/null +++ b/contract_price_revision/wizards/contract_price_revision.py @@ -0,0 +1,54 @@ +# Copyright 2019 Tecnativa - Vicent Cubells +# Copyright 2019 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from dateutil.relativedelta import relativedelta + +from odoo import fields, models +import odoo.addons.decimal_precision as dp + + +class ContractPriceRevisionWizard(models.TransientModel): + """ Update contract price based on percentage variation """ + _name = 'contract.price.revision.wizard' + _description = "Wizard to update price based on percentage variation" + + date_start = fields.Date( + required=True, + ) + date_end = fields.Date() + variation_percent = fields.Float( + digits=dp.get_precision('Product Price'), + required=True, + string='Variation %', + ) + + def action_apply(self): + ContractLine = self.env['contract.line'] + active_ids = self.env.context['active_ids'] + for line in self.env['contract.contract'].browse(active_ids).mapped( + 'contract_line_ids'): + if (line.automatic_price or line.successor_contract_line_id or + not line.recurring_next_date): + continue + 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, + }) + action = self.env['ir.actions.act_window'].for_xml_id( + 'contract', 'action_customer_contract') + action['domain'] = [('id', 'in', active_ids)] + return action diff --git a/contract_price_revision/wizards/create_revision_line_views.xml b/contract_price_revision/wizards/contract_price_revision_views.xml similarity index 89% rename from contract_price_revision/wizards/create_revision_line_views.xml rename to contract_price_revision/wizards/contract_price_revision_views.xml index e4d038f3..a50af38c 100644 --- a/contract_price_revision/wizards/create_revision_line_views.xml +++ b/contract_price_revision/wizards/contract_price_revision_views.xml @@ -3,7 +3,7 @@ Create Revision Line - create.revision.line.wizard + contract.price.revision.wizard
@@ -31,8 +31,8 @@ diff --git a/contract_price_revision/wizards/create_revision_line.py b/contract_price_revision/wizards/create_revision_line.py deleted file mode 100644 index 8aca4b84..00000000 --- a/contract_price_revision/wizards/create_revision_line.py +++ /dev/null @@ -1,50 +0,0 @@ -# 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