Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
243cbeb
18 contract multi invoice line wip
tobiaszehntner Sep 16, 2025
1310db1
[15.0][ADD] subscription_oca
carlos-domatix Sep 20, 2023
6204825
[IMP] subscription_oca: tests
ilyasProgrammer Sep 26, 2023
b58dfce
[IMP] subscription_oca: refactoring
ilyasProgrammer Sep 26, 2023
f6a812c
Added translation using Weblate (Spanish)
Ivorra78 Oct 29, 2023
f14f551
[MIG] subscription_oca: Migration to 16.0
carolina-domatix Feb 7, 2024
b21c556
[IMP] subscription_oca: tests
ilyasProgrammer Oct 9, 2023
fc9563f
[IMP] subscription_oca: tests adjustments
carolina-domatix Feb 7, 2024
7b40e77
[UPD] Update subscription_oca.pot
Feb 20, 2024
6618fd9
[BOT] post-merge updates
OCA-git-bot Feb 20, 2024
4462d6b
Added translation using Weblate (French)
gregory-moka Feb 28, 2024
f74cbed
Added translation using Weblate (Dutch)
ThijsvOers Apr 2, 2024
a08cc2d
Translated using Weblate (Dutch)
ThijsvOers Apr 4, 2024
7ef95b4
Added translation using Weblate (Italian)
mymage May 6, 2024
17770a1
[IMP] subscription_oca: pre-commit auto fixes
Tisho99 Jul 8, 2024
71b733a
[MIG] subscription_oca: Migration to 17.0
Tisho99 Jul 8, 2024
f922002
[UPD] Update subscription_oca.pot
Jul 12, 2024
fd21e8c
[BOT] post-merge updates
OCA-git-bot Jul 12, 2024
4d5bcda
Update translation files
weblate Jul 12, 2024
35dfb35
Translated using Weblate (Italian)
mymage Jul 23, 2024
c629e50
Translated using Weblate (Finnish)
jarmokortetjarvi Aug 13, 2024
0eb6072
Translated using Weblate (Turkish)
metingulsoy Aug 20, 2024
a164f25
[UPD] Update subscription_oca.pot
Aug 24, 2024
137ceb1
Update translation files
weblate Aug 24, 2024
afd5506
Translated using Weblate (Italian)
mymage Aug 26, 2024
8a19f8f
Translated using Weblate (Turkish)
Sep 30, 2024
c9e295d
[IMP] subscription_oca: pre-commit auto fixes
tobiaszehntner Feb 28, 2025
54f1d93
[MIG] subscription_oca: Migration to 18.0
tobiaszehntner Mar 7, 2025
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
32 changes: 18 additions & 14 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,24 +587,28 @@ def _prepare_recurring_invoices_values(self, date_ref=False):
if not contract_lines:
continue
invoice_vals = contract._prepare_invoice(date_ref)
invoice_vals["invoice_line_ids"] = []
for line in contract_lines:
invoice_line_vals = line._prepare_invoice_line()
if invoice_line_vals:
# Allow extension modules to return an empty dictionary for
# nullifying line. We should then cleanup certain values.
if "company_id" in invoice_line_vals:
del invoice_line_vals["company_id"]
if "company_currency_id" in invoice_line_vals:
del invoice_line_vals["company_currency_id"]
invoice_vals["invoice_line_ids"].append(
Command.create(invoice_line_vals)
)
invoices_values.append(invoice_vals)
invoice_line_vals = self._prepare_invoice_line_values(contract_lines)
invoice_vals["invoice_line_ids"] = [
Command.create(line_vals) for line_vals in invoice_line_vals
]
# Force the recomputation of journal items
contract_lines._update_last_date_invoiced()
return invoices_values

def _prepare_invoice_line_values(self, contract_lines):
invoice_lines_vals = []
for line in contract_lines:
invoice_line_vals = line._prepare_invoice_line()
if invoice_line_vals:
# Allow extension modules to return an empty dictionary for
# nullifying line. We should then cleanup certain values.
if "company_id" in invoice_line_vals:
del invoice_line_vals["company_id"]
if "company_currency_id" in invoice_line_vals:
del invoice_line_vals["company_currency_id"]
invoice_lines_vals.append(invoice_line_vals)
return invoice_lines_vals

@api.model
def _invoice_followers(self, invoices):
invoice_create_subtype = self.env.ref(
Expand Down
128 changes: 128 additions & 0 deletions subscription_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
=======================
Subscription management
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7ce64c258eeb9f3fbecdec056e16c8e966b2f0b456800d16120468a925be2fea
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/18.0/subscription_oca
:alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-18-0/contract-18-0-subscription_oca
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows creating subscriptions that generate recurring
invoices or orders. It also enables the sale of products that generate
subscriptions.

**Table of contents**

.. contents::
:local:

Usage
=====

To make a subscription:

1. Go to *Subscriptions > Configuration > Subscription templates*.
2. Create the templates you consider, choosing the billing frequency:
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
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
can manually change the subscription status and create an invoice by
using the *Create Invoice* button. This action creates just an
invoice even if the subscription template has the *Sale Order &
Invoice* option selected, because the *Invoicing mode* option is
triggered through the cron job.
5. The cron job will also end the subscription if its end date has been
reached.

To create subscriptions with the sale of a product:

1. Go to *Subscriptions > Subscriptions > Products*.
2. Create the product and in the sales tab, complete the fields
*Subscribable product* and *Subscription template*
3. Create a sales order with the product and confirm it.

Known issues / Roadmap
======================

- Refactor all the onchanges that have business logic to computed
write-able fields when possible. Keep onchanges only for UI purposes.
- Add tests.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20subscription_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Domatix
* Onestein

Contributors
------------

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

- Ilyas <irazor147@gmail.com>

- `Sygel <https://www.sygel.es>`__:

- Harald Panten
- Valentin Vinagre
- Alberto Martínez

- Dennis Sluijk <d.sluijk@onestein.nl>

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 <https://github.com/OCA/contract/tree/18.0/subscription_oca>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions subscription_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
29 changes: 29 additions & 0 deletions subscription_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Domatix - Carlos Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Subscription management",
"summary": "Generate recurring invoices.",
"version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Subscription Management",
"website": "https://github.com/OCA/contract",
"license": "AGPL-3",
"author": "Domatix, Onestein, Odoo Community Association (OCA)",
"depends": ["sale_management", "account"],
"data": [
"views/product_template_views.xml",
"views/account_move_views.xml",
"views/sale_subscription_views.xml",
"views/sale_subscription_stage_views.xml",
"views/sale_subscription_tag_views.xml",
"views/sale_subscription_template_views.xml",
"views/sale_order_views.xml",
"views/res_partner_views.xml",
"data/ir_cron.xml",
"data/sale_subscription_data.xml",
"wizard/close_subscription_wizard.xml",
"security/ir.model.access.csv",
],
"installable": True,
"application": True,
}
13 changes: 13 additions & 0 deletions subscription_oca/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="ir_cron_subscription_management" model="ir.cron">
<field name="name">Subscriptions management</field>
<field eval="True" name="active" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">24</field>
<field name="interval_type">hours</field>
<field ref="model_sale_subscription" name="model_id" />
<field name="state">code</field>
<field name="code">model.cron_subscription_management()</field>
</record>
</odoo>
71 changes: 71 additions & 0 deletions subscription_oca/data/sale_subscription_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noupdate="1". Some values could be edited by a user (prefix, padding etc)

<data noupdate="1">
<record id="seq_id" model="ir.sequence">
<field name="name">sale_subscription_sequencer</field>
<field name="code">sale.subscription</field>
<field name="prefix">SUB</field>
<field name="padding">5</field>
</record>

<record id="subscription_stage_draft" model="sale.subscription.stage">
<field name="name">Draft</field>
<field name="sequence">0</field>
<field name="type">draft</field>
<field name="description">
Draft, still working on the specifics.
</field>
<field eval="False" name="fold" />
</record>

<record id="subscription_stage_ready" model="sale.subscription.stage">
<field name="name">Ready to start</field>
<field name="sequence">1</field>
<field name="type">pre</field>
<field name="description">
A subscription is ready to start when is not marked as in progress but it can be at any moment. If there's no 'Closed'-type stage defined, when a subscription comes to an end by automatic means, it will be marked with this stage.
</field>
<field eval="False" name="fold" />
</record>

<record id="subscription_stage_in_progress" model="sale.subscription.stage">
<field name="name">In progress</field>
<field name="sequence">2</field>
<field name="type">in_progress</field>
<field eval="False" name="fold" />
<field name="description">
As an 'In progress'-type of stage, it will trigger the recurring invoicing process if applicable. If this stage is the first - sequence order - of the available 'In progress' types and there's a stage change from any other non-'In progress' types to this one, an invoice will be created automatically if the start date is the present day.
</field>
</record>

<record id="subscription_stage_closed" model="sale.subscription.stage">
<field name="name">Closed</field>
<field name="sequence">3</field>
<field name="type">post</field>
<field eval="False" name="fold" />
<field name="description">
The final stage of a subscription. There are two ways to mark a subscription as closed. The easiest one is using the kanban card-moving capabilities, pressing the 'Close subscription' button (only available if a subscription is in progress).
</field>
</record>
</data>

<record id="close_reason_expensive" model="sale.subscription.close.reason">
<field name="name">The subscription is too expensive</field>
</record>

<record id="close_reason_requirement" model="sale.subscription.close.reason">
<field name="name">Subscription does not meet my requirements</field>
</record>

<record id="close_reason_ended" model="sale.subscription.close.reason">
<field name="name">The subscription ended</field>
</record>

<record id="close_reason_use" model="sale.subscription.close.reason">
<field name="name">I don't really use it</field>
</record>

<record id="close_reason_other" model="sale.subscription.close.reason">
<field name="name">Other</field>
</record>
</odoo>
Loading
Loading