Skip to content

Commit

Permalink
[ADD] website_sale_menu_top_user_selling: New module
Browse files Browse the repository at this point in the history
TT52287
  • Loading branch information
pilarvargas-tecnativa committed Jan 8, 2025
1 parent 5b6783b commit 3fc582e
Show file tree
Hide file tree
Showing 23 changed files with 1,024 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_sale_menu_top_user_selling/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,
)
99 changes: 99 additions & 0 deletions website_sale_menu_top_user_selling/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
==================================
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|

This module allows you to display the products most purchased by the user in the online
shop.

**Table of contents**

.. contents::
:local:

Configuration
=============

The module allows you to configure the number of products to be displayed by means of a
configuration parameter.
Limit settings:
Go to Settings > Website > Products and adjust the value in the corresponding field to
set the maximum number of products to be displayed on the top selling products page.
The category panel must also be active in /shop.

Usage
=====

The best-selling products can be viewed by accessing the URL /shop/top_selling_products
on the website.
This URL can be accessed from */shop* by clicking on *Top selling products* in the
category menu.
The page will display the user's best-selling products, sorted by the number of
units sold.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/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/OCA/e-commerce/issues/new?body=module:%20website_sale_menu_top_user_selling%0Aversion:%2015.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
~~~~~~~

* Tecnativa

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

* `Tecnativa <https://www.tecnativa.com>`_

* 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 <https://github.com/OCA/e-commerce/tree/15.0/website_sale_menu_top_user_selling>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_sale_menu_top_user_selling/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
20 changes: 20 additions & 0 deletions website_sale_menu_top_user_selling/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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"],
"assets": {
"web.assets_tests": [
"website_sale_menu_top_user_selling/static/src/js/tours/*.js"
],
},
}
1 change: 1 addition & 0 deletions website_sale_menu_top_user_selling/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
102 changes: 102 additions & 0 deletions website_sale_menu_top_user_selling/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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/<int: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")
param_limit = int(
request.env["ir.config_parameter"]
.sudo()
.get_param("website_sale_menu_top_user_selling.limit", 10)
)
# Get best-selling products from the user
product_data = (
request.env["sale.order.line"]
.sudo()
.read_group(
[
("order_id.partner_id", "=", request.env.user.partner_id.id),
"|",
("product_id.product_tmpl_id.website_id", "=", request.website.id),
("product_id.product_tmpl_id.website_id", "=", False),
"|",
(
"product_id.product_tmpl_id.company_id",
"=",
request.website.company_id.id,
),
("product_id.product_tmpl_id.company_id", "=", False),
],
["product_id", "product_uom_qty:sum"],
["product_id"],
orderby="product_uom_qty DESC",
)
)
top_product_ids = [
rec["product_id"][0] for rec in product_data if rec["product_id"]
]
# Search for templates of best-selling products
product_templates = (
request.env["product.product"]
.sudo()
.search([("id", "in", top_product_ids)])
)
template_quantities = {}
for product in product_templates:
template_id = product.product_tmpl_id.id
if template_id not in template_quantities:
template_quantities[template_id] = 0
template_quantities[template_id] += next(
rec["product_uom_qty"]
for rec in product_data
if rec["product_id"][0] == product.id
)
# Sort the templates by total quantity sold and limit
sorted_template_ids = sorted(
template_quantities.keys(),
key=lambda tmpl_id: template_quantities[tmpl_id],
reverse=True,
)
limited_template_ids = sorted_template_ids[:param_limit]
templates = request.env["product.template"].sudo().browse(limited_template_ids)
# Pagination
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,
step=ppg,
scope=5,
url_args=kwargs,
)
# Shop context for the view
shop_context = self.shop(page=page, ppg=ppg, **kwargs)
shop_context.qcontext.update(
{
"pager": pager,
"products": products_on_page,
"search_product": products_on_page,
"search_count": total_products,
"bins": TableCompute().process(
products_on_page,
ppg,
request.env["website"].get_current_website().shop_ppr or 4,
),
}
)
return request.render("website_sale.products", shop_context.qcontext)
46 changes: 46 additions & 0 deletions website_sale_menu_top_user_selling/i18n/ca.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_menu_top_user_selling
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-08 15:51+0000\n"
"PO-Revision-Date: 2025-01-08 15:51+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_sale_menu_top_user_selling
#: model:ir.model,name:website_sale_menu_top_user_selling.model_res_config_settings
msgid "Config Settings"
msgstr "Ajustos de configuració"

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid ""
"Define the number of best-selling products you want to display in the "
"e-commerce catalog."
msgstr ""
"Defineix el nombre de productes més venuts que vols mostrar al catàleg "
"de comerç electrònic."

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Optional Products"
msgstr "Productes opcionals"

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.products_categories_top_user_selling
msgid "Top Selling Products"
msgstr "Productes Més Venuts"

#. module: website_sale_menu_top_user_selling
#: model:ir.model.fields,field_description:website_sale_menu_top_user_selling.field_res_config_settings__top_selling_products_limit
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Top Selling Products Limit"
msgstr "Límit de productes més venuts"
46 changes: 46 additions & 0 deletions website_sale_menu_top_user_selling/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_menu_top_user_selling
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-08 15:51+0000\n"
"PO-Revision-Date: 2025-01-08 15:51+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_sale_menu_top_user_selling
#: model:ir.model,name:website_sale_menu_top_user_selling.model_res_config_settings
msgid "Config Settings"
msgstr "Opciones de configuración"

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid ""
"Define the number of best-selling products you want to display in the "
"e-commerce catalog."
msgstr ""
"Defina el número de productos más vendidos que desea mostrar en el catálogo "
"de productos de comercio electrónico."

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Optional Products"
msgstr "Productos opcionales"

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.products_categories_top_user_selling
msgid "Top Selling Products"
msgstr "Productos más vendidos"

#. module: website_sale_menu_top_user_selling
#: model:ir.model.fields,field_description:website_sale_menu_top_user_selling.field_res_config_settings__top_selling_products_limit
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Top Selling Products Limit"
msgstr "Límite de productos más vendidos"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_menu_top_user_selling
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-08 15:50+0000\n"
"PO-Revision-Date: 2025-01-08 15:50+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: website_sale_menu_top_user_selling
#: model:ir.model,name:website_sale_menu_top_user_selling.model_res_config_settings
msgid "Config Settings"
msgstr ""

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid ""
"Define the number of best-selling products you want to display in the "
"e-commerce catalog."
msgstr ""

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Optional Products"
msgstr ""

#. module: website_sale_menu_top_user_selling
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.products_categories_top_user_selling
msgid "Top Selling Products"
msgstr ""

#. module: website_sale_menu_top_user_selling
#: model:ir.model.fields,field_description:website_sale_menu_top_user_selling.field_res_config_settings__top_selling_products_limit
#: model_terms:ir.ui.view,arch_db:website_sale_menu_top_user_selling.view_stock_configuration
msgid "Top Selling Products Limit"
msgstr ""
1 change: 1 addition & 0 deletions website_sale_menu_top_user_selling/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_config_settings
Loading

0 comments on commit 3fc582e

Please sign in to comment.