diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_sale_stock/static | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_sale_stock/static')
| -rw-r--r-- | addons/website_sale_stock/static/description/icon.png | bin | 0 -> 6644 bytes | |||
| -rw-r--r-- | addons/website_sale_stock/static/description/icon.svg | 1 | ||||
| -rw-r--r-- | addons/website_sale_stock/static/src/js/variant_mixin.js | 93 | ||||
| -rw-r--r-- | addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml | 29 |
4 files changed, 123 insertions, 0 deletions
diff --git a/addons/website_sale_stock/static/description/icon.png b/addons/website_sale_stock/static/description/icon.png Binary files differnew file mode 100644 index 00000000..c772bceb --- /dev/null +++ b/addons/website_sale_stock/static/description/icon.png diff --git a/addons/website_sale_stock/static/description/icon.svg b/addons/website_sale_stock/static/description/icon.svg new file mode 100644 index 00000000..b519bd02 --- /dev/null +++ b/addons/website_sale_stock/static/description/icon.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="70" viewBox="0 0 70 70"><defs><path id="a" d="M4 0h61c4 0 5 1 5 5v60c0 4-1 5-5 5H4c-3 0-4-1-4-5V5c0-4 1-5 4-5z"/><linearGradient id="c" x1="100%" x2="0%" y1="0%" y2="100%"><stop offset="0%" stop-color="#B06161"/><stop offset="45.785%" stop-color="#984E4E"/><stop offset="100%" stop-color="#7C3838"/></linearGradient><path id="d" d="M24.592 27.281l3.283 14.7L31 41.796V39h19v2.042h1.908c1.441 0 1.441 1.834.088 1.998L28.36 44l.942 3h21.801c.942 0 .942 2 0 2H27.417l-5.65-24h-1.884v1c0 .667-.313 1-.941 1-.628 0-.942-.333-.942-1v-2c.062-.667.376-1 .942-1h3.767c.486 0 .8.333.941 1l.942 3.281zM49.423 55a2.497 2.497 0 0 1-2.493-2.5c0-1.38 1.116-2.5 2.493-2.5a2.497 2.497 0 0 1 2.494 2.5c0 1.38-1.117 2.5-2.494 2.5zm-19.95 0a2.497 2.497 0 0 1-2.494-2.5c0-1.38 1.116-2.5 2.494-2.5a2.497 2.497 0 0 1 2.493 2.5c0 1.38-1.116 2.5-2.493 2.5zM31 35h19v3H31v-3zm0-5h19v4H31v-4zm0-5h19v4H31v-4zm1 1v2h17v-2H32z"/><path id="e" d="M24.592 25.281l3.283 14.7L31 39.796V37h19v2.042h1.908c1.441 0 1.441 1.834.088 1.998L28.36 42l.942 3h21.801c.942 0 .942 2 0 2H27.417l-5.65-24h-1.884v1c0 .667-.313 1-.941 1-.628 0-.942-.333-.942-1v-2c.062-.667.376-1 .942-1h3.767c.486 0 .8.333.941 1l.942 3.281zM49.423 53a2.497 2.497 0 0 1-2.493-2.5c0-1.38 1.116-2.5 2.493-2.5a2.497 2.497 0 0 1 2.494 2.5c0 1.38-1.117 2.5-2.494 2.5zm-19.95 0a2.497 2.497 0 0 1-2.494-2.5c0-1.38 1.116-2.5 2.494-2.5a2.497 2.497 0 0 1 2.493 2.5c0 1.38-1.116 2.5-2.493 2.5zM31 33h19v3H31v-3zm0-5h19v4H31v-4zm0-5h19v4H31v-4zm1 1v2h17v-2H32z"/></defs><g fill="none" fill-rule="evenodd"><mask id="b" fill="#fff"><use xlink:href="#a"/></mask><g mask="url(#b)"><path fill="url(#c)" d="M0 0H70V70H0z"/><path fill="#FFF" fill-opacity=".383" d="M4 1h61c2.667 0 4.333.667 5 2V0H0v3c.667-1.333 2-2 4-2z"/><path fill="#393939" d="M35.869 69H4c-2 0-4-1-4-4V38.32l18.528-17.185h4.459l2.385 7.467L31 23h19v16l2.5 1.5-9.773 4.8H51V47l-.637 1.385 1.485 2.626-.388.927L35.869 69z" opacity=".324"/><path fill="#000" fill-opacity=".383" d="M4 69h61c2.667 0 4.333-1 5-3v4H0v-4c.667 2 2 3 4 3z"/><use fill="#000" fill-rule="nonzero" opacity=".3" xlink:href="#d"/><use fill="#FFF" fill-rule="nonzero" xlink:href="#e"/></g></g></svg>
\ No newline at end of file diff --git a/addons/website_sale_stock/static/src/js/variant_mixin.js b/addons/website_sale_stock/static/src/js/variant_mixin.js new file mode 100644 index 00000000..0c201a82 --- /dev/null +++ b/addons/website_sale_stock/static/src/js/variant_mixin.js @@ -0,0 +1,93 @@ +odoo.define('website_sale_stock.VariantMixin', function (require) { +'use strict'; + +var VariantMixin = require('sale.VariantMixin'); +var publicWidget = require('web.public.widget'); +var ajax = require('web.ajax'); +var core = require('web.core'); +var QWeb = core.qweb; +var xml_load = ajax.loadXML( + '/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml', + QWeb +); + +/** + * Addition to the variant_mixin._onChangeCombination + * + * This will prevent the user from selecting a quantity that is not available in the + * stock for that product. + * + * It will also display various info/warning messages regarding the select product's stock. + * + * This behavior is only applied for the web shop (and not on the SO form) + * and only for the main product. + * + * @param {MouseEvent} ev + * @param {$.Element} $parent + * @param {Array} combination + */ +VariantMixin._onChangeCombinationStock = function (ev, $parent, combination) { + var product_id = 0; + // needed for list view of variants + if ($parent.find('input.product_id:checked').length) { + product_id = $parent.find('input.product_id:checked').val(); + } else { + product_id = $parent.find('.product_id').val(); + } + var isMainProduct = combination.product_id && + ($parent.is('.js_main_product') || $parent.is('.main_product')) && + combination.product_id === parseInt(product_id); + + if (!this.isWebsite || !isMainProduct){ + return; + } + + var qty = $parent.find('input[name="add_qty"]').val(); + + $parent.find('#add_to_cart').removeClass('out_of_stock'); + $parent.find('#buy_now').removeClass('out_of_stock'); + if (combination.product_type === 'product' && _.contains(['always', 'threshold'], combination.inventory_availability)) { + combination.virtual_available -= parseInt(combination.cart_qty); + if (combination.virtual_available < 0) { + combination.virtual_available = 0; + } + // Handle case when manually write in input + if (qty > combination.virtual_available) { + var $input_add_qty = $parent.find('input[name="add_qty"]'); + qty = combination.virtual_available || 1; + $input_add_qty.val(qty); + } + if (qty > combination.virtual_available + || combination.virtual_available < 1 || qty < 1) { + $parent.find('#add_to_cart').addClass('disabled out_of_stock'); + $parent.find('#buy_now').addClass('disabled out_of_stock'); + } + } + + xml_load.then(function () { + $('.oe_website_sale') + .find('.availability_message_' + combination.product_template) + .remove(); + + var $message = $(QWeb.render( + 'website_sale_stock.product_availability', + combination + )); + $('div.availability_messages').html($message); + }); +}; + +publicWidget.registry.WebsiteSale.include({ + /** + * Adds the stock checking to the regular _onChangeCombination method + * @override + */ + _onChangeCombination: function (){ + this._super.apply(this, arguments); + VariantMixin._onChangeCombinationStock.apply(this, arguments); + } +}); + +return VariantMixin; + +}); diff --git a/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml b/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml new file mode 100644 index 00000000..8bb6682e --- /dev/null +++ b/addons/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<templates> + + <t t-name="website_sale_stock.product_availability"> + <t t-if="product_type == 'product' and _.contains(['always', 'threshold'], inventory_availability)"> + <t t-if="virtual_available gt 0"> + <div t-if="inventory_availability == 'always'" t-attf-class="availability_message_#{product_template} text-success mt16"> + <t t-esc="virtual_available_formatted" /> <t t-esc="uom_name" /> available + </div> + <t t-if="inventory_availability == 'threshold'"> + <div t-if="virtual_available lte available_threshold" t-attf-class="availability_message_#{product_template} text-warning mt16"> + <i class="fa fa-exclamation-triangle" title="Warning" role="img" aria-label="Warning"/> + <t t-esc="virtual_available_formatted" /> <t t-esc="uom_name" /> available + </div> + <div t-if="virtual_available gt available_threshold" t-attf-class="availability_message_#{product_template} text-success mt16">In stock</div> + </t> + </t> + <div t-if="cart_qty" t-attf-class="availability_message_#{product_template} text-warning mt8"> + You already added <t t-if="!virtual_available">all</t> <t t-esc="cart_qty" /> <t t-esc="uom_name" /> in your cart. + </div> + <div t-if="!cart_qty and virtual_available lte 0" t-attf-class="availability_message_#{product_template} text-danger mt16"><i class="fa fa-exclamation-triangle" role="img" aria-label="Warning" title="Warning"/> Temporarily out of stock</div> + </t> + <div t-if="product_type == 'product' and inventory_availability == 'custom'" t-attf-class="availability_message_#{product_template} text-success mt16"> + <t t-esc="custom_message" /> + </div> + </t> + +</templates> |
