Compare commits
3 Commits
16.0-sale_
...
e04ab5b009
| Author | SHA1 | Date | |
|---|---|---|---|
| e04ab5b009 | |||
| a7c005c839 | |||
| be44c3c5d4 |
27
pw_sale_total_qty/LICENSE
Normal file
27
pw_sale_total_qty/LICENSE
Normal file
@@ -0,0 +1,27 @@
|
||||
Odoo Proprietary License v1.0
|
||||
|
||||
This software and associated files (the "Software") may only be used (executed,
|
||||
modified, executed after modifications) if you have purchased a valid license
|
||||
from the authors, typically via Odoo Apps, or if you have received a written
|
||||
agreement from the authors of the Software (see the COPYRIGHT file).
|
||||
|
||||
You may develop Odoo modules that use the Software as a library (typically
|
||||
by depending on it, importing it and using its resources), but without copying
|
||||
any source code or material from the Software. You may distribute those
|
||||
modules under the license of your choice, provided that this license is
|
||||
compatible with the terms of the Odoo Proprietary License (For example:
|
||||
LGPL, MIT, or proprietary licenses similar to this one).
|
||||
|
||||
It is forbidden to publish, distribute, sublicense, or sell copies of the Software
|
||||
or modified copies of the Software.
|
||||
|
||||
The above copyright notice and this permission notice must be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
3
pw_sale_total_qty/__init__.py
Normal file
3
pw_sale_total_qty/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
||||
21
pw_sale_total_qty/__manifest__.py
Normal file
21
pw_sale_total_qty/__manifest__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
{
|
||||
"name": "Sale Order Total Quantity",
|
||||
'version': '16.0.1.0.1',
|
||||
'author': 'Preway IT Solutions',
|
||||
'category': 'Sales',
|
||||
'depends': ['sale'],
|
||||
'summary': 'This module helps you to show total qty, delivered qty, invoiced qty and remaining qty on sale order | Sale Order Total Quantity | Sale Total Qty | Total Quantity Of Sale Order Line',
|
||||
'description': """
|
||||
- Sale Order Total Quantity
|
||||
""",
|
||||
'data': [
|
||||
"views/sale_order_view.xml",
|
||||
],
|
||||
'price': 3.0,
|
||||
'currency': "EUR",
|
||||
'application': True,
|
||||
'installable': True,
|
||||
"license": "LGPL-3",
|
||||
"images":["static/description/Banner.png"],
|
||||
}
|
||||
61
pw_sale_total_qty/i18n/fr.po
Normal file
61
pw_sale_total_qty/i18n/fr.po
Normal file
@@ -0,0 +1,61 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * pw_sale_total_qty
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-12-31 13:03+0000\n"
|
||||
"PO-Revision-Date: 2024-12-31 13:03+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: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_remaining_delivery
|
||||
msgid "Pending Delivery Qty"
|
||||
msgstr "Quantités à livrer"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_remaining_invoice
|
||||
msgid "Pending Invoice Qty"
|
||||
msgstr "Quantités à facturer"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model,name:pw_sale_total_qty.model_sale_order
|
||||
msgid "Sales Order"
|
||||
msgstr "Bon de commande"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_qty_delivered
|
||||
msgid "Total Delivered Qty"
|
||||
msgstr "Total quantités livrées"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Deliverted"
|
||||
msgstr "Total quantités"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Demand"
|
||||
msgstr " Total commandé"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_product_uom_qty
|
||||
msgid "Total Demand Qty"
|
||||
msgstr " Total quantités commandées"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Invoiced"
|
||||
msgstr "Total facturé"
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_qty_invoiced
|
||||
msgid "Total Invoiced Qty"
|
||||
msgstr "Total quantités facturées"
|
||||
61
pw_sale_total_qty/i18n/pw_sale_total_qty.pot
Normal file
61
pw_sale_total_qty/i18n/pw_sale_total_qty.pot
Normal file
@@ -0,0 +1,61 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * pw_sale_total_qty
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 16.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-12-31 13:03+0000\n"
|
||||
"PO-Revision-Date: 2024-12-31 13:03+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: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_remaining_delivery
|
||||
msgid "Pending Delivery Qty"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_remaining_invoice
|
||||
msgid "Pending Invoice Qty"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model,name:pw_sale_total_qty.model_sale_order
|
||||
msgid "Sales Order"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_qty_delivered
|
||||
msgid "Total Delivered Qty"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Deliverted"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Demand"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_product_uom_qty
|
||||
msgid "Total Demand Qty"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model_terms:ir.ui.view,arch_db:pw_sale_total_qty.view_order_form_inherit_pw_total_qty
|
||||
msgid "Total Invoiced"
|
||||
msgstr ""
|
||||
|
||||
#. module: pw_sale_total_qty
|
||||
#: model:ir.model.fields,field_description:pw_sale_total_qty.field_sale_order__pw_total_qty_invoiced
|
||||
msgid "Total Invoiced Qty"
|
||||
msgstr ""
|
||||
2
pw_sale_total_qty/models/__init__.py
Normal file
2
pw_sale_total_qty/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import sale_order
|
||||
40
pw_sale_total_qty/models/sale_order.py
Normal file
40
pw_sale_total_qty/models/sale_order.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = 'sale.order'
|
||||
|
||||
pw_total_product_uom_qty = fields.Float(string="Total Demand Qty", compute='_compute_pw_total_product_uom_qty')
|
||||
pw_total_qty_delivered = fields.Float(string="Total Delivered Qty", compute='_compute_pw_total_qty_delivered')
|
||||
pw_total_qty_invoiced = fields.Float(string="Total Invoiced Qty", compute='_compute_pw_total_qty_invoiced')
|
||||
pw_remaining_delivery = fields.Float(string="Pending Delivery Qty", compute="_compute_pw_remaining_delivery")
|
||||
pw_remaining_invoice = fields.Float(string="Pending Invoice Qty", compute="_compute_pw_remaining_invoice")
|
||||
|
||||
@api.depends('order_line.product_uom_qty')
|
||||
def _compute_pw_total_product_uom_qty(self):
|
||||
for order in self:
|
||||
order.pw_total_product_uom_qty = sum(order.order_line.mapped('product_uom_qty'))
|
||||
|
||||
@api.depends('order_line.qty_delivered')
|
||||
def _compute_pw_total_qty_delivered(self):
|
||||
for order in self:
|
||||
order.pw_total_qty_delivered = sum(order.order_line.mapped('qty_delivered'))
|
||||
|
||||
@api.depends('order_line.qty_invoiced')
|
||||
def _compute_pw_total_qty_invoiced(self):
|
||||
for order in self:
|
||||
order.pw_total_qty_invoiced = sum(order.order_line.mapped('qty_invoiced'))
|
||||
|
||||
@api.depends('order_line.product_uom_qty', 'order_line.qty_delivered')
|
||||
def _compute_pw_remaining_delivery(self):
|
||||
for order in self:
|
||||
delivery_qty = sum(order.order_line.filtered(lambda x: x.product_id.type != 'service').mapped('product_uom_qty'))
|
||||
delivered_qty = sum(order.order_line.mapped('qty_delivered'))
|
||||
order.pw_remaining_delivery = delivery_qty - delivered_qty
|
||||
|
||||
@api.depends('pw_total_product_uom_qty', 'pw_total_qty_invoiced')
|
||||
def _compute_pw_remaining_invoice(self):
|
||||
for order in self:
|
||||
order.pw_remaining_invoice = order.pw_total_product_uom_qty - order.pw_total_qty_invoiced
|
||||
BIN
pw_sale_total_qty/static/description/Banner.png
Normal file
BIN
pw_sale_total_qty/static/description/Banner.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
BIN
pw_sale_total_qty/static/description/icon.png
Normal file
BIN
pw_sale_total_qty/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
45
pw_sale_total_qty/static/description/index.html
Normal file
45
pw_sale_total_qty/static/description/index.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<section class="oe_container oe_dark" style="overflow: hidden;
|
||||
background: #cddae8;
|
||||
border-radius: 15px;">
|
||||
<div class="mt32 mb32">
|
||||
<div class="col-md-12">
|
||||
<h2 class="oe_slogan" style="font-family: Quicksand; font-size: 35px;"><b>Sale Order Total Quantity</b></h2>
|
||||
<h3 class="oe_slogn" style="font-family: Quicksand; text-align: center;">This module helps you to show total qty, delivered qty, invoiced qty and remaining qty on sale order
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<br/><br/>
|
||||
|
||||
<section class="oe_container">
|
||||
<div class="alert" style="color: black;background-color: #cddae8;border-color: black;">
|
||||
<i class="fa fa-hand-o-right"></i><b> App Features</b>
|
||||
</div>
|
||||
<ul class="list-unstyled mr32 ml32">
|
||||
<li><i class="fa fa-check" style="color: #cddae8;"></i> Show Total Demand Qty, Delivered and Invoiced Quantity on Sale Order </li>
|
||||
<li><i class="fa fa-check" style="color: #cddae8;"></i> Show Remaining Delivery and Invoice Quantity on Sale Order</li>
|
||||
<li><i class="fa fa-check" style="color: #cddae8;"></i> Also compatible with community and enterprise</li>
|
||||
</ul>
|
||||
<div class="alert text-center mt32" style="background-color: #cddae8;border-color: black;">
|
||||
<b>Sale Order Total Quantity</b>
|
||||
</div>
|
||||
<br/>Total Demand, Delivered, Invoiced, Pending Delivery and Pending Invoiced Quanatity on sale order. (Service product not count in pending delivery)<br/>
|
||||
<img class="img-border img-responsive thumbnail mt32" src="sale1.png" style="width: 100%;">
|
||||
</section>
|
||||
|
||||
<section class="oe_container" style="overflow: hidden;">
|
||||
<div class="mt32 mb32">
|
||||
<div class="col-md-12" style="text-align: center;">
|
||||
<img src="pw_logo.png" style="width: 300px;" /><br>
|
||||
</div><br>
|
||||
<div class="oe_slogan text-center">
|
||||
<h2 class="oe_slogan">
|
||||
Contact US
|
||||
</h2>
|
||||
<p class="btn btn-success mt8" style="background-color: #2355a6; color: #FFFFFF !important;font-size:20px;"> Email : prewayit@gmail.com </p>
|
||||
</div>
|
||||
<div style="text-align: center;">
|
||||
<p>Note: We give free support incase any bug or issue in our apps (Except data recovery).</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
BIN
pw_sale_total_qty/static/description/pw_logo.png
Normal file
BIN
pw_sale_total_qty/static/description/pw_logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
BIN
pw_sale_total_qty/static/description/sale1.png
Normal file
BIN
pw_sale_total_qty/static/description/sale1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 255 KiB |
30
pw_sale_total_qty/views/sale_order_view.xml
Normal file
30
pw_sale_total_qty/views/sale_order_view.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="view_order_form_inherit_pw_total_qty" model="ir.ui.view">
|
||||
<field name="name">sale.order.form.inherit.pw.total.qty</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="sale.view_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='note']" position="before">
|
||||
<group>
|
||||
<field name="pw_total_product_uom_qty"/>
|
||||
<field name="pw_total_qty_delivered"/>
|
||||
<field name="pw_total_qty_invoiced"/>
|
||||
<field name="pw_remaining_delivery"/>
|
||||
<field name="pw_remaining_invoice"/>
|
||||
</group>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='order_line']//tree//field[@name='product_uom_qty']" position="attributes">
|
||||
<attribute name="sum">Total Demand</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='order_line']//tree//field[@name='qty_delivered']" position="attributes">
|
||||
<attribute name="sum">Total Deliverted</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='order_line']//tree//field[@name='qty_invoiced']" position="attributes">
|
||||
<attribute name="sum">Total Invoiced</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -1 +0,0 @@
|
||||
from . import models
|
||||
@@ -1,35 +0,0 @@
|
||||
# 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,
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
# 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"
|
||||
@@ -1,2 +0,0 @@
|
||||
from . import product_restricted_qty_mixin
|
||||
from . import sale_order_line
|
||||
@@ -1,59 +0,0 @@
|
||||
# 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:]
|
||||
@@ -1,62 +0,0 @@
|
||||
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),
|
||||
)
|
||||
@@ -1,45 +0,0 @@
|
||||
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 +0,0 @@
|
||||
from . import test_restricted_qty_website_sale
|
||||
@@ -1,89 +0,0 @@
|
||||
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))
|
||||
@@ -1,19 +0,0 @@
|
||||
<?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