diff --git a/setup/website_sale_menu_top_user_selling/odoo/addons/website_sale_menu_top_user_selling b/setup/website_sale_menu_top_user_selling/odoo/addons/website_sale_menu_top_user_selling new file mode 120000 index 0000000000..f8d27bbae8 --- /dev/null +++ b/setup/website_sale_menu_top_user_selling/odoo/addons/website_sale_menu_top_user_selling @@ -0,0 +1 @@ +../../../../website_sale_menu_top_user_selling \ No newline at end of file diff --git a/setup/website_sale_menu_top_user_selling/setup.py b/setup/website_sale_menu_top_user_selling/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_sale_menu_top_user_selling/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_sale_menu_top_user_selling/README.rst b/website_sale_menu_top_user_selling/README.rst new file mode 100644 index 0000000000..b090723120 --- /dev/null +++ b/website_sale_menu_top_user_selling/README.rst @@ -0,0 +1,78 @@ +================================== +Website Sale Menu Top User Selling +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:72c89f7b3b6be4bf5e26518bbcc2d2ddab1c32e8c6d51624dc39914ef20e6598 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/15.0/website_sale_menu_top_user_selling + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-15-0/e-commerce-15-0-website_sale_menu_top_user_selling + :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/e-commerce&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + + + +**Table of contents** + +.. contents:: + :local: + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_ + + * Pilar Vargas + +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/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_menu_top_user_selling/__init__.py b/website_sale_menu_top_user_selling/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/website_sale_menu_top_user_selling/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_sale_menu_top_user_selling/__manifest__.py b/website_sale_menu_top_user_selling/__manifest__.py new file mode 100644 index 0000000000..e8dd211a6c --- /dev/null +++ b/website_sale_menu_top_user_selling/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Website Sale Menu Top User Selling", + "summary": "Displays the products most sold by the user in the e-commerce.", + "version": "15.0.1.0.0", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["website_sale"], + "data": ["views/res_config_settings_views.xml", "views/templates.xml"], +} diff --git a/website_sale_menu_top_user_selling/controllers/__init__.py b/website_sale_menu_top_user_selling/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_sale_menu_top_user_selling/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_sale_menu_top_user_selling/controllers/main.py b/website_sale_menu_top_user_selling/controllers/main.py new file mode 100644 index 0000000000..5e1999acff --- /dev/null +++ b/website_sale_menu_top_user_selling/controllers/main.py @@ -0,0 +1,67 @@ +from odoo import http +from odoo.http import request + +from odoo.addons.website_sale.controllers.main import TableCompute, WebsiteSale + + +class WebsiteSale(WebsiteSale): + @http.route( + ["/shop/top_selling_products", "/shop/top_selling_products/page/"], + type="http", + auth="public", + website=True, + ) + def user_top_products(self, page=0, ppg=False, **kwargs): + if request.env.user.has_group("base.group_public"): + return request.redirect("/web/login") + # Obtener el contexto base del método 'shop' + shop_context = self.shop(page=page, ppg=ppg, **kwargs) + # Obtener los productos más comprados por el usuario + product_ids = ( + request.env["sale.order.line"] + .sudo() + .read_group( + [("order_id.partner_id", "=", request.env.user.partner_id.id)], + ["product_id"], + ["product_id"], + ) + ) + top_product_ids = [ + rec["product_id"][0] for rec in product_ids if rec["product_id"] + ] + templates = ( + request.env["product.template"] + .sudo() + .search([("product_variant_ids", "in", top_product_ids)]) + ) + # Establecer productos por página y paginador + ppg = ppg or 20 + total_products = len(templates) + page_count = (total_products + ppg - 1) // ppg + page = max(0, min(page, page_count - 1)) + offset = page * ppg + products_on_page = templates[offset : offset + ppg] + pager = request.website.pager( + url="/shop/top_selling_products", + total=total_products, + page=page + 1, # Página actual (en Odoo, las páginas empiezan en 1) + step=ppg, + scope=5, # Número de páginas a mostrar + url_args=kwargs, + ) + # Actualizar el contexto + shop_context.qcontext["pager"] = pager # Añadir el paginador + shop_context.qcontext[ + "products" + ] = products_on_page # Productos de la página actual + shop_context.qcontext["search_product"] = products_on_page # Para búsquedas + shop_context.qcontext[ + "search_count" + ] = total_products # Número total de productos + ppr = ( + request.env["website"].get_current_website().shop_ppr or 4 + ) # Productos por fila + shop_context.qcontext["bins"] = TableCompute().process( + products_on_page, ppg, ppr + ) + return request.render("website_sale.products", shop_context.qcontext) diff --git a/website_sale_menu_top_user_selling/models/__init__.py b/website_sale_menu_top_user_selling/models/__init__.py new file mode 100644 index 0000000000..0deb68c468 --- /dev/null +++ b/website_sale_menu_top_user_selling/models/__init__.py @@ -0,0 +1 @@ +from . import res_config_settings diff --git a/website_sale_menu_top_user_selling/models/res_config_settings.py b/website_sale_menu_top_user_selling/models/res_config_settings.py new file mode 100644 index 0000000000..aabf883043 --- /dev/null +++ b/website_sale_menu_top_user_selling/models/res_config_settings.py @@ -0,0 +1,30 @@ +# Copyright 2024 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = "res.config.settings" + + top_selling_products_limit = fields.Integer(default=10) + + @api.model + def get_values(self): + res = super().get_values() + res.update( + top_selling_products_limit=int( + self.env["ir.config_parameter"] + .sudo() + .get_param("top_selling_products.limit", 20) + ), + ) + return res + + def set_values(self): + res = super().set_values() + self.env["ir.config_parameter"].sudo().set_param( + "top_selling_products.limit", self.top_selling_products_limit + ) + return res diff --git a/website_sale_menu_top_user_selling/readme/CONTRIBUTORS.rst b/website_sale_menu_top_user_selling/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..7029b234a0 --- /dev/null +++ b/website_sale_menu_top_user_selling/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_ + + * Pilar Vargas diff --git a/website_sale_menu_top_user_selling/readme/DESCRIPTION.rst b/website_sale_menu_top_user_selling/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/website_sale_menu_top_user_selling/readme/DESCRIPTION.rst @@ -0,0 +1 @@ + diff --git a/website_sale_menu_top_user_selling/readme/USAGE.rst b/website_sale_menu_top_user_selling/readme/USAGE.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_menu_top_user_selling/static/description/icon.png b/website_sale_menu_top_user_selling/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_menu_top_user_selling/static/description/icon.png differ diff --git a/website_sale_menu_top_user_selling/static/description/index.html b/website_sale_menu_top_user_selling/static/description/index.html new file mode 100644 index 0000000000..81d7ba77f1 --- /dev/null +++ b/website_sale_menu_top_user_selling/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +Website Sale Menu Top User Selling + + + +
+

Website Sale Menu Top User Selling

+ + +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

Table of contents

+ +
+

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

+
    +
  • Tecnativa
  • +
+
+
+

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/e-commerce project on GitHub.

+

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

+
+
+
+ + diff --git a/website_sale_menu_top_user_selling/views/res_config_settings_views.xml b/website_sale_menu_top_user_selling/views/res_config_settings_views.xml new file mode 100644 index 0000000000..1454cc2a33 --- /dev/null +++ b/website_sale_menu_top_user_selling/views/res_config_settings_views.xml @@ -0,0 +1,33 @@ + + + + + res.config.settings + + + +
+
+
+
+
+ + + + diff --git a/website_sale_menu_top_user_selling/views/templates.xml b/website_sale_menu_top_user_selling/views/templates.xml new file mode 100644 index 0000000000..726e4db274 --- /dev/null +++ b/website_sale_menu_top_user_selling/views/templates.xml @@ -0,0 +1,35 @@ + + + +