Skip to content

Commit

Permalink
[ADD] website_sale_subscription_form
Browse files Browse the repository at this point in the history
  • Loading branch information
remytms committed Nov 19, 2024
1 parent 3ec360b commit aeda8a9
Show file tree
Hide file tree
Showing 14 changed files with 804 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_sale_subscription_form/setup.py
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,
)
70 changes: 70 additions & 0 deletions website_sale_subscription_form/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
============================
E-commerce Subscription Form
============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d5514507c207937042ea64484cf364dd8c11232d97806933a51e12dcf7c534f9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-coopiteasy%2Faddons-lightgray.png?logo=github
:target: https://github.com/coopiteasy/addons/tree/16.0/website_sale_subscription_form
:alt: coopiteasy/addons

|badge1| |badge2| |badge3|

Form to order subscription product

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/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/coopiteasy/addons/issues/new?body=module:%20website_sale_subscription_form%0Aversion:%2016.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
~~~~~~~

* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Rémy Taymans

Maintainers
~~~~~~~~~~~

.. |maintainer-remytms| image:: https://github.com/remytms.png?size=40px
:target: https://github.com/remytms
:alt: remytms

Current maintainer:

|maintainer-remytms|

This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/16.0/website_sale_subscription_form>`_ project on GitHub.

You are welcome to contribute.
5 changes: 5 additions & 0 deletions website_sale_subscription_form/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import models
from . import controllers
26 changes: 26 additions & 0 deletions website_sale_subscription_form/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

{
"name": "E-commerce Subscription Form",
"summary": """
Form to order subscription product""",
"version": "16.0.1.0.0",
"category": "Website",
"website": "https://github.com/coopiteasy/addons",
"author": "Coop IT Easy SC",
"maintainers": ["remytms"],
"license": "AGPL-3",
"application": False,
"depends": [
"website_sale",
"product_contract",
],
"excludes": [],
"data": [
"views/templates.xml",
],
"demo": [],
"qweb": [],
}
4 changes: 4 additions & 0 deletions website_sale_subscription_form/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import main
100 changes: 100 additions & 0 deletions website_sale_subscription_form/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import http
from odoo.http import request

from odoo.addons.website_sale.controllers.main import WebsiteSale

SEPA_DEBIT_SUB_DATA = "sepa_debit_subscription_data"


class SubscriptionForm(http.Controller):
@http.route(
[
"/sepa-debit-subscription",
"/sepa-debit-subscription/product/<int:pid>",
],
auth="public",
website=True,
sitemap=False,
)
def sepa_debit_subscriptions(self, pid=None):
"""Show list of available subscription"""
if SEPA_DEBIT_SUB_DATA in request.session:
del request.session[SEPA_DEBIT_SUB_DATA]
products = request.env["product.product"].search(
[("is_contract", "=", True), ("website_published", "=", True)]
)
product = request.env["product.product"].browse(pid).exists()
if product and product in products:
request.session[SEPA_DEBIT_SUB_DATA] = {
"product_id": product.id,
}
return request.redirect("/web/login?redirect=/shop/checkout")
values = {
"products": products,
}
return request.render(
"website_sale_subscription_form.sepa_debit_subscriptions", values
)


class WebsiteSaleSubscription(WebsiteSale):
@http.route(
[
"/shop",
"/shop/page/<int:page>",
'/shop/category/<model("product.public.category"):category>',
'/shop/category/<model("product.public.category"):category>/page/<int:page>',
],
type="http",
auth="public",
website=True,
sitemap=WebsiteSale.sitemap_shop,
)
def shop(
self,
page=0,
category=None,
search="",
min_price=0.0,
max_price=0.0,
ppg=False,
**post
):
if SEPA_DEBIT_SUB_DATA in request.session:
del request.session[SEPA_DEBIT_SUB_DATA]
return super().shop(
page=page,
category=category,
search=search,
min_price=min_price,
max_price=max_price,
ppg=ppg,
**post,
)

@http.route(
["/shop/checkout"], type="http", auth="public", website=True, sitemap=False
)
def checkout(self, **post):
result = super().checkout(**post)
if "sepa_debit_subscription_data" in request.session:
if result.template == "website_sale.checkout":
result.qcontext["only_services"] = False
return result

@http.route(
"/shop/payment", type="http", auth="public", website=True, sitemap=False
)
def shop_payment(self, **post):
if request.httprequest.method == "POST":
# TODO: record IBAN and SEPA mandate
order = request.website.sale_get_order()
# FIXME: save order before ? or use dedicated existing
# route ?
order.with_context(send_email=True).action_confirm()
return request.redirect(order.get_portal_url())
return super().shop_payment(**post)
5 changes: 5 additions & 0 deletions website_sale_subscription_form/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from . import sale_order
from . import website
19 changes: 19 additions & 0 deletions website_sale_subscription_form/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import fields, models


class SaleOrder(models.Model):
_inherit = "sale.order"

is_sepa_dd_payment = fields.Boolean(compute="_compute_is_sepa_dd_payment")

def _compute_is_sepa_dd_payment(self):
payment_mode = self.env["account.payment.mode"].search(
[("payment_method_id.code", "=", "sepa_direct_debit")],
limit=1,
)
for order in self:
order.is_sepa_dd_payment = payment_mode == order.payment_mode_id
45 changes: 45 additions & 0 deletions website_sale_subscription_form/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import models
from odoo.http import request


class Website(models.Model):
_inherit = "website"

def sale_get_order(self, force_create=False, update_pricelist=False):
"""Return the default order or the order from"""
if "sepa_debit_subscription_data" in request.session:
sds_data = request.session["sepa_debit_subscription_data"]
payment_mode = request.env.ref(
"account_banking_sepa_direct_debit.sepa_direct_debit"
)
product = request.env["product.product"].browse(sds_data.get("product_id"))
order = (
request.env["sale.order"]
.sudo()
.new(
{
"partner_id": request.env.user.partner_id.id,
"order_line": [
(
0,
0,
{
"product_id": product.id,
"product_uom_qty": 1,
},
),
],
"payment_mode_id": payment_mode.id,
}
)
)
return order
else:
return super().sale_get_order(
force_create=force_create,
update_pricelist=update_pricelist,
)
3 changes: 3 additions & 0 deletions website_sale_subscription_form/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Rémy Taymans
1 change: 1 addition & 0 deletions website_sale_subscription_form/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Form to order subscription product
Loading

0 comments on commit aeda8a9

Please sign in to comment.