Skip to content

Commit aeda8a9

Browse files
committed
[ADD] website_sale_subscription_form
1 parent 3ec360b commit aeda8a9

File tree

14 files changed

+804
-0
lines changed

14 files changed

+804
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../website_sale_subscription_form
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
============================
2+
E-commerce Subscription Form
3+
============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:d5514507c207937042ea64484cf364dd8c11232d97806933a51e12dcf7c534f9
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-coopiteasy%2Faddons-lightgray.png?logo=github
20+
:target: https://github.com/coopiteasy/addons/tree/16.0/website_sale_subscription_form
21+
:alt: coopiteasy/addons
22+
23+
|badge1| |badge2| |badge3|
24+
25+
Form to order subscription product
26+
27+
**Table of contents**
28+
29+
.. contents::
30+
:local:
31+
32+
Bug Tracker
33+
===========
34+
35+
Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/issues>`_.
36+
In case of trouble, please check there if your issue has already been reported.
37+
If you spotted it first, help us to smash it by providing a detailed and welcomed
38+
`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**>`_.
39+
40+
Do not contact contributors directly about support or help with technical issues.
41+
42+
Credits
43+
=======
44+
45+
Authors
46+
~~~~~~~
47+
48+
* Coop IT Easy SC
49+
50+
Contributors
51+
~~~~~~~~~~~~
52+
53+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
54+
55+
* Rémy Taymans
56+
57+
Maintainers
58+
~~~~~~~~~~~
59+
60+
.. |maintainer-remytms| image:: https://github.com/remytms.png?size=40px
61+
:target: https://github.com/remytms
62+
:alt: remytms
63+
64+
Current maintainer:
65+
66+
|maintainer-remytms|
67+
68+
This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/16.0/website_sale_subscription_form>`_ project on GitHub.
69+
70+
You are welcome to contribute.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
from . import models
5+
from . import controllers
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
{
6+
"name": "E-commerce Subscription Form",
7+
"summary": """
8+
Form to order subscription product""",
9+
"version": "16.0.1.0.0",
10+
"category": "Website",
11+
"website": "https://github.com/coopiteasy/addons",
12+
"author": "Coop IT Easy SC",
13+
"maintainers": ["remytms"],
14+
"license": "AGPL-3",
15+
"application": False,
16+
"depends": [
17+
"website_sale",
18+
"product_contract",
19+
],
20+
"excludes": [],
21+
"data": [
22+
"views/templates.xml",
23+
],
24+
"demo": [],
25+
"qweb": [],
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
from . import main
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import http
6+
from odoo.http import request
7+
8+
from odoo.addons.website_sale.controllers.main import WebsiteSale
9+
10+
SEPA_DEBIT_SUB_DATA = "sepa_debit_subscription_data"
11+
12+
13+
class SubscriptionForm(http.Controller):
14+
@http.route(
15+
[
16+
"/sepa-debit-subscription",
17+
"/sepa-debit-subscription/product/<int:pid>",
18+
],
19+
auth="public",
20+
website=True,
21+
sitemap=False,
22+
)
23+
def sepa_debit_subscriptions(self, pid=None):
24+
"""Show list of available subscription"""
25+
if SEPA_DEBIT_SUB_DATA in request.session:
26+
del request.session[SEPA_DEBIT_SUB_DATA]
27+
products = request.env["product.product"].search(
28+
[("is_contract", "=", True), ("website_published", "=", True)]
29+
)
30+
product = request.env["product.product"].browse(pid).exists()
31+
if product and product in products:
32+
request.session[SEPA_DEBIT_SUB_DATA] = {
33+
"product_id": product.id,
34+
}
35+
return request.redirect("/web/login?redirect=/shop/checkout")
36+
values = {
37+
"products": products,
38+
}
39+
return request.render(
40+
"website_sale_subscription_form.sepa_debit_subscriptions", values
41+
)
42+
43+
44+
class WebsiteSaleSubscription(WebsiteSale):
45+
@http.route(
46+
[
47+
"/shop",
48+
"/shop/page/<int:page>",
49+
'/shop/category/<model("product.public.category"):category>',
50+
'/shop/category/<model("product.public.category"):category>/page/<int:page>',
51+
],
52+
type="http",
53+
auth="public",
54+
website=True,
55+
sitemap=WebsiteSale.sitemap_shop,
56+
)
57+
def shop(
58+
self,
59+
page=0,
60+
category=None,
61+
search="",
62+
min_price=0.0,
63+
max_price=0.0,
64+
ppg=False,
65+
**post
66+
):
67+
if SEPA_DEBIT_SUB_DATA in request.session:
68+
del request.session[SEPA_DEBIT_SUB_DATA]
69+
return super().shop(
70+
page=page,
71+
category=category,
72+
search=search,
73+
min_price=min_price,
74+
max_price=max_price,
75+
ppg=ppg,
76+
**post,
77+
)
78+
79+
@http.route(
80+
["/shop/checkout"], type="http", auth="public", website=True, sitemap=False
81+
)
82+
def checkout(self, **post):
83+
result = super().checkout(**post)
84+
if "sepa_debit_subscription_data" in request.session:
85+
if result.template == "website_sale.checkout":
86+
result.qcontext["only_services"] = False
87+
return result
88+
89+
@http.route(
90+
"/shop/payment", type="http", auth="public", website=True, sitemap=False
91+
)
92+
def shop_payment(self, **post):
93+
if request.httprequest.method == "POST":
94+
# TODO: record IBAN and SEPA mandate
95+
order = request.website.sale_get_order()
96+
# FIXME: save order before ? or use dedicated existing
97+
# route ?
98+
order.with_context(send_email=True).action_confirm()
99+
return request.redirect(order.get_portal_url())
100+
return super().shop_payment(**post)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
from . import sale_order
5+
from . import website
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import fields, models
6+
7+
8+
class SaleOrder(models.Model):
9+
_inherit = "sale.order"
10+
11+
is_sepa_dd_payment = fields.Boolean(compute="_compute_is_sepa_dd_payment")
12+
13+
def _compute_is_sepa_dd_payment(self):
14+
payment_mode = self.env["account.payment.mode"].search(
15+
[("payment_method_id.code", "=", "sepa_direct_debit")],
16+
limit=1,
17+
)
18+
for order in self:
19+
order.is_sepa_dd_payment = payment_mode == order.payment_mode_id
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import models
6+
from odoo.http import request
7+
8+
9+
class Website(models.Model):
10+
_inherit = "website"
11+
12+
def sale_get_order(self, force_create=False, update_pricelist=False):
13+
"""Return the default order or the order from"""
14+
if "sepa_debit_subscription_data" in request.session:
15+
sds_data = request.session["sepa_debit_subscription_data"]
16+
payment_mode = request.env.ref(
17+
"account_banking_sepa_direct_debit.sepa_direct_debit"
18+
)
19+
product = request.env["product.product"].browse(sds_data.get("product_id"))
20+
order = (
21+
request.env["sale.order"]
22+
.sudo()
23+
.new(
24+
{
25+
"partner_id": request.env.user.partner_id.id,
26+
"order_line": [
27+
(
28+
0,
29+
0,
30+
{
31+
"product_id": product.id,
32+
"product_uom_qty": 1,
33+
},
34+
),
35+
],
36+
"payment_mode_id": payment_mode.id,
37+
}
38+
)
39+
)
40+
return order
41+
else:
42+
return super().sale_get_order(
43+
force_create=force_create,
44+
update_pricelist=update_pricelist,
45+
)

0 commit comments

Comments
 (0)