How to disable clear button in attachment form view odoo11? - odoo

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
}

Related

Settings page can save values but does not display saved values

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.

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>

hide a span with text in odoo, wanna hide the span element in xml file?

In Leads after Contact name Title is coming and in between them one comma is there as ,
<span attrs="{'invisible': [('title', '=', '')]}">, </span>
I want to move Title before the Contact Name, and hide this comma.
How can i achieve this?
<field name="title" position="replace">
</field>
<span attrs="{'invisible': [('title', '=', '')]}" position="replace">
</span>
<field name="contact_name" position="before">
<field name="title" placeholder="Title" domain="[('domain', '=', 'contact')]" class="oe_inline" options='{"no_open": True}'/>
<span attrs="{'invisible': ['|',('title', '=', ''),('title', '=', False)]}">, </span>
</field>

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)

Kanban view in OpenERP

How do I create a kanban view in OpenERP?
The developer book doesn't seem to have any information on the new kanban view, and I didn't see anything useful in the OpenERP forum.
Here is sample code showing how to develop a kanban view in OpenERP.
For the kanban view you have to prepare 2 files: (1)xml file and (2) css file. The CSS file is used for the formating of the kanban view.
<record model="ir.ui.view" id="resource_kanban_view">
<field name="name">any name of ur model</field>
<field name="model">object.name</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<a type="edit"><img t-att-src="kanban_image('object.name', 'photo', record.id.value)" class="oe_resource_picture"/></a>
</div>
<div class="oe_resource_details">
<ul>
<!--Here you have to write the object's field name which you want to display in kanban view -->
<li><field name="name"/></li>
<li><field name="author"/></li>
<li><field name="description"/></li>
<li><field name="available_copy"/> </li>
</ul>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
Their is Doc on this, KANBAN view is created based on QWEB technology, developed by OF itself, you can see the the whole lib QWEB lib and under Doc Section you can see how you can define the qWeb QWEB Template, Now if you understand it then all you just need to do is out your web template under tag in view declaration, where other systex is same as generic view declaration :
<record model="ir.ui.view" id="view_external_id">
<field name="name">View Name</field>
<field name="model">openerp.modelfield>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<field name="color"/>
<!--list of field to be loaded -->
<field name="list_price"/>
<templates>
<!--Your Qweb based template goes here, each record will be wrapped in template so you can arrange field veyr easily in box -->
</templates>
</kanban>
</field>
</record>
Hope this will help you.
Regards
I can't see any documentation for it yet, so the best you can do is look for examples in the addons project. Search all the XML files for <kanban>. Here's an example from the stock module:
<record model="ir.ui.view" id="product.product_kanban_view">
<field name="name">Product Kanban</field>
<field name="model">product.product</field>
<field name="type">kanban</field>
<field name="arch" type="xml">
<kanban>
<field name="color"/>
<field name="type"/>
<field name="product_image"/>
<field name="list_price"/>
<templates>
<t t-name="kanban-box">
<div class="oe_product_vignette">
<div class="oe_product_img">
<a type="edit"><img t-att-src="kanban_image('product.product', 'product_image', record.id.value)" class="oe_product_photo"/></a>
</div>
<div class="oe_product_desc">
<h4><a type="edit"><field name="name"></field></a></h4>
<ul>
<li t-if="record.type.raw_value != 'service'">Stock on hand: <field name="qty_available"/> <field name="uom_id"/></li>
<li t-if="record.type.raw_value != 'service'">Stock available: <field name="virtual_available"/> <field name="uom_id"/></li>
<li>Price: <field name="lst_price"></field></li>
<li>Cost: <field name="standard_price"></field></li>
</ul>
</div>
</div>
<script>
$('.oe_product_photo').load(function() { if($(this).width() > $(this).height()) { $(this).addClass('oe_product_photo_wide') } });
</script>
<div></div>
</t>
</templates>
</kanban>
</field>
</record>
Simply in xml file update this model="ir.actions.act_window" with view_mode like:
<record id="action_id" model="ir.actions.act_window">
<field name="name">Name1</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">model_name</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form,calendar,graph,gantt</field>
.....
</record>
This is the way how to call all view, and link http://www.slideshare.net/openobject/openerp-61-framework-changes will help u how to create kanban view.
I hope it will help you...