简体   繁体   中英

What is the relationship between res.partner and res.user in odoo13?

I was working in odoo12 and whenever I want to differentiate between partner and user I use following code

is_customer = False/True    
self.env['res.partner'].search([('customer', '=', is_customer)])

But now in odoo13 they removed customer field. I want suggestion how to differentiate between them like above? There is a field employee that is not working for me.

The comparison or using customer field working for you is more of a coincidence, because you never had partners in your Odoo without customer or supplier not being users.

But you should really use user_ids instead, for every version down to like Odoo 8. Because that is the one2many field using res.users partner_id field as relation which should always work.

res.user have many2one field to res.partner called partner_id , You can extract all partners that are users like this:

   # this will extract every partner that is related to user
   partner_users = self.env['res.users'].search([]).mapped('partner_id')  

If you want to filter partner with other field like name :

 # first extract all ids to use them in the domain
 partner_users_ids = self.env['res.users'].search([('partner_id.name', 'ilike', some_value)]).mapped('partner_id').ids     

You can find a detailed explanation and examples in the base: Remove customer/supplier fields on res.partner commit message.

excerpt

This commit allows to call name_search with context key res_partner_search_mode that can take currently two values: "customer" or "supplier".

When ordering search results, order partners by the number of SO they have when the value is "customer" and by the number of PO if the value is "supplier".

Top suppliers/customers are displayed above in a PO/SO partner dropdown.

We have thought about different implementations before selecting this one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM