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.

1

Using self.write in on_change method [Closed]

By
Leopo
on 2/20/13, 6:01 PM 4,125 views

The Question has been closed

by
Sudhir Arya (SA)
on 04/18/2013 04:52:19

Hello, I need change the value in a field in the form when change the selection in fields.selection. I try use write method with on_change but doesn't work. The on_change take the value ok, but can't write it in the other field. The field sequence_use is always blank.

Thanks


#-- xml

<field name="sequence_lot" on_change="onchange_sequence_lot(sequence_lot)"/> 
<field name="sequence_use" colspan="2" />

#-- py

_columns = {
    'sequence_lot': fields.selection([(seq1,'Lot Products A'),(seq2,'Lot Products B'),(seq3,'Lot Products C')],'Sequence to use '),

    'sequence_use': fields.char('Production Lot', size=64, required=True, help="Unique production lot to use"),
}

def onchange_sequence_lot(self, cr, uid, ids, sequence_lot, context=None):
    if sequence_lot == "seq1":
        seq_choosen = self.pool.get('ir.sequence').get_id(cr, uid, 31, context={} ) #Using id of seq.
        self.write(cr, uid, ids, {'sequence_use': seq_choosen}, context = context)
        #raise osv.except_osv(_('Warning!'), _('Seq Ch %s.'%str(sequence_lot)))
    else : seq_choosen = self.pool.get('ir.sequence').get_id(cr, uid, 12, context={} )
           self.write(cr, uid, ids, {'sequence_use': seq_choosen}, context = context)
    return True
4

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 2/21/13, 12:59 AM

You should return value to fields rather than updating them.

def onchange_sequence_lot(self, cr, uid, ids, sequence_lot, context=None):
    result = {}
    if sequence_lot == "seq1":
        seq_choosen = self.pool.get('ir.sequence').get_id(cr, uid, 31, context={} ) #Using id of seq.
        result['value'] = {'sequence_use': seq_choosen,}
    else:
        seq_choosen = self.pool.get('ir.sequence').get_id(cr, uid, 12, context={} )
        result['value'] = {'sequence_use': seq_choosen,}
    return result

Ok, thank you for your help, now is working very good. Solved

Leopo
on 2/21/13, 1:29 PM

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 2/20/13, 6:01 PM
Seen: 4125 times
Last updated: 3/16/15, 8:10 AM