Odoo Help

Welcome!

This community 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.

0

How to get the values from a form when updating

By
Jason Villamin
on 9/19/14, 2:08 PM 1,034 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 }}

res_processing_request()

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
0

Sudhir Arya (SA)

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

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
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

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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/19/14, 2:08 PM
Seen: 1034 times
Last updated: 3/16/15, 8:10 AM