Skip to Content
Menu
This question has been flagged
2 Replies
609 Views

Hi, 
i want to fetch my table account.move.line depending on the value provided from the form.

so normally I have to do this:

"

domains = [(' partner_id ', '=', 'self.partener_id.id'), (' account_id ', '=', 'self.account_id.id'),]

 moves = self.env['account.move.line'].search(domains)

"

But now, having two (02) parameter in domain is not required, so i can have 0, or 1, 0r 2 parameter depending if i filled the imput form   partener_id and  account_id 


so this is what i tried:

"

 if rec. partner_id  .id != False:                

    domains += "('partner_id', '=', '" + str(rec. partner_id  .id) + "'),"           

 if rec. account_id .id != False:                

     domains   += "('account_id', '=', '" + str(rec. account_id .id) + "'),"                                         


moves = self.env['account.move.line'].search([domains])

"

but this return the following error: 

ValueError: Invalid leaf ('partner_id', '=', '8'),('account_id', '=', '2'),


How can i fix it?

 

Avatar
Discard

make sure that the fields are in the corresponding models.
also you can refer this: https://www.youtube.com/watch?v=dq5Vtj_pwuI

Author
hi, my post displays: 

500: Internal Server Error

can you see what happened?

Le jeu. 30 déc. 2021 à 15:17, Léo Auvray <lau@2crsi.com> a écrit :

Une nouvelle question Create python filter domain dinamically odoo14 le Aide a été publiée. Cliquez ici pour accéder à la question :

Voir la question

Envoyé par Odoo S.A. utilisant Odoo.

Best Answer

This error is because you are concating the string and use it as domain,
As domains are must be a list of tuples or list of list

So you can make your domain like this.

domains = []

if rec.partner_id.id != False:
domains += [('partner_id', '=', rec.partner_id.id)]

if rec.account_id.id != False:
domains += [('account_id', '=', rec.account_id.id)]


Create python filter domain dinamically odoo14
https://www.odoo.com

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard
Author Best Answer

thanks but this not answer to my question.

the user have 2 field to filled: parameter_id and account_id.
if he field none of the 2 fields, my script 'ld look like :   moves = self.env['account.move.line'].search([])

if he field  parameter_id  only ->  moves = self.env['account.move.line'].search([ (' partner_id ', '=', 'self.partener_id.id') ])

if he field   account_id only ->  moves = self.env['account.move.line'].search([(' account_id ', '=', 'self.account_id.id')]) 

if he field  parameter_id and  account_id  ->  moves = self.env['account.move.line'].search([ (' account_id ', '=', 'self.account_id.id') ,(' account_id ', '=', 'self.account_id.id') ])


and then i use   'moves' for others treatements   

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
1482
1
Nov 24
1187
2
Sep 24
1046
1
Aug 24
2450
3
Aug 24
2682