Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
15784 Vizualizări

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,

Imagine profil
Abandonează

I have the error today!

Cel mai bun răspuns

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)]"/>
Imagine profil
Abandonează

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 Răspunsuri Vizualizări Activitate
1
mai 24
2549
0
nov. 23
1085
2
iun. 23
11630
1
nov. 22
4896
2
iul. 22
3617