Odoo Help


How to get the values from a form when updating

Jason Villamin
on 9/19/14, 2:08 PM 1,363 views

I'm trying to get the partner_id upon updating the form, unfortunately I can't capture it. I've added a def write function in order to modify the updating. What I wanted to do is, when the form is submitted and the field "state" is equals to approved, it will create another record at other table/object. But I can't seem to make it work and capture the partner id using vals['partner_id'] which is also in the form..Please help and thanks in advance

class res_processing_request(osv.osv):
    _name = 'res.processing.request'
    _description = 'res.processing.request'

    _columns = {
        'date': fields.datetime('Date Requested', required=True),
        'partner_id': fields.many2one('res.partner', 'Client', required=True),
        'status': fields.many2one('res.partner.application.status', 'Status'),
        'name': fields.char('Request Name', size=255, required=True),
        'requestor_id': fields.many2one('res.users', 'Requested By', required=True),
        'approver_id': fields.many2one('res.users', 'Approved By'),
        'state': fields.selection([
            ('For Approval', 'For Approval'),
            ('On-hold', 'On-hold'),
            ('Approved', 'Approved'),
        ], 'State', required=True),
        'active': fields.boolean('Active'),
    _defaults = {
        'active': lambda *a: 't',
        'state': lambda *a: 'For Approval',

    def write(self, cr, uid, ids, vals, context=context):
        if vals['state'] == 'Approved':
            # processing_request = self.read(cr, uid, ids, context=context)

            application_history_data = {
                'create_uid' : uid,
                'create_date' : time.strftime('%Y-%m-%d %H:%M:%S'),
                'status' : 348,
                'user_id' : uid,
                'email' : '',
                'subject' : '',
                'date' : time.strftime('%Y-%m-%d %H:%M:%S'),
                'partner_id' : vals['partner_id'],
                'visible' : 1

            self.pool.get('res.partner.application.history').create(cr, uid, application_history_data)

        return super(res_processing_request, self).write(cr, uid, ids, vals, context)

    def onchange_status(self, cr, uid, ids, status_id, context={}):
        if status_id:
            status = pooler.get_pool(cr.dbname).get('res.partner.application.status').browse(cr, uid, status_id, context)
            return {'value': { 'name': status.name }}


Weird. It should be there. Maybe the xml file associated with the model is the erroneous one?

Ben Bernard
on 9/20/14, 12:15 PM

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
On 9/20/14, 1:05 PM

Hello Jason,

You are doing right to create a another record if state is approved.

I think you didn't understood the working flow of the write method.
Write method will have only those records in vals which are being altered/updated.

So the reason you are not getting partner id in vals is that, you are not changing the value of partner_id field.

Instead of using vals, you should first call the method of the super class so that all the changes will get affect in database and then browse the records.

Try this:

def write(self, cr, uid, ids, vals, context=context):
    res = super(res_processing_request, self).write(cr, uid, ids, vals, context=context)
    for rec in self.browse(cr, uid, ids, context=context):
        if rec.state == 'Approved':
            application_history_data = {
                'create_uid' : uid,
                'create_date' : time.strftime('%Y-%m-%d %H:%M:%S'),
                'status' : 348,
                'user_id' : uid,
                'email' : '',
                'subject' : '',
                'date' : time.strftime('%Y-%m-%d %H:%M:%S'),
                'partner_id' : rec.partner_id and rec.partner_id.id,
                'visible' : 1
            self.pool.get('res.partner.application.history').create(cr, uid, application_history_data, context=context)
    return res

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/19/14, 2:08 PM
Seen: 1363 times
Last updated: 3/16/15, 8:10 AM