Delete one record ,I want to know here the usage of mapped..need a help.. what did this code exactly mainly
mapped
@api.multi
def unlink(self):
resources = self.mapped('resource_id')
super(Employee, self).unlink()
return resources.unlink()
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hello,
'mapped' provided function can be a string to get field values. so here 'mapped' get Value of 'resource_id' and unlink that value.
You can find in Detail from below link.
https://www.odoo.com/documentation/8.0/reference/orm.html
Thank You.
This is what i am looking Tx STCKFLOW-
https://stackoverflow.com/questions/42228900/use-mapped-in-odoo-9
tx...
Basically it is a convenience method to return recordsets (lists of objects or values). Lets say you wanted a list of all partners email addresses matching a specific domain. You could easily accomplish this like so.
domain = [('email','not in',[False,None])]
records = self.env['res.partner'].search(domain)
email_list = records.mapped('email')
print(email_list)
>>> [u'john@gmail.com',u'suzy@gmail.com',u'bob@hotmail.com']
This way you do not need to do this
email_list = []
domain = [('email','not in',[False,None])]
for rec in self.env['res.partner'].search(domain):
if rec.email:
email_list.append(rec.email)
print(email_list)
>>> [u'john@gmail.com',u'suzy@gmail.com',u'bob@hotmail.com']
In the above example odoo would have iterated through all of the records and returned the email from each record in the form of a list.
So rather than looping through all records to obtain the same field from each record you can use mapped.