← Back to team overview

openerp-community team mailing list archive

Re: Domain filters comparing 2 fields

 

I think, and that is my opinion, there is not such a bug,

Some of the fields your are trying to compare are functional fields,
in order to allow comparing each functional field has to bear a function
search as pointed in class function

https://github.com/odoo/odoo/blob/8.0/openerp/osv/fields.py#L1054

:param fnct_search: the callable that allows searching on the field (if not
provided, search will not return any result)
This is true either to fields.property() which inherits from function,

in this case credit, is searchable
https://github.com/odoo/odoo/blob/8.0/addons/account/partner.py#L287
'credit': fields.function(_credit_debit_get, *fnct_search*=_credit_search,
string='Total Receivable', multi='dc', help="Total amount this customer
owes you."),
As Holger pointed out your chances of getting what you want improves by
defining a functional field of type boolean,
which for instance will bear as a mandatory requirement a fnct_search,
because you want to know when it is true
and when is false, and the field is dynamic as previous fields are always
changing,

Hope this could clarify any doubt about dealing with functional fields.

Just to highlight something that is wierd for me I think that both  credit
& debit functional fields shoud bear type=float,
as of now is lacking that argument.

Once this lack of argument in property fields get some overnight debuggings,

Best Regards.

2014-12-08 15:51 GMT-04:30 Mohamed M. Hagag <mohamedhagag1981@xxxxxxxxx>:

>  Dears,
>
>
>  Anybody tried this ?
>
>
>  is it a bug ? should we report ?
>
>
>
>  Regards,
>
>
>
>  On 12/08/2014 11:47 AM, Mohamed M. Hagag wrote:
>
> Dear,
>
>
>  Thanks for your reply.
>
>
>  But even after adding the fields to tree "res.partner.tree" view and
> doing the filter in search view I still get the 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 tried the same on v.7 and I got the error:
>
>  Uncaught TypeError: Cannot read property 'length' of undefined
>
>
>
>  Regards,
>
>
>  On 12/08/2014 09:47 AM, atchuthantu@xxxxxxxxx wrote:
>
> Hello Mohamed,
>
>     To search for a field credit_limit and credit using *filter*, you
> need these fields defined at TREE view.
>
>         <record model="ir.ui.view" id="base_view_partner_tree_inherit">
>             <field name="name">res.partner.tree.inherit</field>
>             <field name="model">res.partner</field>
>             <field name="inherit_id" ref="base.view_partner_tree" />
>             <field name="arch" type="xml">
>                 <field name="email" position="after">
>                     <field name="credit_limit" invisible="1"/>
>                     <field name="credit" invisible="1"/>
>                 </field>
>             </field>
>         </record>
>
>     Then add the filter condition at *SEARCH* view.
>
> On Monday 08 December 2014 12:35 AM, Mohamed M. Hagag wrote:
>
> Dears,
>
>
>  Again 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,
>
>
>  On 10/26/2014 01:11 PM, Mohamed M. Hagag wrote:
>
> Dears,
>
>
>  How can i add filter that compares 2 fields in the object for ex.
> [('credit_limit','<',credit)] on partners ?
>
>
>  Now I'm making an advanced search and saving it then using the automated
> actions I edit the search.
>
>
>  But if I wrote it like the previous example I always get "credit not
> defined" error.
>
>
>  I always get the second field  not defined error .
>
>
>  Any idea how this should be done in the code?
>
>
>  And why the second field is always not defined, how should i code it ??!
>
>
>  Regards,
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : openerp-community@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>
>
> --Thanks & Regards,
> Atchuthan
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~openerp-community
> Post to     : openerp-community@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openerp-community
> More help   : https://help.launchpad.net/ListHelp
>
>

References