From 19094b68294aa7dea509b6f56514c8c7359c2982 Mon Sep 17 00:00:00 2001 From: alejandro Date: Fri, 21 Nov 2025 13:35:21 +0000 Subject: [PATCH] [18.0][UPD] Updated sale_subscription,sale_subscription_line and sale_subscription_views to add sections and notes support --- subscription_oca/README.rst | 3 +- .../models/sale_subscription_line.py | 35 ++++++++++++++++++- subscription_oca/readme/CONTRIBUTORS.md | 1 + subscription_oca/readme/USAGE.md | 6 ++-- .../static/description/index.html | 3 +- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/subscription_oca/README.rst b/subscription_oca/README.rst index 57a6d31363..b27fc3198f 100644 --- a/subscription_oca/README.rst +++ b/subscription_oca/README.rst @@ -11,7 +11,7 @@ Subscription management !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:ab6023e140886cb5c4fe2d8e969d404ab4a58de4701d6b906c424c9521d1b5d1 + !! source digest: sha256:bb329d140601b7b2d00180949e54d8e069943b704fc84d1fbdaf665386f79120 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -102,6 +102,7 @@ Contributors - Carlos Martínez - Carolina Ferrer +- Alejandro Roser - `Ooops404 `__: - Ilyas diff --git a/subscription_oca/models/sale_subscription_line.py b/subscription_oca/models/sale_subscription_line.py index 2bd40bcdbd..5096452343 100644 --- a/subscription_oca/models/sale_subscription_line.py +++ b/subscription_oca/models/sale_subscription_line.py @@ -1,5 +1,7 @@ # Copyright 2023 Domatix - Carlos Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from dateutil.relativedelta import relativedelta + from odoo import Command, api, fields, models from odoo.tools.misc import get_lang @@ -301,7 +303,8 @@ def _prepare_account_move_line(self): self.product_id.property_account_income_id or self.product_id.categ_id.property_account_income_categ_id ) - return { + + vals = { "product_id": self.product_id.id, "name": self.name, "quantity": self.product_uom_qty, @@ -313,3 +316,33 @@ def _prepare_account_move_line(self): "account_id": account.id, "analytic_distribution": self.analytic_distribution, } + + if ( + self.sale_subscription_id + and self.sale_subscription_id.recurring_next_date + and vals.get("name") + and ("#START#" in vals["name"] or "#END#" in vals["name"]) + ): + start_date = self.sale_subscription_id.recurring_next_date + end_date = self.get_next_recurring_date(start_date) + vals["name"] = self._insert_markers(start_date, end_date) + + return vals + + def get_next_recurring_date(self, date): + template = self.sale_subscription_id.template_id + type_interval = template.recurring_rule_type + interval = int(template.recurring_interval) + return date + relativedelta(**{type_interval: interval}) + + def _insert_markers(self, first_date_invoiced, last_date_invoiced): + self.ensure_one() + lang_obj = self.env["res.lang"] + lang = lang_obj.search( + [("code", "=", self.sale_subscription_id.partner_id.lang)] + ) + date_format = lang.date_format or "%m/%d/%Y" + name = self.name + name = name.replace("#START#", first_date_invoiced.strftime(date_format)) + name = name.replace("#END#", last_date_invoiced.strftime(date_format)) + return name diff --git a/subscription_oca/readme/CONTRIBUTORS.md b/subscription_oca/readme/CONTRIBUTORS.md index 885a89aa19..443e651a8c 100644 --- a/subscription_oca/readme/CONTRIBUTORS.md +++ b/subscription_oca/readme/CONTRIBUTORS.md @@ -1,5 +1,6 @@ - Carlos Martínez \<\> - Carolina Ferrer \<\> +- Alejandro Roser \<\> - [Ooops404](https://www.ooops404.com): - Ilyas \<\> - [Sygel](https://www.sygel.es): diff --git a/subscription_oca/readme/USAGE.md b/subscription_oca/readme/USAGE.md index 707414ff28..60bc153427 100644 --- a/subscription_oca/readme/USAGE.md +++ b/subscription_oca/readme/USAGE.md @@ -5,8 +5,10 @@ To make a subscription: daily, monthly... and the method of creating the invoice and/or order. 3. Go to *Subscription \> Subscriptions*. -4. Create a subscription and indicate the start date. When the - *Subscriptions Management* cron job is executed, the subscription +4. Create a subscription and indicate the start date.You are able to pass + the start and end dates to generated invoices by inserting #START# and + #END# markers to the descriptions of the subscription invoce's products, + When the *Subscriptions Management* cron job is executed, the subscription will begin and the first invoice will be created if the execution date matches the start date. The invoice will also be created when the execution date matches the next invoice date. Additionally, you diff --git a/subscription_oca/static/description/index.html b/subscription_oca/static/description/index.html index 50e903fc3d..47601a8278 100644 --- a/subscription_oca/static/description/index.html +++ b/subscription_oca/static/description/index.html @@ -372,7 +372,7 @@

Subscription management

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

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

This module allows creating subscriptions that generate recurring @@ -452,6 +452,7 @@

Contributors