generate warning when button click odoo website - odoo

I want to generate a warning near ADDTOCART when the ADDTOCART button clicked on odoo website.
XML file:
<t t-if="website.get_promo_code_error(delete=False)">
<div class="card bg-danger text-white mt16">
<div class="card-header clearfix">
<span class="float-left"><t t-esc="website.get_promo_code_error()" /></span>
</div>
</div>
</t>
Controler:
request.session['error_promo_code'] = "Can not add"
return request.redirect("/shop/product/%s" % product.id)
model:
def get_promo_code_error(self, delete=True):
error = request.session.get('error_promo_code')
if error and delete:
request.session.pop('error_promo_code')
return error

In Odoo there is a default feature which provides on the website.
Goto Product -> Ecommerce tab -> there you find field Availability-> select this option
Show inventory below a threshold and prevent sales if not enough stock
It will allow you to add the Availability Threshold, Add your product stock value like 10.
When you go on the webshop and add more than 10 qty for the same product it will trigger the message near the add to cart button.

Related

Right way of using asp-page and asp-route in asp.net core razor pages between _layout and index page

Below is the file structure
I have default Index page under Pages folder, which has layout as _LayoutHarman.cshmtl
Code : Pages/Shared/_LayoutHarman.chtml
header menu : pages are in subfolder.ie category folder in this case
<a asp-route-cat_slug="electronic" asp-page="./category/Index">Electronic</a>
<a asp-route-cat_slug="beauty-care" asp-page="./category/index" >Beauty Care</a>
<a asp-route-cat_slug="toy" asp-page="./category/index" >Toy</a>
footer menu : pages are on root folder
<a asp-page="./Contact" >Contact</a>
<a asp-page="./terms" >Terms</a>
<a asp-page="./privacy" >Privacy</a>
Code : Pages/category/Index.cshtml
#page "{cat_slug?}/{pageIndex:int?}"
#model bList.Pages.category.IndexModel
#{
}
<nav aria-label="Page navigation example">
<ul class="pagination text-center">
#if(Model.prev_no!=0){
<li><a asp-page="category" asp-route-cat_slug="#Model.cat_url" asp-route-pageIndex="#Model.prev_no"> Previous</a></li>
}
#if (Model.no_more_record != "YES")
{
<li><a asp-page="category" asp-route-cat_slug="#Model.cat_url" asp-route-pageIndex="#Model.next_no">Next</a></li>
}
</ul>
</nav>
Here Next/ previous button generate url as follow
https://localhost:8080/category/toy/1
https://localhost:8080/category/toy/2
https://localhost:8080/category/toy/3
respective on selected category
Issue : When i visit on category page and click on prev or next button and then try to click on link Contact,Terms,Privacy i.e (which is on _LayoutHarman.cshtml) or on header menu then href become blank.
Edited One:
Code: On _LayoutHarman.cshtml
HeaderMenu:
<a href="./category/toy" >toy</a>
Footer Menu
<a asp-page="./Contact" >Contact</a>
<a asp-page="./terms" >Terms</a>
Code: On Category/Index.html page
Prev</li>
Next
Now on Next/ Prev button click , header menu generates url as
https://localhost:44382/category/toy/category/toy hence error page occurs. but for footer menu contact/term/privacy works properly
I did reproduce your problem, you need to delete the point(.) in asp-page attribute in your _LayoutHarman.cshmtl.
Changed like this:
<a asp-route-cat_slug="electronic" asp-page="/category/Index">Electronic</a>
<a asp-route-cat_slug="beauty-care" asp-page="/category/index" >Beauty Care</a>
<a asp-route-cat_slug="toy" asp-page="/category/index" >Toy</a>
<a asp-page="/Contact" >Contact</a>
<a asp-page="/terms" >Terms</a>
<a asp-page="/privacy" >Privacy</a>
And you don't need to add asp-page="category" in Pages/category/Index.cshtml, just delete this attribute in this page.
Here is my test result:
Do you really need all this extra server side processing, asp-route-cat_slug asp-page?
Can't you just use plain old fashion HTML hyperlink? As for the dynamic parameters maybe you can set only them...
View category
Just an idea to think on...
Cheers

Select new products by hand on PrestaShop

PrestaShop v. 1.7.6 shows new products on homepage which are added to shop in last X days. But usually, this doesn't work for my clients, because they want to select them by hand. There are a lot of new products and only a few have to be promoted.
How it is possible to let the client Select which products will be in section "New" on the homepage and these products also should have LABEL "NEW" in categories listing everywhere in the shop, as it is by default for new products in PrestaShop.
New products are selected automatically by PrestaShop.
By default, all products you add are considered to be New. You may change number of days during which your products is considered as New at
Shop Parameters -> Product Settings -> Number of days for which the product is considered 'new'
Then the only way to select the products considered as new is modifying the field date_add at table ps_product.
You can override module ps_newproducts to change the expected behavior.
I did that on one of my project. I have override the module for a manual selection of products to display, it's more simple
The simple way is to use the ps_featuredproducts module and change translations.
This module works by position and you can change position manually.
I created a new category "News" to select products by hand. So now I need to add label in listing and product page:
/catalog/_partials/miniatiures/product.tpl:
{block name='product_flags'}
<ul class="product-flags">
<!-- CUSTOM CODE -->
{foreach from=Product::getProductCategoriesFull($product.id_product) item=cat}
{if $cat.name== 'News' }
<li class="product-flag new">New</li>
{/if}
{/foreach}
<!-- / CUSTOM CODE -->
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
/catalog/product.tpl:
{block name='product_flags'}
<ul class="product-flags">
<!-- CUSTOM CODE -->
{foreach from=Product::getProductCategoriesFull(Tools::getValue('id_product')) item=cat}
{if $cat.name== 'News' }
<li class="product-flag new">New</li>
{/if}
{/foreach}
<!-- / CUSTOM CODE -->
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
To show these products in homepage I have used this FREE MODULE:
https://mypresta.eu/modules/front-office-features/featured-products.html

Add extra option in Karenderia food item

I have used "Karenderia Multiple Restaurant System". I want to add an extra option to Food item. For that i have done this as bellow.
Added to food-item-add.php
<div class="uk-form-row">
<label class="uk-form-label uk-h3"><?php echo t("Food Type")?></label>
<div class="clear"></div>
<ul class="uk-list uk-list-striped">
<li>
<?php
if(!isset($data['non_veg'])){
$data['non_veg']='';
}
echo CHtml::checkBox('non_veg',
$data['non_veg']==2?true:false
,array(
'class'=>"icheck",
'value'=>2
))?>
<?php echo t("Non Veg")?>
</li>
</ul>
</div>
After that i have added this in AjaxAdmin.php to FoodItemAdd function, which action in the admin.js
'non_veg'=>isset($this->data['non_veg'])?$this->data['non_veg']:1,
After that i have added to the table_structure.php to "CREATE TABLE IF NOT EXISTS ".$table_prefix."item"
`non_veg` int(1) NOT NULL DEFAULT '1',
Now, I want to add the option to an item. But i am getting the a ajax error like this
Uncaught ReferenceError: data is not defined
at Object.error (admin.js?ver=1:290)
at c (jquery-1.10.2.min.js:4)
at Object.fireWith [as rejectWith] (jquery-1.10.2.min.js:4)
at k (jquery-1.10.2.min.js:6)
at XMLHttpRequest.r (jquery-1.10.2.min.js
Can i know where is the problem to add an option ?
Actually i have done everything right. But it not saved in the DB. So i have added a col with the name. Now it is saved.
Thank you.

how to access custom module using t-if condition in xml odoo

I have a custom module test and created pages called test_1, test_2, test_3.
I have inherited calendar view and wrote a condition in js like all the calendar changes should be reflected to test_1. And that is working fine.
Now i need to remove Day and Month button from test_1 page -> Calendar view.
So i am trying to write t-if condition. I dont have idea how to call model. i tried below code but it is not working.
<template>
<tr t-extend="CalendarView.quick_create">
<t t-if="widget.model=='test_1'">
<t t-jquery=".form-group" t-operation="after">
<div class="form-group">
<h3>Example - put fields here </h3>
</div>
</t>
</t>
</tr>
</template>
It is not working throws an TypeError: Cannot read property 'model' of undefined
How to access model in t-if condition?

Not finding the Correct xpath

I'm trying write a Python script to get some information from Google's products listed on the top right of the screen. (Usual 6 pictures with price and seller)
I am using Python, PhantomJS and Selenium
Doing a google search for "red shoe" I want my script to return the prices. I get stuck in the step where I try to even find the element containing the products. Am I missing something with my xpath?
def getTopSongs(object):
print "Working YETI"
browser = webdriver.PhantomJS('c:/projects/phantomjs/phantomjs.exe')
browser.get('http://google.com/search?q=red+shoe')
time.sleep(5)
title = browser.find_element_by_xpath('//div[contains#class, "pla-unit")]/text()[contains(., "red")]/following::b').text
From Google's webpage I element under a few nested
<div id="rhs">
...
<div class="_Pwb">
<div class="_Ohb">
<div style="width:109px" class="pla-unit">
<div class="_PD">
<div class="pla-unit-img-container">
<div class="_Z5">
<div class="_vT"><a href="http://www.somewebsite.com">
<span class="rhsl4">Nina 'Forbes' Peep Toe Pump <b>Red</b> R...</span>
<span class="rhsg3 rhsl5">Nina 'Forbes' Peep Toe Pum...</span>
<span class="rhsg4">Nina 'Forbes' Peep Toe Pu...</span></a>
</div>
<div class="_QD"><b>$78.95</b></div>
<div class="_mC">
<span class="rhsl4 a">Nordstrom</span>
<span class="rhsg3 rhsl5 a">Nordstrom</span>
<span class="rhsg4 a">Nordstrom</span>
</div>
</div>
*Update:
I added more HTML. In this example I am looking to get the text from ($78.95) annd (Norstrom)
*Update
To clarify,
<div id="rhs">
is an unique element
There are however multiple (6) elements of:
<div style="width:109px" class="pla-unit">
The elements under each category have the same name and follow the same structure and substructures
ie, there are 6
<div class="_PD">
<div class="pla-unit-img-container">
<div class="_Z5">
<div class="_vD">
<div class="_QD">
<div class="_mC">
and so on.
The main objective is to get all of the elements but for purposes of debugging I was asking help to get the first one.
The xpath for a price unit using XPathChecker on Firefox is:
id('rhs_block')/x:div[1]/x:div/x:div/x:div/x:div[1]/x:div[1]/x:div[2]/x:div[2]/x:b
You can use ancestor:: to go back up then following-sibling:: to get elements at the same level that follow it.
I haven't tried this but give it a shot:
title = browser.find_element_by_xpath('//div[contains#class, "pla-unit")]/text()[contains(., "red")]/ancestor::div/following-sibling::div[1]').text
Then to get to your div class ='mC' you just change:
following-sibling::div[1]
to
following-sibling::div[2]
and get the text from the spans under that.