Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2653 Zobrazení

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
Zrušit
Autor

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>

Nejlepší odpověď

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
Zrušit

<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>

Autor

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 Odpovědi Zobrazení Aktivita
2
bře 19
12769
1
zář 24
1679
1
srp 24
1029
0
srp 24
1198
1
čvn 24
1337