odoo, qweb: I like to replace attribute's value in odoo report - qweb

In odoo, qweb report. I have created an inherited report whith objective to change t-call attribute value from internal_layout to external layout. i have used the next code:
<template id="!!!!!!!!!!!!" inherit_id="!!!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="attrs">{'t-call':'web.external_layout'}</attribute>
</xpath>
</template>
This code did not work, I wonder if there is a way to insert sub part of the same report.
<template id="!!!!!!!!!!!!!!!!!!" inherit_id="!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="replace">
<t t-call='web.external_layout'>
insert here original sub report
</t>
</xpath>
</template>

Operation doable by this small changment !
<data>
<template id="!!!!!!!!!!" inherit_id="!!!!!!!!!!!!!!!!!">
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="t-call">web.external_layout</attribute>
</xpath>
</template>
</data>

If your views is for multiple object, like contains:
<t t-set="o" t-value="o.with_context({'lang':o.customer_id.lang})" />
you must add others attributes modification:
<xpath expr="//t[#t-call='web.internal_layout']" position="attributes">
<attribute name="t-call">web.external_layout</attribute>
<attribute name="t-foreach">docs</attribute>
<attribute name="t-as">o</attribute>
</xpath>

Related

How to make button in tree view always visible odoo 15

In odoo 15, i've created a button in tree view, but it not always visible, i must click on a record in the tree view to make the button appear.
My code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="grabfood_orders_tree" model="ir.ui.view">
<field name="name">grabfood.orders.tree</field>
<field name="model">grabfood.orders</field>
<field name="arch" type="xml">
<tree create="false">
<header>
<button string="Read GrabFood API" name="action_read_grabfood_api" type="object" class="btn-primary"/>
</header>
<field name="name"/>
</tree>
</field>
</record>
</data>
</odoo>
Please help, thanks.
Try this:
https://github.com/Tlki/web_tree_header_buttons_always_visible
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="grabfood_orders_tree" model="ir.ui.view">
<field name="name">grabfood.orders.tree</field>
<field name="model">grabfood.orders</field>
<field name="arch" type="xml">
<tree create="false">
<header>
<button string="Read GrabFood API"
name="action_read_grabfood_api" type="object" class="btn-primary"
attrs="{'always_visible': True}"
/>
</header>
<field name="name"/>
</tree>
</field>
</record>
</data>
</odoo>

Hide create and edit button from move lines in stock picking

I'm trying to hide the create and edit button from the model stock.picking
I already hide it from invoices but when I try to do it in picking like this
<record id="picking_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.picking.custom2</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook/page/field[#name='move_lines']/tree/field[#name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
<xpath expr="//field[#name='partner_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>
Appears the following error
Element '<xpath expr="//form/sheet/notebook/page/field[#name='move_lines']/tree/field[#name='product_id']">' cannot be located in parent view
Apparently doesn't find the product_id, I also tried changing the /tree/field for /kanban/field and allow me to upgrade the module but doesn't work neither to hide the create and edit button so any help will be appreciated.
I found the solution
What I had to do was the following
I have to change the model from stock.picking to stock.move because the move lines are from there and also change the ref to stock.view_move_picking_tree like the following code and it work!
<record id="picking_view_inherit_duvan1" model="ir.ui.view">
<field name="name">my.picking.custom2</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_picking_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='product_id']" position="attributes">
<attribute name="options">{'no_create_edit':True,'no_create':True,'no_open':True}</attribute>
</xpath>
</field>
</record>
Here is the answer in the Odoo Forum. https://www.odoo.com/es_ES/forum/ayuda-1/question/hide-the-create-and-edit-button-from-product-id-in-move-lines-stock-picking-159503.

Odoo 10 : Removing a button from customer form view

I want to remove 'Unpublished on Website' button from customer form view.
This button is not part of form view so when i tried below code ,i got an error that element doesn't exist in parent view:
<xpath expr='//div[#class="oe_button_box"]//button[#name="website_publish_button"]' position='replace'>
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</xpath>
Then i tried to remove it using css. My css.css file :
button[name=website_publish_button]
{
display:none !important;
}
and template :
<openerp>
<data>
<!-- Adds all assets in Odoo -->
<template id="assets_backend" name="contacts_custom assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!--These links will be called when loading your Odoo -->
<link rel="stylesheet" href="/contacts_custom/static/css/css.css"/>
</xpath>
</template>
</data>
</openerp>
But still button appears.Am i doing something wrong or Is there any other method to remove this button?
You could do it extending the view like this:
<record id="view_partners_form_website" model="ir.ui.view">
<field name="name">view.res.partner.form.website</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="website_partner.view_partners_form_website"/>
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<data>
<button name="website_publish_button" position="replace">
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</button>
</data>
</field>
</record>
Add a depends entry to the module website_partner to be able to inherit the view that add the button like the snippet above

'active_id' for project in kanban view?

I've added a notes section in the project kanban view. The problem is when I click it I get an error NameError: name 'active_id' is not defined
I've used this method to create smart buttons in project, contact, and product form views and it works well. When you click the smart button it will redirect to a pre-filtered notes page. I fear that since there's not really an "active" project open, that there will not be an active_id. If that's the case, how can I filter by the one I've clicked on?
Kanban view
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<div class="o_project_kanban_box">
<a name="%(note.action_note_note)d" type="action" context="{'search_default_project': active_id, 'default_project': active_id}">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</div>
</xpath>
</data>
</field>
</record>
Form view (which works)
<record id="view_project_notes_form" model="ir.ui.view">
<field name="name">triangle.project.note.form</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#name='button_box']" position="inside">
<button class="oe_stat_button" type="action" name="%(note.action_note_note)d"
icon="fa-sticky-note" context="{'search_default_project': active_id, 'default_project': active_id}">
<field string="Notes" name="note_count" widget="statinfo"/>
</button>
</xpath>
</data>
</field>
</record>
Please try record.id instead of active_id, ie :-
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<div class="o_project_kanban_box">
<a name="%(note.action_note_note)d" type="action" context="{'search_default_project': record.id, 'default_project': record.id}">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</div>
</xpath>
</data>
</field>
</record>
Ok, I adjusted my method a little bit because the context should actually be on the note.note action and not the project.project view.
New Project Kanban:
<record id="view_project_notes_kanban" model="ir.ui.view">
<field name="name">triangle.project.note.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<data>
<xpath expr="//div[#class='o_project_kanban_boxes']" position="inside">
<a name="%(triangle.act_project_2_note)d" type="action" class="o_project_kanban_box">
<span class="o_value"><field name="note_count"/></span>
<span class="o_label">Notes</span>
</a>
</xpath>
</data>
</field>
</record>
New Note Window Action:
<act_window id="act_project_2_note"
name="Notes"
res_model="note.note"
view_mode="kanban,tree,form"
context="{'search_default_project': [active_id], 'default_project': active_id}"/>
This totally solved my problem!

Import data to qweb report odoo

I'm creating a simple odoo qweb report to display some records in the database. Up to now I can create a report with some static content(hardcoded).But I want to connect my template with the table in my database. My table is Faculty. Here is my template file
`<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="ums_faculty_report">
<div class="page">
<h2>Report title</h2>
<p>This is the description</p>
<!--
In here i want to display the list of data-
<t t-foreach="dbrecords" t-as="o">
<p><t t-esc="i"/></p>
</t>
->
</div>
</template>
</data>
</openerp>`
And this is my report.xml file
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="ums.faculty_report"
model="ums.faculty"
string="All Faculties"
report_type="qweb-pdf"
name="ums.ums_faculty_report"
attachment_use="False"
/>
</data>
Simply I will repeat my problem again, I want to know how to bind a model to dbrecords in figure 1.Thanks in advance

Resources