Compare commits
1 Commits
16.0
...
16.0-sale_
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d8293f73e |
@@ -1,42 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Run the Python tests of the given Odoo modules.
|
|
||||||
#
|
|
||||||
# This script is meant to be executed *inside* an Elabore doodba image
|
|
||||||
# (docker.0k.io/mirror/odoo:rc_<version>-ELABORE-LIGHT), with a
|
|
||||||
# PostgreSQL service reachable at $PGHOST. The modules under test are
|
|
||||||
# read from the current working directory (the checked-out repository),
|
|
||||||
# which is prepended to the addons path so that the PR's code takes
|
|
||||||
# precedence over the modules already baked in the image.
|
|
||||||
#
|
|
||||||
# Usage: odoo-tests.sh <module1,module2,...>
|
|
||||||
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
modules="${1:?usage: odoo-tests.sh <module1,module2,...>}"
|
|
||||||
|
|
||||||
export PGHOST=postgres
|
|
||||||
export PGUSER=odoo
|
|
||||||
export PGPASSWORD=odoopassword
|
|
||||||
export PGDATABASE="test_$(basename "$PWD" | tr '.-' '__')"
|
|
||||||
export WITHOUT_DEMO=all
|
|
||||||
export DB_FILTER='.*'
|
|
||||||
|
|
||||||
# Generate /opt/odoo/auto/odoo.conf from the environment and wait for
|
|
||||||
# the database to accept connections.
|
|
||||||
/opt/odoo/common/entrypoint
|
|
||||||
|
|
||||||
# Odoo test-tags format: "/module1,/module2" (one leading slash).
|
|
||||||
tags="/$(echo "$modules" | tr ',' ',/')"
|
|
||||||
|
|
||||||
exec odoo \
|
|
||||||
--config=/opt/odoo/auto/odoo.conf \
|
|
||||||
--max-cron-threads=0 \
|
|
||||||
--limit-time-real=10000 \
|
|
||||||
--workers=0 \
|
|
||||||
--test-enable \
|
|
||||||
--stop-after-init \
|
|
||||||
--addons-path="$PWD,/opt/odoo/auto/addons" \
|
|
||||||
-d "$PGDATABASE" \
|
|
||||||
-i "$modules" \
|
|
||||||
--test-tags "$tags"
|
|
||||||
@@ -2,6 +2,8 @@ name: pre-commit
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- "16.0*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
@@ -13,10 +15,10 @@ jobs:
|
|||||||
python-version: "3.11"
|
python-version: "3.11"
|
||||||
- name: Get python version
|
- name: Get python version
|
||||||
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
|
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
|
||||||
- uses: https://gitea.com/actions/cache@v3
|
# - uses: actions/cache@v4
|
||||||
with:
|
# with:
|
||||||
path: ~/.cache/pre-commit
|
# path: ~/.cache/pre-commit
|
||||||
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
# key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
|
||||||
- name: Install pre-commit
|
- name: Install pre-commit
|
||||||
run: pip install pre-commit
|
run: pip install pre-commit
|
||||||
- name: Run pre-commit
|
- name: Run pre-commit
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
name: tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "16.0*"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: odoo-ci
|
|
||||||
container:
|
|
||||||
image: docker.0k.io/mirror/odoo:rc_16.0-ELABORE-LIGHT
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: docker.0k.io/postgres:17.2.0-myc
|
|
||||||
env:
|
|
||||||
POSTGRES_USER: odoo
|
|
||||||
POSTGRES_PASSWORD: odoopassword
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
steps:
|
|
||||||
# The doodba image ships no Node.js, so actions/checkout@v4 cannot
|
|
||||||
# run here. The repository is private, so the job token is required.
|
|
||||||
- name: Checkout
|
|
||||||
env:
|
|
||||||
SECRET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
||||||
SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
set -eu
|
|
||||||
token="${GITEA_TOKEN:-${GITHUB_TOKEN:-${SECRET_GITEA_TOKEN:-${SECRET_GITHUB_TOKEN:-}}}}"
|
|
||||||
if [ -z "$token" ]; then
|
|
||||||
echo "::error::No job token available to clone the repository"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
server="${GITHUB_SERVER_URL:-https://git.elabore.coop}"
|
|
||||||
repo="${GITHUB_REPOSITORY:?GITHUB_REPOSITORY is not set}"
|
|
||||||
ref="${GITHUB_REF:-${GITHUB_SHA:?neither GITHUB_REF nor GITHUB_SHA is set}}"
|
|
||||||
auth_url="$(printf '%s' "${server%/}/${repo}.git" |
|
|
||||||
sed -E "s#^https://#https://${token}@#")"
|
|
||||||
git init -q .
|
|
||||||
git config --global --add safe.directory "$PWD"
|
|
||||||
git remote add origin "$auth_url"
|
|
||||||
git fetch -q --depth=1 origin "$ref"
|
|
||||||
git checkout -q FETCH_HEAD
|
|
||||||
|
|
||||||
- name: Detect changed modules
|
|
||||||
id: changed
|
|
||||||
run: |
|
|
||||||
set -eu
|
|
||||||
if [ -n "${GITHUB_BASE_REF:-}" ]; then
|
|
||||||
git fetch -q --depth=1 origin "refs/heads/$GITHUB_BASE_REF"
|
|
||||||
base_rev="FETCH_HEAD"
|
|
||||||
scope="diff against $GITHUB_BASE_REF"
|
|
||||||
else
|
|
||||||
base_rev=""
|
|
||||||
scope="all installable modules (manual run)"
|
|
||||||
fi
|
|
||||||
if [ -n "$base_rev" ]; then
|
|
||||||
modules="$(
|
|
||||||
git diff --name-only "$base_rev" HEAD |
|
|
||||||
awk -F/ '{print $1}' | sort -u |
|
|
||||||
while read -r dir; do
|
|
||||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
|
||||||
done | paste -sd, -
|
|
||||||
)"
|
|
||||||
else
|
|
||||||
modules="$(
|
|
||||||
for dir in */; do
|
|
||||||
dir="${dir%/}"
|
|
||||||
[ -f "$dir/__manifest__.py" ] && echo "$dir"
|
|
||||||
done | paste -sd, -
|
|
||||||
)"
|
|
||||||
fi
|
|
||||||
echo "modules=$modules" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "Modules to test ($scope): ${modules:-<none>}"
|
|
||||||
|
|
||||||
- name: Run Odoo tests
|
|
||||||
if: steps.changed.outputs.modules != ''
|
|
||||||
run: bash .gitea/scripts/odoo-tests.sh "${{ steps.changed.outputs.modules }}"
|
|
||||||
90
.gitignore
vendored
90
.gitignore
vendored
@@ -1,88 +1,2 @@
|
|||||||
# Byte-compiled / optimized / DLL files
|
*.*~
|
||||||
__pycache__/
|
*.pyc
|
||||||
*.py[cod]
|
|
||||||
/.venv
|
|
||||||
/.pytest_cache
|
|
||||||
/.ruff_cache
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
env/
|
|
||||||
bin/
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
eggs/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
*.eggs
|
|
||||||
|
|
||||||
# Windows installers
|
|
||||||
*.msi
|
|
||||||
|
|
||||||
# Debian packages
|
|
||||||
*.deb
|
|
||||||
|
|
||||||
# Redhat packages
|
|
||||||
*.rpm
|
|
||||||
|
|
||||||
# MacOS packages
|
|
||||||
*.dmg
|
|
||||||
*.pkg
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.coverage
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
|
|
||||||
# Pycharm
|
|
||||||
.idea
|
|
||||||
|
|
||||||
# Eclipse
|
|
||||||
.settings
|
|
||||||
|
|
||||||
# Visual Studio cache/options directory
|
|
||||||
.vs/
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
# OSX Files
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# Mr Developer
|
|
||||||
.mr.developer.cfg
|
|
||||||
.project
|
|
||||||
.pydevproject
|
|
||||||
|
|
||||||
# Rope
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# Backup files
|
|
||||||
*~
|
|
||||||
*.swp
|
|
||||||
|
|
||||||
# OCA rules
|
|
||||||
!static/lib/
|
|
||||||
|
|||||||
@@ -49,9 +49,12 @@ repos:
|
|||||||
$(git rev-parse --show-toplevel))"'
|
$(git rev-parse --show-toplevel))"'
|
||||||
- id: oca-gen-addon-readme
|
- id: oca-gen-addon-readme
|
||||||
entry:
|
entry:
|
||||||
bash -c 'oca-gen-addon-readme --addons-dir=. --branch=$(git symbolic-ref
|
bash -c 'oca-gen-addon-readme
|
||||||
|
--addons-dir=.
|
||||||
|
--branch=$(git symbolic-ref
|
||||||
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
|
refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@")
|
||||||
--repo-name=$(basename $(git rev-parse --show-toplevel)) --org-name="Elabore"
|
--repo-name=$(basename $(git rev-parse --show-toplevel))
|
||||||
|
--org-name="Elabore"
|
||||||
--if-source-changed --keep-source-digest'
|
--if-source-changed --keep-source-digest'
|
||||||
|
|
||||||
- repo: https://github.com/OCA/odoo-pre-commit-hooks
|
- repo: https://github.com/OCA/odoo-pre-commit-hooks
|
||||||
|
|||||||
1
sale_restricted_qty_website_sale/__init__.py
Normal file
1
sale_restricted_qty_website_sale/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
35
sale_restricted_qty_website_sale/__manifest__.py
Normal file
35
sale_restricted_qty_website_sale/__manifest__.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Copyright 2026 Elabore ()
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "sale_restricted_qty_website_sale",
|
||||||
|
"version": "16.0.1.0.0",
|
||||||
|
"author": "Elabore",
|
||||||
|
"website": "https://elabore.coop",
|
||||||
|
"maintainer": "Elabore",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"category": "Sales",
|
||||||
|
"summary": "Improve UX handling on e-commerce product page",
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
"depends": [
|
||||||
|
"sale_restricted_qty","website_sale",
|
||||||
|
],
|
||||||
|
"qweb": [],
|
||||||
|
"external_dependencies": {
|
||||||
|
"python": [],
|
||||||
|
},
|
||||||
|
# always loaded
|
||||||
|
"data": [
|
||||||
|
"views/restricted_qty_website_sale_view.xml"
|
||||||
|
],
|
||||||
|
"assets": {
|
||||||
|
"web.assets_frontend": [
|
||||||
|
"sale_restricted_qty_website_sale/static/src/js/add_to_cart.js",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"installable": True,
|
||||||
|
# Install this module automatically if all dependency have been previously
|
||||||
|
# and independently installed. Used for synergetic or glue modules.
|
||||||
|
"auto_install": True,
|
||||||
|
"application": False,
|
||||||
|
}
|
||||||
80
sale_restricted_qty_website_sale/i18n/fr.po
Normal file
80
sale_restricted_qty_website_sale/i18n/fr.po
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
# * elabore_website_sale_restricted_qty
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Odoo Server 16.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"PO-Revision-Date: 2026-08-18 00:00+0000\n"
|
||||||
|
"Last-Translator: Élabore <https://elabore.coop>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: fr\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/sale_order_line.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid ""
|
||||||
|
"The selected quantity is not available for sale:\n"
|
||||||
|
"\n"
|
||||||
|
"%s\n"
|
||||||
|
"\n"
|
||||||
|
"Please adjust the quantity."
|
||||||
|
msgstr ""
|
||||||
|
"La quantité choisie n'est pas disponible à la vente :\n"
|
||||||
|
"\n"
|
||||||
|
"%s\n"
|
||||||
|
"\n"
|
||||||
|
"Merci d'ajuster la quantité."
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/sale_order_line.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "%(product)s: minimum order quantity is %(qty)s."
|
||||||
|
msgstr "%(product)s : quantité minimum de commande %(qty)s."
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/sale_order_line.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "%(product)s: maximum order quantity is %(qty)s."
|
||||||
|
msgstr "%(product)s : quantité maximum de commande %(qty)s."
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/sale_order_line.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "%(product)s: must be ordered in multiples of %(qty)s."
|
||||||
|
msgstr "%(product)s : à commander par multiples de %(qty)s."
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/product_restricted_qty_mixin.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "minimum order: %(qty)s %(uom)s"
|
||||||
|
msgstr "commande minimum : %(qty)s %(uom)s"
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/product_restricted_qty_mixin.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "in multiples of %(qty)s %(uom)s"
|
||||||
|
msgstr "par multiples de %(qty)s %(uom)s"
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#. odoo-python
|
||||||
|
#: code:addons/elabore_website_sale_restricted_qty/models/product_restricted_qty_mixin.py:0
|
||||||
|
#, python-format
|
||||||
|
msgid "maximum: %(qty)s %(uom)s"
|
||||||
|
msgstr "maximum : %(qty)s %(uom)s"
|
||||||
|
|
||||||
|
#. module: elabore_website_sale_restricted_qty
|
||||||
|
#: model:ir.ui.view,name:elabore_website_sale_restricted_qty.product_restricted_qty_info
|
||||||
|
msgid "Restricted Quantity Information"
|
||||||
|
msgstr "Information sur les quantités restreintes"
|
||||||
2
sale_restricted_qty_website_sale/models/__init__.py
Normal file
2
sale_restricted_qty_website_sale/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
from . import product_restricted_qty_mixin
|
||||||
|
from . import sale_order_line
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Copyright 2026 Élabore (https://elabore.coop)
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import _, models
|
||||||
|
from odoo.tools import float_is_zero
|
||||||
|
from odoo.tools.misc import formatLang
|
||||||
|
|
||||||
|
|
||||||
|
class ProductRestrictedQtyMixin(models.AbstractModel):
|
||||||
|
"""Extending the OCA abstract mixin makes these helpers available at once
|
||||||
|
on product.product, product.template and product.category."""
|
||||||
|
|
||||||
|
_inherit = "product.restricted.qty.mixin"
|
||||||
|
|
||||||
|
def _format_restricted_qty(self, qty):
|
||||||
|
"""Short form: 6 rather than 6.0, and a locale-aware separator
|
||||||
|
for decimals."""
|
||||||
|
if float_is_zero(qty - int(qty), precision_digits=3):
|
||||||
|
return str(int(qty))
|
||||||
|
return formatLang(self.env, qty)
|
||||||
|
|
||||||
|
def _get_restricted_qty_hint(self):
|
||||||
|
"""Sentence shown to the customer. Empty when nothing restricts him.
|
||||||
|
|
||||||
|
OCA semantics: `force_sale_min_qty` / `force_sale_max_qty` set to Yes
|
||||||
|
make the bound purely indicative -- the constraint does not block, so
|
||||||
|
we announce nothing rather than promising a rule that does not exist.
|
||||||
|
"""
|
||||||
|
self.ensure_one()
|
||||||
|
uom = self.uom_id.name if "uom_id" in self._fields else ""
|
||||||
|
parts = []
|
||||||
|
if self.sale_min_qty and not self.force_sale_min_qty:
|
||||||
|
parts.append(
|
||||||
|
_(
|
||||||
|
"minimum order: %(qty)s %(uom)s",
|
||||||
|
qty=self._format_restricted_qty(self.sale_min_qty),
|
||||||
|
uom=uom,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if self.sale_multiple_qty:
|
||||||
|
parts.append(
|
||||||
|
_(
|
||||||
|
"in multiples of %(qty)s %(uom)s",
|
||||||
|
qty=self._format_restricted_qty(self.sale_multiple_qty),
|
||||||
|
uom=uom,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if self.sale_max_qty and not self.force_sale_max_qty:
|
||||||
|
parts.append(
|
||||||
|
_(
|
||||||
|
"maximum: %(qty)s %(uom)s",
|
||||||
|
qty=self._format_restricted_qty(self.sale_max_qty),
|
||||||
|
uom=uom,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not parts:
|
||||||
|
return ""
|
||||||
|
hint = " · ".join(parts)
|
||||||
|
return hint[0].upper() + hint[1:]
|
||||||
62
sale_restricted_qty_website_sale/models/sale_order_line.py
Normal file
62
sale_restricted_qty_website_sale/models/sale_order_line.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
from odoo import _, api, models
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
|
class SaleOrderLine(models.Model):
|
||||||
|
_inherit = "sale.order.line"
|
||||||
|
|
||||||
|
@api.constrains(
|
||||||
|
"product_uom_qty", "sale_min_qty", "sale_max_qty", "sale_multiple_qty"
|
||||||
|
)
|
||||||
|
def check_constraint_restricted_qty(self):
|
||||||
|
"""Rewrite the error message raised by `sale_restricted_qty`.
|
||||||
|
|
||||||
|
The upstream message is written for a salesperson: it dumps the
|
||||||
|
offending products and explains how to tick "force min quantity" on
|
||||||
|
the product form. Unreadable for an eCommerce customer.
|
||||||
|
|
||||||
|
Detection is left to the OCA module -- the `is_qty_*` fields stay the
|
||||||
|
single source of truth. Only the wording is replaced, so an upstream
|
||||||
|
change to the rules is followed without breaking anything.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return super().check_constraint_restricted_qty()
|
||||||
|
except ValidationError:
|
||||||
|
raise ValidationError(self._get_restricted_qty_error_message()) from None
|
||||||
|
|
||||||
|
def _get_restricted_qty_error_message(self):
|
||||||
|
"""Customer-facing message, one line per unmet restriction."""
|
||||||
|
details = []
|
||||||
|
for line in self:
|
||||||
|
product = line.product_id
|
||||||
|
if not product.force_sale_min_qty and line.is_qty_less_min_qty:
|
||||||
|
details.append(
|
||||||
|
_(
|
||||||
|
"%(product)s: minimum order quantity is %(qty)s.",
|
||||||
|
product=product.display_name,
|
||||||
|
qty=product._format_restricted_qty(line.sale_min_qty),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if not product.force_sale_max_qty and line.is_qty_bigger_max_qty:
|
||||||
|
details.append(
|
||||||
|
_(
|
||||||
|
"%(product)s: maximum order quantity is %(qty)s.",
|
||||||
|
product=product.display_name,
|
||||||
|
qty=product._format_restricted_qty(line.sale_max_qty),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if line.is_qty_not_multiple_qty:
|
||||||
|
details.append(
|
||||||
|
_(
|
||||||
|
"%(product)s: must be ordered in multiples of %(qty)s.",
|
||||||
|
product=product.display_name,
|
||||||
|
qty=product._format_restricted_qty(line.sale_multiple_qty),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return _(
|
||||||
|
"The selected quantity is not available for sale:\n\n"
|
||||||
|
"%s\n\n"
|
||||||
|
"Please adjust the quantity.",
|
||||||
|
"\n".join(details),
|
||||||
|
)
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
odoo.define("sale_restricted_qty_website_sale.add_to_cart", function (require) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const publicWidget = require("web.public.widget");
|
||||||
|
const wSaleUtils = require("website_sale.utils");
|
||||||
|
const WebsiteSale = require("website_sale.website_sale").WebsiteSale;
|
||||||
|
|
||||||
|
WebsiteSale.include({
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
_addToCartInPage: function () {
|
||||||
|
return this._super.apply(this, arguments).catch((error) => {
|
||||||
|
const message = this._getRestrictedQtyMessage(error);
|
||||||
|
if (!message) {
|
||||||
|
// Not a quantity restriction: let the real error surface.
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
if (error && error.event && error.event.preventDefault) {
|
||||||
|
// Legacy convention: tells the crash manager the error is
|
||||||
|
// handled, so it does not open its own dialog on top.
|
||||||
|
error.event.preventDefault();
|
||||||
|
}
|
||||||
|
wSaleUtils.showWarning(message);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @param {Object} error rejection from the legacy RPC
|
||||||
|
* @returns {string|false} the message, or false to re-throw
|
||||||
|
*/
|
||||||
|
_getRestrictedQtyMessage: function (error) {
|
||||||
|
const data =
|
||||||
|
(error && error.message && error.message.data) ||
|
||||||
|
(error && error.data);
|
||||||
|
if (!data || data.name !== "odoo.exceptions.ValidationError") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return data.message;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
1
sale_restricted_qty_website_sale/tests/__init__.py
Normal file
1
sale_restricted_qty_website_sale/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import test_restricted_qty_website_sale
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
from lxml import html
|
||||||
|
|
||||||
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tests import HttpCase, tagged
|
||||||
|
|
||||||
|
from odoo.addons.http_routing.models.ir_http import slug
|
||||||
|
|
||||||
|
|
||||||
|
@tagged("post_install", "-at_install")
|
||||||
|
class TestRestrictedQtyInfo(HttpCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.partner = cls.env["res.partner"].create({"name": "eCommerce customer"})
|
||||||
|
cls.product_min = cls._create_product(
|
||||||
|
"Product min 6", manual_sale_min_qty=6.0
|
||||||
|
)
|
||||||
|
cls.product_free = cls._create_product("Unrestricted product")
|
||||||
|
# force = Yes -> purely indicative bound, nothing to tell the customer
|
||||||
|
cls.product_indicative = cls._create_product(
|
||||||
|
"Product min 6 indicative",
|
||||||
|
manual_sale_min_qty=6.0,
|
||||||
|
manual_force_sale_min_qty="force",
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create_product(cls, name, **restrictions):
|
||||||
|
values = {
|
||||||
|
"name": name,
|
||||||
|
"type": "consu",
|
||||||
|
"list_price": 10.0,
|
||||||
|
"sale_ok": True,
|
||||||
|
"is_published": True,
|
||||||
|
}
|
||||||
|
values.update(restrictions)
|
||||||
|
return cls.env["product.template"].create(values).product_variant_id
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Error message
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _create_line(self, product, qty):
|
||||||
|
order = self.env["sale.order"].create({"partner_id": self.partner.id})
|
||||||
|
self.env["sale.order.line"].create(
|
||||||
|
{
|
||||||
|
"order_id": order.id,
|
||||||
|
"product_id": product.id,
|
||||||
|
"product_uom_qty": qty,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
# @api.constrains are evaluated on flush, not on create().
|
||||||
|
self.env.flush_all()
|
||||||
|
return order
|
||||||
|
|
||||||
|
def test_error_message_is_customer_facing(self):
|
||||||
|
with self.assertRaises(ValidationError) as error:
|
||||||
|
self._create_line(self.product_min, 1)
|
||||||
|
|
||||||
|
message = str(error.exception)
|
||||||
|
self.assertIn("Product min 6", message)
|
||||||
|
self.assertIn("6", message)
|
||||||
|
self.assertNotIn("force min", message, "Upstream jargon still present")
|
||||||
|
|
||||||
|
def test_valid_quantity_raises_nothing(self):
|
||||||
|
self._create_line(self.product_min, 6)
|
||||||
|
|
||||||
|
def test_indicative_minimum_still_does_not_block(self):
|
||||||
|
self._create_line(self.product_indicative, 1)
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# Product page display
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _hint_on_page(self, product):
|
||||||
|
response = self.url_open("/shop/%s" % slug(product.product_tmpl_id))
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
tree = html.fromstring(response.content)
|
||||||
|
return tree.xpath("//div[contains(@class, 'o_wsale_qty_restriction')]")
|
||||||
|
|
||||||
|
def test_hint_is_displayed(self):
|
||||||
|
hint = self._hint_on_page(self.product_min)
|
||||||
|
self.assertEqual(len(hint), 1)
|
||||||
|
self.assertIn("6", hint[0].text_content())
|
||||||
|
|
||||||
|
def test_no_hint_without_restriction(self):
|
||||||
|
self.assertFalse(self._hint_on_page(self.product_free))
|
||||||
|
|
||||||
|
def test_no_hint_for_an_indicative_minimum(self):
|
||||||
|
self.assertFalse(self._hint_on_page(self.product_indicative))
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<!-- Product page: tell the customer about the orderable quantities,
|
||||||
|
right below the quantity selector and the add-to-cart button. -->
|
||||||
|
<template id="product_restricted_qty_info"
|
||||||
|
inherit_id="website_sale.product_quantity"
|
||||||
|
name="Restricted Quantity Information">
|
||||||
|
<xpath expr="//div[@id='add_to_cart_wrap']" position="after">
|
||||||
|
<t t-set="qty_hint" t-value="product._get_restricted_qty_hint()"/>
|
||||||
|
<div t-if="qty_hint"
|
||||||
|
class="o_wsale_qty_restriction alert alert-info d-flex align-items-center w-100 mt-2 mb-0 py-2 px-3">
|
||||||
|
<i class="fa fa-info-circle me-2" role="img" aria-label="Information"/>
|
||||||
|
<span t-out="qty_hint"/>
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user