Odoo Help


Clear previously selected value in the many2one field

on 5/2/15, 6:26 AM 1,248 views

Hai to all.......

  I created to field (field1, and field2) in order line of Sale Order module. In onchange method of  field1 , get corresponding value of field2 and return it by using 'domain', but if I select field2 without selecting field1, previously selected value can not cleared. How can clear the previously selected value

This is the Code

XML file

<field name="accom_date" >

<field name="accom_type" domain="[('is_accom_type','=',1)]" options="{'create': false, 'create_edit': false}"/>                                     <field name="bed_type" domain="[('is_room','=',1),('categ_id', '=', accom_type)]" options="{'create': false, 'create_edit': false}"/>

<field name="cost"/>

.Py file


    def change_accom_type(self):

        bed_list = []

        room_list = []

        vacant_list = []

        if self.accom_type and self.accom_date:

            pid = self.env['product.product'].search([('categ_id', '=', self.accom_type.id)])

            print 'PID: ', pid

            for record in pid:


                roomid = self.search([('bed_type', '=', record.id)])

                for val in roomid:

                    if val.status == 'occupied' and val.accom_date == self.accom_date:


            print 'List: ', bed_list

            print 'Room List: ', room_list

            for item in room_list:

                if item not in bed_list:


            print 'Vaccant Rooms: ', vacant_list

            domain = {'bed_type': [('id', 'in', vacant_list)]}

            return {'domain': domain, 'value': {'bed_type': False}}

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

1 follower(s)


Asked: 5/2/15, 6:26 AM
Seen: 1248 times
Last updated: 5/2/15, 6:26 AM