Skip to Content
Menu
This question has been flagged
3 Replies
612 Views

I have an issue with understanding the core use of xml in odoo !

for example ,If i want to cerate an window action I can do that in 2 ways:

  1. xml code
  2. directly through UI 

but the difficult questions: 

does doing that in the UI also generate an XML file and why?

for the option 1 ,if doing that using XML will in the end insert a new record in DB ,what is the need of writing the xml code ,I cannot get the idea of using XML ,I am too much confused since data are stored in DB.

Avatar
Discard
Best Answer

Hi Yahya,

First, let's differentiate XML File and XML Code (I am not sure if it's should be called as code or just the way to define).

  1. XML File is file that consists XML "code", just like json file
  2. XML "Code" is define and store data in a shareable manner (Just like how JSON object also do)

Yes, changing UI will also update the Architecture that is written in XML form (form not file)

Let me share my thoughts on this. It will be best if you are familiar with "Factory and Seeding" or Creating Initial Data by Code if you used ORM before.

Example:
How do we add the very first user account? do we technically do an insert query to db? of course we can. But what if we can set it without access directly to db - as it might be concerning to access directly. Of course after you have the user let's say the "Administrator", if you want to change the access will it be easier for you to change it through UI that will update the DB or you prefer to update your xml file to update your code, commit, push, pull, restart your server, upgrade your module.

In short this is how you can think about it:

Uploading XML file that has the XML code > create data in db with the xml code as the architecture > you can edit the architecture (which written in XML format) from the UI on the db - more convenient this way.

Key note: XML file sets the initial data by the data that formatted in XML form written in it, DB plays for the changes in future.

Hope this helps.

Avatar
Discard
Author

Thanks Andry ,but I think most of MVC frameworks do not use XML like Laravel ......etc ,why odoo user xml . we can handle the data and insert also in the HTML ?

Author

moreover ,how can I display content for by XML ,it is not HTML . so how does browser knows the for example
<field> tag should represents as a gray rectangle for example.

Author

look at this XML code I ,I do not know how it will be rendered in the browser since it is not an HTML code but I think it will be translated via something ,additionally this code is four 2 things UI display and for sending the record to DB ?

<record id="window_action_hospital_patient" model="ir.actions.act_window">
<field name = "name">Patient</field>
<field name="res_model">Hospitaal<field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="o_view_noncontent_smiling_face">
Create a new inconterm
</p>
</field>
</record>

Author

also I think there is a mapping between view code and XML code so :
data will flow: UI -> view code -> XML -> DB ,is that correct ?

Hi Yahya,
1. XML is only a way of formatting data.
2. XML is not HTML, browser use HTML to render UI
3. In Odoo, there is explanation on why they use XML, check https://www.odoo.com/documentation/18.0/developer/reference/backend/data.html

Remember, browser always use HTML.
XML in Odoo which stored in db will be translated by QWeb Template engine to HTML

Best Answer

XML is used to create database records. (1)

You can create database records within the database. (2)

Creating a database record (2) does not create an XML file.

XML is just one way Odoo creates database records from files during the installation of a module. The other main way is via CSV files.

Avatar
Discard
Author

Thanks Ray ,If i have for imagination some UI not related to the DB or inserting just for showing some info ,in this situation why to use XML ?

Best Answer

I guess it is because you can make them persistent using xml, because they will be added in your module and not only at the db. Take for example if we update the mail module and we added the custom templates using the UI you will overwrite the modifications unless you marked it as noupdate.

That is appart of the ease of installing a module and adding new templates or views on the fly without using the UI.

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
1504
0
Jan 25
833
1
Mar 25
652
1
Sep 23
1843
0
Dec 22
1481