Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][MIG] website_sale_secondary_unit: Migration to version 17.0 #1003

Merged
merged 32 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
042c03e
[11.0][ADD] website_sale_secondary_unit: New module
sergio-teruel Mar 4, 2019
6983a1a
[11.0][FIX] website_sale_secondary_unit: Crash if product_uom not com…
sergio-teruel Apr 16, 2019
4783de2
[11.0][FIX] website_sale_secondary_unit: Fix tour tests
sergio-teruel Apr 18, 2019
db5476c
[11.0][IMP] website_sale_secondary_unit: Display product uom after pr…
sergio-teruel Jun 14, 2019
7f4006c
[MIG] website_sale_secondary_unit: Migration to v12.0
sergio-teruel Oct 24, 2019
ddc9394
[FIX] website_sale_secondary_unit: Fix quantity position in cart lines
sergio-teruel May 4, 2020
21642fe
[IMP] website_sale_secondary_unit: Set default secondary uom for prod…
sergio-teruel Jul 21, 2020
7062b4f
Added translation using Weblate (German)
AndreVolksdorf Aug 11, 2020
1769ae4
[IMP] website_sale_secondary_unit: black, isort, prettier
CarlosRoca13 Feb 17, 2021
8f88e60
[MIG] website_sale_secondary_unit: Migration to v13.0
CarlosRoca13 Feb 17, 2021
68c687f
[FIX] website_sale_secondary_unit: Adjust to upstream changes
pedrobaeza Apr 5, 2021
92d5697
[FIX] website_sale_secondary_unit: Remove sudo access to avoid to dis…
sergio-teruel Jul 15, 2021
b516d97
FIX: script for delete view before update
celm1990 Sep 10, 2021
ab328b6
[FIX] website_sale_secondary_unit: Fixed price computation
CarlosRoca13 May 14, 2021
9d68f44
[IMP] website_sale_secondary_unit: black, isort, prettier
CarlosRoca13 May 26, 2022
7789303
[MIG] website_sale_secondary_unit: Migration to 15.0
CarlosRoca13 May 27, 2022
b2a3fde
[UPD] Update website_sale_secondary_unit.pot
Oct 1, 2022
bbc4cf9
[IMP] website_sale_secondary_unit: mobile UX
chienandalu Dec 20, 2022
a426427
Translated using Weblate (Italian)
francesco-ooops Apr 7, 2023
825ccbc
Translated using Weblate (Spanish)
Ivorra78 Jul 5, 2023
efb67ca
Translated using Weblate (Italian)
mymage Jul 18, 2023
fee8ca8
[UPD] Update website_sale_secondary_unit.pot
Aug 11, 2023
1017fa8
[FIX] website_sale_secondary_unit: t-esc directives are deprecated
pilarvargas-tecnativa Sep 13, 2023
403f23c
[IMP] website_sale_secondary_unit: Hide/show uom name in secondary qu…
pilarvargas-tecnativa Sep 13, 2023
fd1b6cc
[UPD] Update website_sale_secondary_unit.pot
Sep 14, 2023
c4e502d
Translated using Weblate (Italian)
mymage Sep 22, 2023
62be6de
Translated using Weblate (Spanish)
Ivorra78 Oct 4, 2023
c749438
[IMP] website_sale_b2x_alt_price: test performance improvement
josep-tecnativa Oct 18, 2023
cd60a22
[IMP] website_sale_secondary_unit: test performance improvement
josep-tecnativa Oct 18, 2023
42f836b
Translated using Weblate (Italian)
mymage Oct 29, 2023
16499ce
[IMP] website_sale_secondary_unit: pre-commit auto fixes
carlos-lopez-tecnativa Jan 9, 2025
09b889c
[MIG] website_sale_secondary_unit: Migration to version 17.0
carlos-lopez-tecnativa Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions website_sale_secondary_unit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
===========================
Website Sale Secondary Unit
===========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b22305a090cabad4fd64b941824c90c602eec985747acf0fc3039558a4b22968
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/17.0/website_sale_secondary_unit
: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-17-0/e-commerce-17-0-website_sale_secondary_unit
: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=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of saleorder_secondary_unit module
to allow sell products in online store in secondary units defined.

**Table of contents**

.. contents::
:local:

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

For define the secondary units, you should active *Manage multiples
units of measure* on the user that will be responsable of this function.

Usage
=====

To use this module you need to:

- Go to *'Website > Products > Products'*.
- Select a template.
- Set the secondary units that you need.
- Go to Website Shop and buy this product, you will see a selectable
option with all secondary units defined in the product and visible in
website.
- If you do not want to sell in a base product unit and only allow sell
in a secondary unit you can disable the option *'Allow to sell in unit
of measure'* in a product sale tab.

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_secondary_unit%0Aversion:%2017.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>`__:

- Sergio Teruel
- Carlos Roca
- Pilar Vargas
- Carlos Lopez

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/17.0/website_sale_secondary_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions website_sale_secondary_unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import controllers
from . import models
from .hooks import post_init_hook
33 changes: 33 additions & 0 deletions website_sale_secondary_unit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2019 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Website Sale Secondary Unit",
"summary": "Allow manage secondary units in website shop",
"version": "17.0.1.0.0",
"development_status": "Beta",
"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", "sale_order_secondary_unit"],
"data": [
"security/ir.model.access.csv",
"security/website_sale_secondary_unit.xml",
"views/product_secondary_unit_views.xml",
"views/product_template_views.xml",
"views/templates.xml",
],
"demo": ["data/demo.xml"],
"post_init_hook": "post_init_hook",
"assets": {
"web.assets_frontend": [
"/website_sale_secondary_unit/static/src/js/**/*.esm.js",
"/website_sale_secondary_unit/static/src/scss/website_sale_secondary_unit.scss",
],
"web.assets_tests": [
"/website_sale_secondary_unit/static/tests/tours/website_sale_secondary_unit_tour.esm.js"
],
},
}
2 changes: 2 additions & 0 deletions website_sale_secondary_unit/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import main
69 changes: 69 additions & 0 deletions website_sale_secondary_unit/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2019 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import http
from odoo.http import request

from odoo.addons.website_sale.controllers.main import WebsiteSale


class WebsiteSaleSecondaryUnit(WebsiteSale):
@http.route()
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
# Add secondary uom info to session
request.session.pop("secondary_uom_id", None)

Check warning on line 13 in website_sale_secondary_unit/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_secondary_unit/controllers/main.py#L13

Added line #L13 was not covered by tests
if kw.get("secondary_uom_id"):
secondary_uom = request.env["product.secondary.unit"].browse(

Check warning on line 15 in website_sale_secondary_unit/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_secondary_unit/controllers/main.py#L15

Added line #L15 was not covered by tests
int(kw["secondary_uom_id"])
)
request.session["secondary_uom_id"] = secondary_uom.id
return super().cart_update(product_id, add_qty=add_qty, set_qty=set_qty, **kw)

Check warning on line 19 in website_sale_secondary_unit/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_secondary_unit/controllers/main.py#L18-L19

Added lines #L18 - L19 were not covered by tests

@http.route()
def cart_update_json(
self, product_id, line_id=None, add_qty=None, set_qty=None, display=True, **kw
):
so_line = request.env["sale.order.line"].browse(line_id)
request.session.pop("secondary_uom_id", None)
if kw.get("secondary_uom_id"):
secondary_uom = request.env["product.secondary.unit"].browse(
int(kw["secondary_uom_id"])
)
request.session["secondary_uom_id"] = secondary_uom.id
if so_line.sudo().secondary_uom_id:
request.session["secondary_uom_id"] = so_line.sudo().secondary_uom_id.id

Check warning on line 33 in website_sale_secondary_unit/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_secondary_unit/controllers/main.py#L33

Added line #L33 was not covered by tests
return super().cart_update_json(
product_id,
line_id=line_id,
add_qty=add_qty,
set_qty=set_qty,
display=display,
**kw,
)

def _prepare_product_values(self, product, category, search, **kwargs):
res = super()._prepare_product_values(product, category, search, **kwargs)
res["secondary_uom_ids"] = product.secondary_uom_ids.filtered(
lambda su: su.active and su.is_published
)
return res

def _get_cart_notification_information(self, order, line_ids):
res = super()._get_cart_notification_information(order, line_ids)
for line in res.get("lines", []):
sale_line = request.env["sale.order.line"].browse(line["id"])
line["secondary_uom_name"] = ""
line["secondary_uom_qty"] = sale_line.secondary_uom_qty
secondary_uom = sale_line.secondary_uom_id
if not secondary_uom:
continue
factor = (
int(secondary_uom.factor) == secondary_uom.factor
and int(secondary_uom.factor)
or secondary_uom.factor
)
uom_name = secondary_uom.product_tmpl_id.sudo().uom_id.name
secondary_uom_name = f"{secondary_uom.name} {factor}"
if uom_name != secondary_uom.name:
secondary_uom_name += f" {uom_name}"
line["secondary_uom_name"] = secondary_uom_name
return res
31 changes: 31 additions & 0 deletions website_sale_secondary_unit/data/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="0">
<record id="secondary_unit_box_5" model="product.secondary.unit">
<field name="name">Box</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="factor">5.0</field>
<field
name="product_tmpl_id"
ref="product.product_product_11_product_template"
/>
<field name="website_published">True</field>
</record>
<record id="secondary_unit_box_10" model="product.secondary.unit">
<field name="name">Box</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="factor">10.0</field>
<field
name="product_tmpl_id"
ref="product.product_product_11_product_template"
/>
<field name="website_published">True</field>
</record>
<record id="product.product_product_11" model="product.product">
<field
name="secondary_uom_ids"
eval="[(6, 0, [ref('website_sale_secondary_unit.secondary_unit_box_5'),
ref('website_sale_secondary_unit.secondary_unit_box_10')]),]"
/>
<field name="allow_uom_sell" eval="True" />
</record>
</odoo>
16 changes: 16 additions & 0 deletions website_sale_secondary_unit/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2019 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).


def post_init_hook(env):
"""
At installation time, set allow_uom_sell field as true for all products
that have already been created.
"""
env.cr.execute(
"""
UPDATE product_template
SET allow_uom_sell=true
WHERE allow_uom_sell IS NULL;
"""
)
102 changes: 102 additions & 0 deletions website_sale_secondary_unit/i18n/ca.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_secondary_unit
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-01-20 20:44+0000\n"
"Last-Translator: claudiagn <claudia.gargallo@qubiq.es>\n"
"Language-Team: none\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"

#. module: website_sale_secondary_unit
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.cart_lines
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.secondary_qty
msgid "Add one"
msgstr "Afegir un"

#. module: website_sale_secondary_unit
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_product__allow_uom_sell
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_template__allow_uom_sell
msgid "Allow to sell in unit of measure"
msgstr "Permetre vendre en una unitat de mesura"

#. module: website_sale_secondary_unit
#: model:product.secondary.unit,name:website_sale_secondary_unit.secondary_unit_box_10
#: model:product.secondary.unit,name:website_sale_secondary_unit.secondary_unit_box_5
msgid "Box"
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_secondary_unit__can_publish
msgid "Can Publish"
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_secondary_unit__is_published
msgid "Is Published"
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model,name:website_sale_secondary_unit.model_product_secondary_unit
msgid "Product Secondary Unit"
msgstr "Unitat secundària de producte"

#. module: website_sale_secondary_unit
#: model:ir.model,name:website_sale_secondary_unit.model_product_template
msgid "Product Template"
msgstr "Plantilla de producte"

#. module: website_sale_secondary_unit
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.cart_popover
msgid "Qty:"
msgstr "Quantitat:"

#. module: website_sale_secondary_unit
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.cart_lines
msgid "Quantity"
msgstr "Quantitat"

#. module: website_sale_secondary_unit
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.cart_lines
#: model_terms:ir.ui.view,arch_db:website_sale_secondary_unit.secondary_qty
msgid "Remove one"
msgstr "Elimina un"

#. module: website_sale_secondary_unit
#: model:ir.model,name:website_sale_secondary_unit.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model,name:website_sale_secondary_unit.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línia de comanda de venda"

#. module: website_sale_secondary_unit
#: model:ir.model.fields,help:website_sale_secondary_unit.field_product_secondary_unit__website_url
msgid "The full URL to access the document through the website."
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_secondary_unit__website_published
msgid "Visible on current website"
msgstr ""

#. module: website_sale_secondary_unit
#: model:ir.model.fields,field_description:website_sale_secondary_unit.field_product_secondary_unit__website_url
msgid "Website URL"
msgstr ""

#~ msgid "Is published"
#~ msgstr "Està publicat"

#~ msgid "Sale Order"
#~ msgstr "Comanda de venda"
Loading
Loading