Call a Functional Field from another module

26 views
Skip to first unread message

Josias Pérez

unread,
Feb 15, 2018, 4:55:07 PM2/15/18
to tryton-dev
Hi,

I would appreciate if could tell how I can call a functional field from another module, in this case, I need to call the payable function field from account module.

The code is the follow:

currency_digits = fields.Function(fields.Integer('Currency Digits'),
'get_currency_digits')

receivable = fields.Function(
fields.Numeric('Por cobrar',
digits=(16, Eval('currency_digits', 2)),
depends=['currency_digits']),
'get_receivable_payable')

@classmethod
def get_currency_digits(cls, parties, name):
pool = Pool()
Company = pool.get('company.company')
company_id = Transaction().context.get('company')
if company_id:
company = Company(company_id)
digits = company.currency.digits
else:
digits = 2
return {p.id: digits for p in parties}

@classmethod
def get_receivable_payable(cls, subscriptions, names):
for subscription in subscriptions:
if subscription.party:
amount = subscription.party.receivable
return amount
else:
return 0

I'm trying to get the value of the payable field of account module. [1]

Thanks in advance!

[1] https://github.com/tryton/account/blob/develop/party.py#L75

Josias Pérez

unread,
Feb 15, 2018, 5:35:08 PM2/15/18
to tryton-dev
With the code describe above I receive the follow error message:
Traceback (most recent call last):
File "/opt/cr/local/lib/python2.7/site-packages/trytond/protocols/dispatcher.py", line 165, in _dispatch
result = rpc.result(meth(*c_args, **c_kwargs))
File "/opt/cr/local/lib/python2.7/site-packages/trytond/model/modelsql.py", line 780, in read
getter_result = getter_results[fname]
TypeError: 'Decimal' object has no attribute '__getitem__'

Cédric Krier

unread,
Feb 16, 2018, 4:05:07 AM2/16/18
to tryton-dev
You should not try to call getter of Function field directly indeed you
should use the ORM and just access the corresponding field.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
Reply all
Reply to author
Forward
0 new messages