Skip to Content
Menu
This question has been flagged
1 Reply
2431 Views

I create a methode in claim model that return the current user 
@api.model def get_current_user_parent_partner_id(self): 

​current_user = self.env.user

​parent_partner_id = current_user.partner_id.parent_id.id  

​return parent_partner_id


and this the XMl code that I Write it 

 
  

I List Of Claims 

claim 

[('create_uid.partner_id.parent_id.id', '=', context.get('parent_partner_id'))]

I had Errors when I call the method 
how can I well call this method


I use odoo 17 

Avatar
Discard
Author

This is the Full code

@api.model
def get_current_user_parent_partner_id(self): 

​current_user = self.env.user

​parent_partner_id = current_user.partner_id.parent_id.id  

​return parent_partner_id

- XMl code that I Write it 

<record id="ca_claim_action" model="ir.actions.act_window"> 

<field name= "name">I List Of Claims</field> 

<field name= "res_model">claim</field> 

<{"parent_partner_id": get_current_user_parent_partner_id()}</field>

<field name="domain">[('create_uid.partner_id.parent_id.id', '=', context.get('parent_partner_id'))]</field> </record>

Best Answer

It seems like you're trying to pass the result of the get_current_user_parent_partner_id method as a value for the context variable in your XML code. However, the way you're trying to do it is not correct. Here's the corrected version:

    List Of Claims

    claim

    {

        'default_parent_partner_id': get_current_user_parent_partner_id()

    }

    [('create_uid.partner_id.parent_id.id', '=', default_parent_partner_id)]





   
 




In the above XML code:
  • We're using the context field to pass values to the context dictionary.
  • We're setting the key 'default_parent_partner_id' in the context dictionary to the result of the get_current_user_parent_partner_id method.
  • In the domain field, we're using default_parent_partner_id to filter claims based on the current user's parent partner ID.

Make sure your get_current_user_parent_partner_id method is properly defined in your Python code, and the method should be accessible from the XML context. With this setup, when you open the list of claims, it will filter the claims based on the parent partner ID of the current user.

Avatar
Discard

<record id="ca_claim_action" model="ir.actions.act_window">
<field name="name">List Of Claims</field>
<field name="res_model">claim</field>
<field name="context">{
'default_parent_partner_id': get_current_user_parent_partner_id()
}</field>
<field name="domain">[('create_uid.partner_id.parent_id.id', '=', default_parent_partner_id)]</field>
</record>

Author

I use your code logic
and I also well define the function but it show me that error
EvalError: Can not evaluate python expression: ({
'default_parent_partner_id': get_current_user_parent_partner_id()
})
Error: Name 'get_current_user_parent_partner_id' is not defined

Related Posts Replies Views Activity
2
Mar 19
12608
1
Sep 24
1310
1
Aug 24
806
0
Aug 24
948
1
Jun 24
1234