Odoo Help


How to pass value from one form to another form using contrext? I tried but did not work out. Here is my code " onchange_reference_storage" funcation.

Rokon Uddin
on 9/13/14, 6:24 AM 1,695 views

from openerp.osv import osv, fields
from datetime import date

class archive_storage(osv.Model):
    _name = 'archive.storage'


       'item_name': fields.char('Name'),
        'storage_device': fields.many2one('archive.storage.type','Storage Device', required=True),
        'name': fields.char('Accession Number', required=True),
        'accession_date': fields.datetime('Accession Date', required=True),
        'barcode_number': fields.char('Barcode NO'),
        'properties': fields.text('Properties'),
        'company': fields.char('Company'),
        # 'description': fields.text('Description'),
        'disk_quantity': fields.integer('Disk Quantity'),

        'is_issued': fields.boolean('Is Issued'),
        'issued_to': fields.many2one('hr.employee', 'Issued To'),
        'issue_date': fields.datetime('Issue Date'),
        'return_date': fields.datetime('Return Date'),
        'shelf_no': fields.char('Shelf No'),
        'row_no': fields.char('Row No'),
        'tray_no': fields.char('Tray No'),
        'robotic': fields.selection([('na', 'N/A'),('in robotic', 'In Robotic'), ('out of robotic', 'Out of Robotic')],'Robotic'),

        'category': fields.many2one('archive.storage.category','Category', required=True),
        'remark': fields.char('Remarks'),
        'condition': fields.selection([('fine','Fine'),('damage','Damage'), ('lost', 'Lost')],'Condition'),
        'tape_type': fields.many2one('archive.tape.type', 'Tape Type', required=True),
        'duration': fields.char('Duration'),

        'submitted_by': fields.many2one('hr.employee','Submitted By'),

        'storage_media_content_id': fields.one2many('archive.storage.media.content', 's_m_c_id', 'Master Program'),
        'entry_by': fields.many2one('hr.employee', 'Entry By'),




    _defaults = {
        'entry_by': lambda s, cr, uid, c: uid,
        'accession_date':  fields.datetime.now,
        'disk_quantity': 1,

    _sql_constraints = [
        ('name_unique', 'unique(name)', 'Accession Numer already exists!')


    def onchange_storage_device(self, cr, uid, ids, storage_device, context=None):
        if storage_device:
            storage_name = self.pool.get('archive.storage.type').browse(cr, uid, storage_device, context=context)
            return {'value': {'name':self.pool.get('ir.sequence').get(cr, uid, storage_name.name)}}
            # return {'value': {'name':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid,'bank_pay_voucher')}}
        return {'value': {}}

    def onchange_reference_storage(self, cr, uid, ids, name, context):
        ctx = dict(context)
        ctx.update({'storage_source': 'asdfs'})
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'archive.media.content',
                'context': ctx,
                'type': 'ir.actions.act_window',
                'target': 'inline',





Sudhir Arya (SA)

--Sudhir Arya (SA)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow




Sudhir Arya (SA)
On 9/13/14, 7:05 AM

You cannot return an action from onchange method. Onchage only returns value, domain and warning only.

You can read documentation about What should onchange method do and return? and onchange method.

To return an action from method, the method should be called from button of type object. To fill the values of the fields in the form which you want to open, you have to pass the fields and their values in context as given in below example:

    if context is None:
        context = {}
    ctx = context.copy()
    ctx.update({'default_storage_source': 'asdfs'})
    return {
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'archive.media.content',
        'context': ctx,
        'type': 'ir.actions.act_window',
        'target': 'inline',
        'context': ctx,

You can find examples in addons as well. Return action with default values.


In Sales module, Quotations tab under Sales after selecting Customer from dropdown eg(Agrolait) when create or edite option is select from Contract/Analytic filed, the new pop up form sets customer "Agrolait" autometically. How can I do this? Plz help

Rokon Uddin
on 9/13/14, 8:02 AM

Rokon, as Sudhir has mentioned, you cannot call an action from on_change method. Assuming that you code it as Sudhir had mentioned, you can pass 'default_XXXX' key-value in the context where XXXX is the field name and the value is the value that you wish to be displayed by default in the called view.

on 9/13/14, 2:07 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 9/13/14, 6:24 AM
Seen: 1695 times
Last updated: 3/16/15, 8:10 AM