0

I have a problem when i was try to create a condition for selection field. I not have idea how to create condition for selection field. So, here my code :

_columns = {
    'choose': fields.selection((
            ('first','First'),
            ('second', 'Second'),
    ))
} 

As all of you know, after i selected the choice, i want to make a condition using "if else". If using basic python,i understand what i have to do. But in odoo, I still confuse about it. Should i build a method or what, i noy have idea.

Scarlett stone
  • 225
  • 1
  • 15

1 Answers1

0

If You are working with the same object (model) :

for line in self:
    if line.choose == 'first' :
        print 'You choose the first choice'
    elif line.choose == 'second':
        print 'You choose the second choice'

If You are working on separate object (model):

sale_id=self.search([('name','=','SO102')]).ids
for line in self.browse(sale_id):
    if line.choose == 'first' :
        print 'You choose the first choice'
    elif line.choose == 'second':
        print 'You choose the second choice'

Add this logic under your calcuation method and use it

DASADIYA CHAITANYA
  • 2,850
  • 3
  • 18
  • 41
  • Is there doesn't need a function method ? – Scarlett stone Sep 16 '17 at 12:07
  • Yes sure because without function what you have do in odoo ? – DASADIYA CHAITANYA Sep 16 '17 at 12:09
  • 1
    I was try it, not error but not give me what i want. ```_columns = { 'active_ids' : fields.char(string='Active IDS'), 'choose': fields.selection(( ('by space','By Space'), ('by coma', 'By Coma'), )) } def _get_choose(self, cr, uid, ids, choose, context=None): if choose == 'by space': print "::::::::::::::::::" print "NICE" print "::::::::::::::::::" else: print "::::::::::::::::::" print "GOOD" print "::::::::::::::::::"``` – Scarlett stone Sep 16 '17 at 12:18
  • My code is workable in odoo-8 and its later version also comes under new api only use the method with @api.multi decorator method and implement in your business logic – DASADIYA CHAITANYA Sep 18 '17 at 02:23
  • if you not yet solved then send me you module on dasadiya.chaitanya@gmail.com – DASADIYA CHAITANYA Sep 19 '17 at 05:30