When i add an image field in kanban view in odoo11 it has raised the error as "QWeb2 - template['kanban-box']: Runtime Error: TypeError: Cannot read property 'raw_value' of undefined" ". And the same code worked for me in odoo 9. I'm struck in identifying the cause of the issue. Here's my code.
Python Code:
class Test(models.Model):
_name = "test.test"
image = fields.Binary(attachment=True)
XML Code:
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="image" />
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
</kanban>
</field>
</record>
Thanks for your support and time.
You need to add the id field to the kanban view (in any view) if you will be referencing it. This applies up to Odoo 14 as well.
Added <field name="id" attrs="{'invisible': True}"/> to code below:
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="image" />
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
<field name="id" attrs="{'invisible': True}"/>
</kanban>
</field>
</record>
Kanban Docs: https://www.odoo.com/documentation/11.0/howtos/backend.html#kanban
you can try it by adding the "id"
<record id = "test_id" model = "ir.ui.view">
<field name = "name">Test Image</field>
<field name = "model">test.test</field>
<field name = "arch" type = "xml">
<kanban>
<field name="id"/>
<field name="image"/>
<templates>
<t t-name="kanban-box">
<div class="oe_resource_vignette">
<div class="oe_resource_image">
<img t-att-src="kanban_image('test.test','image',record.id.raw_value)" class="oe_resource_picture"/>
</div>
</templates>
</kanban>
</field>
Related
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>
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
I am using Odoo 10-e. I am working on a sample module.
I have 5 models (customer, product, order, order details, movement)
Customer :
class Customer(models.Model):
_name ="amgl.customer"
…… all other fields related to customer
product_ids = fields.Many2many('amgl.products', string='Products')
Products :
class Products(models.Model):
_name ="amgl.products"
…… all other fields related to product
customer_ids = fields.Many2many('amgl.customer', string='Customers')
Order :
class Order(models.Model):
_name ="amgl.order"
order_line = fields.One2many('amgl.order_line', 'order_id', string='Order Lines')
…… all other fields related to Order
Order Details :
class OrderLine(models.Model):
_name = 'amgl.order_line'
order_id = fields.Many2one('amgl.order', string='Orders')
products = fields.Many2one('amgl.products', string="Products")
…… all other fields related to order details
Movement
class Movement(models.Model):
_name = 'amgl.metal_movement'
customer = fields.Many2one("amgl.customer", string="Customer", required=True)
order_lines = fields.One2many('amgl.order_line','metal_movement_id')
…… all other fields related to movement
What i am trying to do is, i am creating a movement form in which user will select a customer from customer drop down first then user will add order_lines and in that he will be able to add products i want to filter products which are associated with above selected customer . How can i do that ? I have been trying since last month.
Movement View
<odoo>
<data>
<record id="action_metal_movement" model="ir.actions.act_window">
<field name="name">Metal Movement Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">metal.movement</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to create
</p><p>
<!-- More details about what a user can do with this object will be OK -->
</p>
</field>
</record>
<record id="form_metal_movement" model="ir.ui.view">
<field name="name">Metal Movement Request </field>
<field name="model">metal.movement</field>
<field name="arch" type="xml">
<form string="Metal Movement">
<sheet>
<group>
<group string="Metal Movement Request">
<field name="date_create" string="Date Created"/>
<field name="reference"/>
<field name="metal_movement_type"/>
<field name="first_approve"/>
<field name="second_approve" domain="[('id', '!=', first_approve)]"/>
<field name="customer"/>
<field name="sepcial_instruction" widget="html"/>
</group>
<group string="Metal Movement From">
<group colspan="6">
<field name="custodian"/>
<field name="mmf_name"/>
<field name="mmf_account_number"/>
<field name="mmf_account_type"/>
</group>
<group string="Metal Movement To" colspan="6">
<field name="mmt_name"/>
<field name="mmt_address" attrs="{'invisible':[('metal_movement_type', '=', 'IT')]}"/>
<field name="mmt_account_number" />
<field name="mmt_company" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU','IT'))]}"/>
<field name="pickup_date" string="Pick up Datetime" attrs="{'invisible':[('metal_movement_type','not in',('AC','IPPU'))]}"/>
</group>
</group>
<group string="Metals To Be Moved" colspan="12">
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" domain="[('customer_ids','in', parent.customer)]" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
</group>
</group>
</sheet>
</form>
</field>
</record>
</data>
</odoo>
Thank you for updation of question.
First add customer in product field context.
<field name="order_lines">
<tree editable="bottom">
<field name="quantity" string="Quantity"/>
<field name="products" context="{'customer_id':parent.customer}" string="Product Name"/>
<field name="weight" string="Weight"/>
<field name="total_weight" string="Total Weight"/>
</tree>
</field>
Then in product's model write it's name_get method like this.
#api.multi
def name_get(self):
if self.env.context('customer_id',False):
customer = self.env['amgl.customer'].browse(self.env.context('customer_id',False))
for product in customer.product_ids:
res.append((product.id,product.name))
else:
res=super(product_product,self).name_get()
return res
Thats it.
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')
i am trying onchange method programme in openerp using python. but there is no error at the same time there is no response while i change name in field.
xml coding (cus_view.xml)
<?xml version="1.0"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record model = "ir.ui.view" id = "custom_tree">
<field name = "name">Custom</field>
<field name = "model">cus.custom</field>
<field name = "type">form</field>
<field name = "arch1" type = "xml">
<tree string = "custom" version = "7.0">
<field name = "name"/>
<field name = "customer_name"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record model = "ir.ui.view" id = "custom_form">
<field name = "name">Custom</field>
<field name = "model">cus.custom</field>
<field name = "type">form</field>
<field name = "arch1" type = "xml">
<form string = "custom" version = "7.0">
<label for = "name" string = "Lab Id"/>
<field name = "name" style = "width:10%%" /><br/>
<label for = "customer_name" string = "Customer Name" />
<field name = "customer_name" style = "width:10%%" on_change="on_change_customer(customer_name)" /><br/>
<label for = "Street1" string = "Address"/>
<field name = "customer_street1" style = "width:10%%"/><br/>
<field name = "customer_street2" style = "width:10%%"/><br/>
<field name = "customer_city" style = "width:10%%"/><br/>
<field name = "customer_state" style = "width:10%%"/><br/>
<field name = "customer_zip" style = "width:10%%"/><br/>
<field name = "customer_country" style = "width:10%%"/><br/>
<label for ="customer_mobile" string = "Mobile"/>
<field name = "customer_mobile" style = "width:10%%"/><br/>
<label for ="customer_mail" string = "Email"/>
<field name ="customer_mail" style = "width:10%%"/>
</form>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record model = "ir.actions.act_window" id = "action_custom">
<field name = "name">Custom</field>
<field name = "res_model">cus.custom</field>
<field name = "view_type">form</field>
<field name = "view_mode">tree,form</field>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lab Information" id = "menu_cus_custom" action = "action_custom"/>
</data>
</openerp>
python coding (cus.py)
from osv import osv
from osv import fields
class cus(osv.osv):
_name = "cus.custom"
_description = "This table is for keeping personal data of student"
_columns = {
'name': fields.char('Lab Id',size=64,required=True),
'customer_name': fields.many2one('res.partner', 'Customer'),
'customer_street1': fields.char('Street', size=64),
'customer_street2': fields.char('Street', size=64),
'customer_city': fields.char('City', size=64),
'customer_state': fields.char('State', size=64),
'customer_zip': fields.char('Zip', size=64),
'customer_country': fields.char('Country', size=64),
'customer_mobile': fields.char('Mobile', size=64),
'customer_mail': fields.char('Mail', size=64)
}
def on_change_customer(self, cr, uid, ids, customer_name, context=None):
values = {}
if customer_name:
cust = self.pool.get('res.partner').browse(cr, uid, customer_name, context=context)
values = {
'customer_country': cust.name
}
return {'value' : values}
update your xml file, no need to write label for each, try this
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- ===================== This is tree layout =============================-->
<record id="custom_tree" model="ir.ui.view">
<field name="name">Custom</field>
<field name="model">cus.custom</field>
<field name="arch" type="xml">
<tree string="custom">
<field name = "customer_name"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</tree>
</field>
</record>
<!-- ========================This is Form layout===============================-->
<record id="custom_form" model="ir.ui.view">
<field name="name">cus.custom</field>
<field name="model">cus.custom</field>
<field name="arch" type="xml">
<form string="custom" version="7.0">
<label for="name" class="oe_edit_only"/>
<h1><field name="name"/></h1>
<group>
<field name = "customer_name" on_change="on_change_customer(customer_name)"/>
<field name = "customer_street1"/>
<field name = "customer_street2"/>
<field name = "customer_city"/>
<field name = "customer_state"/>
<field name = "customer_zip"/>
<field name = "customer_country"/>
<field name = "customer_mobile"/>
<field name = "customer_mail"/>
</group>
</form>
</field>
</record>
<!-- ========================= Action Layout ============================= -->
<record id="action_custom" model="ir.actions.act_window">
<field name="name">Custom</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">cus.custom</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="custom_form"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name = "Lab Information" id = "menu_cus_custom" action = "action_custom"/>
</data>
</openerp>
You have wrote onchange on label because of that its not responding. Try this,
<label for = "customer_name" string = "Customer Name"/>
<field name = "customer_name" onchange="on_change_customer(customer_name)" style = "width:10%%"/><br/>
There is one another mistake you have made, improve field name in tree view,
<field name = "customer_country"/>
This will work.