Reputation: 179
I would like to define my name depends on my asset tags plus my asset brand but my asset tag and asset brand fields is Many2one and it doesn't give me an error but the output is wrong. It gives me a number, integer instead of a string(which is the tag name plus the brand name). My expected result is for example my asset tag is Computer, then my asset brand is Asus then my expected result in name would be Computer-Asus. Please help. Many thanks.
This is what i do.
@api.model
def create(self,vals):
if vals['asset_tag']:
asset_tag = vals['asset_tag']
else:
asset_tag = ''
if vals['asset_brands_id']:
brand_id = vals['asset_brands_id']
else:
brand_id = ''
name = "{}-{}".format(asset_tag, brand_id)
vals['name'] = name
return super(ModifiedAssetAsset, self).create(vals)
then the output is this
It gives me 2-4 on my asset name but my expecting result is Vehicle-Toyota
Upvotes: 1
Views: 547
Reputation: 718
@api.model
def create(self,vals):
if vals['asset_tag']:
asset_tag = vals['asset_tag']
else:
asset_tag = ''
if vals['asset_brands_id']:
brand_id=self.env['asset.brand.model.name'].search([('id','=',vals
['asset_brands_id'])],limit=1).name
else:
brand_id = ''
name = "{}-{}".format(asset_tag, brand_id)
vals['name'] = name
return super(ModifiedAssetAsset, self).create(vals)@api.model
Upvotes: 1