Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    Real Estate
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    Consulting
    • Accounting Firm
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • Solar Energy Systems
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    Others
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

extend the functionality of the module website_sale_stock

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
developmentecommerce
3032 มุมมอง
อวตาร
David Ventas

Well, the current behavior when we go to the shop, is according to how much item is left of a product, shows you the amount of Item that remains this logic does not take into account whether you are a registered user of the online store, or not. what I want is to expand the behavior and that if it is user without registering, do not show you the amount of stock I have of this item.

Current code of the module to be modified

website_sale_stock>static>src>xml>website_sale_stock_product_available.xml I can't show xml view


website_sale_stock>static>src>js>variant_mixin.js

odoo.define('website_sale_stock.VariantMixin', function (require) {
'use strict';

const {Markup} = require('web.utils');
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;

const loadXml = async () => {
return ajax.loadXML('/website_sale_stock/static/src/xml/website_sale_stock_product_availability.xml', QWeb);
};

require('website_sale.website_sale');

/**
* 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) {
let 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();
}
const isMainProduct = combination.product_id &&
($parent.is('.js_main_product') || $parent.is('.main_product')) &&
combination.product_id === parseInt(product_id);

if (!this.isWebsite || !isMainProduct) {
return;
}

const $addQtyInput = $parent.find('input[name="add_qty"]');
let qty = $addQtyInput.val();

$parent.find('#add_to_cart').removeClass('out_of_stock');
$parent.find('.o_we_buy_now').removeClass('out_of_stock');
if (combination.product_type === 'product' && !combination.allow_out_of_stock_order) {
combination.free_qty -= parseInt(combination.cart_qty);
$addQtyInput.data('max', combination.free_qty || 1);
if (combination.free_qty combination.free_qty = 0;
}
if (qty > combination.free_qty) {
qty = combination.free_qty || 1;
$addQtyInput.val(qty);
}
if (combination.free_qty $parent.find('#add_to_cart').addClass('disabled out_of_stock');
$parent.find('.o_we_buy_now').addClass('disabled out_of_stock');
}
}

loadXml().then(function (result) {
$('.oe_website_sale')
.find('.availability_message_' + combination.product_template)
.remove();
combination.has_out_of_stock_message = $(combination.out_of_stock_message).text() !== '';
combination.out_of_stock_message = Markup(combination.out_of_stock_message);
const $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);
},
/**
* Recomputes the combination after adding a product to the cart
* @override
*/
_onClickAdd(ev) {
return this._super.apply(this, arguments).then(() => {
if ($('div.availability_messages').length) {
this._getCombinationInfo(ev);
}
});
}
});

return VariantMixin;

});

website_sale_stock>controller>main.py

class PaymentPortal(website_sale_controller.PaymentPortal):

@http.route()
def shop_payment_transaction(self, *args, **kwargs):
""" Payment transaction override to double check cart quantities before
placing the order
"""
order = request.website.sale_get_order()
values = []
for line in order.order_line:
if line.product_id.type == 'product' and not line.product_id.allow_out_of_stock_order:
cart_qty = sum(order.order_line.filtered(lambda p: p.product_id.id == line.product_id.id).mapped('product_uom_qty'))
avl_qty = line.product_id.with_context(warehouse=order.warehouse_id.id).free_qty
if cart_qty > avl_qty:
values.append(_(
'You ask for %(quantity)s products but only %(available_qty)s is available',
quantity=cart_qty,
available_qty=avl_qty if avl_qty > 0 else 0
))
if values:
raise ValidationError('. '.join(values) + '.')
return super().shop_payment_transaction(*args, **kwargs)

Then the first thins that I do, is add necesary code for extend the behavior from website_sale_stock

website_sale_stock>static>src>xml>website_sale_stock_product_available.xml

Add t-if="user_id != public_user_id"

website_sale_stock>static>src>js>variant_mixin.js

The same origin

website_sale_stock>controller>main.py

class PaymentPortal(website_sale_controller.PaymentPortal):

@http.route()
def shop_payment_transaction(self, *args, **kwargs):
""" Payment transaction override to double check cart quantities before
placing the order
"""
order = request.website.sale_get_order()
values = []
for line in order.order_line:
if line.product_id.type == 'product' and not line.product_id.allow_out_of_stock_order:
cart_qty = sum(order.order_line.filtered(lambda p: p.product_id.id == line.product_id.id).mapped('product_uom_qty'))
avl_qty = line.product_id.with_context(warehouse=order.warehouse_id.id).free_qty
if cart_qty > avl_qty:
values.append(_(
'You ask for %(quantity)s products but only %(available_qty)s is available',
quantity=cart_qty,
available_qty=avl_qty if avl_qty > 0 else 0
))
if values:
raise ValidationError('. '.join(values) + '.')
return super().shop_payment_transaction(*args, **kwargs)

​@http.route('/restingir_visibilidad_stock/product_availability', type='http',auth='public',website=True)
    def custom_route(self, **kwargs):
        return request.render('restringir_visibilidad_stock.restriccion_view', {
            'user_id': request.env.user.id,
            'public_user_id': request.env.ref('base.public_user').id,
        })

And this code is sucessfully.

The last part is  I want to extract the code to create a new module and have generated the following code.

restringir_visibilidad_stock>static>src>xml>restriccion_view.xml

restringir_visibilidad_stock>static>src>js>variant.js

I copy origin code, and I change only, call to xml view

restringir_visibilidad_stock>controller>main.py

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.addons.website_sale.controllers import main as website_sale_controller

from odoo import http, _
from odoo.http import request
from odoo.exceptions import ValidationError

# código hecho por David Ymant
class PaymentPortal(http.HTTP):
       
    @http.route('/restingir_visibilidad_stock/product_availability', type='http',auth='public',website=True)
    def custom_route(self, **kwargs):
        return request.render('restringir_visibilidad_stock.restriccion_view', {
            'user_id': request.env.user.id,
            'public_user_id': request.env.ref('base.public_user').id,
        })

is functional, but this way I disable the option that in the search engine of the online store, show me the list of components that match the search, for example, if I put key, it don't display all items that begin with key...


Any thelp is welcome.

0
อวตาร
ละทิ้ง
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
อวตาร
0
พ.ย. 25
122
How to make all branches for user active automatically after login his account?
development
อวตาร
0
พ.ย. 25
146
How to create a new field have 2 related field by developer mode
development
อวตาร
อวตาร
2
ต.ค. 25
488
i face one error while edit my website
development
อวตาร
0
ต.ค. 25
610
How to add market price of the product to the Odoo 18 Community POS receipt?
development
อวตาร
0
ต.ค. 25
532
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now