Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1719 Lượt xem

Environment: Odoo Version: 17.0 (Enterprise/Community)- Module: Point of Sale

Business Requirement:

We need to implement a maximum quantity limit per product in POS orders to prevent bulk purchases during promotional periods. 

Specific Requirements:

1. Configure maximum allowed quantity per product

2. Display warning/restriction in POS when quantity exceeds the limit

3. Prevent order completion OR show alert message when limit is exceeded

Use Case:

During promotional offers, we need to ensure fair distribution of discounted products to end consumers by preventing bulk purchases. For example:- Product A has a max limit of 5 units per order- If customer tries to purchase 7 units, system should either:  - Show warning message  - OR prevent adding more than 5 units  - OR require manager approval for exceeding limit

Questions:

1. Is there any existing functionality in Odoo 17 to achieve this?

2. If not, what would be the recommended approach to implement this?   

​2a. Custom field for max quantity limit on product form?   

​2b. POS order line validation?   

​2c. Alert/restriction mechanism?

What we've Investigated: Checked standard POS configuration options- Reviewed product form fields- Searched for similar implementations

Any guidance on implementing this feature would be greatly appreciated. Technical implementation details or pointers to similar solutions would be helpful.


Regards
odoo@tenthplanet

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello, Tenth Planet,


To implement a maximum purchase quantity limit per product in a POS order, follow the steps outlined below:


1. Add a New Field in the Product Model


File: `models/product_product.py`

Objective: Add a new field to the `product.product` model to store the quantity limit for each product.


//Code 1 in comment//


2. Inherit the POS Data Loader in POS Session Model


File: `models/pos_session.py`

Objective: Ensure the `pos_product_qty_limit` field is loaded into the POS session for use in the frontend.


//Code 2 in comment//


3. Patch the POS Order Model


File: `static/src/js/models/order.js`

Objective: Add a validation step in the `pay` method to enforce the product quantity limit during payment.


Add this file path in the manifest under `"point_of_sale.assets_prod"`.


//Code 3 in Comment//


Ensure the `point_of_sale` dependency is added to the `__manifest__.py` file. Additionally, include the new JavaScript file path in `"point_of_sale.assets_prod"`.


5. Payment Button Behavior


When a user clicks the "Payment" button in the POS screen: 

- If a product's quantity exceeds the limit, an error popup is displayed. 

- Payment is blocked until the product quantities are corrected.


6. Output


Below is an example of the error popup displayed when a product's quantity exceeds its limit. 


 


Hope this helps! If you need any assistance with customization, feel free to contact us.


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari


Ảnh đại diện
Huỷ bỏ

//Code 1//

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ProductProduct(models.Model):
_inherit = "product.product"

# New field to define the maximum quantity limit for a product in POS.
pos_product_qty_limit = fields.Integer("POS Product Quantity Limit")

//Code 2//

# -*- coding: utf-8 -*-
from odoo import models

class PosSession(models.Model):
_inherit = "pos.session"

def _loader_params_product_product(self):
"""
This method customizes the loader parameters for loading product data in a POS session.
Specifically, it ensures that the `pos_product_qty_limit` field is included
when product data is loaded into the POS interface.
"""
result = super()._loader_params_product_product()

# Add the `pos_product_qty_limit` field to the list of fields to be loaded.
result["search_params"]["fields"].extend(["pos_product_qty_limit"])

return result

//Code 3//

/* @odoo-module */

import { patch } from "@web/core/utils/patch";
import { Order } from "@point_of_sale/app/store/models";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
import { _t } from "@web/core/l10n/translation";

// Patch the Order model to include quantity validation during payment.
patch(Order.prototype, {
/**
* Override the `pay` method to include custom validation logic for product quantity limits.
* This ensures that users cannot pay for an order if any product's quantity exceeds its defined limit.
*/
async pay() {
const orderLines = this.get_orderlines();

for (const line of orderLines) {
const posProductQtyLimit = line.product.pos_product_qty_limit;
// Check if the quantity exceeds the limit.
if (posProductQtyLimit > 0 && line.quantity > posProductQtyLimit) {
// Display a warning popup if the limit is exceeded.
this.env.services.popup.add(ErrorPopup, {
title: _t("Product Quantity Exceeded"),
body: _t(`The quantity for the product "${line.product.display_name}" exceeds the limit. You cannot add a quantity greater than "${posProductQtyLimit}".`),
});
return;
}
}
return super.pay(...arguments);
},
});

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 1 25
1285
1
thg 1 25
1294
1
thg 8 24
1238
0
thg 6 24
1154
2
thg 8 16
4089