Odoo Help

0

Whats is this self.mapped('id')?

By
Odoo
on 9/25/17, 3:45 AM 580 views
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()
1
Palkesh Baraiya
On 9/25/17, 3:53 AM

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.


0

Odoo

--Odoo --

1439
| 5 2 5
India
--Odoo --

Working in Odoo TEchnologies

Odoo
On 9/25/17, 5:54 AM

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.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/25/17, 3:45 AM
Seen: 580 times
Last updated: 1/12/18, 10:16 PM