Skip to Content
Menu
This question has been flagged

Hi friends,

Here is my problem/scenario:

I've added a new field named spot_id to 'account.payment' model:


spot_id=fields.Many2one(
​​comodel_name='exchange.spot',
​string='Spot',
​readonly=True

​)

Each spot has two following fields:


out_currency_id=fields.Many2one(
​​comodel_name="res.currency",
​string="Outgoing Currency"
​)

company_currency_id=fields.Many2one(
​related="company_id.currency_id"
​)

Suppose that for example, both two fields have a value of 25,
Now, I want to show just payments that have the following condition:

​(​'spot_id.out_currency_id', '=', 'spot_id.company_currency_id')

To do that, I'm trying to get payments with the following domain on account.paymeny model at XML:[Say: first domain]: 

[('spot_id.out_currency_id', '=', 'spot_id.company_currency_id')]


But it doesn't work!!!


I've tried the following domains separately and each one is working well:

[('spot_id.out_currency_id', '=', 25)] ​​

[('spot_id.company_currency_id', '=', 25)]

But the domain [first domain] doesn't work!!

Can anyone say what is the issue? and what is the solution?
I don't want to solve it with hard-coded using of 25.



	




Avatar
Discard
Best Answer

Hello Masood,

i hope this will help to you

The issue you're facing with the domain [('spot_id.out_currency_id', '=', 'spot_id.company_currency_id')] not working is because you're trying to directly compare two fields within the domain, and this is not supported in Odoo's domain filtering.


In Odoo's domain filters, you can't compare two fields directly like that. However, you can achieve your goal using a technique called "inverse relationship" or "related field" along with a search() function.


Here's how you can modify your search domain to achieve the desired result:


# Use a related field to retrieve the company's currency for each payment

spot_company_currency = fields.Many2one(

related='spot_id.company_currency_id',

string='Spot Company Currency',

readonly=True,

)


# In your XML, use the domain as follows:

[('spot_id.out_currency_id', '=', spot_company_currency)]



In this approach, you're creating a related field spot_company_currency which retrieves the currency of the company associated with the spot. Then, in your XML domain, you're comparing the out_currency_id of the spot with the spot_company_currency of the payment, which is the equivalent of comparing these two fields.


This should allow you to filter the payments as you intended.

Avatar
Discard
Author

Thank u very much because of your detailed answer. I do that but still the problem is remained as before.

Related Posts Replies Views Activity
2
Jun 23
4273
1
May 23
3235
2
May 23
2943
2
Feb 18
11990
0
May 15
6101