Hello Mohammed,
There is NO disadvantage here. Look at the example code i sent in my
previous mail. I will rewrite the 1.8 example the way you are trying to do
here:
#! /usr/bin/env python
from trytond.config import CONFIG
from trytond.modules import register_classes
from trytond.pool import Pool
from trytond.backend import Database
from trytond.model import Cache
from trytond.transaction import Transaction
# Load the configuration file
CONFIG.configfile = '/etc/trytond.conf' # Replace with your path
CONFIG.load()
# Register classes populates the pool of models:
register_classes()
# dbname contains the db you want to use
DBNAME = 'test'
# Instantiate the database and the pool
DB = Database(DBNAME).connect()
POOL = Pool(DBNAME)
POOL.init()
# Clean the global cache for multi-instance
Cache.clean(DBNAME)
# User 0 is root user. We use it to get the admin id:
Transaction().start(DBNAME, 0, None):
user_obj = POOL.get('res.user')
user = user_obj.search([('login', '=', 'admin')], limit=1)[0]
Transaction.stop()
Transaction().start(DBNAME, user, None):
# No password is needed, because we are working directly with the
# API, bypassing any networking stuff.
party_obj = POOL.get('party.party')
new_party_id = party_obj.create({'name': 'New party'})
Transaction.stop()
print new_party_id
# Reset the global cache for multi-instance
Cache.resets(DBNAME)
Remember to manage the cursor yourself.
On Wed, Dec 1, 2010 at 2:21 PM, Mohammad <[email protected]> wrote:
> Hi,
>
> i haven't disappointed with the concept behind the Transaction, But i
> lost the opportunity to call methods one by one.
> I used the below patterns few min ago. Of course it works fine.
> But from the beginning part of this transaction to the end part i
> could not see any result.
> Maybe the method of development in my pc is different from others.
> I take advantages of interactive python to call functions quickly then
> i decide what to do in the real module.
> But here i have to put everything (For example 7 lines of code within
> the Transaction and then if i typed a mistake in the last one, I only
> get an error message.
> Previously it was faster.
> Anyway i checked your links , the new change is very nice in my point.
> But i always remember this rule in the world of IT that any advantage
> WILL have disadvantage.(this rule is true so far for me without
> exception)
>
> Regards,
>
> On Dec 1, 4:33 pm, Sharoon Thomas <[email protected]> wrote:
> > Hi,
> >
> > On Wed, Dec 1, 2010 at 1:40 PM, Mohammad <[email protected]>
> wrote:
> > > Hi,
> > > I saw the document and now it works fine with CRUD functionality.
> > > But i disappointed to use it in my PyCrust Python IDE.
> > > Earlier i used to connect to db to call my customized functions
> > > quickly.
> > > But here we always have to call any Function within the Transaction
> > > method.
> > > But it worths according to the advantages of using Transaction method
> > > probably.
> > > Maybe it is time for me to migrate to this Poteus , A client library
> > > to work with ORM.
> > > Thanks Cedric,
> >
> > I dont know why you are "disappointed" with the transaction change and
> with
> > statement.
> >
> > The syntax for with statement is here:
> http://docs.python.org/reference/compound_stmts.html#the-with-statement
> > The transaction implementation is here:
> http://hg.tryton.org/1.8/trytond/file/08867d5bf793/trytond/transactio...
> >
> > You can replace the following with usage with:
> >
> > '''
> > with Transaction().start(DBNAME, 0, None):
> > # Do something
> > '''
> >
> > """
> > Transaction().start(DBNAME, 0, None)
> > # Do Something
> > Transaction().stop()
> > """
> >
> > which is exactly what the Transaction manager does
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > On Dec 1, 3:28 pm, Cédric Krier <[email protected]> wrote:
> > > > On 30/11/10 23:10 -0800, Mohammad wrote:
> >
> > > > > But When i used the simple method like below one the error message
> > > > > apprears and i think it is related to Cache :(
> > > > > ===========================================================
> > > > > >>party_obj = POOL.get('party.party')
> > > > > >>party_obj.browse([1])
> > > > > Traceback (most recent call last):
> > > > > File "<input>", line 1, in <module>
> > > > > File "/home/mohammad/workspace/tryton-dist/trytond1.8/trytond/
> > > > > trytond/model/modelstorage.py", line 507, in browse
> > > > > for x in ids))
> > > > > File "/home/mohammad/workspace/tryton-dist/trytond1.8/trytond/
> > > > > trytond/model/browse.py", line 15, in __init__
> > > > > super(BrowseRecordList, self).__init__(lst)
> > > > > File "/home/mohammad/workspace/tryton-dist/trytond1.8/trytond/
> > > > > trytond/model/modelstorage.py", line 507, in <genexpr>
> > > > > for x in ids))
> > > > > File "/home/mohammad/workspace/tryton-dist/trytond1.8/trytond/
> > > > > trytond/model/browse.py", line 55, in __init__
> > > > > cache = self._cursor.get_cache(self._context)
> > > > > AttributeError: 'NoneType' object has no attribute 'get_cache'
> >
> > > > >
> =======================================================================
> >
> > > > You should take a look athttp://
> > > code.google.com/p/tryton/wiki/HowToUseTrytondAsAModule#Version...
> >
> > > > You must use now Transaction manager.
> >
> > > > --
> > > > Cédric Krier
> >
> > > > B2CK SPRL
> > > > Rue de Rotterdam, 4
> > > > 4000 Liège
> > > > Belgium
> > > > Tel: +32 472 54 46 59
> > > > Email/Jabber: [email protected]
> > > > Website:http://www.b2ck.com/
> >
> > > > application_pgp-signature_part
> > > > < 1KViewDownload
> >
> > > --
> > > [email protected] mailing list
> >
> > --
> > Sharoon Thomas
> > Business Analyst & Open Source ERP Consultant
> > CEO @http://openlabs.co.in
>
> --
> [email protected] mailing list
>
--
Sharoon Thomas
Business Analyst & Open Source ERP Consultant
CEO @ http://openlabs.co.in
--
[email protected] mailing list