TypeError: dict.record.id is undefined when I access to my custom kanban view in Odoo 11 - image

I have a custom module that had a kanban view. His model inherits from res.users (and res.users inherits from res.partner).
I have a problem when I try to access to kanban view of my module. I know where is the error, but i don´t have idea for how to solve.
The error is:
Error: QWeb2 - template['kanban-box']: Runtime Error: TypeError: dict.record.id is undefined
This is my kanban view (maestro):
<record model="ir.ui.view" id="maestro_kanban_view">
<field name="name">maestro.kanban.view</field>
<field name="model">aula10.maestro</field>
<field name="groups_id" eval="[(4, ref('grupo_maestros'))]"/>
<field name="arch" type="xml">
<kanban>
<field name='name'/>
<field name='image'/>
<templates>
<t t-name="kanban-box">
<div class="oe_kanban_global_click">
<div class="o kanban_image">
<img t-att-src="kanban_image('maestro','image_medium', record.id.value)"/>
<div class="oe_kanban_details">
<!-- Title and Data content -->
<h4>
<a type="open">
<field name="name"/>
</a>
</h4>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>
I know the problem is in the image, in record.id.value, because when I erase the img tag, the error disappear.
How can I fix this?

In kanban view you must mention every fields you use in the field list like in your code you have mentioned two fields nameand image just add id to them and Odoo should recognize it.
<field name='id'/>
<field name='name'/>
<field name='image'/>

Related

Custom view of model inside the form view

I have this two models EstatePropertyModel and AuthorsModel, and I would like to display the entries of the AuthorsModel in the form of the EstatePropertyModel:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_estate_property_advertisement_form" model="ir.ui.view">
<field name="name">estate.property.form</field>
<field name="model">estate.property</field>
<field name="arch" type="xml">
name="name"/>
name="description"/>
name="postcode"/>
name="date_availability"/>
name="expected_price"/>
name="selling_price"/>
name="bedrooms"/>
name="living_area"/>
name="facades"/>
name="garage"/>
name="garden"/>
name="garden_area"/>
name="garden_orientation"/>
name="state_property"/>
name="active"/>
<field name="author_ids" position="after">
<div class="oe_title">Authors</div>
<div class="oe_subtitle">
<t t-if="len(record.author_ids) == 0">No authors</t>
<t t-if="len(record.author_ids) > 0">
<t t-foreach="record.author_ids" t-as="author">
<span t-field="author.name"/>
</t>
</t>
</div>
</field>
</odoo>
Is this possible?
I am new in the odoo development, and I am asking to point me the direction where to look! 
Thanks
yeeah it's possible through One2many field in odoo, after that, create a Notebook in the form view in that notebook and create a page, on that page add the one2many view in it
it will be made like this...
<notebook>
<page>
<field name="one2many_field_name">
<tree string="Example" editable="bottom">
<field name="field_1_from_2nd_model"/>
<field name="field_2_from_2nd_model"/>
</tree>
</field>
</page>
</notebook>
as per the comment below the answer is below this:
class ExampleModelFirst(models.Model):
_name = 'first.model'
field_1 = fields.Char(string='Field 1')
field_2 = fields.Integer(string='Field 2')
class ExampleModelSecond(models.Model):
_name = 'second.model'
field_3 = fields.Many2one('first.model', string='reference')
field_4 = fields.Char(related='field_3.field_1')
field_5 = field.Integer(related='field_3.field_2')
Add these second.model field in form view you will get the values...
author_ids should be one2many field
To create a One2many field you can refer to this https://www.odoo.com/documentation/16.0/developer/howtos/rdtraining/08_relations.html#one2many
Do this if you want to show all fields
<notebook>
<page string="Authors">
<field name="author_ids"/>
</page>
</notebook>
Do this if you want to show specific fields
<notebook>
<page string="Authors">
<field name="author_ids">
<tree>
<field name="author_ids.name"/>
</tree>
</field>
</page>
</notebook>

odoo wizard cant inherit the model

I created a model like this
class FoundCheque(models.TransientModel):
_name = "found.cheque"
date_Found = fields.Date(string='Found Date', default=fields.Date.context_today, required=True, translate=True)
and its view
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="wizard_found_cheque">
<field name="name">found.cheque.wizard</field>
<field name="model">found.cheque</field>
<field name="arch" type="xml">
<form string="found Cheque">
<group>
<field name="date_found" style="width:40%%"/>
</group>
<footer>
<button name="found_cheque" string="Post" type="object" class="oe_highlight"/>
or <button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
</data>
</odoo>
but when I try to update the module after restarting the service
it just says:
Field `date_found` does not exist
Error context:
View `found.cheque.wizard`
[view_id: 4100, xml_id: n/a, model: found.cheque, parent_id: n/a]
None" while parsing /opt/odoo/odoo11-custom-addons/cheque_management/views/found_cheque.xml:4, near
<record model="ir.ui.view" id="wizard_found_cheque">
<field name="name">found.cheque.wizard</field>
<field name="model">found.cheque</field>
<field name="arch" type="xml">
<form string="found Cheque">
<group>
<field name="date_found" style="width:40%%"/>
</group>
<footer>
<button name="found_cheque" string="Post" type="object" class="oe_highlight" confirm="آیا مطمئن هستید؟"/>
or <button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
and just to add I restarted the service several times
more information will be added on request
Your field name in python file is date_Found and date_found in xml. Both are different. so change field name in xml file
the defined field in model was "date_Found" and the defined field in wizard was "date_found"
F

Odoo - Change specific column color in one2many tree view

I am using odoo 10. I have a customer view and in that customer form view i am also showing all order that are associated with that specific customer in one2many tree view (editable).
What i want to do is i want to show a button in one2many tree view but i want to change that button's color only based on condition.
Here is what i tried but its not working.
<record id="amgl.customer_form" model="ir.ui.view">
<field name="name">Customer</field>
<field name="model">amgl.customer</field>
<field name="arch" type="xml">
<form string="Create New Customer" duplicate="0">
<sheet>
<group colspan="4">
<group>
<field name="is_admin" invisible="1"/>
<field name="is_custodian" invisible="1"/>
<field name="is_vault" invisible="1"/>
<field name="is_o2m" invisible="1"/>
<field name="is_goldstar" invisible="1"/>
<field name="custodian_edit" invisible="1"/>
<field name="first_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="last_name"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="gst_account_number" string="GoldStar Account Number"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)], 'invisible':[('is_goldstar','=',False)]}"/>
</group>
<group>
<field name="date_opened"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="account_type"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
<field name="custodian_id" options='{"no_open": True}'
attrs="{'readonly':[('is_admin','=', False)]}"/>
<field name="customer_notes"
attrs="{'readonly':['|',('is_vault','=', True),('custodian_edit','=', True),('is_admin','=', False)]}"/>
</group>
</group>
<notebook>
<!--CURRENT INVENTORY-->
<page string="CURRENT INVENTORY">
<field name="customer_order_lines2"
attrs="{'readonly':['|',('is_custodian','=', True),('is_o2m','=', False)]}"
context="{'default_is_deposit_related': True,'group_by':'products'}"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins"
domain="[('state','=','completed')]" default_order='state desc'
widget="one2many_list">
<h4 style="float:right;">
<field name="total_received_quantity"/>
</h4>
<tree open="false" editable="bottom"
groups="amgl.group_amark_admins,amgl.group_amark_vault,amgl.group_amark_custodian,amgl.group_amark_sub_admins">
<field name="is_deposit_related" invisible="1"/>
<field name="is_vault_edit" invisible="1"/>
<field name="is_admin" invisible="1"/>
<field style="color:red !important;" name="products" attrs="{'readonly':[('is_vault_edit','=', True)]}"/>
<field name="commodity"/>
<field name="total_received_quantity"
attrs="{'readonly':[('is_vault_edit','=', True)]}" class="oe_edit_only"
col_border="1" string="Received"/>
<field name="temp_received_weight" class="oe_edit_only" col_border="1"/>
<field name="date_received" attrs="{'readonly':[('is_vault_edit','=', True)]}"
class="oe_edit_only" col_border="1"/>
<field name="state" invisible="1"/>
<field name="notes_boolean" invisible="1"/>
<button attrs="{'invisible':[('notes_boolean','=', False)]}" type="object" name="add_notes" class="btn btn-primary btn-sm o_list_button_add">
<i class="fa-lg fa-pencil-square"></i>
</button>
<button attrs="{'invisible':[('notes_boolean','=', True)]}" type="object" name="add_notes" class="btn btn-default">
<i class="fa-lg fa-pencil-square"></i>
</button>
<!--<button colors="red: notes_boolean is True" name="add_notes" type="object"-->
<!--string="Add Notes" icon="fa-lg fa-pencil-square" class="btn btn-primary btn-sm o_list_button_addhlight"/>-->
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
What you are doing is the right solution you cannot change attributes of button using attrs
so you need to create two button with the same name and label and show or hide one of them
based on condition.
but this code will not work on tree because Odoo will not take your class attribute or style attribute
in consideration no matter what you put there if you inspect the button element in your browser you will find that
the two buttons are the same and the classes are the same and your classes are not there and there is no style attribute.
I don't know why Odoo developer decided to do so.
I needed something like this before what I did is to add css in backend_assets that select a button in tree
view with data-field attribute equal the name of the method because that attribute will not change in translation.
/* make button color red in temporary exit tree view.*/
.openerp .oe_list_content [data-field='cancel_entry'] button{
background-color: red !important;
color: white !important;
}
you will notice that only this attribute change in the buttons that are in the tree view.
so if you want to do something like this you need to to create two method
#api.multi
def add_notes_red(self): # i added _red to make sure no one else will name he's method like this
pass
#api.multi
def add_notes_green(self):
return self.add_notes_red() # because it does the same thing just call the orignal method
And in your custom css file
/* make button color red.*/
.openerp .oe_list_content [data-field='add_notes_red'] button{
background-color: red !important;
color: white !important;
}
/* make button color green.*/
.openerp .oe_list_content [data-field='add_notes_green'] button{
background-color: green !important;
color: white !important;
}
Note: Don't forget to css file in backend_assets template.

Button not displaying report in odoo

I have been battling with an issue for a while now....Kindly help me. Below is the issue:
I created a button on the header of a form, the idea of this button is to show a report of an image file on click. But anytime i click this button, nothing happens. And when i edited the form view from developer's mode, i realized that the button is picking a different name. i.e
<header>
<button name="reports/bh_customcustom.report_formdownload_view" type="report" string="Form Download" class="oe_highlight"/>
</header>
instead of this which is in the code:
<header>
<button name="action_formdownloader" type="object"
string="Form Downloader" class="oe_highlight"/>
</header>
Below are my code snippet:
The form view:
<record model="ir.ui.view" id="form_download_form_view">
<field name="name">form_download.form</field>
<field name="model">formdownload</field>
<field name="arch" type="xml">
<form string="Form Download Form">
<header>
<button name="action_formdownloader" type="object"
string="Form Downloader" class="oe_highlight"/>
</header>
<sheet>
<group string="Company Name">
<!--<field name="company_name_id"/>-->
<field name="name"/>
<!--<field name="form_serial_no" />-->
</group>
</sheet>
</form>
</field>
</record>
The model:
class FormDownload(models.Model):
_name = 'formdownload'
_rec_name = 'form_serial_no'
# #api.multi
def action_formdownloader(self):
return self.env['report'].get('bh_customcustom.report_formdownload_view')
name = fields.Many2one('companyname', string="Company Name", ondelete='cascade',
required=True)
form_serial_no = fields.Char(string="Form Serial No", readonly=True)
status = fields.Boolean(string="Status", default=False)
Part of the openerp.py file related to it
'depends': ['base', 'construction_plot_4devnet', 'bh_custom', 'report'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/bh_customcustom.xml',
'sequences.xml',
'report/form_download_report.xml',
'security/security_groups.xml',
'templates.xml',
],
'images': [
'img/firstpage.png',
],
The report file:
<openerp>
<data>
<report
id="report_form_download"
model="formdownload"
string="Form Download Report"
name="bh_customcustom.report_formdownload_view"
file="bh_customcustom.report_formdownload_view"
report_type="qweb-pdf"/>
<record id="paperformat_formdownloadcheck" model="report.paperformat">
<field name="name">Form Download Check</field>
<field name="default" eval="True"/>
<field name="format">custom</field>
<field name="page_height">80</field>
<field name="page_width">175</field>
<field name="orientation">Portrait</field>
<field name="margin_top">3</field>
<field name="margin_bottom">3</field>
<field name="margin_left">3</field>
<field name="margin_right">3</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">3</field>
<field name="dpi">80</field>
</record>
<template id="report_formdownload_view">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="doc">
<t t-call="report.external_layout">
<div class="page">
<!--<img class="img img-responsive" src="/bh_customcustom/static/src/img/firstpage.png"-->
<!--style="max-height: 45px"/>-->
<img src="/static/src/img/firstpage.png"
style="max-height: 45px"/>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>
The problem was from my path on the view xml file cos i edited the form view now and it's picking the exact method that it suppose to pick after i reviewed the path. Moreso, the method that would pull the report should be like this:
#api.multi
def action_formdownloader(self):
return self.env['report'].get_action(self, 'bh_customcustom.report_formdownload_view')

How do I get an editable multilines layout in OpenERP?

I want to create Delivery orders based on a selection of order lines to invoices (as shown below) with the possibility to adjust quantity used in the delivery order.
Expected UI
Looking around, I found a UI similar to want I want in Delivery orders > More > Return Shipments (cf. _stock/wizard/stock_return_picking_view.xml_).
What I got
But I don't get the same result with my XML
view.xml
<record id="view_create_delivery_button" model="ir.ui.view">
<field name="name">Create Delivery</field>
<field name="model">sale.order.line</field>
<field name="arch" type="xml">
<form string="Create Delivery" version="7.0">
<label string="Select the quantities to create."/>
<group>
<field name="order_id"/>
<field name="name"/>
<field name="product_uom_qty"/>
<field name="state" invisible="1" />
</group>
<footer>
<button name="create_returns" string="Create delivery" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Question
How do I get this editable multilines layout?
What you see in the Return Shipments wizard is a one2many field that related to stock.return.picking.line on it tree view with editable=top attribute.
I am assuming this is what you wanted:
<record id="view_create_delivery_button" model="ir.ui.view">
<field name="name">Create Delivery</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<form string="Create Delivery" version="7.0">
<label string="Select the quantities to create."/>
<field name="order_line" >
<tree editable="top">
<field name="order_id"/>
<field name="name"/>
<field name="product_uom_qty"/>
<field name="state" invisible="1" />
</tree>
</field>
<footer>
<button name="create_returns" string="Create delivery" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>
Note: This is just a sample of how to use the field many2one's tree view, you might need adjust to your on needs.

Resources