From 382eccbf656503fdc43f759b184345a092be1ef3 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 20 Sep 2023 21:49:04 +0200 Subject: [PATCH] [15.0][ADD] subscription_oca --- .../odoo/addons/subscription_oca | 1 + setup/subscription_oca/setup.py | 6 + subscription_oca/README.rst | 99 ++++ subscription_oca/__init__.py | 2 + subscription_oca/__manifest__.py | 28 ++ subscription_oca/data/ir_cron.xml | 15 + .../data/sale_subscription_data.xml | 76 +++ subscription_oca/models/__init__.py | 11 + subscription_oca/models/account_move.py | 12 + subscription_oca/models/product_template.py | 12 + subscription_oca/models/res_partner.py | 33 ++ subscription_oca/models/sale_order.py | 83 +++ subscription_oca/models/sale_order_line.py | 17 + subscription_oca/models/sale_subscription.py | 470 +++++++++++++++++ .../models/sale_subscription_close_reason.py | 10 + .../models/sale_subscription_line.py | 322 ++++++++++++ .../models/sale_subscription_stage.py | 29 ++ .../models/sale_subscription_tag.py | 10 + .../models/sale_subscription_template.py | 102 ++++ subscription_oca/readme/CONTRIBUTORS.rst | 1 + subscription_oca/readme/DESCRIPTION.rst | 1 + subscription_oca/readme/ROADMAP.rst | 2 + subscription_oca/readme/USAGE.rst | 13 + subscription_oca/security/ir.model.access.csv | 8 + .../static/description/index.html | 439 ++++++++++++++++ subscription_oca/static/img/icon.png | Bin 0 -> 16096 bytes .../views/product_template_views.xml | 20 + subscription_oca/views/res_partner_views.xml | 28 ++ subscription_oca/views/sale_order_views.xml | 29 ++ .../views/sale_subscription_stage_views.xml | 73 +++ .../views/sale_subscription_tag_views.xml | 27 + .../sale_subscription_template_views.xml | 135 +++++ .../views/sale_subscription_views.xml | 473 ++++++++++++++++++ subscription_oca/wizard/__init__.py | 1 + .../wizard/close_subscription_wizard.py | 25 + .../wizard/close_subscription_wizard.xml | 30 ++ 36 files changed, 2643 insertions(+) create mode 120000 setup/subscription_oca/odoo/addons/subscription_oca create mode 100644 setup/subscription_oca/setup.py create mode 100644 subscription_oca/README.rst create mode 100644 subscription_oca/__init__.py create mode 100644 subscription_oca/__manifest__.py create mode 100644 subscription_oca/data/ir_cron.xml create mode 100644 subscription_oca/data/sale_subscription_data.xml create mode 100644 subscription_oca/models/__init__.py create mode 100644 subscription_oca/models/account_move.py create mode 100644 subscription_oca/models/product_template.py create mode 100644 subscription_oca/models/res_partner.py create mode 100644 subscription_oca/models/sale_order.py create mode 100644 subscription_oca/models/sale_order_line.py create mode 100644 subscription_oca/models/sale_subscription.py create mode 100644 subscription_oca/models/sale_subscription_close_reason.py create mode 100644 subscription_oca/models/sale_subscription_line.py create mode 100644 subscription_oca/models/sale_subscription_stage.py create mode 100644 subscription_oca/models/sale_subscription_tag.py create mode 100644 subscription_oca/models/sale_subscription_template.py create mode 100644 subscription_oca/readme/CONTRIBUTORS.rst create mode 100644 subscription_oca/readme/DESCRIPTION.rst create mode 100644 subscription_oca/readme/ROADMAP.rst create mode 100644 subscription_oca/readme/USAGE.rst create mode 100644 subscription_oca/security/ir.model.access.csv create mode 100644 subscription_oca/static/description/index.html create mode 100644 subscription_oca/static/img/icon.png create mode 100644 subscription_oca/views/product_template_views.xml create mode 100644 subscription_oca/views/res_partner_views.xml create mode 100644 subscription_oca/views/sale_order_views.xml create mode 100644 subscription_oca/views/sale_subscription_stage_views.xml create mode 100644 subscription_oca/views/sale_subscription_tag_views.xml create mode 100644 subscription_oca/views/sale_subscription_template_views.xml create mode 100644 subscription_oca/views/sale_subscription_views.xml create mode 100644 subscription_oca/wizard/__init__.py create mode 100644 subscription_oca/wizard/close_subscription_wizard.py create mode 100644 subscription_oca/wizard/close_subscription_wizard.xml diff --git a/setup/subscription_oca/odoo/addons/subscription_oca b/setup/subscription_oca/odoo/addons/subscription_oca new file mode 120000 index 0000000000..55d96c3d7d --- /dev/null +++ b/setup/subscription_oca/odoo/addons/subscription_oca @@ -0,0 +1 @@ +../../../../subscription_oca \ No newline at end of file diff --git a/setup/subscription_oca/setup.py b/setup/subscription_oca/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/subscription_oca/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/subscription_oca/README.rst b/subscription_oca/README.rst new file mode 100644 index 0000000000..0b03b4bf12 --- /dev/null +++ b/subscription_oca/README.rst @@ -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 `_. +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Domatix + +Contributors +~~~~~~~~~~~~ + +* Carlos Martínez + +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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/subscription_oca/__init__.py b/subscription_oca/__init__.py new file mode 100644 index 0000000000..9b4296142f --- /dev/null +++ b/subscription_oca/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/subscription_oca/__manifest__.py b/subscription_oca/__manifest__.py new file mode 100644 index 0000000000..8e9cb33b82 --- /dev/null +++ b/subscription_oca/__manifest__.py @@ -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, +} diff --git a/subscription_oca/data/ir_cron.xml b/subscription_oca/data/ir_cron.xml new file mode 100644 index 0000000000..fbc7f7c888 --- /dev/null +++ b/subscription_oca/data/ir_cron.xml @@ -0,0 +1,15 @@ + + + + Subscriptions management + + + 24 + hours + -1 + + + code + model.cron_subscription_management() + + diff --git a/subscription_oca/data/sale_subscription_data.xml b/subscription_oca/data/sale_subscription_data.xml new file mode 100644 index 0000000000..6ee56a620e --- /dev/null +++ b/subscription_oca/data/sale_subscription_data.xml @@ -0,0 +1,76 @@ + + + + + + sale_subscription_sequencer + sale.subscription + SUB + 5 + + + + + + + Ready to start + 0 + pre + + 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. + + + + + + + In progress + 1 + in_progress + + + 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. + + + + + + Closed + 2 + post + + + 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). + + + + + + + + + The subscription is too expensive + + + + + Subscription does not meet my requirements + + + + + The subscription ended + + + + + I don't really use it + + + + + Other + + + + diff --git a/subscription_oca/models/__init__.py b/subscription_oca/models/__init__.py new file mode 100644 index 0000000000..6fa4481885 --- /dev/null +++ b/subscription_oca/models/__init__.py @@ -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 diff --git a/subscription_oca/models/account_move.py b/subscription_oca/models/account_move.py new file mode 100644 index 0000000000..570a02f29a --- /dev/null +++ b/subscription_oca/models/account_move.py @@ -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" + ) diff --git a/subscription_oca/models/product_template.py b/subscription_oca/models/product_template.py new file mode 100644 index 0000000000..c866cfa3ed --- /dev/null +++ b/subscription_oca/models/product_template.py @@ -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" + ) diff --git a/subscription_oca/models/res_partner.py b/subscription_oca/models/res_partner.py new file mode 100644 index 0000000000..e4107108e3 --- /dev/null +++ b/subscription_oca/models/res_partner.py @@ -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, + }, + } diff --git a/subscription_oca/models/sale_order.py b/subscription_oca/models/sale_order.py new file mode 100644 index 0000000000..0aabac0cb8 --- /dev/null +++ b/subscription_oca/models/sale_order.py @@ -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 diff --git a/subscription_oca/models/sale_order_line.py b/subscription_oca/models/sale_order_line.py new file mode 100644 index 0000000000..b843e48f7f --- /dev/null +++ b/subscription_oca/models/sale_order_line.py @@ -0,0 +1,17 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + def get_subscription_line_values(self): + return { + "product_id": self.product_id.id, + "name": self.product_id.name, + "product_uom_qty": self.product_uom_qty, + "price_unit": self.price_unit, + "discount": self.discount, + "price_subtotal": self.price_subtotal, + } diff --git a/subscription_oca/models/sale_subscription.py b/subscription_oca/models/sale_subscription.py new file mode 100644 index 0000000000..4cc562ee49 --- /dev/null +++ b/subscription_oca/models/sale_subscription.py @@ -0,0 +1,470 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import logging +from datetime import date, datetime + +from dateutil.relativedelta import relativedelta + +from odoo import _, api, fields, models +from odoo.exceptions import AccessError + +logger = logging.getLogger(__name__) + + +class SaleSubscription(models.Model): + _name = "sale.subscription" + _description = "Subscription" + _inherit = ["mail.thread", "mail.activity.mixin"] + _order = "id desc" + + color = fields.Integer("Color Index") + name = fields.Char( + compute="_compute_name", + store=True, + ) + sequence = fields.Integer() + company_id = fields.Many2one( + "res.company", + "Company", + required=True, + index=True, + default=lambda self: self.env.company, + ) + partner_id = fields.Many2one( + comodel_name="res.partner", required=True, string="Partner", index=True + ) + fiscal_position_id = fields.Many2one( + "account.fiscal.position", + string="Fiscal Position", + domain="[('company_id', '=', company_id)]", + check_company=True, + ) + active = fields.Boolean(default=True) + template_id = fields.Many2one( + comodel_name="sale.subscription.template", + required=True, + string="Subscription template", + ) + code = fields.Char( + string="Reference", + default=lambda self: self.env["ir.sequence"].next_by_code("sale.subscription"), + ) + in_progress = fields.Boolean(string="In progress", default=False) + recurring_rule_boundary = fields.Boolean( + string="Boundary", compute="_compute_rule_boundary", store=True + ) + pricelist_id = fields.Many2one( + comodel_name="product.pricelist", required=True, string="Pricelist" + ) + recurring_next_date = fields.Date(string="Next invoice date", default=date.today()) + user_id = fields.Many2one( + comodel_name="res.users", + string="Commercial agent", + default=lambda self: self.env.user.id, + ) + date_start = fields.Date(string="Start date", default=date.today()) + date = fields.Date( + string="Finish date", + compute="_compute_rule_boundary", + store=True, + readonly=False, + ) + description = fields.Text() + sale_order_id = fields.Many2one( + comodel_name="sale.order", string="Origin sale order" + ) + terms = fields.Text( + string="Terms and conditions", + compute="_compute_terms", + store=True, + readonly=False, + ) + invoice_ids = fields.One2many( + comodel_name="account.move", + inverse_name="subscription_id", + string="Invoices", + ) + sale_order_ids = fields.One2many( + comodel_name="sale.order", + inverse_name="order_subscription_id", + string="Orders", + ) + recurring_total = fields.Monetary( + compute="_compute_total", string="Recurring price", store=True + ) + amount_tax = fields.Monetary(compute="_compute_total", store=True) + amount_total = fields.Monetary(compute="_compute_total", store=True) + tag_ids = fields.Many2many(comodel_name="sale.subscription.tag", string="Tags") + image = fields.Binary("Image", related="user_id.image_512", store=True) + journal_id = fields.Many2one(comodel_name="account.journal", string="Journal") + currency_id = fields.Many2one( + related="pricelist_id.currency_id", + depends=["pricelist_id"], + store=True, + ondelete="restrict", + ) + + @api.model + def _read_group_stage_ids(self, stages, domain, order): + stage_ids = stages.search([], order=order) + return stage_ids + + stage_id = fields.Many2one( + comodel_name="sale.subscription.stage", + string="Stage", + tracking=True, + group_expand="_read_group_stage_ids", + store="true", + ) + stage_str = fields.Char( + related="stage_id.name", + string="Etapa", + store=True, + ) + sale_subscription_line_ids = fields.One2many( + comodel_name="sale.subscription.line", + inverse_name="sale_subscription_id", + ) + sale_order_ids_count = fields.Integer( + compute="_compute_sale_order_ids_count", string="Sale orders" + ) + account_invoice_ids_count = fields.Integer( + compute="_compute_account_invoice_ids_count", string="Invoice Count" + ) + close_reason_id = fields.Many2one( + comodel_name="sale.subscription.close.reason", string="Close Reason" + ) + crm_team_id = fields.Many2one(comodel_name="crm.team", string="Sale team") + to_renew = fields.Boolean(default=False, string="To renew") + + def cron_subscription_management(self): + today = date.today() + for subscription in self.search([]): + if subscription.in_progress: + if ( + subscription.recurring_next_date == today + and subscription.sale_subscription_line_ids + ): + try: + subscription.generate_invoice() + except Exception: + logger.exception("Error on subscription invoice generate") + if not subscription.recurring_rule_boundary: + if subscription.date == today: + subscription.action_close_subscription() + + else: + if subscription.date_start == today: + subscription.action_start_subscription() + subscription.generate_invoice() + + @api.depends("sale_subscription_line_ids") + def _compute_total(self): + for record in self: + recurring_total = amount_tax = 0.0 + for order_line in record.sale_subscription_line_ids: + recurring_total += order_line.price_subtotal + amount_tax += order_line.amount_tax_line_amount + record.update( + { + "recurring_total": recurring_total, + "amount_tax": amount_tax, + "amount_total": recurring_total + amount_tax, + } + ) + + @api.depends("template_id", "code") + def _compute_name(self): + for record in self: + template_code = record.template_id.code if record.template_id.code else "" + code = record.code if record.code else "" + slash = "/" if template_code and code else "" + record.name = "{}{}{}".format(template_code, slash, code) + + @api.depends("template_id", "date_start") + def _compute_rule_boundary(self): + for record in self: + if record.template_id.recurring_rule_boundary == "unlimited": + record.date = False + record.recurring_rule_boundary = True + else: + record.date = ( + relativedelta(months=+record.template_id.recurring_rule_count) + + record.date_start + ) + record.recurring_rule_boundary = False + + @api.depends("template_id") + def _compute_terms(self): + for record in self: + record.terms = record.template_id.description + + @api.onchange("template_id", "date_start") + def _onchange_template_id(self): + today = date.today() + if self.date_start: + today = self.date_start + if self.template_id and self.account_invoice_ids_count > 0: + self.calculate_recurring_next_date(self.recurring_next_date) + else: + self.calculate_recurring_next_date(today) + + def calculate_recurring_next_date(self, start_date): + if self.account_invoice_ids_count == 0: + self.recurring_next_date = date.today() + else: + type_interval = self.template_id.recurring_rule_type + interval = int(self.template_id.recurring_interval) + self.recurring_next_date = start_date + relativedelta( + **{type_interval: interval} + ) + + @api.onchange("partner_id") + def onchange_partner_id(self): + self.pricelist_id = self.partner_id.property_product_pricelist + + @api.onchange("partner_id", "company_id") + def onchange_partner_id_fpos(self): + self.fiscal_position_id = ( + self.env["account.fiscal.position"] + .with_company(self.company_id) + .get_fiscal_position(self.partner_id.id) + ) + + def action_start_subscription(self): + self.close_reason_id = False + in_progress_stage = self.env["sale.subscription.stage"].search( + [("type", "=", "in_progress")], limit=1 + ) + self.stage_id = in_progress_stage + + def action_close_subscription(self): + self.recurring_next_date = False + return { + "view_type": "form", + "view_mode": "form", + "res_model": "close.reason.wizard", + "type": "ir.actions.act_window", + "target": "new", + "res_id": False, + } + + def _prepare_sale_order(self, line_ids=False): + self.ensure_one() + return { + "partner_id": self.partner_id.id, + "fiscal_position_id": self.fiscal_position_id.id, + "date_order": datetime.now(), + "payment_term_id": self.partner_id.property_payment_term_id.id, + "user_id": self.user_id.id, + "origin": self.name, + "order_line": line_ids, + } + + def _prepare_account_move(self, line_ids): + self.ensure_one() + values = { + "partner_id": self.partner_id.id, + "invoice_date": self.recurring_next_date, + "invoice_payment_term_id": self.partner_id.property_payment_term_id.id, + "invoice_origin": self.name, + "invoice_user_id": self.user_id.id, + "partner_bank_id": self.company_id.partner_id.bank_ids[:1].id, + "invoice_line_ids": line_ids, + } + if self.journal_id: + values["journal_id"] = self.journal_id.id + return values + + def create_invoice(self): + if not self.env["account.move"].check_access_rights("create", False): + try: + self.check_access_rights("write") + self.check_access_rule("write") + except AccessError: + return self.env["account.move"] + line_ids = [] + for line in self.sale_subscription_line_ids: + line_values = line._prepare_account_move_line() + line_ids.append((0, 0, line_values)) + invoice_values = self._prepare_account_move(line_ids) + invoice_id = ( + self.env["account.move"] + .sudo() + .with_context(default_move_type="out_invoice", journal_type="sale") + .create(invoice_values) + ) + self.write({"invoice_ids": [(4, invoice_id.id)]}) + return invoice_id + + def create_sale_order(self): + if not self.env["sale.order"].check_access_rights("create", False): + try: + self.check_access_rights("write") + self.check_access_rule("write") + except AccessError: + return self.env["sale.order"] + line_ids = [] + for line in self.sale_subscription_line_ids: + line_values = line._prepare_sale_order_line() + line_ids.append((0, 0, line_values)) + values = self._prepare_sale_order(line_ids) + order_id = self.env["sale.order"].sudo().create(values) + self.write({"sale_order_ids": [(4, order_id.id)]}) + return order_id + + def generate_invoice(self): + invoice_number = "" + msg_static = _("Created invoice with reference") + if self.template_id.invoicing_mode in ["draft", "invoice", "invoice_send"]: + invoice = self.create_invoice() + if self.template_id.invoicing_mode != "draft": + invoice.action_post() + if self.template_id.invoicing_mode == "invoice_send": + mail_template = self.template_id.invoice_mail_template_id + invoice.with_context(force_send=True).message_post_with_template( + mail_template.id, + composition_mode="comment", + email_layout_xmlid="mail.mail_notification_paynow", + ) + invoice_number = invoice.name + message_body = ( + "%s %s" + % (msg_static, invoice.id, invoice_number) + ) + + if self.template_id.invoicing_mode == "sale_and_invoice": + order_id = self.create_sale_order() + order_id.action_done() + new_invoice = order_id._create_invoices() + new_invoice.action_post() + new_invoice.invoice_origin = order_id.name + ", " + self.name + invoice_number = new_invoice.name + message_body = ( + "%s %s" + % (msg_static, new_invoice.id, invoice_number) + ) + if not invoice_number: + invoice_number = _("To validate") + message_body = "%s %s" % (msg_static, invoice_number) + self.calculate_recurring_next_date(self.recurring_next_date) + self.message_post(body=message_body) + + def manual_invoice(self): + invoice_id = self.create_invoice() + self.calculate_recurring_next_date(self.recurring_next_date) + context = dict(self.env.context) + context["form_view_initial_mode"] = "edit" + return { + "name": self.name, + "views": [ + (self.env.ref("account.view_move_form").id, "form"), + (self.env.ref("account.view_move_tree").id, "tree"), + ], + "view_type": "form", + "view_mode": "form", + "res_model": "account.move", + "res_id": invoice_id.id, + "type": "ir.actions.act_window", + "context": context, + } + + @api.depends("invoice_ids", "sale_order_ids.invoice_ids") + def _compute_account_invoice_ids_count(self): + for record in self: + record.account_invoice_ids_count = len(self.invoice_ids) + len( + self.sale_order_ids.invoice_ids + ) + + def action_view_account_invoice_ids(self): + return { + "name": self.name, + "views": [ + (self.env.ref("account.view_move_tree").id, "tree"), + (self.env.ref("account.view_move_form").id, "form"), + ], + "view_type": "form", + "view_mode": "tree,form", + "res_model": "account.move", + "type": "ir.actions.act_window", + "domain": [ + ("id", "in", self.invoice_ids.ids + self.sale_order_ids.invoice_ids.ids) + ], + "context": self.env.context, + } + + def _compute_sale_order_ids_count(self): + data = self.env["sale.order"].read_group( + domain=[("order_subscription_id", "in", self.ids)], + fields=["order_subscription_id"], + groupby=["order_subscription_id"], + ) + count_dict = { + item["order_subscription_id"][0]: item["order_subscription_id_count"] + for item in data + } + for record in self: + record.sale_order_ids_count = count_dict.get(record.id, 0) + + def action_view_sale_order_ids(self): + active_ids = self.sale_order_ids.ids + return { + "name": self.name, + "view_type": "form", + "view_mode": "tree,form", + "res_model": "sale.order", + "type": "ir.actions.act_window", + "domain": [("id", "in", active_ids)], + "context": self.env.context, + } + + def _check_dates(self, start, next_invoice): + if start and next_invoice: + date_start = start + date_next_invoice = next_invoice + if not isinstance(date_start, date) and not isinstance( + date_next_invoice, date + ): + date_start = fields.Date.to_date(start) + date_next_invoice = fields.Date.to_date(next_invoice) + if date_start > date_next_invoice: + return True + return False + + def write(self, values): + res = super().write(values) + if "stage_id" in values: + for record in self: + if record.stage_id: + if record.stage_id.type == "in_progress": + record.in_progress = True + record.date_start = date.today() + elif record.stage_id.type == "post": + record.close_reason_id = False + record.in_progress = False + else: + record.in_progress = False + + return res + + @api.model + def create(self, values): + if "recurring_rule_boundary" in values: + if not values["recurring_rule_boundary"]: + template_id = self.env["sale.subscription.template"].search( + [("id", "=", values["template_id"])] + ) + date_start = values["date_start"] + if not isinstance(values["date_start"], date): + date_start = fields.Date.to_date(values["date_start"]) + values["date"] = template_id._get_date(date_start) + if "date_start" in values and "recurring_next_date" in values: + res = self._check_dates(values["date_start"], values["recurring_next_date"]) + if res: + values["date_start"] = values["recurring_next_date"] + values["stage_id"] = ( + self.env["sale.subscription.stage"] + .search([("type", "=", "pre")], order="sequence desc")[-1] + .id + ) + return super(SaleSubscription, self).create(values) diff --git a/subscription_oca/models/sale_subscription_close_reason.py b/subscription_oca/models/sale_subscription_close_reason.py new file mode 100644 index 0000000000..36107a0296 --- /dev/null +++ b/subscription_oca/models/sale_subscription_close_reason.py @@ -0,0 +1,10 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class SaleSubscriptionCloseReason(models.Model): + _name = "sale.subscription.close.reason" + _description = "Close reason model" + + name = fields.Char(required=True) diff --git a/subscription_oca/models/sale_subscription_line.py b/subscription_oca/models/sale_subscription_line.py new file mode 100644 index 0000000000..b90792d1b5 --- /dev/null +++ b/subscription_oca/models/sale_subscription_line.py @@ -0,0 +1,322 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import api, fields, models +from odoo.tools.misc import get_lang + + +class SaleSubscriptionLine(models.Model): + _name = "sale.subscription.line" + _description = "Subscription lines added to a given subscription" + + product_id = fields.Many2one( + comodel_name="product.product", + domain=[("sale_ok", "=", True)], + string="Product", + ) + currency_id = fields.Many2one( + "res.currency", + related="sale_subscription_id.currency_id", + store=True, + readonly=True, + ) + name = fields.Char( + string="Description", compute="_compute_name", store=True, readonly=False + ) + product_uom_qty = fields.Float(default=1.0, string="Quantity") + price_unit = fields.Float( + string="Unit price", compute="_compute_price_unit", store=True, readonly=False + ) + discount = fields.Float( + string="Discount (%)", compute="_compute_discount", store=True, readonly=False + ) + tax_ids = fields.Many2many( + comodel_name="account.tax", + relation="subscription_line_tax", + column1="subscription_line_id", + column2="tax_id", + string="Taxes", + compute="_compute_tax_ids", + store=True, + readonly=False, + ) + + @api.depends("product_id", "price_unit", "product_uom_qty", "discount", "tax_ids") + def _compute_subtotal(self): + for record in self: + price = record.price_unit * (1 - (record.discount or 0.0) / 100.0) + taxes = record.tax_ids.compute_all( + price, + record.currency_id, + record.product_uom_qty, + product=record.product_id, + partner=record.sale_subscription_id.partner_id, + ) + record.update( + { + "amount_tax_line_amount": sum( + t.get("amount", 0.0) for t in taxes.get("taxes", []) + ), + "price_total": taxes["total_included"], + "price_subtotal": taxes["total_excluded"], + } + ) + + price_subtotal = fields.Monetary( + string="Subtotal", readonly="True", compute=_compute_subtotal, store=True + ) + price_total = fields.Monetary( + string="Total", readonly="True", compute=_compute_subtotal, store=True + ) + amount_tax_line_amount = fields.Float( + string="Taxes Amount", compute="_compute_subtotal", store=True + ) + sale_subscription_id = fields.Many2one( + comodel_name="sale.subscription", string="Subscription" + ) + company_id = fields.Many2one( + related="sale_subscription_id.company_id", + string="Company", + store=True, + index=True, + ) + + @api.depends("product_id") + def _compute_name(self): + for record in self: + if not record.product_id: + record.name = False + lang = get_lang(self.env, record.sale_subscription_id.partner_id.lang).code + product = record.product_id.with_context(lang=lang) + record.name = product.with_context( + lang=lang + ).get_product_multiline_description_sale() + + @api.depends("product_id", "sale_subscription_id.fiscal_position_id") + def _compute_tax_ids(self): + for line in self: + fpos = ( + line.sale_subscription_id.fiscal_position_id + or line.sale_subscription_id.fiscal_position_id.get_fiscal_position( + line.sale_subscription_id.partner_id.id + ) + ) + # If company_id is set, always filter taxes by the company + taxes = line.product_id.taxes_id.filtered( + lambda t: t.company_id == line.env.company + ) + line.tax_ids = fpos.map_tax(taxes) + + @api.depends( + "product_id", + "sale_subscription_id.partner_id", + "sale_subscription_id.pricelist_id", + ) + def _compute_price_unit(self): + for record in self: + if not record.product_id: + continue + if ( + record.sale_subscription_id.pricelist_id + and record.sale_subscription_id.partner_id + ): + product = record.product_id.with_context( + partner=record.sale_subscription_id.partner_id, + quantity=record.product_uom_qty, + date=fields.datetime.now(), + pricelist=record.sale_subscription_id.pricelist_id.id, + uom=record.product_id.uom_id.id, + ) + record.price_unit = product._get_tax_included_unit_price( + record.company_id, + record.sale_subscription_id.currency_id, + fields.datetime.now(), + "sale", + fiscal_position=record.sale_subscription_id.fiscal_position_id, + product_price_unit=record._get_display_price(product), + product_currency=record.sale_subscription_id.currency_id, + ) + + @api.depends( + "product_id", + "price_unit", + "product_uom_qty", + "tax_ids", + "sale_subscription_id.partner_id", + "sale_subscription_id.pricelist_id", + ) + def _compute_discount(self): + for record in self: + if not ( + record.product_id + and record.product_id.uom_id + and record.sale_subscription_id.partner_id + and record.sale_subscription_id.pricelist_id + and record.sale_subscription_id.pricelist_id.discount_policy + == "without_discount" + and self.env.user.has_group("product.group_discount_per_so_line") + ): + record.discount = 0.0 + continue + + record.discount = 0.0 + product = record.product_id.with_context( + lang=record.sale_subscription_id.partner_id.lang, + partner=record.sale_subscription_id.partner_id, + quantity=record.product_uom_qty, + date=fields.Datetime.now(), + pricelist=record.sale_subscription_id.pricelist_id.id, + uom=record.product_id.uom_id.id, + fiscal_position=record.sale_subscription_id.fiscal_position_id + or self.env.context.get("fiscal_position"), + ) + + price, rule_id = record.sale_subscription_id.pricelist_id.with_context( + partner_id=record.sale_subscription_id.partner_id.id, + date=fields.Datetime.now(), + uom=record.product_id.uom_id.id, + ).get_product_price_rule( + record.product_id, + record.product_uom_qty or 1.0, + record.sale_subscription_id.partner_id, + ) + new_list_price, currency = record.with_context( + partner_id=record.sale_subscription_id.partner_id.id, + date=fields.Datetime.now(), + uom=record.product_id.uom_id.id, + )._get_real_price_currency( + product, rule_id, record.product_uom_qty, record.product_id.uom_id + ) + + if new_list_price != 0: + if record.sale_subscription_id.pricelist_id.currency_id != currency: + new_list_price = currency._convert( + new_list_price, + record.sale_subscription_id.pricelist_id.currency_id, + record.sale_subscription_id.company_id or self.env.company, + fields.Date.today(), + ) + discount = (new_list_price - price) / new_list_price * 100 + if (discount > 0 and new_list_price > 0) or ( + discount < 0 and new_list_price < 0 + ): + record.discount = discount + + def _get_real_price_currency(self, product, rule_id, qty, uom): + PricelistItem = self.env["product.pricelist.item"] + field_name = "lst_price" + currency_id = None + product_currency = product.currency_id + if rule_id: + pricelist_item = PricelistItem.browse(rule_id) + if pricelist_item.pricelist_id.discount_policy == "without_discount": + while ( + pricelist_item.base == "pricelist" + and pricelist_item.base_pricelist_id + and pricelist_item.base_pricelist_id.discount_policy + == "without_discount" + ): + _price, rule_id = pricelist_item.base_pricelist_id.with_context( + uom=uom.id + ).get_product_price_rule( + product, qty, self.sale_subscription_id.partner_id + ) + pricelist_item = PricelistItem.browse(rule_id) + + if pricelist_item.base == "standard_price": + field_name = "standard_price" + product_currency = product.cost_currency_id + elif ( + pricelist_item.base == "pricelist" and pricelist_item.base_pricelist_id + ): + field_name = "price" + product = product.with_context( + pricelist=pricelist_item.base_pricelist_id.id + ) + product_currency = pricelist_item.base_pricelist_id.currency_id + currency_id = pricelist_item.pricelist_id.currency_id + + if not currency_id: + currency_id = product_currency + cur_factor = 1.0 + else: + if currency_id.id == product_currency.id: + cur_factor = 1.0 + else: + cur_factor = currency_id._get_conversion_rate( + product_currency, + currency_id, + self.company_id or self.env.company, + fields.Date.today(), + ) + + product_uom = self.env.context.get("uom") or product.uom_id.id + if uom and uom.id != product_uom: + # the unit price is in a different uom + uom_factor = uom._compute_price(1.0, product.uom_id) + else: + uom_factor = 1.0 + + return product[field_name] * uom_factor * cur_factor, currency_id + + def _get_display_price(self, product): + if self.sale_subscription_id.pricelist_id.discount_policy == "with_discount": + return product.with_context( + pricelist=self.sale_subscription_id.pricelist_id.id, + uom=self.product_id.uom_id.id, + ).price + + final_price, rule_id = self.sale_subscription_id.pricelist_id.with_context( + partner_id=self.sale_subscription_id.partner_id.id, + date=fields.Datetime.now(), + uom=self.product_id.uom_id.id, + ).get_product_price_rule( + product or self.product_id, + self.product_uom_qty or 1.0, + self.sale_subscription_id.partner_id, + ) + base_price, currency = self.with_context( + partner_id=self.sale_subscription_id.partner_id.id, + date=fields.Datetime.now(), + uom=self.product_id.uom_id.id, + )._get_real_price_currency( + product, rule_id, self.product_uom_qty, self.product_id.uom_id + ) + if currency != self.sale_subscription_id.pricelist_id.currency_id: + base_price = currency._convert( + base_price, + self.sale_subscription_id.pricelist_id.currency_id, + self.sale_subscription_id.company_id or self.env.company, + fields.Date.today(), + ) + return max(base_price, final_price) + + def _prepare_sale_order_line(self): + self.ensure_one() + return { + "product_id": self.product_id.id, + "name": self.name, + "product_uom_qty": self.product_uom_qty, + "price_unit": self.price_unit, + "discount": self.discount, + "price_subtotal": self.price_subtotal, + "tax_id": self.tax_ids, + "product_uom": self.product_id.uom_id.id, + } + + def _prepare_account_move_line(self): + self.ensure_one() + account = ( + self.product_id.property_account_income_id + or self.product_id.categ_id.property_account_income_categ_id + ) + return { + "product_id": self.product_id.id, + "name": self.name, + "quantity": self.product_uom_qty, + "price_unit": self.price_unit, + "discount": self.discount, + "price_subtotal": self.price_subtotal, + "tax_ids": [(6, 0, self.tax_ids.ids)], + "product_uom_id": self.product_id.uom_id.id, + "account_id": account.id, + } diff --git a/subscription_oca/models/sale_subscription_stage.py b/subscription_oca/models/sale_subscription_stage.py new file mode 100644 index 0000000000..ee6b6bb460 --- /dev/null +++ b/subscription_oca/models/sale_subscription_stage.py @@ -0,0 +1,29 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models +from odoo.exceptions import ValidationError + + +class SaleSubscriptionStage(models.Model): + _name = "sale.subscription.stage" + _description = "Subscription stage" + _order = "sequence, name, id" + + name = fields.Char(required=True, translate=True) + sequence = fields.Integer() + display_name = fields.Char(string="Display name") + in_progress = fields.Boolean(string="In progress", default=False) + fold = fields.Boolean(string="Kanban folded") + description = fields.Text(translate=True) + type = fields.Selection( + [("pre", "Ready to start"), ("in_progress", "In progress"), ("post", "Closed")], + default="pre", + ) + + @api.constrains("type") + def _check_lot_product(self): + post_stages = self.env["sale.subscription.stage"].search( + [("type", "=", "post")] + ) + if len(post_stages) > 1: + raise ValidationError(_("There is already a Closed-type stage declared")) diff --git a/subscription_oca/models/sale_subscription_tag.py b/subscription_oca/models/sale_subscription_tag.py new file mode 100644 index 0000000000..19101a160f --- /dev/null +++ b/subscription_oca/models/sale_subscription_tag.py @@ -0,0 +1,10 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class SaleSubscriptionTag(models.Model): + _name = "sale.subscription.tag" + _description = "Tags for sale subscription" + + name = fields.Char("Tag name", required=True) diff --git a/subscription_oca/models/sale_subscription_template.py b/subscription_oca/models/sale_subscription_template.py new file mode 100644 index 0000000000..df89f401b0 --- /dev/null +++ b/subscription_oca/models/sale_subscription_template.py @@ -0,0 +1,102 @@ +# 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 api, fields, models + + +class SaleSubscriptionTemplate(models.Model): + _name = "sale.subscription.template" + _description = "Subscription templates" + + name = fields.Char(required=True) + description = fields.Text(string="Terms and conditions") + recurring_interval = fields.Integer(string="Repeat every", default=1) + recurring_rule_type = fields.Selection( + [ + ("days", "Day(s)"), + ("weeks", "Week(s)"), + ("months", "Month(s)"), + ("years", "Year(s)"), + ], + string="Recurrence", + default="months", + ) + recurring_rule_boundary = fields.Selection( + [("unlimited", "Forever"), ("limited", "Fixed")], + string="Duration", + default="unlimited", + ) + invoicing_mode = fields.Selection( + default="draft", + string="Invoicing mode", + selection=[ + ("draft", "Draft"), + ("invoice", "Invoice"), + ("invoice_send", "Invoice & send"), + ("sale_and_invoice", "Sale order & Invoice"), + ], + ) + code = fields.Char() + recurring_rule_count = fields.Integer(default=1, string="Rule count") + invoice_mail_template_id = fields.Many2one( + comodel_name="mail.template", + string="Invoice Email", + domain="[('model', '=', 'account.move')]", + ) + product_ids = fields.One2many( + comodel_name="product.template", + inverse_name="subscription_template_id", + string="Products", + ) + product_ids_count = fields.Integer( + compute="_compute_product_ids_count", string="product_ids" + ) + subscription_ids = fields.One2many( + comodel_name="sale.subscription", + inverse_name="template_id", + string="Subscriptions", + ) + subscription_count = fields.Integer( + compute="_compute_subscription_count", string="subscription_ids" + ) + + def _compute_subscription_count(self): + data = self.env["sale.subscription"].read_group( + domain=[("template_id", "in", self.ids)], + fields=["template_id"], + groupby=["template_id"], + ) + count_dict = { + item["template_id"][0]: item["template_id_count"] for item in data + } + for record in self: + record.subscription_count = count_dict.get(record.id, 0) + + def action_view_subscription_ids(self): + return { + "name": self.name, + "view_mode": "tree,form", + "res_model": "sale.subscription", + "type": "ir.actions.act_window", + "domain": [("id", "in", self.subscription_ids.ids)], + } + + def _get_date(self, date_start): + self.ensure_one() + return relativedelta(months=+self.recurring_rule_count) + date_start + + @api.depends("product_ids") + def _compute_product_ids_count(self): + for record in self: + record.product_ids_count = len(self.product_ids) + + def action_view_product_ids(self): + return { + "name": self.name, + "view_type": "form", + "view_mode": "tree,form", + "res_model": "product.template", + "type": "ir.actions.act_window", + "domain": [("id", "in", self.product_ids.ids)], + } diff --git a/subscription_oca/readme/CONTRIBUTORS.rst b/subscription_oca/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..e4139ac7d2 --- /dev/null +++ b/subscription_oca/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Carlos Martínez diff --git a/subscription_oca/readme/DESCRIPTION.rst b/subscription_oca/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..648d69835f --- /dev/null +++ b/subscription_oca/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module allows creating subscriptions that generate recurring invoices or orders. It also enables the sale of products that generate subscriptions. diff --git a/subscription_oca/readme/ROADMAP.rst b/subscription_oca/readme/ROADMAP.rst new file mode 100644 index 0000000000..c6355d44b0 --- /dev/null +++ b/subscription_oca/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +* Refactor all the onchanges that have business logic to computed write-able fields when possible. Keep onchanges only for UI purposes. +* Add tests. diff --git a/subscription_oca/readme/USAGE.rst b/subscription_oca/readme/USAGE.rst new file mode 100644 index 0000000000..4c5a5ed85a --- /dev/null +++ b/subscription_oca/readme/USAGE.rst @@ -0,0 +1,13 @@ +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. diff --git a/subscription_oca/security/ir.model.access.csv b/subscription_oca/security/ir.model.access.csv new file mode 100644 index 0000000000..cd0f7dba90 --- /dev/null +++ b/subscription_oca/security/ir.model.access.csv @@ -0,0 +1,8 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_custom_sale_subscription_template,sale.subscription.template,model_sale_subscription_template,sales_team.group_sale_salesman,1,1,1,1 +access_custom_sale_subscription,sale.subscription,model_sale_subscription,sales_team.group_sale_salesman,1,1,1,1 +access_custom_sale_subscription_close_reason,sale.subscription.close.reason,model_sale_subscription_close_reason,sales_team.group_sale_salesman,1,1,1,1 +access_custom_sale_subscription_stage,sale.subscription.stage,model_sale_subscription_stage,sales_team.group_sale_salesman,1,1,1,1 +access_custom_sale_subscription_line,sale.subscription.line,model_sale_subscription_line,sales_team.group_sale_salesman,1,1,1,1 +access_custom_sale_subscription_tag,sale.subscription.tag,model_sale_subscription_tag,sales_team.group_sale_salesman,1,1,1,1 +access_close_subscription,Close subscription access,model_close_reason_wizard,sales_team.group_sale_salesman,1,1,1,1 diff --git a/subscription_oca/static/description/index.html b/subscription_oca/static/description/index.html new file mode 100644 index 0000000000..5e4490677c --- /dev/null +++ b/subscription_oca/static/description/index.html @@ -0,0 +1,439 @@ + + + + + + +Subscription management + + + +
+

Subscription management

+ + +

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

+

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

+

Table of contents

+ +
+

Usage

+

To make a subscription:

+
    +
  1. Go to Subscriptions > Configuration > Subscription templates.
  2. +
  3. Create the templates you consider, choosing the billing frequency: daily, monthly… and the method of creating the invoice and/or order.
  4. +
  5. Go to Subscription > Subscriptions.
  6. +
  7. 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.
  8. +
  9. The cron job will also end the subscription if its end date has been reached.
  10. +
+

To create subscriptions with the sale of a product:

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

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Domatix
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/sale-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/subscription_oca/static/img/icon.png b/subscription_oca/static/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..bab981dd92b92c32d5d27f100be3ff90bfa3b561 GIT binary patch literal 16096 zcmcIr1ydYNw8hmWR}cAIb8`#!clxHO2MIK+u13;gvaNHg%!QWgFOMv|kXrG;x=TT`G6`X&e> zjB>1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st?qguNlaFj zQN6?)-erb+AqQ0W`CZlUhEtDn%3?dZ7EC>sNi9Wkx9gg8pMAWW{m$yi~tuX|1PK# zP)t5vDY!QFpk{@BM1o;t)$$Jvwqy`~(eC|3LN96@+yHc)2VbNg1pdDZB0d=CfOu-r zdy)*m2JY_><4&@)FY#Fuzz>NCt&>2WtQ0l9uI_o)U!zrqwRN^o0E2!NFH!HnYVpGW zgRhvjp_~5sNGGHXoB~haG>wBI;I=p4#{quEWm?f2@gJtn7T!ArY6>6kFs%R|= MPD)9#3TzDdAGpB)Gynhq literal 0 HcmV?d00001 diff --git a/subscription_oca/views/product_template_views.xml b/subscription_oca/views/product_template_views.xml new file mode 100644 index 0000000000..0ef00a86bc --- /dev/null +++ b/subscription_oca/views/product_template_views.xml @@ -0,0 +1,20 @@ + + + + product.template.sub.form + product.template + + + + + + + + + + + + diff --git a/subscription_oca/views/res_partner_views.xml b/subscription_oca/views/res_partner_views.xml new file mode 100644 index 0000000000..3be7a6690a --- /dev/null +++ b/subscription_oca/views/res_partner_views.xml @@ -0,0 +1,28 @@ + + + + + res.partner.form + res.partner + + + + + + + diff --git a/subscription_oca/views/sale_order_views.xml b/subscription_oca/views/sale_order_views.xml new file mode 100644 index 0000000000..674776bf1c --- /dev/null +++ b/subscription_oca/views/sale_order_views.xml @@ -0,0 +1,29 @@ + + + + view.sale_order.form + sale.order + + + + +

+ +
+ + + + + diff --git a/subscription_oca/views/sale_subscription_stage_views.xml b/subscription_oca/views/sale_subscription_stage_views.xml new file mode 100644 index 0000000000..8e6b0bd724 --- /dev/null +++ b/subscription_oca/views/sale_subscription_stage_views.xml @@ -0,0 +1,73 @@ + + + + + view.subscription.stage.form + sale.subscription.stage + +
+ + + + + + + + + + + + + + + +
+
+
+ + + view.subscription.stage.tree + sale.subscription.stage + + + + + + + + + + Susbcription stages + sale.subscription.stage + tree,form + +

+ Click to create a new subscription stage. +

+
+
+ + + +
diff --git a/subscription_oca/views/sale_subscription_tag_views.xml b/subscription_oca/views/sale_subscription_tag_views.xml new file mode 100644 index 0000000000..d5997c98c1 --- /dev/null +++ b/subscription_oca/views/sale_subscription_tag_views.xml @@ -0,0 +1,27 @@ + + + + view.sale.subscription.tag.tree + sale.subscription.tag + + + + + + + + + Tags + sale.subscription.tag + tree + + + + + diff --git a/subscription_oca/views/sale_subscription_template_views.xml b/subscription_oca/views/sale_subscription_template_views.xml new file mode 100644 index 0000000000..d683c55b7b --- /dev/null +++ b/subscription_oca/views/sale_subscription_template_views.xml @@ -0,0 +1,135 @@ + + + + + sale.subscription.template.form + sale.subscription.template + + +
+ + +
+ + +
+
+
+

+ +

+
+ + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+ + + sale.subscription.template.tree + sale.subscription.template + + + + + + + + + + + Subscription templates + sale.subscription.template + tree,form + + + +
diff --git a/subscription_oca/views/sale_subscription_views.xml b/subscription_oca/views/sale_subscription_views.xml new file mode 100644 index 0000000000..4279143483 --- /dev/null +++ b/subscription_oca/views/sale_subscription_views.xml @@ -0,0 +1,473 @@ + + + + + sale.subscription.form + sale.subscription + +
+
+
+ + +
+ + + + +
+ +
+

+ +

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + +
+
+
+
+ + + sale.subscription.tree + sale.subscription + + + + + + + + + + + + + + + + + + + sale.subscription.kanban + sale.subscription + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + +
+ +
+
+
+ +
+ +
+ +
+ + + , + + + + +
+ +
+
+ +
+
+ + + + + +
+
+ +
+
+
+
+
+
+
+ + + sale.order.pending.filter + sale.subscription + + + + + + + + + + product.suscribable.filter + product.template + + + + + + + + + + view.subscription.close.reason.tree + sale.subscription.close.reason + + + + + + + + + Close reasons + sale.subscription.close.reason + tree + + + + Subscriptions + sale.subscription + tree,kanban,form + + + + Products + product.template + tree,form + + {'search_default_subsproducts': True, "default_type": "service", "default_subscribable": True} + + + + + + + + + + + + + + + +
diff --git a/subscription_oca/wizard/__init__.py b/subscription_oca/wizard/__init__.py new file mode 100644 index 0000000000..a1aca59def --- /dev/null +++ b/subscription_oca/wizard/__init__.py @@ -0,0 +1 @@ +from . import close_subscription_wizard diff --git a/subscription_oca/wizard/close_subscription_wizard.py b/subscription_oca/wizard/close_subscription_wizard.py new file mode 100644 index 0000000000..1f38879e40 --- /dev/null +++ b/subscription_oca/wizard/close_subscription_wizard.py @@ -0,0 +1,25 @@ +# Copyright 2023 Domatix - Carlos Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class CloseSubscriptionWizard(models.TransientModel): + _name = "close.reason.wizard" + _description = "Close reason wizard" + + close_reason_id = fields.Many2one( + comodel_name="sale.subscription.close.reason", string="Reason" + ) + + def button_confirm(self): + sale_subscription = self.env["sale.subscription"].browse( + self.env.context["active_id"] + ) + sale_subscription.close_reason_id = self.close_reason_id.id + stage = sale_subscription.stage_id + closed_stage = self.env["sale.subscription.stage"].search( + [("type", "=", "post")], limit=1 + ) + if stage != closed_stage: + sale_subscription.stage_id = closed_stage + sale_subscription.active = False diff --git a/subscription_oca/wizard/close_subscription_wizard.xml b/subscription_oca/wizard/close_subscription_wizard.xml new file mode 100644 index 0000000000..132a897227 --- /dev/null +++ b/subscription_oca/wizard/close_subscription_wizard.xml @@ -0,0 +1,30 @@ + + + + close.reason.wizard.view + close.reason.wizard + +
+ + + +
+
+
+
+
+ + + Close reason + close.reason.wizard + form + new + +