Community mailing list archives

community@mail.odoo.com

Re: Create XML-record from an object

by
Anders Wallenquist
- 04/22/2015 02:53:34
I have done some methods that might work, I am however interested in 
feedback:

from lxml import etree

def export_xml(lines):
     document = etree.Element('openerp')
     data = etree.SubElement(document,'data')
     for line in lines:
         if line.id:
             k,id = line.get_external_id().items()[0] if 
line.get_external_id() else 0,"%s-%s" % (line._name,line.id)
             _logger.info("Reporting Block id = %s" % id)
             record = etree.SubElement(data,'record',id=id,model=line._name)
             names = [name for name in line.fields_get().keys() if 
fnmatch(name,'in_group*')] + [name for name in line.fields_get().keys() 
if fnmatch(name,'sel_groups*')]
             for field,values in line.fields_get().items():
                 if not field in 
['create_date','nessage_ids','id','write_date','create_uid','__last_update','write_uid',] 
+ names:
                     if values.get('type') in 
['boolean','char','text','float','integer','selection','date','datetime']:
                         if eval('line.%s' % field):
                             etree.SubElement(record,'field',name = 
field).text = "%s" % eval('line.%s' % field)
                     elif values.get('type') in ['many2one']:
                         if eval('line.%s' % field):
                             k,id = 
eval('line.%s.get_external_id().items()[0]' % field) if 
eval('line.%s.get_external_id()' % field) else (0,"%s-%s" % 
(eval('line.%s._name' % field),eval('line.%s.id' % field)))
                             if id == "":
                                 id = "%s-%s" % (eval('line.%s._name' % 
field),eval('line.%s.id' % field))
etree.SubElement(record,'field',name=field,ref="%s" % id)
                     elif values.get('type') in ['one2many']:  # Update 
from the other end
                         pass
                     elif values.get('type') in ['many2many']: # TODO
etree.SubElement(record,'field',name=field,ref="%s %s" % 
(values.get('type'),eval('line.%s' % field)))

     return document

def get_related(models,depth):
     objects = set()
     if depth //xml eg /web/export/178/1/xml
You can find the code at controllers.py line 110


Regards,

Anders Wallenquist
Vertel AB

Den 2015-04-18 14:42, Markus Schneider skrev:
> We start wor



> I came out, that it is not easy. As you need to interpret the data as
> one graph and analyses the relation. Then you need to remove all cycles
> in a way that you can not remove required relation. I m sure we can
> solve this, but need some time ;)
>
> On 17.04.2015 18:22, Anders Wallenquist wrote:
> > What is the best practice to create a XML-record from an object in Python?
> >
> >
> > I have a sale.order.line, or an other object from an Odoo-model, and
> > want to create a record like this:
> >
> >
> >
> >              Laptop E5023
> >
> >              3
> >              3
> >
> >              2950.00
> >
> >
> > Are there any methods from models.Model I can use? eg line._export_xml()
> >
> > Second question: what is best practice to programaticly load such xml-file?
> >
> >
> > Regards
> > Anders Wallenquist
> > Vertel AB
> >
> > _______________________________________________
> > Mailing-List: https://www.odoo.com/groups/community-59
> > Post to: mailto:community@mail.odoo.com
> > Unsubscribe: https://www.odoo.com/groups?unsubscribe
> >
>
> -- 
> Dipl.-Comp.-Math. Markus Schneider
> Softwareentwickler
>
> initOS GmbH & Co. KG
> An der Eisenbahn 1
> 21224 Rosengarten
>
> Mobil:   +49 (0)172 2303699
> Phone:   +49 (0)4105 5615613
> Fax:     +49 (0)4105 5615610
>
> Email:   markus.schneider@initos.com
> Web:     http://www.initos.com
>
> Geschäftsführung:
> Dipl. Wirt.-Inf. Frederik Kramer & Dipl.-Ing. (FH) Torsten Francke
> Haftende Gesellschafterin: initOS Verwaltungs GmbH
>
> Sitz der Gesellschaft: Rosengarten – Klecken
> Amtsgericht Tostedt, HRA 201840
> USt-IdNr: DE 275698169
> Steuer-Nr: 15/205/21402
>
> _______________________________________________
> Mailing-List: https://www.odoo.com/groups/community-59
> Post to: mailto:community@mail.odoo.com
> Unsubscribe: https://www.odoo.com/groups?unsubscribe
>