Skip to content

Commit 32fb4ad

Browse files
committed
[ADD] website_sale_product_trial
1 parent 3eda82a commit 32fb4ad

File tree

16 files changed

+754
-0
lines changed

16 files changed

+754
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../website_sale_product_trial
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+
)

website_sale_product_trial/README.rst

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
==========================
2+
Website Sale Product Trial
3+
==========================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:a25ed6054ea1e7db1fe6f90cdb8102edd80859c7504cc1cebdaae1a0123c4819
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_product_trial
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_product_trial%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_product_trial>`_ project on GitHub.
69+
70+
You are welcome to contribute.
+5
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
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
{
6+
"name": "Website Sale Product Trial",
7+
"summary": """
8+
Configure product contract to be a trial subscription.""",
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_product_compatibility",
18+
"product",
19+
],
20+
"excludes": [],
21+
"data": [
22+
"views/product_views.xml",
23+
"views/templates.xml",
24+
],
25+
"demo": [],
26+
"qweb": [],
27+
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
11+
class WebsiteSaleProductTrial(WebsiteSale):
12+
@http.route(
13+
"/shop/payment/validate",
14+
type="http",
15+
auth="public",
16+
website=True,
17+
sitemap=False,
18+
)
19+
def shop_payment_validate(self, sale_order_id=None, **post):
20+
result = super().shop_payment_validate(sale_order_id=sale_order_id, **post)
21+
if "my/order" in result.location:
22+
result.location = "/shop/main/confirmation"
23+
return result
24+
25+
@http.route(
26+
"/shop/main/confirmation",
27+
type="http",
28+
auth="public",
29+
website=True,
30+
sitemap=False,
31+
)
32+
def shop_main_confirmation(self):
33+
"""General confirmation for product. Used to skip view of the
34+
invoice."""
35+
return request.render("website_sale_product_trial.main_confirmation", {})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * website_sale_restrict_sepa_dd
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 16.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: website_sale_restrict_sepa_dd
17+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_product_product__allow_sepa_dd_payment
18+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_product_template__allow_sepa_dd_payment
19+
msgid "Allow SEPA Direct Debit Payment"
20+
msgstr ""
21+
22+
#. module: website_sale_restrict_sepa_dd
23+
#. odoo-python
24+
#: code:addons/website_sale_restrict_sepa_dd/models/product_template.py:0
25+
#, python-format
26+
msgid ""
27+
"Allow SEPA Direct Debit payment for the product in ordre to set Only SEPA "
28+
"Direct Debit payment."
29+
msgstr ""
30+
31+
#. module: website_sale_restrict_sepa_dd
32+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_sale_order__allow_sepa_dd_payment
33+
msgid "Allow Sepa Dd Payment"
34+
msgstr ""
35+
36+
#. module: website_sale_restrict_sepa_dd
37+
#. odoo-python
38+
#: code:addons/website_sale_restrict_sepa_dd/models/sale_order.py:0
39+
#, python-format
40+
msgid ""
41+
"Cannot add product that does not allow SEPA Direct Debit with products that "
42+
"allow only SEPA Direct Debit payment."
43+
msgstr ""
44+
45+
#. module: website_sale_restrict_sepa_dd
46+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_product_product__only_sepa_dd_payment
47+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_product_template__only_sepa_dd_payment
48+
msgid "Only SEPA Direct Debit Payment"
49+
msgstr ""
50+
51+
#. module: website_sale_restrict_sepa_dd
52+
#: model:ir.model.fields,field_description:website_sale_restrict_sepa_dd.field_sale_order__only_sepa_dd_payment
53+
msgid "Only Sepa Dd Payment"
54+
msgstr ""
55+
56+
#. module: website_sale_restrict_sepa_dd
57+
#: model:ir.model,name:website_sale_restrict_sepa_dd.model_payment_provider
58+
msgid "Payment Provider"
59+
msgstr ""
60+
61+
#. module: website_sale_restrict_sepa_dd
62+
#: model:ir.model,name:website_sale_restrict_sepa_dd.model_product_template
63+
msgid "Product"
64+
msgstr ""
65+
66+
#. module: website_sale_restrict_sepa_dd
67+
#: model:ir.model,name:website_sale_restrict_sepa_dd.model_sale_order
68+
msgid "Sales Order"
69+
msgstr ""
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 product_template
5+
from . import sale_order
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
is_trial = fields.Boolean()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2024 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
6+
from odoo import _, api, models
7+
from odoo.exceptions import ValidationError
8+
9+
10+
class SaleOrder(models.Model):
11+
_inherit = "sale.order"
12+
13+
@api.constrains("order_line")
14+
def _check_trial_alone(self):
15+
"""Ensure trial are not mixed in a sale order."""
16+
for order in self:
17+
at_least_one_trial = any(
18+
order.order_line.mapped("product_id").mapped("is_trial")
19+
)
20+
if at_least_one_trial and order.order_line > 1:
21+
raise ValidationError(
22+
_(
23+
"Cannot add product trial in an order that "
24+
"contains other products."
25+
)
26+
)
27+
28+
def check_product_compatibility(self, product_id):
29+
warning = super().check_product_compatibility(product_id)
30+
if not warning:
31+
product = self.env["product.product"].browse(product_id).exists()
32+
non_trials = self.order_line.mapped("product_id").filtered(
33+
lambda p: not p.is_trial
34+
)
35+
any_trial = any(self.order_line.mapped("product_id").mapped("is_trial"))
36+
if product:
37+
if product.is_trial and non_trials:
38+
warning = _(
39+
f"Product {product.name} cannot be added because "
40+
"it's a trial and trial must be ordered seperately."
41+
)
42+
elif not product.is_trial and any_trial:
43+
warning = _(
44+
f"Product {product.name} cannot be added because "
45+
"order contains products that are trials and "
46+
"trials must be ordered separately."
47+
)
48+
return warning
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* `Coop IT Easy SC <https://coopiteasy.be>`_:
2+
3+
* Rémy Taymans
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Form to order subscription product

0 commit comments

Comments
 (0)