Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
15782 Переглядів

Dears,

Plz let me know how to make this filter work,  adding filter on partners search form:

                    <field name="credit_limit"/>
                    <field name="credit"/>

                   <filter name="credit limit" domain="[('credit','>',credit_limit)]"/>

Applying this filter gives below error:

Uncaught Error: Failed to evaluate search criterions:
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nNameError: name 'credit_limit' is not defined\n\n{\"domains\":[[],\"[('customer','=',1)]\",\"[('credit','=',credit_limit)]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":\"Africa/Cairo\",\"uid\":1,\"search_default_customer\":1}],\"group_by_seq\":[]}"}}

I googled many times to find a solution without finding anyone .

the simple form [('credit_limit','<',credit)] always returns the error "can not convert string to float" where string is credit and float is credit_limit.

is there any way to say [('credit_limit','<',valueof(credit))] or [('field1','=',valueof(field2))] ??

Regards,

Аватар
Відмінити

I have the error today!

Найкраща відповідь

Hi,

simply create a stored  boolean function field, which depends of the 2 fields you want to compare, test the operation you need in function, you can now filter by the boolean value.

using last api

in your python file

from odoo import api, fields, models

class ResPartner(models.Model):
    _inherit = 'res.partner'

    credit = fields.Float(string="Credit")
    credit_limit = fields.Float(string="Credit limit")
    is_credit_limit_exceeded = fields.Boolean(compute='_get_is_credit_limit_exceeded',
string="Credit limit exceeded",
compute_sudo=True, store=True)

   @api.multi
    @api.depends('credit', 'credit_limit')
    def _get_is_credit_limit_exceeded(self):
        self.is_credit_limit_exceeded = self.credit > self.credit_limit

in your xml file, in search view

<filter name="Credit limit" domain="[('is_credit_limit_exceeded', '=', True)]"/>
Аватар
Відмінити

Without forgetting to add the boolean field with invisible="1"

Hi,

this is a stored field function with dependecies, no need to add the field in view.

Bye

Related Posts Відповіді Переглядів Дія
1
трав. 24
2547
0
лист. 23
1085
2
черв. 23
11630
1
лист. 22
4895
2
лип. 22
3617