python-2.7


“TypeError: Cannot read property 'value' of null” in on_change event


I am finding the documentation for openerp 7 to be frustrating.
I am attempting to call a function from an on_change event to perform a calculation and place the result into another field within the same row.
from openerp.osv import osv, fields
class degree_day(osv.osv):
_name = "degree.day"
_columns={
'date': fields.date('Date'),
'high_temp': fields.integer('High Temp'),
'low_temp': fields.integer('Low Temp'),
'heat_degree_day': fields.integer('Heat Degree Day' ),
'hw_degree_day': fields.integer('HW Degree Day' ),
}
def generate_degree_day(self, cr, uid, ids, high_temp = 0, low_temp = 0, context=None):
""" On change of temperature generate degree day numbers
#param high_temp: The day's high temperature
#param low_temp: The day's low temperature
"""
if not (high_temp and low_temp):
return
temp = 65 - (high_temp + low_temp) / 2
if temp < 0:
temp = 0
heat_degree_day = temp
hw_degree_day = temp + 5
<>
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="degree_day_tree" model="ir.ui.view">
<field name="name">degree.day.tree</field>
<field name="model">degree.day</field>
<field name="arch" type="xml">
<tree string="Degree Day List" editable="bottom">
<field name="date" />
<field name="high_temp" on_change="generate_degree_day(high_temp, low_temp)" />
<field name="low_temp" />
<field name="heat_degree_day" />
<field name="hw_degree_day" />
</tree>
</field>
</record>
<record id="show_degree_day" model="ir.actions.act_window">
<field name="name">Degree Day</field>
<field name="res_model">degree.day</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Degree Day" id="menu_degree_day" action="show_degree_day"/>
</data>
</openerp>
OpenERP expect the onchange function to return the data in the following format
{
'value' : {
'<field_x>': <value for field x>,
'<field_y>': <value for field y>,
}
'context' : <Context dict>
'domain' : {
'field_a' : <domain filter for field_a>,
'field_b' : <domain filter for fied_b>,
}
'warning' : {
'title': '<warning message title>',
'message': '<Warning message>'
}
}
context, domain, warning are optional. Value is mandatory and you can include the updated value for zero or more fileds in that vale dict.
In your case, at end of your onchange function, you may add
return {'value':{'heat_degree_day':temp,'hw_degree_day':temp + 5}}

Related Links

http headers in flask not working on linux server
Getting Asynchronous Sessions cleanup phase starting NOW using Phantomjs
Is there an efficient way to fill date gaps in python?
Finding max element in a list in Python
Python 2.7 pySerial read() returns all characters in Python interpreter but not Python script. Also need robust way to read until buffer is empty
Python script could not find a filename
sqlalchemy insert data from dictionary
python 2.7 - trying to print a string and the (printed) output of function in the same line
create and use NumPy array with dtype of builtin int
Need help extracting links from a TD in webpage
Python Numpy Installation Windows 10 64-bit
What does python code do and what does xml code do in odoo?
Cython.Compiler.Errors.CompileError: hamilton_filter.pyx
MemoryError of Python Module dbf
Python 2.7, Tkinter and PIL, grab the screen and show the Image I grabbed when I click a button
log messages from non-default module not showing up in google app engine console

Categories

HOME
android-studio
seedstack
kivy
mongoid
bing-search
greasemonkey
bittorrent
timber
tfs2010
stack-overflow
hystrix
lc3
amazon-emr
circleci
business-intelligence
pm2
jodatime
pinterest
asciimath
fosuserbundle
checkout
tableview
neo4j.rb
batch-rename
pymongo
ava
raima
managed-c++
plyr
morris.js
fstar
network-analysis
audit
tilemill
objectmapper
epplus
listjs
restful-architecture
xerces-c
redgate
cloudera-quickstart-vm
git-tfs
sendinput
oracle-bmcs
libreoffice-writer
nusoap
karabiner
renderman
android-sharing
sequence-diagram
palindrome
kendo-treeview
scheduledexecutorservice
multi-touch
google-identity-toolkit
logical
spring-mongo
codecharge
xcopy
verisign
polymerfire
ioctl
wikimedia-commons
pack
m4
cfwheels
green-threads
phpredis
flow-js
quercus
deque
scala-swing
maven-shade-plugin
adhoc-polymorphism
global-scope
smacss
relationships
jquery-mobile-flipswitch
senchatouch-2.4
redpitaya
sqlbindparameter
webaii
django-sites
notifyjs
ax
asp.net-mvc-3-areas
tfs-sdk
linkbutton
datacontracts
firefly-mv
winsxs
nsconnection
django-pagination
suphp
eaccelerator
fgetc
asdoc
aspbutton
ntruencrypt
code-camp

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile