İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

extend the functionality of the module website_sale_stock

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
developmentecommerce
3050 Görünümler
Avatar
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
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
How to make all branches for user active automatically after login his account?
development
Avatar
Avatar
1
Kas 25
169
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
Avatar
Avatar
1
Kas 25
165
How to create a new field have 2 related field by developer mode
development
Avatar
Avatar
2
Eki 25
504
i face one error while edit my website
development
Avatar
0
Eki 25
621
How to add market price of the product to the Odoo 18 Community POS receipt?
development
Avatar
0
Eki 25
551
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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