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

Closed
wants to merge 1 commit into from
Closed

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?)

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.

content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
Copy link
Contributor

@vava-odoo vava-odoo left a comment

Choose a reason for hiding this comment

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

Really liked reading this tutorial, and learned a few tips in the process. Thanks @bouvyd!

No big comment (except maybe the one about store default value). This can be merged as is.

Tiny last point: I don't know if this tutorial needs to be exhaustive, but maybe mentioning the following items, although a bit advanced wouldn't hurt:

  • use of <function/>
  • add image/file as ir.attachment
  • add some JS like a tour
  • add ir.model.data records to exclude from cloc

Cheers!

content/developer/tutorials.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
content/developer/tutorials/data_modules.rst Outdated Show resolved Hide resolved
@bouvyd
Copy link
Contributor Author

bouvyd commented Oct 16, 2024

Hey there

Thx for both your reviews!

@vava-odoo

Tiny last point: I don't know if this tutorial needs to be exhaustive, but maybe mentioning the following items, although a bit advanced wouldn't hurt:

use of <function/>

Could be a good idea, though i have few useful examples and can't really think of one that makes sense in the context of the 'Real Estate' app. Even for industry modules, i'm not convinced it's a frequent need?

add image/file as ir.attachment

You mean like adding an image in a knowledge article, or an html description, etc.? Makes sense for your case; a bit less for a ps-tech training. Could actually be included in the 'define module data' imho.

add some JS like a tour

Yes, i thought i included some info about including js files but apparently not. The tour seems like a simple enough example. (done)

add ir.model.data records to exclude from cloc

Not sure this is something that should be included in a generic tutorial that is on the documentation website? Seems more like internal stuff 🤔

@bouvyd bouvyd requested a review from a team October 16, 2024 15:07
@bouvyd bouvyd marked this pull request as ready for review October 16, 2024 15:07
@C3POdoo C3POdoo requested review from a team October 16, 2024 15:08
@ryv-odoo ryv-odoo removed the request for review from a team October 17, 2024 08:29
@AntoineVDV AntoineVDV requested review from AntoineVDV and removed request for a team October 17, 2024 09:37
@bouvyd
Copy link
Contributor Author

bouvyd commented Oct 21, 2024

@AntoineVDV my newbie will need this next week, if we can merge this week it would be swell

anything missing on your end? any way i can help?

Copy link
Collaborator

@AntoineVDV AntoineVDV left a comment

Choose a reason for hiding this comment

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

Nice work! I learned a few things about data modules :)

  • The tutorial could use fewer references to the Server framework 101 tutorial because it can and will change over time, and the references only remind the reader when they learned something, which I don't find worth maintaining.
  • I pushed a fixup! commit with nitpicking/styling changes. Feel free to keep what you want and squash. In particular, I removed the exercise summaries you put as headers because they're not rendered as such but displayed in the body of the admonition. Also, they don't really add value IMHO.

@robodoo delegate+

Comment on lines 94 to 102
It is also possible to deploy the module using the `odoo-bin` command line tool with the `deploy`
command:

.. code-block:: bash

$ odoo-bin deploy <path_to_your_module> https://<your_odoo_instance> --login <your_login> --password <your_password>

This command also accepts the `--force` option, which is equivalent to the `Force init` option
in the wizard.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It could be interesting to document these commands and options and reference them here with

:option:`--example <odoo-bin --example>`

Comment on lines 254 to 268
for each field. For example, it is possible to set the default value of the
``x_selling_price`` field to ``100000`` for all properties by creating the following record:

.. code-block:: xml

<odoo>
<!-- ...model definition from before... -->
<record id="default_real_estate_property_selling_price" model="ir.default">
<field name="field_id" ref="estate.field_real_estate_property_selling_price" />
<field name="json_value">100000</field>
</record>
</odoo>

For more details, refer to the `ir.default` model in the database available in the
:menuselection:`Settings --> Technical --> Actions --> User-defined Defaults` menu or
see the `ir.default` model definition in the `base` module.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that this should rather be an exercise of the tutorial. The reader can use what they learned above and find the fields to populate to create the ir.default themselves.

.. note::

If your action needs to return an action to the client (for example to redirect the user to
another view), you can assign it to a semi-magical ``action`` variable inside your server
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not super reassuring :D

Suggested change
another view), you can assign it to a semi-magical ``action`` variable inside your server
another view), you can assign it to an ``action`` variable inside your server

200).
- `request.make_json_response(data, headers=None, cookies=None, status=200)` to manually create a
JSON response; the data will be json-serialiazed using `json.dumps` utility; this can be useful
to set up machine-to-machine communications via API calls.
Copy link
Collaborator

Choose a reason for hiding this comment

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

machine-to-machine sounds like the Quebec version of S2S 😄

@AntoineVDV
Copy link
Collaborator

I added the odoo/doc-review team as codeowner of this new tutorial to keep it simple, but we'll make sure to tag you if your review is needed for future PRs.

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
@bouvyd
Copy link
Contributor Author

bouvyd commented Oct 31, 2024

@robodoo r+

robodoo pushed a commit that referenced this pull request Oct 31, 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

closes #11050

Signed-off-by: Bouvy Damien (dbo) <[email protected]>
@robodoo robodoo closed this Oct 31, 2024
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.

5 participants