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[0].full_address )
This will print out all names and the first full address of each.
Party Relations (a seperate module):
p.relations
Would give you output similar to this (if there are relations - in my case 2):
[proteus.Model.get('party.relation.all')(2),
proteus.Model.get('party.relation.all')(4)]
Interesting fields there (for me):
p.relations[0].type.name # returns the name of the relation as entered
p.relations[0].reverse # reverse relation as entered
# the next 2 are self explainatory anyway just note the '_' with from
p.relations[0].to
p.relations[0].from_
Now to add a new one:
np = Party()
np.name='Test Customer from Proteus'
np.save()
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 id
(np.id
) is -1. By default it also comes with one (empty address).
Here's how to edit/add:
np.addresses[0].zip='1234'
np.addresses.new(zip='2345')
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:
np.reload()
d
Share on Twitter Share on Facebook
Comments
There are currently no comments
New Comment