Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
15779 Tampilan

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,

Avatar
Buang

I have the error today!

Jawaban Terbai

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)]"/>
Avatar
Buang

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

Post Terkait Replies Tampilan Aktivitas
1
Mei 24
2547
0
Nov 23
1084
2
Jun 23
11629
1
Nov 22
4894
2
Jul 22
3607