-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] website_sale_disable_shop module
pre-commit fix
- Loading branch information
1 parent
a67a7b1
commit aff3d0d
Showing
13 changed files
with
148 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,4 @@ | ||
# Copyright 2024 Onestein | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). | ||
|
||
from . import models |
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,18 @@ | ||
# Copyright 2024 Onestein | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). | ||
|
||
{ | ||
"name": "Website Sale Enable/Disable Shop", | ||
"category": "Website", | ||
"version": "16.0.1.0.0", | ||
"author": "Onestein, Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/website", | ||
"license": "LGPL-3", | ||
"depends": [ | ||
"website_sale", | ||
], | ||
"data": [ | ||
"views/res_config_settings_view.xml", | ||
], | ||
"installable": 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,6 @@ | ||
# Copyright 2024 Onestein | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). | ||
|
||
from . import ir_http | ||
from . import res_config_settings | ||
from . import website |
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,37 @@ | ||
# Copyright 2024 Onestein | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0). | ||
from pathlib import Path | ||
|
||
from odoo import models | ||
from odoo.http import request | ||
|
||
|
||
class IrHttp(models.AbstractModel): | ||
_inherit = "ir.http" | ||
|
||
@classmethod | ||
def _dispatch(cls, endpoint): | ||
res = cls._check_shop_enabled_disabled() | ||
if res: | ||
return res | ||
return super()._dispatch(endpoint) | ||
|
||
@classmethod | ||
def _serve_fallback(cls): | ||
res = cls._check_shop_enabled_disabled() | ||
if res: | ||
return res | ||
return super()._serve_fallback() | ||
|
||
@classmethod | ||
def _check_shop_enabled_disabled(cls): | ||
# if not website request - skip | ||
website = request.env["website"].sudo().get_current_website() | ||
if not website: | ||
return None | ||
if not website.shop_enabled: | ||
path = request.httprequest.path | ||
if path == "/shop" or Path("/shop") in Path(path).parents: | ||
if path == "/shop/cart" and request.params.get("type") == "popover": | ||
return None | ||
return request.redirect("/") |
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,10 @@ | ||
# Copyright 2024 Onestein | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
shop_enabled = fields.Boolean(related="website_id.shop_enabled", readonly=False) |
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,10 @@ | ||
# Copyright 2024 Onestein | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class Website(models.Model): | ||
_inherit = "website" | ||
|
||
shop_enabled = fields.Boolean(default=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 @@ | ||
* Onestein <https://www.onestein.nl> |
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 @@ | ||
This module allows to enable/disable shops per website. |
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,5 @@ | ||
To configure this module, you need to: | ||
|
||
#. Go to **Website > Configuration > Settings** | ||
#. Search 'Shop Enabled' option. | ||
#. When shop is disabled when user tries to access mywebsite.com/shop or any of its child pages, they will be redirected to homepage. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
from . import test_ir_http |
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,27 @@ | ||
from odoo.tests import HttpCase | ||
|
||
|
||
class TestIrHttp(HttpCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.website = self.env["website"].sudo().get_current_website() | ||
self.path = "/shop" | ||
|
||
def test_dispatch_shop_enabled(self): | ||
# Test that a user can access "/shop | ||
response = self.url_open(self.path) | ||
self.assertEqual( | ||
response.status_code, | ||
200, | ||
"Expected the response status code to be 200 which means no redirection", | ||
) | ||
|
||
def test_dispatch__shop_disabled(self): | ||
# Test that a user cannot access "/shop | ||
self.website.shop_enabled = False | ||
response = self.url_open(self.path, allow_redirects=False) | ||
self.assertEqual( | ||
response.status_code, | ||
303, | ||
"Expected the response status code to be 303 indicating a redirect", | ||
) |
28 changes: 28 additions & 0 deletions
28
website_sale_disable_shop/views/res_config_settings_view.xml
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 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- Copyright 2024 Onestein | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record id="view_website_config_settings" model="ir.ui.view"> | ||
<field name="name">Website Shop Enable/Disable</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="website_sale.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<div id="website_shop_checkout" position="after"> | ||
<h2>Website Shop</h2> | ||
<div class="row mt16 o_settings_container" id="website_shop_setting"> | ||
<div class="col-12 col-lg-6 o_setting_box"> | ||
<div class="o_setting_left_pane"> | ||
<field name="shop_enabled"/> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="shop_enabled"/> | ||
<div class="text-muted"> | ||
Is website shop enabled? | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</field> | ||
</record> | ||
</odoo> |