view

1. From view properties

The group TAB

  1. By default, a group defines two columns, and each of the most direct child elements occupies one column. Elements of type field display a label by default

  2. The title of the group can be defined by setting the String property; Outside of the group, we can use basic HTML elements for headings, such as div, SPAN, H1, and H2, and can add style attributes to specify CSS styles.

  3. The col and colSPAN properties specify the number of columns to contain in the group. The default value is 2. It can also be changed to any number, even numbers work better because each field adds up to two columns

  4. The number of columns occupied by group elements, including elements, can be set using the colSPAN property, which defaults to 2 columns.

  5. The newline tag, useful only in the group element, opens a newline. Enforces a newline layout when a group row is not full.

  6. Add an intra group divider with the element; The title of this section can be set through the String attribute

Paging the notebook

Define a TAB block. Each TAB is defined by a page child element. Each page can have the following attributes:

  • String (Required) — The name of the TAB label
  • accesskey –html accesskey
  • Attrs — Dynamic attributes (visible, read-only) based on recorded values, e.g. Attrs =”{‘invisible’: [(expression)]}”

field

Displays a field of the current record with the following properties:

1.name

(Mandatory) Field name.Copy the code

2.attrs

There are only two label attributes: invisible and ReadOnly. The two values can be determined according to the expression value, so as to dynamically control the display/hide of the label, and read-only/modifiable. You can set the attrs attribute in either of the following ways: 1. Set the attrs attribute in a unified mannerCopy the code

attrs="{'invisible': [('state', '!=', 'draft'), ('state', '!=', 'disable')]}"

2. Set the attribute name separately and explicitlyCopy the code

<field name="" invisible="1" readonly="1"/>

3. widget

Each field has a default presentation based on its data type, and the Widget property can specify an alternative presentation.Copy the code

4. options

Tag behavior, the JSON object used to specify the widget field configuration. This depends on what widgets are used to display the field. Odoo native field types have default widgets that encapsulate some behavior. You can view the js file for the specific widget definition to see what options are available from the words this.options.XX. You can also add options by customizing widgets and inheriting widgets. Options can only be set using the options property: // Set using the options propertyCopy the code

options="{'no_create': 1, 'no_open': 1}"

5. class

To set the CSS style of the current element, oDOO has the following built-in style class names, you can also use boostrap-related style class names, custom CSS style file class names. [Note: these styles can be used not only for field tags, but for any element in the form.] -oe_inline: Prevents line breaking, which automatically wraps subsequent fields so that they are displayed on the same line. - oe_left, oe_right: equivalent to CSS float, float left and float right. -oe_read_only, oE_edit_ONLY: display only in the corresponding mode. Read_only means display only in the non-editing state, and edit_only means display only in the editing state. -oe_no_button: does not show the navigation button for many2one field - oe_avatar: when the field is a picture, it is displayed as an avatar (90*90 square) - oe_highlight: the button is highlightedCopy the code

6. groups

Specifies that the user group can see this field. [Can do privacy and data isolation for some fields]Copy the code

7. on_change

The corresponding method is called when the field value changes, starting from 8.0 using odoo.api.onchange() in the model.Copy the code

8. domain

During editing, filter data when associated fields are selected in a drop-down selection mode.Copy the code

9. context

Used to associate fields and provide context when displaying data.Copy the code

10. readonly

This field can be displayed in read and edit mode, but is never editable.Copy the code

11. required

Makes the field mandatory, gives an error message and prevents saving if the value is not set.Copy the code

12. nolabel

Does not display the label of a field, only if the field is a group child. <label for=' field name 'style=" style ">Copy the code

13. placeholder

The prompt displayed when the field value is null. (Watermark text)Copy the code

14. mode

For the one2many field, which displays the form of its associated record, there is tree, Form, Kanban, graph, and the default is Tree.Copy the code

15. help

A prompt that is displayed when the mouse is placed over a field or labelCopy the code

16. filename

For binary fields, the related fields give the filename.Copy the code

17. password

Indicates that the field is a password and is not displayed in plain text.Copy the code

18. string

'string=" Display name "' display name will replace the point field defined in the Models fieldCopy the code

2. Search view properties

Added quick search using the Field tag

Added quick filter using the filter tag with the domain attribute

<filter string="Confirmed" name="is_ill" domain="[('is_ill', '=', True)]"/>
<filter string="Undiagnosed." name="is_ill" domain="[('is_ill', '=', False)]"/>
Copy the code

Add shortcut groups using the filter tag with context

You can use the element to add an intra-group divider

field

Conventional field

Simple fields are atomic values that are stored directly in the model table, and whatever you put in the view, that’s what’s stored in the data table. Relational fields are linked to records (same or different models) by using foreign keys. You can only select records (same or different models). After saving, the table stores the ids of the records you selected.

Simple fields like Image, Char, Boolean, Date, Datetime, Text, Html, Float, Integer, and Selection are all simple fields.

Like Many2one, Many2many, One2many belong to relational fields.

1. Boolean type field definition

fields.Boolead()

2. Many2one field type is used

The user_id = fields.many2one (‘ res.users’) parameter is the target model name

3. Use the Text field type

Note = fields.text () Text type field

Readonly, Required, Invisible, attrs

Some fields are not of the same type, but they have the same attributes. For example, the string field property, like string, can be used to modify properties of different fields, which we call common properties. Common odoo attributes commonly used in Odoo are:

The property name Attribute value type The default value Function and Description
string

Unicode (string)

The field name

The field label displayed in the view.

required

bool

False

Indicates whether this field can be null (required)

help

Unicode (string)

 

In the same, to provide users with help tips.

index

bool

False

Whether to create a database index on the corresponding database column.

There’s also invisible

Attrs sets field attributes dynamically based on conditions:

attrs='{'invisible': [('is_ill', '=', True)], 'required': [('is_ill', '=', False)]}'

5. Field default values

The default attribute can be a fixed value or a function (depending on the requirement and the field type)

gender = fields.Selection(
    [("1"."Men"), ("2"."Women"), ("3"."Other")],
    string="Gender", default="1"
)
Copy the code

Set the default value directly:

default='value'

Value is a method

default=_default_fields_value
def _default_fields_value(self)
      return value
Copy the code

Create_user_id = fields.Many2one(' res.users', string= 'founder', default=lambda: self, self.env.uid)

7. Reserved fields

When we create a model, the model maps to tables in the database, and the fields in the model map to columns in the table. But did you know that even if you don’t create the following fields in the model, the corresponding columns will still appear in the mapped table? These are created by the Odoo system administration, and we do not recommend that you create them in the model. These fields are:

The field name type instructions
id Integer Table primary key, unique identifier of records in mo model.
create_date Datetime Record creation date.

create_uid

Many2one The creator of the record.
write_date Datetime The last modification date of the record.

write_uid

Many2one The last modifier of the record.

8. Special fields

In Odoo, there are a few special fields:

active Boolean This is special. If you create this field and add default=Fasle to it, all records you create will not be seen unless you filter out default=False.
name Unicode (string)

Why say this field, you better create it in the model. Because Odoo requires and needs a field that shows and displays various behaviors. If not, it won’t affect the system, it just won’t show you what your current record is when you open a record.

Here’s how to use the fields

from odoo import api, fields, models, _
 
 
class ZeroneBook(models.Model) :
    _name = "zerone.book"
    _description = "Zerone Books"
 
    _inherit = ['image.mixin']
 
    image_1920 = fields.Image(string="Sample book")
    name = fields.Char(string="Book Name", required=True)
    code = fields.Char(string="Book Number", copy=False.help="Management number for quick book location")
    isbn = fields.Char(string="ISBN", copy=False)
    author = fields.Char(string="The author")
    pages = fields.Integer(string="Pages")
    publish_date = fields.Date(string="Publication Date")
    publisher = fields.Char(string="Publishing house")
    price = fields.Float(string="Price", digits=(7.2))
    description = fields.Text(string="Content Introduction".help=""" Describe the contents of this book to the borrower """)
    binding_type = fields.Selection(
        [("common"."Ordinary"), ("hardcover"."Hard cover")],
        string="Binding type", index=True, default='common'
    )
    e_link = fields.Html(string="Electronic Link")
    borrowed = fields.Boolean(string="Is it borrowed or not?", default=False)
    date_last_borrowed = fields.Datetime("Last borrowed time", index=True, readonly=True)
 
    shelf_id = fields.Many2one('zerone.shelf', string='On the shelf')
    tags_ids = fields.Many2many("zerone.tags", string="Label")
 
    @api.depends('isbn'.'name')
    def name_get(self) :
        result = []
        for book in self:
            result.append((book.id.'%s(%s)' % (book.name, book.isbn)))
        return result
Copy the code

In simple fields, fields of type Image are specified here. To use this field, you need to inherit Image mixin in the current model to handle Image display. If you do not inherit Image.

Odoo one2many many2many write value rules

After odoo12 one2many many2many write value rules are basically the same

# many2many
Create a new record based on the information in values.
(0.0,{values}) 
Select * from 'id' where id= 'id'
(1,ID,{values})
Select * from unlink; select * from unlink;
(2,ID)
# Break the link between primary and secondary data without deleting this data
(3,ID)
Add master-slave link for id= id;
(4,ID)
Call (3,ID) on all slave data
(5)
Mysql > select ID from IDs where ID = 4
(6.0,[IDs])
Copy the code