-
-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by simahawk
- Loading branch information
Showing
36 changed files
with
2,643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../subscription_oca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
======================= | ||
Subscription management | ||
======================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:3772d65a58c07d0348bd13d3c882810c94bfb87389c62fec6d16fe8ef130252c | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/15.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-15-0/contract-15-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=15.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: | ||
|
||
#. Go to *Subscriptions > Configuration > Subscription templates*. | ||
#. Create the templates you consider, choosing the billing frequency: daily, monthly... and the method of creating the invoice and/or order. | ||
#. Go to *Subscription > Subscriptions*. | ||
#. 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. | ||
#. The cron job will also end the subscription if its end date has been reached. | ||
|
||
To create subscriptions with the sale of a product: | ||
|
||
#. Go to *Subscriptions > Subscriptions > Products*. | ||
#. Create the product and in the sales tab, complete the fields *Subscribable product* and *Subscription template* | ||
#. 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:%2015.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 | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Carlos Martínez <carlos@domatix.com> | ||
|
||
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/15.0/subscription_oca>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 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": "15.0.1.0.0", | ||
"development_status": "Beta", | ||
"category": "Subscription Management", | ||
"website": "https://github.com/OCA/contract", | ||
"license": "AGPL-3", | ||
"author": "Domatix, Odoo Community Association (OCA)", | ||
"depends": ["sale_management", "account"], | ||
"data": [ | ||
"views/product_template_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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<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 name="numbercall">-1</field> | ||
<field eval="False" name="doall" /> | ||
<field ref="model_sale_subscription" name="model_id" /> | ||
<field name="state">code</field> | ||
<field name="code">model.cron_subscription_management()</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<data> | ||
<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> | ||
</data> | ||
|
||
<data noupdate="1"> | ||
<record id="subscription_stage_draft" model="sale.subscription.stage"> | ||
<!-- <field eval="True" name="active"/> --> | ||
<field name="name">Ready to start</field> | ||
<field name="sequence">0</field> | ||
<field name="type">pre</field> | ||
<field name="description"> | ||
Draft equivalent, 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 eval="True" name="active"/> --> | ||
<field name="name">In progress</field> | ||
<field name="sequence">1</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 eval="True" name="active"/> --> | ||
<field name="name">Closed</field> | ||
<field name="sequence">2</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 eval="True" name="active"/> --> | ||
<field name="name">The subscription is too expensive</field> | ||
</record> | ||
|
||
<record id="close_reason_requirement" model="sale.subscription.close.reason"> | ||
<!-- <field eval="True" name="active"/> --> | ||
<field name="name">Subscription does not meet my requirements</field> | ||
</record> | ||
|
||
<record id="close_reason_ended" model="sale.subscription.close.reason"> | ||
<!-- <field eval="True" name="active"/> --> | ||
<field name="name">The subscription ended</field> | ||
</record> | ||
|
||
<record id="close_reason_use" model="sale.subscription.close.reason"> | ||
<!-- <field eval="True" name="active"/> --> | ||
<field name="name">I don't really use it</field> | ||
</record> | ||
|
||
<record id="close_reason_other" model="sale.subscription.close.reason"> | ||
<!-- <field eval="True" name="active"/> --> | ||
<field name="name">Other</field> | ||
</record> | ||
|
||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from . import account_move | ||
from . import product_template | ||
from . import res_partner | ||
from . import sale_order | ||
from . import sale_order_line | ||
from . import sale_subscription | ||
from . import sale_subscription_close_reason | ||
from . import sale_subscription_line | ||
from . import sale_subscription_stage | ||
from . import sale_subscription_tag | ||
from . import sale_subscription_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 Domatix - Carlos Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
subscription_id = fields.Many2one( | ||
comodel_name="sale.subscription", string="Subscription" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 Domatix - Carlos Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class Product(models.Model): | ||
_inherit = "product.template" | ||
|
||
subscribable = fields.Boolean(string="Subscribable product") | ||
subscription_template_id = fields.Many2one( | ||
comodel_name="sale.subscription.template", string="Subscription template" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2023 Domatix - Carlos Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class Partner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
subscription_ids = fields.One2many( | ||
comodel_name="sale.subscription", | ||
inverse_name="partner_id", | ||
string="Subscriptions", | ||
) | ||
subscription_count = fields.Integer( | ||
required=False, | ||
compute="_compute_subscription_count", | ||
) | ||
|
||
def _compute_subscription_count(self): | ||
for record in self: | ||
record.subscription_count = len(record.subscription_ids) | ||
|
||
def action_view_subscription_ids(self): | ||
return { | ||
"type": "ir.actions.act_window", | ||
"res_model": "sale.subscription", | ||
"domain": [("id", "in", self.subscription_ids.ids)], | ||
"name": self.name, | ||
"view_mode": "tree,form", | ||
"context": { | ||
"default_partner_id": self.id, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright 2023 Domatix - Carlos Martínez | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from collections import defaultdict | ||
from datetime import date | ||
|
||
from dateutil.relativedelta import relativedelta | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
subscription_ids = fields.One2many( | ||
comodel_name="sale.subscription", | ||
inverse_name="sale_order_id", | ||
string="Subscriptions", | ||
) | ||
subscriptions_count = fields.Integer(compute="_compute_subscriptions_count") | ||
order_subscription_id = fields.Many2one( | ||
comodel_name="sale.subscription", string="Subscription" | ||
) | ||
|
||
@api.depends("subscription_ids") | ||
def _compute_subscriptions_count(self): | ||
for record in self: | ||
record.subscriptions_count = len(record.subscription_ids) | ||
|
||
def action_view_subscriptions(self): | ||
return { | ||
"type": "ir.actions.act_window", | ||
"res_model": "sale.subscription", | ||
"domain": [("id", "in", self.subscription_ids.ids)], | ||
"name": self.name, | ||
"view_mode": "tree,form", | ||
} | ||
|
||
def get_next_interval(self, type_interval, interval): | ||
date_start = date.today() | ||
date_start += relativedelta(**{type_interval: interval}) | ||
return date_start | ||
|
||
def create_subscription(self, lines, subscription_tmpl): | ||
subscription_lines = [] | ||
for line in lines: | ||
subscription_lines.append((0, 0, line.get_subscription_line_values())) | ||
|
||
if subscription_tmpl: | ||
rec = self.env["sale.subscription"].create( | ||
{ | ||
"partner_id": self.partner_id.id, | ||
"user_id": self._context["uid"], | ||
"template_id": subscription_tmpl.id, | ||
"pricelist_id": self.partner_id.property_product_pricelist.id, | ||
"date_start": date.today(), | ||
"sale_order_id": self.id, | ||
"sale_subscription_line_ids": subscription_lines, | ||
} | ||
) | ||
rec.action_start_subscription() | ||
self.subscription_ids = [(4, rec.id)] | ||
rec.recurring_next_date = self.get_next_interval( | ||
subscription_tmpl.recurring_rule_type, | ||
subscription_tmpl.recurring_interval, | ||
) | ||
|
||
def group_subscription_lines(self): | ||
grouped = defaultdict(list) | ||
for order_line in self.order_line.filtered( | ||
lambda line: line.product_id.subscribable | ||
): | ||
grouped[ | ||
order_line.product_id.product_tmpl_id.subscription_template_id | ||
].append(order_line) | ||
return grouped | ||
|
||
def action_confirm(self): | ||
res = super(SaleOrder, self).action_confirm() | ||
for record in self: | ||
grouped = self.group_subscription_lines() | ||
for tmpl, lines in grouped.items(): | ||
record.create_subscription(lines, tmpl) | ||
return res |
Oops, something went wrong.