hello there, i want to get the value of the city field of the res.partner table filled up in a field of my custome module,
partner_id = fields.Many2one('res.partner', string='Prestataire')
def _get_default_city(self): return self.env['res.partner'].search([('name', '=', 'city')], limit=1).id ville = fields.Many2one('res.partner', string='Ville', default=_get_default_city, domain=[('name', '=', 'city')]) @api.onchange('partner_id') def onchange_partner_id(self): self.ville = self.partner_id.city
but i keep receiving this error
res = self._obj.execute(query, params) psycopg2.DataError: invalid input syntax for integer: "Fremont" LINE 1: ...sg" FROM "res_partner" WHERE "res_partner".id IN ('Fremont') ^
yes i am trying to once i choose the partner_id name, the 'ville' filed to be filled in by the value of the city filed, i use often just the onchange function, i had used this code and it works just fine
employee_id = fields.Many2one('hr.employee', string="employé", required=True)
poste = fields.Many2one('hr.job', string='poste')
@api.onchange('employee_id')
def onchange_employee_id(self):
self.poste = self.employee_id.job_id
but i don't know why the same principe not working in this case
partner_id = fields.Many2one('res.partner', string="employé", required=True)
ville = fields.Many2one('res.partner', string='ville')
@api.onchange('partner_id')
def onchange_partner_id(self):
self.ville = self.partner_id.city
by the way i tried your code but i still got the same error
self.ville is many2one; self.partner_id.city is char. It is not possible to apply char for many2one. You can't store string in database cell which requires integer.
self.poste is many2one; self.employee_id.job_id is also many2one. Both relate to the same object. Both relate assume integer value.
Although I didn't check my code running, the same error is hardly possible. Most probably, you haven't updated the module to change the field type.
yes exactly, i had to change the type of the ville field to char, thank any way sir