I am trying to add a breadcrumb entry to portal pages. I try to copy form the sale module. Inside this module there is this template that adds new breadcrumb entries:
<template id="portal_my_home_menu_sale" name="Portal layout : sales menu entries" inherit_id="portal.portal_breadcrumbs" priority="20">
<xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
<li t-if="page_name == 'quote' or sale_order and sale_order.state in ('sent', 'cancel')" t-attf-class="breadcrumb-item #{'active ' if not sale_order else ''}">
<a t-if="sale_order" t-attf-href="/my/quotes?{{ keep_query() }}">Quotations</a>
<t t-else="">Quotations</t>
</li>
<li t-if="page_name == 'order' or sale_order and sale_order.state not in ('sent', 'cancel')" t-attf-class="breadcrumb-item #{'active ' if not sale_order else ''}">
<a t-if="sale_order" t-attf-href="/my/orders?{{ keep_query() }}">Sales Orders</a>
<t t-else="">Sales Orders</t>
</li>
<li t-if="sale_order" class="breadcrumb-item active">
<span t-field="sale_order.type_name"/>
<t t-esc="sale_order.name"/>
</li>
</xpath>
</template>
The templates I created don't have a page_name attribute. How can I add this to my templates?
Stock portal pages have home, order, or invoice as page_name but I couldn't find that in stock templates.
Variables settings are added either at the time of calling the render function or using t-set inside the template, or both.
On your particular case, page_name gets assigned inside portal_my_quotes (See <path_to_v12>/addons/sale/controllers/portal.py lines 39-90. See an excerpt below.) which is the controller for the route /my/quotes
#http.route(['/my/quotes', '/my/quotes/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_quotes(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
values = self._prepare_portal_layout_values()
...
values.update({
'date': date_begin,
'quotations': quotations.sudo(),
'page_name': 'quote',
'pager': pager,
'archive_groups': archive_groups,
'default_url': '/my/quotes',
'searchbar_sortings': searchbar_sortings,
'sortby': sortby,
})
return request.render("sale.portal_my_quotations", values)
Documentation regarding the use of t-set can be found at https://www.odoo.com/documentation/12.0/reference/qweb.html#setting-variables
Related
i was tryin to add a section block which allows me to block all the possible sections (except for the first) and then if all the slides in the section are complete, makes the next one available
I tried with the templates but it don't seem the way to approach this problem cause I cannot find any way to check the previous slides, I was trying to figure it out with javascript maybe but I'm not that good with JS
that's my actual progress:
<odoo>
<data>
<template id="section_lock" inherit_id='website_slides.course_slides_list_slide'>
<xpath expr="//div[#class='text-truncate mr-auto']" position="replace">
<div class="text-truncate mr-auto">
<a t-if="slide.is_preview or slide.previous_category_complete is False or channel.can_publish"
class="o_wslides_js_slides_list_slide_link" t-attf-href="/slides/slide/#{slug(slide)}">
<span t-field="slide.name"/>
</a>
<span t-else="">
<span t-esc="slide.name"/>
</span>
</div>
</xpath>
</template>
</data>
and then the model with the flag needed for the check
class Slide(models.Model):
_inherit = 'slide.slide'
previous_category_complete = fields.Boolean(default=True)
how do u suggest to do it? I think i'm way off th road with this
The relationship between an e-Course and its section is based on the same model (slide.slide) using these relational fields :
category_id = fields.Many2one('slide.slide', string="Section", compute="_compute_category_id", store=True)
slide_ids = fields.One2many('slide.slide', "category_id", string="Slides")
#api.depends('channel_id.slide_ids.is_category', 'channel_id.slide_ids.sequence')
def _compute_category_id(self):
self.category_id = False # initialize whatever the state
channel_slides = {}
for slide in self:
if slide.channel_id.id not in channel_slides:
channel_slides[slide.channel_id.id] = slide.channel_id.slide_ids
for cid, slides in channel_slides.items():
current_category = self.env['slide.slide']
slide_list = list(slides)
slide_list.sort(key=lambda s: (s.sequence, not s.is_category))
for slide in slide_list:
if slide.is_category:
current_category = slide
elif slide.category_id != current_category:
slide.category_id = current_category.id
To know wether a specific student has attended an e-course, there is an existing field in the model 'slide.slide.partner':
class SlidePartnerRelation(models.Model):
_name = 'slide.slide.partner'
slide_id = fields.Many2one('slide.slide', ondelete="cascade", index=True, required=True)
partner_id = fields.Many2one('res.partner', index=True, required=True, ondelete='cascade')
completed = fields.Boolean('Completed')
So you can check wether all the previous Slide Sections are completed for the current partner_id, inheriting the class WebsiteSlides located in website_slides/controllers/main.py > def channel(...)... :
from odoo.addons.website_slides.controllers.main import WebsiteSlides
class WebsiteSlidesCustom(WebsiteSlides):
#http.route()
def channel(self, channel, category=None, tag=None, page=1, slide_type=None, uncategorized=False, sorting=None, search=None, **kw):
res_super = super(WebsiteSlidesCustom, self).channel(channel, category=None, tag=None, page=1, slide_type=None, uncategorized=False, sorting=None, search=None, **kw)
values = res_super.qcontext
sections_completion = request.env['slide.slide.partner'].sudo().search([
('channel_id', '=', current_channel_id),
('is_category','=', True),
('partner_id', '=', request.env.user.partner_id.id)
])
dic_sections_completion={}
for sec in sections_completion.sorted('sequence'):
dic_sections_completion[sec.id] = sec.completed
values['sections_completion'] = dic_sections_completion
return request.render('website_slides.course_main', values)
in your module directory views, create a new xml file : course_main_custom.xml
<template id="course_main_custom" inherit_id="website_slides.course_main" name="Course Main" >
<xpath expr="//t[#t-set='category']" position="after">
...
</xpath>
</template>
I'd like to display in the new products tab in prestashop 1.6 homepage only products from a specific category
I use blocknewproducts_home.tpl
I tried this code below but nothing display from the category 114 (with get products attached)
{if $id_category == 114}
{include file="$tpl_dir./product-list.tpl" products=$new_products class='blocknewproducts tab-pane' id='blocknewproducts'}
{/if}
{if isset($new_products) && $new_products}
{include file="$tpl_dir./product-list.tpl" products=$new_products class='blocknewproducts tab-pane' id='blocknewproducts'}
{else}
<ul id="blocknewproducts" class="blocknewproducts tab-pane">
<li class="alert alert-info">{l s='No new products at this time.' mod='blocknewproducts'}</li>
</ul>
{/if}
Thanks for your help
try width : {if $smarty.get.id_category == 114}
Regards
I'm creating a web in Prestashop and my problem is the next:
I has created a new table in db (mysql) called 'tallas' and I have the size's preferences of the users. Now, I need call this table since the page product-variants.tpl because I would like to put cheeked for default the option select by the customer.
I create this function in classes/Product.php
public function getTalla($id_customer){
$result = Db::getInstance()->ExecuteS('
SELECT `talla1`
FROM `tallas`
WHERE `cliente` = `$id_customer`');
return $result;
}
ok, I would like to receive for parameters the user id (I don't know how to do that yet) and I would like to receive the value of talla1 and then I would like put cheeked the option selected by the customer here in the themes/asmart/templates/catalog/_partials/product-variants.tpl in the radio.
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
Sincerely I don't know any idea to how to do that, can someone help me?
UPDATE: The problem is solved!
The problem is solved. I do that:
in classes/Product.php
public function getTalla(){
$variable = Context::getContext()->customer->id;
$result = Db::getInstance()->ExecuteS('SELECT * FROM `tallas` WHERE `cliente` = `$variable`');
return $result;
}
in ProductController.php
$this->context->smarty->assign('images_ex',$this->product->getTalla());
in product-variants.tpl
{if $images_ex[0]['talla1'] == $group_attribute.name} checked="checked"{/if}
I hope this can help someone in the future.
I would like to print some product barcodes with the custom configuration.
Now, the problem is, I have created the wizard but when I click the print button there is no data is transferred to the report.
class BarcodeConfig(models.Model):
_name = 'report.barcode.print'
#api.model
def _default_product_line(self):
active_ids = self._context.get('active_ids', [])
products = self.env['product.product'].browse(active_ids)
return [(0, 0, {'product_id': x.id, 'qty': 1}) for x in products]
product_line = fields.One2many('product.print.wizard', 'barcode_id', string="Products",
default=_default_product_line)
#api.multi
def print_report(self):
data = self.read()[0]
ids = [x.product_id.id for x in self.product_line]
config = self.env['barcode.config'].get_values()
data.update({
'config': config
})
datas = {'ids': ids,
'form': data
}
return self.env.ref('odoo_barcode.barcode_report').report_action(self,data=datas)
In the above code, I had ids as well for product.product model.
<template id="report_barcode_temp">
<t t-call="web.html_container">
<t t-call="web.internal_layout">
<div class="page">
<h2>Report title</h2>
<strong t-esc="docs"/>
<strong t-esc="doc_ids"/>
<span t-esc="data"/>
<t t-foreach="docs" t-as="o">
<span t-esc="o"/>
<p>This object's name is
<span t-field="o.name"/>
</p>
</t>
</div>
</t>
</t>
In the above code, I'm just trying to print what the data's I've, but I've nothing in docs.
<strong t-esc="docs"/>
this line print product.product model as well. but ids not here, That's the problem I have.
Can anyone help me to tell why this happens? Or is there any other way to achieve this?
I have solved this by get_report_values method.
class classname(models.AbstractModel):
_name = 'report.modulename.templatename'
#api.model
def get_report_values(self, docids, data=None):
# docids: pass from the wizard print button.
records = self.env[objectname].browse(docids)
return {
'doc_ids': docids,
'doc_model': objectname,
'docs': records,
'data': data,}
I'm trying to scrape the following html code:
<ul class="results-list" id="search-results">
<li>
<h3 class="name">First John</h3>
<div class="details">
email
<span class="phone">999999999</span>
</div>
</li>
<li>
<h3 class="name">Second John</h3>
<div class="details">
email
<span class="phone">999999999</span>
</div>
</li>
</ul>
When I run my spider, I get 2 rows, containing the same information. I have name,email,phone columns and for example in the name column for both I would get:
First John,Second John.
My Scrapy code is the following:
people= response.xpath('//ul[#class="results-list"]/li')
for person in people:
item = SpiderItem()
item['Name'] = person.xpath(
'//h3/text()').extract()
item['Email'] = person.xpath(
'//div[#class="details"]/a/#href').extract()
item['Phone'] = person.xpath(
'//div[#class="details"]/span[#class="phone"]/text()').extract()
yield item
However when I run scrapy crawl MySpider -o output.csv I get the same information in all rows.
you are using absolute path on your xpath expressions, change them to:
for person in people:
item = SpiderItem()
item['Name'] = person.xpath(
'.//h3/text()').extract_first()
item['Email'] = person.xpath(
'.//div[#class="details"]/a/#href').extract_first()
item['Phone'] = person.xpath(
'.//div[#class="details"]/span[#class="phone"]/text()').extract_first()
yield item