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

Clear previously selected value in the many2one field

By
shameem
on 5/2/15, 6:26 AM 567 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

@api.onchange('accom_type')

    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:

                room_list.append(record.id)

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

                for val in roomid:

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

                        bed_list.append(record.id)

            print 'List: ', bed_list

            print 'Room List: ', room_list

            for item in room_list:

                if item not in bed_list:

                    vacant_list.append(item)

            print 'Vaccant Rooms: ', vacant_list

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

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



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

1 follower(s)

Stats

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