This question has been flagged

Odoo v8

I have wizard with two fields:

class Roll_wizard(models.TransientModel):

_name = 'roll.wizard'

calc_model = fields.Many2one("techdoc", "Car Model")

calc_year = fields.Many2one("techdoc.year", "Car Year")

I need to display in field calc_model a model of the car, instead of field name, so i decided to override name_get()

The model "techdoc" has fields: 

class Car(models.Model):

_name = 'techdoc'

name = fields.Char(string="Brand", size=30, required=True)

car_model = fields.Char(string="Model", size=30, required=True)

car_year = fields.Integer(string="Year", size=30, required=True)

car_engine = fields.Float(string="Engine size", digits=(3, 1), required=True)

car_transmission = fields.Char(string="Transmission type", size=30, required=True)

car_modify = fields.Char(string="Model Modification", size=30)

def name_get(self,cr,uid,ids,context=None):

model = []

result = self.browse(cr,uid,ids,context=context)

for record in result:

tup=(record.car_model, record.car_model.title())

model.append(tup)

model = list(set(model))

return sorted(model)

But after this in field calc_year i need to display car manufactures years.

I've created a new model, inherit "techdoc" model and overrides name_get() agan to display years

class Car_year(models.Model):

_name = 'techdoc.year'

_inherit= 'techdoc'


def name_get(self,cr,uid,ids,context=None):

model = []

result = self.env['techdoc'].browse(cr,uid,ids,context=context)

for record in result:

tup=(record.car_year, record.car_year)

model.append(tup)

model = list(set(model))

return sorted(model)

And I have an error:

AttributeError: 'techdoc.year' object has no attribute 'env'

I want to use instances from "techdoc" model. 

Avatar
Discard
Best Answer

instr,

Your way of your defining a class is as per Odoo 8(new) api:

class Car_year(models.Model):

but the way you are defining the functions inside it are according to odoo7(old) api:   

def name_get(self,cr,uid,ids,context=None):
so here to get a pool and browse on any object you have to use:

 result = self.pool.get('techdoc').browse(cr,uid,ids,context=context)
in place of:
 result = self.env['techdoc'].browse(cr,uid,ids,context=context)

where as if you want to stick to new api only, then you must define your function also according to it only, as:

 def name_get(self ,context=None):
and then you can browse as per new api :
 result = self.env['techdoc'].browse(cr,uid,ids,context=context
for further reference visit this link:

https://www.odoo.com/documentation/8.0/reference/orm.html

Hope it Helps!!

Avatar
Discard