Add custom text in qweb report odoo9 - odoo

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.

Related

How do I migrate a module to remove a custom `res.config.settings` field?

Suppose I have a module which defines some custom res.config.settings fields like so:
from odoo import models, fields
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
custom_field = fields.Char(config_parameter="custom.field")
some_other_custom_field = fields.Char(config_parameter="some.other.custom.field")
And then in my XML I have something like this:
<odoo>
<record id="custom_settings_view_form" model="ir.ui.view">
<field name="name">custom.settings.view.form</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="custom_base_settings_view_form"/>
<field name="arch" type="xml">
<div data-string="custom" position="inside">
<h2>Custom</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="custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
<div class="o_setting_right_pane">
<label for="some_other_custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="some_other_custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Suppose that now later I've implemented some new functionality elsewhere that eliminates my need for custom_field. As such, I'd like to remove it entirely. However, as you can see, the custom_settings_view_form also includes some_other_custom_field, which I need to keep. This means that my options are limited:
I cannot just remove the ir.ui.view record, because then I would lose the UI for some_other_custom_field.
I also cannot just uninstall and then install the module again, because it would result in data loss elsewhere.
So specifically I want to remove the following line from my model:
custom_field = fields.Char(config_parameter="custom.field")
And the following block from my XML:
<div class="o_setting_right_pane">
<label for="custom_field"/>
<div class="text-muted">Description...</div>
<div class="content-group">
<div class="mt16">
<field name="custom_field"
placeholder="Placeholder..."/>
</div>
</div>
</div>
However, when I remove that code and then run my Odoo server again with -u <name_of_containing_module>, I get the following error:
odoo.tools.convert.ParseError: "Error while validating view
Field `custom_field` does not exist
Error context:
View `custom.settings.view.form`
[view_id: <id>, xml_id: <name_of_containing_module>.custom_settings_view_form, model: res.config.settings, parent_id: <parent_id>]
...
I just learned that I can create scripts at <module_root>/migrations/<version>/ to help with this sort of situation, but I have no idea what I would need to put in my migration script to deal with this issue. How can I remove fields and modify views in a module without causing errors and without requiring that the module be reinstalled?
You could try this steps:
Remove custom_field from XML view and change the actual id
custom_settings_view_form.
Update your module, that shouldn't produce any error and you won't see custom_field any more.
At this moment you could deside ignore custom_field, nothing will happend. Any way if you are a person that don't like death code inside his project like me, you can continue with the next steps.
Remove custom_field definition for .py file.
Update your module.
If you have the same error reported, you sould execute the 3.1 step bellow.
3.1. Clean the database data for custom_field. By SQL. Continue with 4 and 5 steps.
Please share your comments of the execution of these steps.
I hope this answer can be helpful for you.

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 to give Odoo xpath in t-attf-id

How to give xpath in this position inside.
<div t-attf-id="o_payment_form_acq_{{acq.id}}" t-attf-class="hidden {{'panel-footer' if acq.save_token == 'ask' else ''}}">
I tried the following but it gives an error:
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//div[hasid('o_payment_form_acq_{{acq.id}}')]" position="after">
<div>hello</div>
</xpath>
</template>
Maybe try
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//div[#t-attf-id='o_payment_form_acq_{{acq.id}}']" position="after">
<div>hello</div>
</xpath>
</template>
When it is hard to get element I use relative path. The element you want to get contains inout element.
<div t-attf-id="o_payment_form_acq_{{acq.id}}" t-attf-class="hidden {{'panel-footer' if acq.save_token == 'ask' else ''}}">
<label t-if="acq.save_token == 'ask'"><input type="checkbox" name="o_payment_form_save_token" data-remove-me=""/> Save my payment data</label>
</div>
So you can get it using this code
<template id="stripe_form_type" inherit_id="payment.payment_tokens_list">
<xpath expr="//input[#name='o_payment_form_save_token']/.." position="after">
<div>hello</div>
</xpath>
</template>

Reach field in invoice report

I need to extend invoice report with field note. but I'm getting error that field does not exist. I'm stuck and don't know how to reach that field. did tried with partner_id.note too but also getting error.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_invoice_document" inherit_id="account.report_invoice_document">
<xpath expr="//div[#class='page']/*[last()]" position="after">
<div class="row">
<div class="col-xs-6">
<span t-esc="o.note"/><br/>
<div class="left_sign_block">
<span>Note</span>
</div>
</div>
</div>
</xpath>
</template>
</data>
</openerp>
class AccountInvoiceTax(models.Model):
_inherit = 'account.invoice.tax'
note = fields.Text(related='tax_id.note', string='Note')
QWebException: "'account.invoice' object has no attribute 'note'" while evaluating 'o.note'
You have extended the model account.invoice.tax and not account.invoice. The error message is correct. So either you extend invoice or you have to use note from the invoice tax lines (tax_line_ids).

Title in odoo 9

How in kanban view fill from databse t-att-title? Now title show
ODOO I want display name or descrption here..
<div class="oe_product_desc" t-att-title='_t("ODOO")'>
<h3><field name="name" /></h3>
<h4>
<field name="descrption"/>
</h4>
<ul>
Or any other solution for display text on mose hover...
Use record to access field names, so for example if you have a title field in your model you can do this
<div class="oe_product_desc" t-att-title="record.title.value">
<h3><field name="name" /></h3>
<h4>
<field name="descrption"/>
</h4>
<ul>