Python import problem

58 views
Skip to first unread message

Felipe Alvarez Harnecker

unread,
Feb 3, 2012, 7:18:07 AM2/3/12
to tryto...@googlegroups.com, try...@googlegroups.com
Hi,

can someone explain me why this works


Python 2.7.2+ (default, Dec 1 2011, 01:55:02)
[GCC 4.6.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import trytond.modules.account_invoice.invoice

/usr/lib/python2.7/dist-packages/trytond/modules/__init__.py:28: UserWarning:
Module trytond was already imported from /usr/lib/python2.7/dist-
packages/trytond/__init__.pyc, but /usr/lib/pymodules/python2.7 is being added
to sys.path
import pkg_resources

>>> trytond.modules.account_invoice.invoice

<module 'trytond.modules.account_invoice.invoice' from
'/usr/lib/python2.7/dist-
packages/trytond/modules/account_invoice/invoice.pyc'>

>>> trytond.modules.account_invoice.invoice.__dict__.keys()

['PrintInvoiceReportWarning', 'PayInvoice', '_ZERO', 'Wizard', 'Bool',
'_TYPE2JOURNAL', 'CreditInvoiceInit', 'operator', 'InvoiceLineTax',
'_DEPENDS', 'FIELDS', 'base64', 'InvoiceTax', '__package__', 'Eval', 'Report',
'ModelWorkflow', 'Pool', 'PayInvoiceInit', '_TYPE', 'Transaction',
'__builtins__', 'ModelView', '__file__', 'InvoiceLine', '__name__',
'CreditInvoice', 'PrintInvoiceReport', 'InvoiceReport', 'TableHandler',
'InvoicePaymentLine', 'fields', '_STATES', 'Decimal', '__doc__', 'ModelSQL',
'Invoice', 'reduce_ids', 'PayInvoiceAsk', 'If']
>>>


and if define a tryton module with a single file with

import trytond.modules.account_invoice.invoice

trytond.modules.account_invoice.invoice


fails loading with:

File "/usr/lib/python2.7/dist-
packages/trytond/modules/ql_account_invoice/invoice.py", line 31, in <module>
trytond.modules.account_invoice.invoice
AttributeError: 'module' object has no attribute 'account_invoice'


thank you very much.

--
Felipe Alvarez Harnecker
fel...@ql.cl - 9.874.60.17

Sharoon Thomas

unread,
Feb 3, 2012, 7:28:59 AM2/3/12
to tryto...@googlegroups.com, try...@googlegroups.com

On Feb 3, 2012, at 7:18 AM, Felipe Alvarez Harnecker wrote:

> and if define a tryton module with a single file with
>
> import trytond.modules.account_invoice.invoice
>
> trytond.modules.account_invoice.invoice
>
>
> fails loading with:
>
> File "/usr/lib/python2.7/dist-
> packages/trytond/modules/ql_account_invoice/invoice.py", line 31, in <module>
> trytond.modules.account_invoice.invoice
> AttributeError: 'module' object has no attribute 'account_invoice'
>

This is because the modules and classes are not registered. See the example of how to use
tryton as a module here:

http://code.google.com/p/tryton/wiki/HowToUseTrytondAsAModule

However, this direct import is NOT the preferred way to use Tryton as a module. This will only
serve the purpose when you want to import some other python object (Not one of the Model
instances of triton) to reuse them elsewhere in your code.

The final state of a Tryton model (its attributes, method etc) depends on the modules installed
in a specific database. So fetching from the pool is the "best way" if you want to access trytond
model objects in your script or from the command line.

Thanks,


Sharoon Thomas
http://openlabs.co.in

signature.asc

Cédric Krier

unread,
Feb 3, 2012, 7:33:11 AM2/3/12
to try...@googlegroups.com

Please don't cross-post!

See https://groups.google.com/d/topic/tryton/-IA9TLq5qag/discussion

--
Cédric Krier

B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: cedric...@b2ck.com
Website: http://www.b2ck.com/

Felipe Alvarez Harnecker

unread,
Feb 3, 2012, 7:41:04 AM2/3/12
to tryto...@googlegroups.com, Sharoon Thomas, try...@googlegroups.com


Thanks for yor reply.


my intention is to extend account_invoice, as first step i need to add a new
state 'nula' to invoices, so my idea is to read from account_invoice.invoice
to obtain states values, say STATES, and redefine column state = STATES +
['nula'] , bla


which is the tryton way todo this ?


thanks.

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages