I have this method, which should create a new stock.location
every time a new car model is added to fleet.vehicle
class in Odoo v9 community.
class fleet_vehicle(models.Model):
_inherit = 'fleet.vehicle'
@api.onchange('model_id')
def crear_location(self):
self.env['stock.location'].search([('name', '=', self.model_id)])
self.env['stock.location'].create({'name': self.model_id})
return crear_location
location_id = fields.Many2one("stock.location", string="Almacén Origen", store=True, compute=crear_location)
But, the field on fleet.vehicle
form is readonly, for some reason, I mean, I can't select, nor create anything, it's just there.
What am I missing here?
EDIT
I partially solved the issue by putting the attribute readonly=False
on the location_id
field, ut still, the stock.location
isn't created whatsoever.