Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subscription_oca/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,6 +102,7 @@ Contributors

- Carlos Martínez <carlos@domatix.com>
- Carolina Ferrer <carolina@domatix.com>
- Alejandro Roser <alejandro@domatix.com>
- `Ooops404 <https://www.ooops404.com>`__:

- Ilyas <irazor147@gmail.com>
Expand Down
35 changes: 34 additions & 1 deletion subscription_oca/models/sale_subscription_line.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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
1 change: 1 addition & 0 deletions subscription_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- Carlos Martínez \<<carlos@domatix.com>\>
- Carolina Ferrer \<<carolina@domatix.com>\>
- Alejandro Roser \<<alejandro@domatix.com>\>
- [Ooops404](https://www.ooops404.com):
- Ilyas \<<irazor147@gmail.com>\>
- [Sygel](https://www.sygel.es):
Expand Down
6 changes: 4 additions & 2 deletions subscription_oca/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion subscription_oca/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ <h1>Subscription management</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:ab6023e140886cb5c4fe2d8e969d404ab4a58de4701d6b906c424c9521d1b5d1
!! source digest: sha256:bb329d140601b7b2d00180949e54d8e069943b704fc84d1fbdaf665386f79120
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/18.0/subscription_oca"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-18-0/contract-18-0-subscription_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows creating subscriptions that generate recurring
Expand Down Expand Up @@ -452,6 +452,7 @@ <h3><a class="toc-backref" href="#toc-entry-6">Contributors</a></h3>
<ul class="simple">
<li>Carlos Martínez &lt;<a class="reference external" href="mailto:carlos&#64;domatix.com">carlos&#64;domatix.com</a>&gt;</li>
<li>Carolina Ferrer &lt;<a class="reference external" href="mailto:carolina&#64;domatix.com">carolina&#64;domatix.com</a>&gt;</li>
<li>Alejandro Roser &lt;<a class="reference external" href="mailto:alejandro&#64;domatix.com">alejandro&#64;domatix.com</a>&gt;</li>
<li><a class="reference external" href="https://www.ooops404.com">Ooops404</a>:<ul>
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
</ul>
Expand Down