콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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.



	




아바타
취소
베스트 답변

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.

아바타
취소
작성자

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

관련 게시물 답글 화면 활동
2
6월 23
4645
1
5월 23
3442
2
5월 23
3163
2
2월 18
12181
0
5월 15
6277