Going to be using this blog post to add bits and pieces of how to use proteus to handle data in tryton.
Just noticed the proteus readme is quite good: here's a link to the proteus github
IMPORTANT: One thing I noticed (the hard way) is that if you are connected with a proteus session and you add&activate a module (at least when it is not done using proteus) you need to re-connect as it does not seem to add things like extra fields added to models otherwise.
First thing: connect:
from proteus import config, Model, Wizard, Report
pcfg = config.set_trytond(database='trytond', config_file='/etc/tryton/trytond.conf')
Then we just get ourselved our parties:
Party = Model.get('party.party') all_parties=Party.find() for p in all_parties: print(p.name) print(p.addresses.full_address )
This will print out all names and the first full address of each.
Party Relations (a seperate module):
Would give you output similar to this (if there are relations - in my case 2):
Interesting fields there (for me):
p.relations.type.name # returns the name of the relation as entered
p.relations.reverse # reverse relation as entered
# the next 2 are self explainatory anyway just note the '_' with from
Now to add a new one:
np = Party()
np.name='Test Customer from Proteus'
This just creates a new party with just a name. default values that are set up (like default language) are set. Until it is saved the
np.id) is -1. By default it also comes with one (empty address).
Here's how to edit/add:
np.save() # don't forget this
Extra fields from other (possibly own) can be accessed exactly the same way as the normal ones (just don't forget to reconnect - like i did ;) )
Here's how you refresh the data:
dShare on Twitter Share on Facebook