Skip to content

Commit 4f9f0ea

Browse files
committed
[ADD] website_sale_free_qty_virtual_available: Change no stock message from free_qty to virtual_available
1 parent fe9923e commit 4f9f0ea

8 files changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../website_sale_free_qty_virtual_available
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg
2+
:target: https://opensource.org/licenses/LGPL-3.0
3+
:alt: License: LGPL-3
4+
5+
=======================================================
6+
Website Sale Free Qty Virtual Available
7+
=======================================================
8+
9+
Overview
10+
========
11+
12+
The **Website Sale Free Qty Virtual Available** module replaces the usage of `free_qty` with `virtual_available` to determine if stock is available or not in the context of online sales. This adjustment ensures that only the available quantity (considering reserved stock) is used to check stock availability.
13+
14+
Features
15+
========
16+
17+
- **Stock Availability Based on Virtual Available**:
18+
- The module uses the `virtual_available` field instead of `free_qty` to determine if a product is available for sale, ensuring a more accurate representation of stock levels.
19+
20+
- **Customization**:
21+
- Modifies the product availability template to check stock availability using `virtual_available` when determining if the product is out of stock.
22+
23+
- **Updated Variant Controller**:
24+
- The module extends the variant controller to include the `virtual_available` value for a product, ensuring accurate stock information is provided when querying product combinations.
25+
26+
Usage
27+
=====
28+
29+
1. **Install the Module**:
30+
- Install the **Website Sale Free Qty Virtual Available** module from the Apps menu.
31+
32+
2. **Product Availability Check**:
33+
- After installation, the stock availability check on the website will be based on the `virtual_available` field, which accounts for both real stock and reserved quantities.
34+
35+
3. **Combination Info**:
36+
- When querying product combinations, the updated `virtual_available` value will be included in the response, providing accurate stock information for each variant.
37+
38+
Configuration
39+
=============
40+
41+
No additional configuration is required. The module will automatically replace the use of `free_qty` with `virtual_available` for stock availability checks.
42+
43+
Testing
44+
=======
45+
46+
1. Test by adding a product to the website and verifying that the stock status is based on `virtual_available`.
47+
2. Confirm that when querying product combinations, the `virtual_available` field is correctly included in the response.
48+
49+
Bug Tracker
50+
===========
51+
52+
If you encounter any issues, please report them on the GitHub repository at `GitHub Issues <https://github.com/avanzosc/odoo-addons/issues>`_.
53+
54+
Credits
55+
=======
56+
57+
Contributors
58+
------------
59+
60+
* Ana Juaristi <anajuaristi@avanzosc.es>
61+
* Unai Beristain <unaiberistain@avanzosc.es>
62+
63+
For specific questions or support, please contact the contributors.
64+
65+
License
66+
=======
67+
68+
This project is licensed under the LGPL-3 License. For more details, refer to the LICENSE file or visit <https://opensource.org/licenses/LGPL-3.0>.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import controllers
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Website Sale Free Qty Virtual Available",
3+
"version": "16.0.1.0.0",
4+
"category": "Website",
5+
"author": "Avanzosc",
6+
"license": "LGPL-3",
7+
"depends": ["website_sale_stock"],
8+
"assets": {
9+
"web.assets_frontend": [
10+
"website_sale_free_qty_virtual_available/static/src/xml/**/*",
11+
],
12+
},
13+
"installable": True,
14+
"application": False,
15+
"website": "https://github.com/avanzosc/sale-addons",
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import variant
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from odoo import http
2+
from odoo.http import request
3+
4+
from odoo.addons.sale.controllers.variant import VariantController
5+
6+
7+
class VariantControllerInherit(VariantController):
8+
9+
@http.route(
10+
["/sale/get_combination_info"], type="json", auth="user", methods=["POST"]
11+
)
12+
def get_combination_info(
13+
self, product_template_id, product_id, combination, add_qty, pricelist_id, **kw
14+
):
15+
res = super().get_combination_info(
16+
product_template_id, product_id, combination, add_qty, pricelist_id, **kw
17+
)
18+
19+
# Obtener el product.template y agregar el campo virtual_available al resultado
20+
product_template = request.env["product.template"].browse(
21+
int(product_template_id)
22+
)
23+
res.update({"virtual_available": product_template.virtual_available})
24+
25+
return res
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates id="template" xml:space="preserve">
3+
<t
4+
t-name="product_availability"
5+
t-inherit="website_sale_stock.product_availability"
6+
>
7+
<xpath expr="//t[@t-if='has_out_of_stock_message']/../.." position="attributes">
8+
<attribute name="t-if">virtual_available lte 0 and !cart_qty</attribute>
9+
</xpath>
10+
</t>
11+
</templates>

0 commit comments

Comments
 (0)