Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] Developer: data module tutorial #11050

Draft
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Draft

Conversation

bouvyd
Copy link
Contributor

@bouvyd bouvyd commented Sep 19, 2024

Introduce a new tutorial about creating Odoo modules using XML data files
instead of Python code.

This guide is follows closely the 'Server Framework 101' tutorial and
covers the following:

  • Module structure and deployment
  • Defining models and fields
  • Setting up security and access rights
  • Creating views and actions
  • Implementing relational fields (many2one, many2many, one2many)
  • Working with computed and related fields
  • Adding business logic through server actions and automation rules
  • Creating website controllers for API endpoints

The tutorial includes practical exercises and code examples to reinforce
learning, catering to developers who need to customize Odoo without writing
Python code (e.g. Odoo PS-Tech employees, partners that focus on SaaS instances
or author of Industry modules).

Task-4167176

@robodoo
Copy link
Collaborator

robodoo commented Sep 19, 2024

Pull request status dashboard

@bouvyd
Copy link
Contributor Author

bouvyd commented Sep 19, 2024

Will need a new entry in codeowners (doc-review team i guess, same as the other tutorials?)

Introduce a new tutorial about creating Odoo modules using XML data files
instead of Python code.

This guide is follows closely the 'Server Framework 101' tutorial and
covers the following:

- Module structure and deployment
- Defining models and fields
- Setting up security and access rights
- Creating views and actions
- Implementing relational fields (many2one, many2many, one2many)
- Working with computed and related fields
- Adding business logic through server actions and automation rules
- Creating website controllers for API endpoints

The tutorial includes practical exercises and code examples to reinforce
learning, catering to developers who need to customize Odoo without writing
Python code (e.g. Odoo PS-Tech employees, partners that focus on SaaS instances
or author of Industry modules).

Task-4167176
Copy link
Contributor

@jdkirkwood jdkirkwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff 👍
Just the style issue of putting id first in the XML <record/>s and some minor typos.

This tutorial assumes familiarity with the :doc:`server_framework_101` tutorial and the
:doc:`define_module_data` tutorial.

Although as developpers, we prefer to have the full power of Python to write our modules,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Although as developpers, we prefer to have the full power of Python to write our modules,
Although, as developers, we prefer to have the full power of Python to write our modules,


However, the flexible nature of Odoo is meant to allow customizations out of the box. Whilst
a lot is possible with :doc:`Studio </applications/studio>`, it is also possible to define
models, fields and logic in :doc:`XLM Data File <define_module_data>`. This makes it easier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
models, fields and logic in :doc:`XLM Data File <define_module_data>`. This makes it easier
models, fields and logic in :doc:`XML Data Files <define_module_data>`. This makes it easier


<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="ir.model" id="model_real_estate_property">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id should come first. https://www.odoo.com/documentation/15.0/contributing/development/coding_guidelines.html#xml-files

Suggested change
<record model="ir.model" id="model_real_estate_property">
<record id="model_real_estate_property" model="ir.model">

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- ...model definition from before... -->
<record model="ir.model.fields" id="field_real_estate_property_name">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<record model="ir.model.fields" id="field_real_estate_property_name">
<record id="field_real_estate_property_name" model="ir.model.fields">

<field name="required">True</field>
</record>

<record model="ir.model.fields" id="field_real_estate_property_selling_price">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<record model="ir.model.fields" id="field_real_estate_property_selling_price">
<record id="field_real_estate_property_selling_price" model="ir.model.fields">


- Add a server action to the ``x_estate.property.offer`` model that sets the ``x_status``
field of an offer to ``Accepted`` and update the selling price and buyer of the property
to which the offer is attached accordingly. This action also marks all the other offers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to which the offer is attached accordingly. This action also marks all the other offers
to which the offer is attached accordingly. This action should also mark all the other offers


.. code-block:: xml

<record model="ir.ui.view" id="view_sale_order_form">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<record model="ir.ui.view" id="view_sale_order_form">
<record id="view_sale_order_form" model="ir.ui.view">


.. code-block:: xml

<record model="ir.actions.server" id="action_x_estate_property_create_from_sale_order">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<record model="ir.actions.server" id="action_x_estate_property_create_from_sale_order">
<record id="action_x_estate_property_create_from_sale_order" model="ir.actions.server">


.. code-block:: xml

<record model="ir.actions.server" id="server_action_estate_list">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<record model="ir.actions.server" id="server_action_estate_list">
<record id="server_action_estate_list" model="ir.actions.server">

- add an access right record to allow public users to read and write the model
- prevent any write from the public user by adding a record rule for the write operation
with an impossible domain (e.g. `[('id', '=', False)]`) to prevent any write operation
- add a record rule so that properties marked as `x_api_published` are can be read by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- add a record rule so that properties marked as `x_api_published` are can be read by the
- add a record rule so that properties marked as `x_api_published` can be read by the

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants