Skip to Content
Menu
This question has been flagged
2524 Views

Hey, so we have a selection field where we need to change the data in it whenever another field changes. 

We have tried doing the field = newdataset but it says invalid data [(60049,'SAI Automotive Ltd')]
altough that data looks correct to me for a selection field.

We have also tried re-calling the function and setting the data which also hasnt worked.

Here is the current code:

    recipient_model_real = fields.Selection(selection = 'get_contact', required=True)
    
    @api.multi    
    def get_contact(self):   
        if self.x_serial_number.id != False:
            self._cr.execute("SELECT P.id, P.name FROM stock_production_lot L INNER JOIN stock_quant Q ON L.id = Q.lot_id INNER JOIN stock_location SL ON Q.location_id = SL.id INNER JOIN res_partner P ON SL.partner_id = P.id WHERE L.id = '"+ str(self.x_serial_number.id) +"' AND P.name NOT LIKE 'Maxim%'")
            data = self._cr.fetchall() 
            return data
        else:
            self._cr.execute("SELECT P.id, P.name FROM stock_production_lot L INNER JOIN stock_quant Q ON L.id = Q.lot_id INNER JOIN stock_location SL ON Q.location_id = SL.id INNER JOIN res_partner P ON SL.partner_id = P.id WHERE P.name NOT LIKE 'Maxim%'")
            data = self._cr.fetchall() 
            return data
 
    
    #On change serial number, change contact selection field
    @api.multi
    @api.onchange('x_serial_number')
    def _onchange_x_serial_number(self):
        if self.x_serial_number.id != False:
            self.get_contact()
Avatar
Discard
Related Posts Replies Views Activity
4
Dec 23
20438
5
Jul 24
13733
1
Jun 22
25204
9
May 22
50534
0
Jul 20
1880