From 42d37ea5319b054c08a0912ee7000b07bf769923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Berm=C3=BAdez?= Date: Thu, 23 Oct 2025 14:55:14 +0200 Subject: [PATCH] [16.0][IMP]contract: add recurring total --- contract/README.rst | 5 ++++- contract/i18n/contract.pot | 18 ++++++++++++++++ contract/i18n/es.po | 30 ++++++++++++++++++++------ contract/models/contract.py | 12 +++++++++++ contract/models/contract_line.py | 25 +++++++++++++++++++++ contract/readme/CONTRIBUTORS.rst | 5 ++++- contract/static/description/index.html | 10 ++++++++- contract/views/contract.xml | 15 +++++++++++++ 8 files changed, 110 insertions(+), 10 deletions(-) diff --git a/contract/README.rst b/contract/README.rst index 538410ea4d..6ee613d6d0 100644 --- a/contract/README.rst +++ b/contract/README.rst @@ -7,7 +7,7 @@ Recurring - Contracts Management !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:fcbf0d9e74385728a9b6214b0550105168ee739aa8bb1dec3d63680a70413c66 + !! source digest: sha256:d6e8454bf1db630a530d6bbf831fa37a084b8db5a3cc15e95a06a25e0908eea8 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png @@ -131,6 +131,9 @@ Contributors * Antoni Marroig +* `Trey `__: + * Alejandro Bermudez + Maintainers ~~~~~~~~~~~ diff --git a/contract/i18n/contract.pot b/contract/i18n/contract.pot index 83324a2203..bc79d82df3 100644 --- a/contract/i18n/contract.pot +++ b/contract/i18n/contract.pot @@ -6,6 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-06-26 10:37+0000\n" +"PO-Revision-Date: 2025-06-26 10:37+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -1163,6 +1165,7 @@ msgstr "" #. module: contract #: model:ir.model.fields,help:contract.field_contract_contract__message_has_error +#: model:ir.model.fields,help:contract.field_contract_contract__message_has_sms_error msgid "If checked, some messages have a delivery error." msgstr "" @@ -1785,6 +1788,16 @@ msgstr "" msgid "Recurring Invoices" msgstr "" +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_line__recurring_subtotal +msgid "Recurring Subtotal" +msgstr "" + +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_contract__recurring_total +msgid "Recurring Total" +msgstr "" + #. module: contract #: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view msgid "Recurring Type" @@ -1848,6 +1861,11 @@ msgstr "" msgid "Responsible User" msgstr "" +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_contract__message_has_sms_error +msgid "SMS Delivery error" +msgstr "" + #. module: contract #: model:ir.model.fields,field_description:contract.field_res_partner__sale_contract_count #: model:ir.model.fields,field_description:contract.field_res_users__sale_contract_count diff --git a/contract/i18n/es.po b/contract/i18n/es.po index 34369c74fe..b3a829dd1d 100644 --- a/contract/i18n/es.po +++ b/contract/i18n/es.po @@ -9,8 +9,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 11.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-12-31 14:54+0000\n" -"PO-Revision-Date: 2025-04-16 12:00+0000\n" +"POT-Creation-Date: 2025-06-26 10:37+0000\n" +"PO-Revision-Date: 2025-06-26 12:40+0200\n" "Last-Translator: Carlos Sainz-Pardo Ortiz \n" "Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" "Language: es\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 5.10.4\n" +"X-Generator: Poedit 3.0.1\n" #. module: contract #: model:mail.template,body_html:contract.email_contract_template @@ -183,8 +183,8 @@ msgid "" " " msgstr "" "

Hola,

\n" -"

Le notificamos que hay nuevas modificaciones en el " -"contrato.

\n" +"

Le notificamos que hay nuevas modificaciones en el contrato.\n" " " #. module: contract @@ -831,8 +831,8 @@ msgid "" msgstr "" "Línea de contrato para %(product)s\n" " parado:
\n" -" - Fin: %(old_end)s -- %(new_end)" -"s\n" +" - Fin: %(old_end)s -- " +"%(new_end)s\n" " " #. module: contract @@ -1342,6 +1342,7 @@ msgstr "Si está marcado los nuevos mensajes requieren su atención." #. module: contract #: model:ir.model.fields,help:contract.field_contract_contract__message_has_error +#: model:ir.model.fields,help:contract.field_contract_contract__message_has_sms_error msgid "If checked, some messages have a delivery error." msgstr "Si está marcado algunos mensajes tienen un error de entrega." @@ -1974,6 +1975,16 @@ msgstr "Mixin de recurrencia para modelos contractuales" msgid "Recurring Invoices" msgstr "Facturas recurrentes" +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_line__recurring_subtotal +msgid "Recurring Subtotal" +msgstr "Subtotal Recurrente" + +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_contract__recurring_total +msgid "Recurring Total" +msgstr "Total Recurrente" + #. module: contract #: model_terms:ir.ui.view,arch_db:contract.contract_contract_form_view msgid "Recurring Type" @@ -2037,6 +2048,11 @@ msgstr "Responsable" msgid "Responsible User" msgstr "Usuario Responsable" +#. module: contract +#: model:ir.model.fields,field_description:contract.field_contract_contract__message_has_sms_error +msgid "SMS Delivery error" +msgstr "Mensaje de Error de entrega" + #. module: contract #: model:ir.model.fields,field_description:contract.field_res_partner__sale_contract_count #: model:ir.model.fields,field_description:contract.field_res_users__sale_contract_count diff --git a/contract/models/contract.py b/contract/models/contract.py index 036270315a..e23645f963 100644 --- a/contract/models/contract.py +++ b/contract/models/contract.py @@ -136,6 +136,11 @@ class ContractContract(models.Model): inverse_name="contract_id", string="Modifications", ) + recurring_total = fields.Monetary( + compute="_compute_recurring_total", + currency_field="currency_id", + store=True, + ) def get_formview_id(self, access_uid=None): if self.contract_type == "sale": @@ -717,3 +722,10 @@ def action_cancel_contract_termination(self): "terminate_date": False, } ) + + @api.depends("contract_line_ids.recurring_subtotal") + def _compute_recurring_total(self): + for contract in self: + contract.recurring_total = sum( + contract.contract_line_ids.mapped("recurring_subtotal") + ) diff --git a/contract/models/contract_line.py b/contract/models/contract_line.py index f96e26985e..ab31509717 100644 --- a/contract/models/contract_line.py +++ b/contract/models/contract_line.py @@ -3,6 +3,7 @@ # Copyright 2020 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +import math from datetime import timedelta from dateutil.relativedelta import relativedelta @@ -100,6 +101,10 @@ class ContractLine(models.Model): store=True, readonly=True, ) + recurring_subtotal = fields.Monetary( + compute="_compute_recurring_subtotal", + currency_field="currency_id", + ) @api.depends( "last_date_invoiced", @@ -1119,3 +1124,23 @@ def _get_quantity_to_invoice( ): self.ensure_one() return self.quantity if not self.display_type else 0.0 + + @api.depends( + "price_unit", "quantity", "state", "recurring_rule_type", "recurring_interval" + ) + def _compute_recurring_subtotal(self): + rule_type_dict = { + "daily": 365, + "weekly": 52, + "monthly": 12, + "monthlylastday": 12, + "quarterly": 4, + "semesterly": 2, + } + for line in self.filtered(lambda cl: cl.state != "canceled"): + rule_type = rule_type_dict.get(line.recurring_rule_type, 1) + interval = line.recurring_interval or 1 + annual_frequency = math.floor(rule_type / interval) + line.recurring_subtotal = ( + line.price_unit * annual_frequency + ) * line.quantity diff --git a/contract/readme/CONTRIBUTORS.rst b/contract/readme/CONTRIBUTORS.rst index 5826984e76..224ef77e52 100644 --- a/contract/readme/CONTRIBUTORS.rst +++ b/contract/readme/CONTRIBUTORS.rst @@ -16,4 +16,7 @@ * Iván Antón * `[APSL] `_: - * Antoni Marroig \ No newline at end of file + * Antoni Marroig + +* `Trey `__: + * Alejandro Bermudez diff --git a/contract/static/description/index.html b/contract/static/description/index.html index 392dde7d06..7c55bda318 100644 --- a/contract/static/description/index.html +++ b/contract/static/description/index.html @@ -367,7 +367,7 @@

Recurring - Contracts Management

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:fcbf0d9e74385728a9b6214b0550105168ee739aa8bb1dec3d63680a70413c66 +!! source digest: sha256:d6e8454bf1db630a530d6bbf831fa37a084b8db5a3cc15e95a06a25e0908eea8 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Production/Stable License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runboat

This module enables contracts management with recurring @@ -492,6 +492,14 @@

Contributors

+
  • +
    Trey:
    +
    +
    +
    +
  • diff --git a/contract/views/contract.xml b/contract/views/contract.xml index c9d894094c..64f979150c 100644 --- a/contract/views/contract.xml +++ b/contract/views/contract.xml @@ -393,6 +393,20 @@ /> + + + + @@ -524,6 +538,7 @@ widget="many2many_tags" options="{'color_field': 'color'}" /> +