Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
      • Get a Tailored Demo
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +32 2 290 34 90
    • Get a Tailored Demo
  • Pricing
  • Help
  1. APPS
  2. Tool
  3. Tool for generating XML-files from a template v 8.0
  4. Sales Conditions FAQ

Tool for generating XML-files from a template

by Swing Entwicklung betrieblicher Informationssysteme GmbH http://www.swing-system.com
Odoo
v 8.0 Third Party 1051
Download for v 8.0
Apps purchases are linked to your Odoo account, please sign in or sign up first.
Availability
Odoo Online
Odoo.sh
On Premise
Technical Name xml_template
LicenseAGPL-3
Websitehttp://www.swing-system.com
Versions 8.0
You bought this module and need support? Click here!

Generates XML-Files from a Template

The structure and features of the XML-Template:

The XML-template ist copied "as-is" to the output XML-file:

<MyTag1>
<MyTag2 my-attribute="foo">
My Body
</MyTag2>
</MyTag1>

yields:

<MyTag1>
<MyTag2 my-attribute="foo">
My Body
</MyTag2>
</MyTag1>

Additional control-attributes allow to fill the output XML with data from the data-model:

<MyTag1>
<MyTag2 attr-name1="foo" attr-eval="root.foo">
<MyTag3 text-eval="root.bar"/>
</MyTag2>
</MyTag1>

will produce:

<MyTag1>
<MyTag2 foo="FOO">
<MyTag3>BAR</MyTag3>
</MyTag2>
</MyTag1>

provided that the Python expression "root.foo" will return "FOO" and "root.bar" will return "BAR" I.e., "attr-name[0-9]" provides an attribute-name and "attr-eval[0-9]" provides a Python-expression. The "[0-9]" can be any integer as long as "name" and "eval" matches.

List-iterations can be provided with the attributes "loop-eval" and "var":

<MyTag1>
<MyTag2 loop-eval="[1,2,4]" var="number">
<MyTag3 text-eval="number"/>
</MyTag2>
</MyTag1>

will produce

<MyTag1>
<MyTag2>
<MyTag3>1</MyTag3>
<MyTag3>2</MyTag3>
<MyTag3>4</MyTag3>
</MyTag2>
</MyTag1>

A variant of this, "seq-eval" is necessary, if there is no surrounding tag for the list (which is a weak XML-design - but cannot be excluded):

<MyTag1>
<MyTag2 seq-eval="[1,2,4]" var="number">
<MyTag3 text-eval="number"/>
</MyTag2>
</MyTag1>

will produce

<MyTag1>
<MyTag3>1</MyTag3>
<MyTag3>2</MyTag3>
<MyTag3>4</MyTag3>
</MyTag1>

The option "omit_on_empty" is used, if the surrounding tag shall be omitted with empty lists:

<MyTag1>
<MyTag2 loop-eval="[]" var="number" omit_on_empty="True">
<MyTag3 text-eval="number"/>
</MyTag2>
</MyTag1>

will produce

<MyTag1>
</MyTag1>

On the other hand:

<MyTag1>
<MyTag2 loop-eval="[]" var="number" omit_on_empty="False">
<MyTag3 text-eval="number"/>
</MyTag2>
</MyTag1>

will produce

<MyTag1>
<MyTag2>
</MyTag2>
</MyTag1>

The programmatic interface (API) of the XML-Template:

def generate_xml(self, cr, uid, id, nsmap=None, **scope_dict)

returns the output XMl. If a schema is provided, the validity is checked.

def attach_xml(self, cr, uid, id, attach_to, xml, name, fname, description, context)

creates an attachment from the output XML and attaches it to another object.

def write_file(self, cr, uid, id, xml, filename)

writes the output XML to a (server-side) provided file.

Example-Code (generate a XML for an invoice and attach it to that invoice):

template_obj = self.pool.get("xml.template")
template_ref_obj = self.pool.get("xml.template.ref")
template_refs = template_ref_obj.browse | ( cr, uid
, template_ref_obj.search
(cr, uid, [("name", "=", "%s,%s" % (invoice._name, invoice.id))])
)
if not template_refs :
raise osv.except_osv | ( _('Data Error !')
, _('No Template defined for Invoice ') + invoice.name
)

template_ref = template_refs[0]
xml = template_obj.generate_xml | (cr, uid
, template_ref.xml_template_id.id
, invoice = invoice
, partner = partner
, time = time.strftime("%Y-%m-%d %H:%M:%S")
)

template_obj.attach_xml | ( cr, uid
, template_ref.xml_template_id.id
, attach_to = invoice
, xml = xml
, name = invoice.name
, fname = invoice.name + ".xml"
, description = "XML file representing this invoice"
)

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with