Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2678 Widoki

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 

Awatar
Odrzuć
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>

Najlepsza odpowiedź

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.

Awatar
Odrzuć

<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

Powiązane posty Odpowiedzi Widoki Czynność
2
mar 19
12772
1
wrz 24
1694
1
sie 24
1036
0
sie 24
1208
1
cze 24
1343