xmlodooodoo-17

Loading records using XML files in Odoo


I want to create fiscal positions and other records using XML documents, and so far, everything is going well. However, I also want to upload records into many2one relational fields, such as a tax mapping. These are relational fields in a tree view. How can I upload information into this view?

Reference image

This is what I have so far and it works, I just need to add the logic for the relational fields with a tree view.

<odoo>
  <record id="posicion_exportacion" model="account.fiscal.position">
    <field name="name">Exportación</field>
    <field name="auto_apply">True</field>
    <field name="vat_required">False</field>
    <field name="country_id">96</field>
  </record>
</odoo>

Solution

  • Kenly's comment helped me to find the answer, and it is this code that I put. The point is to use the relationship field between the models and then use the “eval” property with the correct arguments to create the records.

    <odoo>
      <record id="posicion_exportacion" model="account.fiscal.position">
        <field name="name">Exportación</field>
        <field name="auto_apply">True</field>
        <field name="vat_required">False</field>
        <field name="country_id">96</field>
        <field name="tax_ids"
          eval="[Command.clear(), Command.create({'tax_src_id': 2, 'tax_dest_id': 3})]" />
      </record>
    </odoo>