Chapter 1
- What are the relevant layers to consider when designing an Odoo application?
First focus on the Data layer, structuring the data model, the models needed and their relations. Entity-relationship diagrams (ERDs) can be a useful tool for this.
Then think about the Presentation layer—how the user interface will be organized to fit the use cases to be supported.
Finally, think about the Logic layer, supporting the required business rules. These can be validations, automation, or helper features.
- How is Developer mode enabled?
Developer Mode, making available the
Settings | Technical menu and the Debug contextual menu, can be enabled in the main Settings screen, using a link in the bottom-right. This has been so since Odoo 10.0; in Odoo 9.0 and before, it is enabled from the About dialog, accessed from the user menu in the top-right. It can also be enabled directly on the page URL, by changing the .../web?#... URL to .../web?debug#....- Where do you create a new Data model?
Data Models can be created and modified in the
Settings app, in the Technical | Database Structure | Models menu option. To have the Technical menu available, you must have Developer Mode enabled. New models must have an x_ prefix, and new fields must also have this same x_ prefix.- How do you make a new data model available for the end users to create and edit records?
You should create a menu item for this, and in most cases, you will also want to design proper List and Form Views. You also need to add the ACLs to a group the user belongs to, or they won't be able to see the menu and views.
- How do you add a field to an existing form?
You first edit the model to add the new field, then find the base View for the form (for example, using the
Debugmenu). Then create an extension view for that base view, adding the new field.- What is a Domain, and when can it be used?
It is a filter to apply when querying records from the database.
- How can you set default values on the form you're navigating to?
You do this by setting a context key with the
default_ prefix, for example, {'default_x_name': '<Type description>'}. This context key can be set on Window Actions, used in Menu items, and for relational fields can be set on the View's field definition.- How do you give a user access to a Model?
You first assign the ACL, for create, read, update, and delete, to a Group, and then make sure that the user belongs to that Group, directly or indirectly (indirectly belonging to another Group that inherits that one, such as Manager groups, which usually inherit from user groups).
- How can you add a Category field to the To-do items, with possible values selectable from an options list? (The options list is editable and can be expanded by users.)
Create a new Model called
x_todo_category. No additional fields needed.
Edit the
x_todo_item Model and add a x_category_id field, of the many-to-one type, with a related x_todo_category Model.
Edit the To-do item form view to add the new field:
<field name="x_category_id" />.
Add the ACL to the To-do User group.
- How can you extend the To-do Category model so that the list of Categories is specific for each user?
It is enough to create a record rule on the To-do category for the To-do User Group. The domain to use is
[('create_uid', '=', user.id)].
You could also reorganize the To-do menu to have two child menu items,
Items and Categories.
The
To-do top menu item should have no action defined, the Items menu item should reuse the existing Action to open the to-do list, and a new Action should be used on the Categories menu item, opening the To-do Category list.Chapter 3
- Is
library-appa valid module name?
It is a technically valid name, so it could be used, but it does not comply with the code conventions for Odoo, so it shouldn't be used.
- Should a module define access control (ACL) for all Models defined in it?
Yes, as a general rule it should. Leaving a Model with no ACLs makes it inaccessible for the end users.
- Can we permit some users to only access a subset of the records in a Model?
Yes, Record Rules allow us to define a Domain filter, and assign it to security Groups. Users in those Groups will only be able to access the records matching the Domain filter.
- What is the difference between a relational field and other field types?
Relational fields store links to other records, not actual values like the other field types.
- What are the main view components used in an Odoo app?
The backend view layer includes menu items, window actions, and views. All these are defined using XML data files. Menu items are usually defined with
<menuitem> data elements, <action> defines Window Actions, and <record model="ir.ui.view"> defines views.- How are backend views defined?
A backend view is defined with an XML architecture declaring the structure of the elements it is composed of.
- Where should business logic be implemented in an Odoo app?
A module business logic should be implemented in the Model methods, using Python code.
- What is the web page templating engine used by Odoo?
For the website/frontend views, Odoo uses the QWeb, an XML-based template engine. It allows templates to be extended by other modules, just like what can be done with the backend views.
Chapter 4
- How do we extend an existing Model to add a mixin, such as
mail.thread?
Both in-place classic extension and mixin prototype inheritance use the same
_inherit Model attribute. For example, to extend x and add the y mixin, we should have the _name='x' model attribute and the _inherit = ['x', 'y'] Model attribute.- What changes are needed to also have the phone field available in the member form view?
No model changes are needed, since a
phone field exists in partners, and delegation inheritance makes all partner fields also available on the member Model. We only need to add the field to the form view, for example, next to the email field: <field name=phone" />.- What happens if you create a Model class with name attribute different form the inherit attribute (for example,
_name='y'and_inherit='x')?
A new
ymodel will be created, copying all the features (data structure and methods) from Model x. If x is a database-stored Model, we will have two database tables with the same fields, but independent data records, which is not a good design practice. That's why this is usually used with abstract mixin classes that don't have an actual database representation.- Can XPath be used to modify data record from other modules?
No. XPath is used only for views, to find the element in the view structure where the extension should be done. This extension is performed at runtime, and no actual change is made to the record being extended.
- When inheriting a Model to extend it, can we extend a method and not use
super()to call original code being inherited?
We can, and sometimes we may have to, but we should avoid it. When not using
super() we are completely replacing the original code, our re-implementation will have different behavior form the original one, and it may have unanticipated side-effects. Also, extensions implemented in other modules may not work as expected. If the parent method is hard to extend, it's best to propose changes to it, so that it includes extension points we can use (separating part of the logic into their own methods will make extension simpler).- How can we extend the book catalog web page to add the ISBN field at the end of the line without referencing any particular field name?
We can insert the ISBN field inside the row
div element: <xpath expr="//div[class='row']"><span t-field="book.isbn"/></xpath>Chapter 5
- What is the difference between an XML ID and an external ID?
None. Both terms refer to the same thing: external identifiers.
- What type of data files can be used, add-on modules?
Odoo add-on modules can use XML and CSV data files.
- What is wrong in this XML fragment:
<field name="user_id">[(4, 0, [ref(base.user_demo)])]</field>?
Three things are wrong: the tag content should instead be in an
eval attribute; the 4 command expects the record references in the second element, not the third; and a single record reference is expected, not a list. The correct syntax is: <field name="user_id" eval="[(4, ref(base.user_demo), 0)] />- Can a data file in one add-on module overwrite a record create in another module?
Yes, in an XML file we can have a
<record> element using the complete External ID of the record to replace (module.identifier).- When an add-on module is upgraded, are all its data records rewritten to the module's default values?
In most cases, yes, but there can be records loaded in a
noupdate="1" data section that won't be rewritten on a module upgrade.
Comments
Post a Comment