Settings page can save values but does not display saved values - odoo

I am trying to create a custom settings page using res.config.settings
I'm using res_config_settings_views.xml in the hr addons folder as a reference for the view.
And I'm using res_config_settings.py also in the hr addons folder as a reference for the model.
It worked I can see my custom settings page. I can save the values. But after I saved, the settings page back to its unset state.
When I look at the database, the values were saved. And I can call the value to use in my model.
Just confused why the settings page cannot display the values I saved?
Am I missing something?
# -*- coding: utf-8 -*-
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
president_director_id = fields.Many2one(comodel_name='hr.employee', string="President Director", readonly=False)
head_of_hr_id = fields.Many2one(comodel_name='hr.employee', string="Head of Human Resources", readonly=False)
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.fhid_recruitment</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="65"/>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="FHID Settings" string="FHID Settings" data-key="fhid_setting">
<h2>FHID Settings</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label for="president_director_id"/>
<!-- <span class="fa fa-lg fa-building-o" title="Values set here are company-specific." role="img" aria-label="Values set here are company-specific." groups="base.group_multi_company"/> -->
<div class="row">
<div class="text-muted col-lg-8">
Set default director, ...
</div>
</div>
<div class="content-group">
<div class="mt16">
<field name="president_director_id" class="o_light_label"/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<label for="head_of_hr_id"/>
<!-- <span class="fa fa-lg fa-building-o" title="Values set here are company-specific." role="img" aria-label="Values set here are company-specific." groups="base.group_multi_company"/> -->
<div class="row">
<div class="text-muted col-lg-8">
Set default manager, ...
</div>
</div>
<div class="content-group">
<div class="mt16">
<field name="head_of_hr_id"/>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
<record id="fhid_recruitment_config_settings_action" model="ir.actions.act_window">
<field name="name">Settings Manager</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.config.settings</field>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="context">{'module' : 'fhid_recruitment'}</field>
</record>
<menuitem id="fhid_recruitment_menu_configuration"
name="Settings"
parent="hr.menu_human_resources_configuration"
sequence="0"
action="fhid_recruitment_config_settings_action"
groups="base.group_system"/>
</odoo>

You will have to use set_values method to save the field values and then to get the value again you will have to you get_values method.
For example you have the following field in res.config.settings model:
head_of_hr_id = fields.Many2one('hr.employee', string="Head")
Now in order to save this field value after clicking the Save button you will have to use the following code:
def set_values(self):
super(ResConfigSettings, self).set_values()
set_param = self.env['ir.config_parameter'].sudo().set_param
set_param('module_name.head_of_hr_id', int(self.head_of_hr_id.id))
To get the value again in the field, use the following code:
#api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
get_param = self.env['ir.config_parameter'].sudo().get_param
res['head_of_hr_id'] = int(get_param('module_name.head_of_hr_id'))
return res
Hope this code help you.

Related

How to disable clear button in attachment form view odoo11?

I am try to disable the clear button in attachment form.
I think this is js code. I search some js code in but nothing find.
Any hint for this problem??
This is the image of clear button
Another approach for only extending this one form view is to set the field dynamically to readonly when filled.
<record id="view_attachment_form" model="ir.ui.view">
<field name="name">disable remove button if filled</field>
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_form" />
<field name="arch" type="xml">
<field name="datas" position="attributes">
<attribute name="attrs">{'invisible':[('type','=','url')], 'readonly':[('datas', '!=', False)]}</attribute>
</field>
</field>
</record>
And a part of the original view:
<sheet>
<label for="name" class="oe_edit_only"/>
<h1>
<field name="name"/>
</h1>
<group>
<group>
<field name="type"/>
<field name="datas" filename="datas_fname" attrs="{'invisible':[('type','=','url')]}"/>
<field name="datas_fname" invisible="1" attrs="{'invisible':[('type','=','url')]}" class="oe_inline oe_right"/>
<!-- and so on -->
If you want to remove the Button for the whole Binary field widget in Odoo, you could just "extend" the QWeb template for that widget, which is:
<t t-name="FieldBinaryFile">
<a t-if="widget.mode === 'readonly'" href="javascript:void(0)" class="o_form_uri"/>
<div t-if="widget.mode !== 'readonly'" class="o_field_binary_file">
<input type="text" class="o_input"
readonly="readonly"
t-att-name="widget.name"
t-att-tabindex="widget.attrs.tabindex"
t-att-autofocus="widget.attrs.autofocus"/>
<button type="button" class="btn btn-sm btn-primary o_select_file_button" title="Select">Upload your file</button>
<button type="button" class="btn btn-sm btn-default fa fa-pencil o_select_file_button" title="Select"/>
<button type="button" class="btn btn-sm btn-default fa fa-trash-o o_clear_file_button" title="Clear"/>
<span class="o_form_binary_progress">Uploading...</span>
<t t-call="HiddenInputFile">
<t t-set="fileupload_id" t-value="widget.fileupload_id"/>
<t t-set="fileupload_style" t-translation="off">overflow-x: hidden</t>
</t>
</div>
</t>
You can extend QWeb templates but have to load them in the manifest file under key qweb.
xml file normally in module at /static/src/xml
<templates>
<t t-name="web.FieldBinaryFile" t-extend="base.FieldBinaryFile">
<t t-jquery="button[title='Clear']"
t-operation="replace" />
</t>
</templates>
And the part of the manifest
{
'name': 'remove button in binary widget',
# and so on
'depends': [
'base',
],
'qweb': [
'static/src/xml/remove_button.xml'
],
# and so on
}

Generate html and render in qweb

Is it possible generate html in .py file and render in qweb?
<openerp>
<data>
<record id="paperformat_time" model="report.paperformat">
<field name="name">Time</field>
<field name="font_size">10</field>
</record>
<report id="time_qweb" model="hr_timesheet_sheet.sheet" string="Time"
report_type="qweb-pdf" name="time.report_time" file="time.report_time" />
<record id="time_qweb" model="ir.actions.report.xml">
<field name="paperformat_id" ref="time.paperformat_time" />
</record>
</data>
</openerp>
qweb
<template id="report_time">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="t">
<span t-esc="t.__compute_html()" />
<div class="page">
<span t-field="t.html_text " />
</div>
</t>
</t>
</template>
.py file
class Time(models.Model):
_inherit = 'hr_timesheet_sheet.sheet'
html_text = fields.Html(string = 'Html')
#api.one
def _compute_html(self):
html_value = "<h1>TEST</h1>"
html_value += "<h1>TEST 2</h1>"
self.html_text = html_value
eg.
html_value = "<h1> + employee_id.name + "</h1>"
html_value += "<h1> + employee_id.phone + "</h1>"
now I need html_value render in qweb in put in <div class="page"> put here html_value </div>
Now I save text in database, any better solution?................................
Yes you can if you have a variable that have html code if you use t-esc or t-field odoo will print it as text.
If you want to render it use. t-raw
<div t-raw="doc.some_attribute" > </div>
Or
<t t-raw="doc.some_attribute" > </t>
You can try this
<span t-raw="my_html_field"/>
Here my_html_field is your html formated data
Since Odoo version 15, t-raw is deprecated. You need to render the HTML in a safe way using Python, then parse that into XML. Reference
import markupsafe
...
class YourController(http.Controller):
...
#http.route(...)
def your_rendering_method(self):
...
return request.render("YOUR_TEMPLATE", {"YOUR_FIELD": markupsafe.Markup("<a href='https://www.stackoverflow.com'>Stack Overflow</a>")})
<t t-esc="YOUR_FIELD" />

How do I add a button with function to export the report as either .pdf,.xls or .csv formats in ODOO 8?

I am using odoo 8.0 and I'm making a report for asset list. So far I have created the asset list report:
How do I add a button with function to export the report as either .pdf,.xls or .csv formats?
Here is a snippet code I have for the report view.
<record model="ir.actions.act_window" id="action_fleet_reporting_asset_listing">
<field name="name">Asset Listing</field>
<field name="res_model">fleet.asset</field>
<field name="view_id" ref="fleet_asset_listing_report"></field>
<field name="view_type">tree</field>
<field name="view_mode">tree</field>
<field name="context">{"search_default_parent_false" : True,}</field>
<field name="help" type="html">
<p>
Odoo helps you managing the costs for your different vehicles
Costs are generally created from services and contract and appears here.
</p>
<p>
Thanks to the different filters, Odoo can only print the effective
costs, sort them by type and by vehicle.
</p>
</field>
</record>
<report id="report_fleet_asset_list"
name="fleet.qweb_fleet_asset_list"
model="fleet.asset"
string="Assets"
report_type="qweb-pdf" />
Then created the Template:
<?xml version="1.0" encoding="utf-8"?>
<!--Custom report.-->
<openerp>
<data>
<template id="qweb_fleet_asset_list">
<t t-call="report.html_container">
<t t-call="report.internal_layout">
<div class="page">
<h2>Aseet List</h2>
<div class="row mt4 mb4" t-as="o" t-foreach="docs">
<div class="col-md-6">
<t t-esc="o.name"/>
</div>
<div class="col-md-6">
<t t-esc="o.location" t-if="o.location"/>
<t t-if="not o.location">-</t>
</div>
</div>
</div>
</t>
</t>
</template>
</data>
</openerp>

Add custom text in qweb report odoo9

How add custom text in inherit qweb?
For example in Sale/view/report_saleorder.xml
below class="oe_structure" i need one table
<p t-field="doc.note" />
<p t-if="doc.payment_term_id.note">
<span t-field="doc.payment_term_id.note"/>
</p>
<p t-if="not doc.payment_term_id and doc.partner_id.property_payment_term_id">
<span t-field="doc.partner_id.property_payment_term_id.note"/>
</p>
<p id="fiscal_position_remark" t-if="doc.fiscal_position_id and doc.fiscal_position_id.note">
<strong>Fiscal Position Remark:</strong>
<span t-field="doc.fiscal_position_id.note"/>
</p>
<div class="oe_structure"/>
<xpath expr="???" position="???">
<table><tr><td>CUSTOM TEXT</td></tr></table>
</xpath>
I am not sure if the above xml is the whole report however you could use something like this.
<xpath expr="//div[#class='oe_structure'][last()]" position="after">
<!-- YOUR TABLE HERE -->
</xpath>
This assumes this is the last instance of oe_structure in the xml you are inheriting from.

How to call onchange function in kanban view in openerp?

I want to call an on-change function in Kanban view. But I don't know how I can call this?
I tried many ways, but still error. But no output.
And I have another question in Kanban view:
When I drag from one to another, some of the values will change.
How can I implement this?
<record model="ir.ui.view" id="hr_kanban_view_transfer">
<field name="name">Employee Transfer Kanban</field>
<field name="model">employee.transfer</field>
<field name="arch" type="xml">
<kanban default_group_by="site1">
<field name="site1"/>
<field name="color"/>
<field name="location1"/>
<field name="location2" />
<field name="site2"/>
<templates>
<t t-name="kanban-tooltip">
<ul class="oe_kanban_tooltip">
<li t-if="record.employee_id.raw_value"><b>Employee:</b> <field name="employee_id"/></li>
<li t-if="record.site1.raw_value"><b>Current Project:</b> <field name="site1"/></li>
<li t-if="record.location1.raw_value"><b>Source Location:</b> <field name="location1"/></li>
<li t-if="record.date.raw_value"><b>Date:</b> <field name="date"/></li>
</ul>
</t>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click oe_semantic_html_override">
<div class="oe_dropdown_toggle oe_dropdown_kanban">
<span class="oe_e">i</span>
<ul class="oe_dropdown_menu">
<t t-if="widget.view.is_action_enabled('delete')"><li><a type="delete">Delete</a></li></t>
<!-- <li><a name="action_makeMeeting" type="object">Schedule Interview</a></li> -->
<li><ul class="oe_kanban_colorpicker" data-field="color"/></li>
</ul>
</div>
<div class="oe_kanban_content" tooltip="kanban-tooltip">
<div>
<t t-if="record.employee_id.raw_value"><b><field name="employee_id"/></b><br/></t>
<i><field name="employee_id"/></i><br/>
<field name="site1"/><br/>
<field name="site2"/><br/>
<t t-if="record.source_location.raw_value">Source Location: <field name="location1"/><br/></t>
<!-- <t t-if="record.title_action.raw_value"><field name="title_action"/><br/></t> -->
<field name="date"/>
</div>
<div class="oe_kanban_right">
<img t-att-src="kanban_image('hr.employee', 'image_small', record.employee_id.raw_value)" t-att-title="record.employee_id.value" width="24" height="24" class="oe_kanban_avatar"/>
</div>
<!-- <div class="oe_kanban_footer_left" style="margin-top:5px;">
<t t-raw="record.message_summary.raw_value"/>
<field name="categ_ids"/>
</div>-->
</div>
<div class="oe_clear"></div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
When I transfer employee from one site to another, i.e., site1 to site2, how can I change my code?
Is it possible in Kanban view?
You can override write method in your model. and check site1 field in values. If it existed and changed do everything you like.
def write(self, cr, user, ids, vals, context=None):
if 'site1' in vals:
# your code
return super(your_model, self).write(cr, user, ids, vals, context)