How to display label of a field in qweb reports? - odoo

Is there a way to display the label we put on a field in a qweb reports?
For example
In my .py
findings = fields.Text(string="Findings")
And in my .xml
<t t-esc="findings" /> <!-- only shows the value -->
Can we also get the label in qweb?

You can not get the label of the field.
Instead you can add html tag to show the label
Ex:
<p>Your Label <t t-esc="findings" /> </p>
or
<span> Some Text <t t-esc="findings" /> </span>

You can get field description (label) using a function but I encourage you to display labels as they did in odoo invoice reports.
To get date_invoice label:
def get_field_label(self, model_name, field_name):
ir_model_obj = self.env['ir.model']
ir_model_fields_obj = self.env['ir.model.fields']
model_id = ir_model_obj.search([('model', '=', model_name)], limit=1)
field_id = ir_model_fields_obj.search([('name', '=', field_name), ('model_id', '=', model_id.id)], limit=1)
return field_id.field_description

Related

odoo 8 make button invisible from compute result

This is my .py
#api.depends('product_id')
def get_sales_divisi(self):
for line in self:
if line.product_id.divisi_update:
line.sales_divisi_id = line.product_id.divisi_update.id
elif line.product_id.divisi_ids:
line.sales_divisi_id = line.product_id.divisi_ids.ids[0]
this is my .xml
<button name="action_approve" string="Approve Checker" type="object" attrs="{'invisible':['|',('sales_divisi_id', '=', '2'),('sales_divisi_id', 'in', ('VET'))]}" groups="ts_addons_tbk.group_tbk_checker" />
I'm tying to make the button invisible when the sales_divisi_id is Vet but it doesn't work. Any advice please? Thank you
Assuming sales_divisi_id is a relation, in operator will query by id or name field.
Furthermore, in order to use fields in queries inside your views, you need to define them first.
For example:
<field name="sales_divisi_id" invisible="1" />
<button name="action_approve" attrs="{'invisible':[('sales_divisi_id', 'in', [1,2])]}" groups="ts_addons_tbk.group_tbk_checker" />
action_approve button will show only if sales_divisi_id is related to a record having id 1 or 2.

how to implement a section block in eLearning module - odoo 14

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>

How to write/update some inherited fields in product category to multicompany

I was inherited some fields in product.category model and i want to show that some other fields on my other companies.. I am tried to give the answer on create function and Also tried on other Button But i can't write the values that i give in the main company to other companies.. Please Help me to find the Answer..
#api.model
def create(self, vals_list):
res = super(ProductCentralized, self).create(vals_list)
vals = []
vals.append({
'property_cost_method': res.property_cost_method,
'name':res.name,
'property_valuation': res.property_valuation,
'property_stock_valuation_account_id': res.property_stock_valuation_account_id,
'property_stock_journal': res.property_stock_journal,
'property_stock_account_input_categ_id': res.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': res.property_stock_account_output_categ_id,
})
res.sudo().create({'property_cost_method': self.property_cost_method,
'name': self.name,
'property_valuation': self.property_valuation,
'property_stock_valuation_account_id': self.property_stock_valuation_account_id,
'property_stock_journal': self.property_stock_journal,
'property_stock_account_input_categ_id': self.property_stock_account_input_categ_id,
'property_stock_account_output_categ_id': self.property_stock_account_output_categ_id})
return res
Please Help me to correct this code or using another button.. Thanks in Advance..
Consider changing the corresponding view : "res.partner.form" instead. You can find it this way : in App Settings, switch to debug mode by adding "?debug=1" in your url, reload the page, then go to the new Technical Menu-tab > View.
Then you can display your partner/company(id= 1344 ) fields, using :
For Back-Office :
<t t-esc="self.env['res.partner'].browse(1344).name" />
For Front-Office :
<t t-esc="request.env['res.partner'].browse(1344).name" />
Or you can display your product_template (id= 135 ) fields, using :
<t t-esc="self.env['product.template'].browse(135).property_valuation" />
Or you can display your stock fields, using :
<t t-esc="self.env['stock.quant'].search([('product_id','=','5')]).location_id.name" />

Odoo11 Custom Report with Wizard

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,}

Odoo : Make changes on Survey module

I am working on editing the survey module in odoo.
When I answer a survey which is composed of pages and then click on submit survey, it calculates the whole score of the survey and displays it. What I want is that it calculates the score of each page and display it when I click on submit survey for example:
It displays: Your score is: 200 points.
And I want it to display: Score of first page : 20 points, Second page: 50 points and so on...
Here is the code that I want to change but I don't know how should I change this function.
questionnaire.py (survey.py) : class survey_user_input
class survey_user_input(osv.Model):
''' Metadata for a set of one user's answers to a particular survey '''
_name = "questionnaire.user_input"
_rec_name = 'date_create'
_description = 'Survey User Input'
def _quizz_get_score(self, cr, uid, ids, name, args, context=None):
ret = dict()
for user_input in self.browse(cr, uid, ids, context=context):
ret[user_input.id] = sum([uil.quizz_mark for uil in user_input.user_input_line_ids] or [0.0])
return ret
_columns = {
'survey_id': fields.many2one('questionnaire.questionnaire', 'Questionnaire', required=True,
readonly=1, ondelete='restrict'),
'date_create': fields.datetime('Date de creation', required=True,
readonly=1, copy=False),
'deadline': fields.datetime("Date limite",
oldname="date_deadline"),
'type': fields.selection([('manually', 'Manuellement'), ('link', 'Lien')],
'Type de reponse', required=1, readonly=1,
oldname="response_type"),
'state': fields.selection([('new', 'Pas encore commence'),
('skip', 'Partiellement acheve'),
('done', 'Termine')],
'Statut',
readonly=True),
'test_entry': fields.boolean('Entree de test', readonly=1),
'token': fields.char("Piece d'identite", readonly=1, required=1, copy=False),
# Optional Identification data
'partner_id': fields.many2one('res.partner', 'Partenaire', readonly=1),
'email': fields.char("E-mail", readonly=1),
# Displaying data
'last_displayed_page_id': fields.many2one('questionnaire.page',
'Derniere page affichee'),
# The answers !
'user_input_line_ids': fields.one2many('questionnaire.user_input_line',
'user_input_id', 'Reponses', copy=True),
# URLs used to display the answers
'result_url': fields.related('survey_id', 'result_url', type='char',
string="Lien public aux resultats du sondage"),
'print_url': fields.related('survey_id', 'print_url', type='char',
string="Lien public au sondage vide"),
'quizz_score': fields.function(_quizz_get_score, type="float", string="Score pour le quiz", store=True)
}
_defaults = {
'date_create': fields.datetime.now,
'type': 'manually',
'state': 'new',
'token': lambda s, cr, uid, c: uuid.uuid4().__str__(),
'quizz_score': 0.0,
}
questionnaire.py (survey.py) : class survey_user_input_line
_name = 'questionnaire.user_input_line'
_description = 'Survey User Input Line'
_rec_name = 'date_create'
_columns = {
'user_input_id': fields.many2one('questionnaire.user_input', 'Entree de l\'utilisateur',
ondelete='cascade', required=1),
'question_id': fields.many2one('questionnaire.question', 'Question',
ondelete='restrict', required=1),
'page_id': fields.related('question_id', 'page_id', type='many2one',
relation='questionnaire.page', string="Page"),
'survey_id': fields.related('user_input_id', 'survey_id',
type="many2one", relation="questionnaire.questionnaire",
string='Questionnaire', store=True),
'date_create': fields.datetime('Date de creation', required=1),
'skipped': fields.boolean('Ignore'),
'answer_type': fields.selection([('text', 'Texte'),
('number', 'Nombre'),
('date', 'Date'),
('free_text', 'Texte Libre'),
('suggestion', 'Suggestion')],
'Type de reponse'),
'value_text': fields.char("Reponse texte"),
'value_number': fields.float("Reponse numerique"),
'value_date': fields.datetime("Reponse date"),
'value_free_text': fields.text("Reponse texte libre"),
'value_suggested': fields.many2one('questionnaire.label', "Reponse suggeree"),
'value_suggested_row': fields.many2one('questionnaire.label', "Reponse en ligne"),
'quizz_mark': fields.float("Score donne pour ce choix")
}
survey_templates.xml
<!-- "Thank you" message when the survey is completed -->
<template id="sfinished" name="Survey Finished">
<t t-call="website.layout">
<div class="wrap">
<div class="container">
<t t-call="questionnaire.back" />
<div class="jumbotron mt32">
<h1>Thank you!</h1>
<div t-field="questionnaire.thank_you_message" class="oe_no_empty" />
<div> You scored <t t-esc="user_input.quizz_score" /> points.</div>
<div>If you want you can <a t-att-href="'/questionnaire/print/%s/%s' % (slug(questionnaire), token)">review your answers</a>.</div>
</div>
</div>
</div>
</t>
</template>
One alternative way is to use pure qweb rather than function field; like this:
<!-- First finding which page is related to the survey. This is a bit odd but I couldn't find any other way!! -->
<t t-set="pages" t-value="dict((l.id, l.page_id.id) for l in user_input.user_input_line_ids).values()" />
<!-- Then print the score per each page -->
<t t-foreach='pages' t-as='p'>
<t t-set="page_score" t-value="sum([(uil.quizz_mark or 0.0) if uil.page_id.id == p else 0.0 for uil in user_input.user_input_line_ids])" />
<div> You scored <t t-esc="page_score" /> points in page <t t-esc="p" />.</div>
</t>
I have not tested this code but logically it seems to work fine.
Thank you so much #MICROCOM .. The line that display the score for each page is diplayed more than once ..
The result Of The code - 1
So i added a condition to just display the score of a certain page once (I don't know if it's correct but it works :p ) .. Here is the code :
<!-- First finding which page is related to the survey. This is a bit odd but I couldn't find any other way!! -->
<t t-set="pages" t-value="dict((l.id, l.page_id.title) for l in user_input.user_input_line_ids).values()" />
<!-- Then print the score per each page -->
<t t-set="previous" t-value="void" />
<t t-foreach='pages' t-as='p'>
<t t-if="p != previous">
<t t-set="page_score" t-value="sum([(uil.quizz_mark or 0.0) if uil.page_id.title == p else 0.0 for uil in user_input.user_input_line_ids])" />
<div> You scored <t t-esc="page_score" /> points in page <t t-esc="p" />.</div>
</t>
<t t-set="previous" t-value="p" />
</t>
The result Of The code - 2
Thank you so much for your help #MICROCOM ^^