How Greater statement of Pyson works with a functional numeric field?

62 views
Skip to first unread message

Jesús Martín Jiménez

unread,
Mar 30, 2016, 7:05:30 AM3/30/16
to tryton
Hi,

I'm trying to set a domain in a M2O field depending on the value of a functional field that is a numeric field this way [1]. But, depending how I define the ZERO constant, I get different tracebacks [2] and [3]. Could somebody tell me what I'm doing wrong?

Thanks,

[1]
        domain=[
            If(
                Or(
                    And(
                        Eval('type') == 'out',
                        Greater(Eval('total_amount', ZERO), ZERO)),
                    And(
                        Eval('type') == 'in',
                        Less(Eval('total_amount', ZERO), ZERO))),
            ('kind', '=', 'receivable'),
            ('kind', '=', 'payable')),
            ],

[2]

for ZERO = '0.0' or ZERO = Decimal('0.0')

  File "/home/aneolf/workspace/trytond_default/trytond/trytond/modules/account_payment_type/invoice.py", line 22, in Invoice
    Greater(Eval('total_amount', ZERO), ZERO)),
  File "/home/aneolf/workspace/trytond_default/trytond/trytond/pyson.py", line 317, in __init__
    'statement must be an integer or a float'
AssertionError: statement must be an integer or a float


[3]

for ZERO = 0.0

Traceback (most recent call last):
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/form.py", line 370, in sig_new
    self.screen.new()
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/screen/screen.py", line 517, in new
    record = group.new(default)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/group.py", line 317, in new
    record.default_get()
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/record.py", line 369, in default_get
    self.set_default(vals)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/record.py", line 433, in set_default
    self.validate(softvalidation=True)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/record.py", line 396, in validate
    if not field.validate(self, softvalidation, pre_validate):
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/field.py", line 86, in validate
    domain = simplify(self.validation_domains(record, pre_validate))
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/field.py", line 440, in validation_domains
    screen_domain, attr_domain = self.domains_get(record, pre_validate)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/field.py", line 53, in domains_get
    attr_domain = record.expr_eval(self.attrs.get('domain', []))
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/gui/window/view_form/model/record.py", line 503, in expr_eval
    val = PYSONDecoder(ctx).decode(expr)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/pyson.py", line 138, in _object_hook
    return klass.eval(dct, self.__context)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/pyson.py", line 354, in eval
    dct = Greater._convert(dct)
  File "/home/aneolf/workspace/trytond_default/tryton/tryton/pyson.py", line 349, in _convert
    dct[i] = float(dct[i])
TypeError: float() argument must be a string or a number

Sergi Almacellas Abellana

unread,
Mar 30, 2016, 7:17:18 AM3/30/16
to try...@googlegroups.com
El 30/03/16 a les 13:05, Jesús Martín Jiménez ha escrit:
> Hi,
>
> I'm trying to set a domain in a M2O field depending on the value of a
> functional field that is a numeric field this way [1]. But, depending
> how I define the ZERO constant, I get different tracebacks [2] and [3].
> Could somebody tell me what I'm doing wrong?

Using 0.0 or 0 works for me.


--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Cédric Krier

unread,
Mar 30, 2016, 7:20:03 AM3/30/16
to tryton
On 2016-03-30 04:05, Jesús Martín Jiménez wrote:
> Hi,
>
> I'm trying to set a domain in a M2O field depending on the value of a
> functional field that is a numeric field this way [1]. But, depending how I
> define the ZERO constant, I get different tracebacks [2] and [3]. Could
> somebody tell me what I'm doing wrong?

PYSON doesn't support Decimal.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Jesús Martín Jiménez

unread,
Mar 30, 2016, 7:21:42 AM3/30/16
to try...@googlegroups.com
2016-03-30 13:19 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
On 2016-03-30 04:05, Jesús Martín Jiménez wrote:
> Hi,
>
> I'm trying to set a domain in a M2O field depending on the value of a
> functional field that is a numeric field this way [1]. But, depending how I
> define the ZERO constant, I get different tracebacks [2] and [3]. Could
> somebody tell me what I'm doing wrong?

PYSON doesn't support Decimal.

Do you mean I cannot compare a Numeric field with Pyson statements?
 

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

--
You received this message because you are subscribed to the Google Groups "tryton" group.
To view this discussion on the web visit https://groups.google.com/d/msgid/tryton/20160330111946.GE7578%40tetsuo.



--

Jesús Martín

Zikzakmedia SL
C/ de Sant Jaume, 9, baixos, 2ª
08720 Vilafranca del Penedès
☏ 93 890 21 08

Cédric Krier

unread,
Mar 30, 2016, 7:35:03 AM3/30/16
to try...@googlegroups.com
On 2016-03-30 13:21, Jesús Martín Jiménez wrote:
> 2016-03-30 13:19 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
>
> > PYSON doesn't support Decimal.
> >
>
> Do you mean I cannot compare a Numeric field with Pyson statements?

https://bugs.tryton.org/issue4879

Jesús Martín Jiménez

unread,
Mar 30, 2016, 7:46:08 AM3/30/16
to try...@googlegroups.com
2016-03-30 13:33 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
On 2016-03-30 13:21, Jesús Martín Jiménez wrote:
> 2016-03-30 13:19 GMT+02:00 Cédric Krier <cedric...@b2ck.com>:
>
> > PYSON doesn't support Decimal.
> >
>
> Do you mean I cannot compare a Numeric field with Pyson statements?

https://bugs.tryton.org/issue4879

Thank you very much for your kind response.

 

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

--
You received this message because you are subscribed to the Google Groups "tryton" group.
Reply all
Reply to author
Forward
0 new messages