Odoo 8.0 New API Overview

Source: Internet
Author: User

Compared to 7来, 8 of the API has improved a lot, in the official words is more object-oriented.

Here's a look at the specific changes.

Preparation knowledge: Use of Python decorators http://blog.csdn.net/thy38/article/details/4471421

In 8, the API interface is divided into traditaional style and record style,traditional style refers to the type we use in 7, the DEF (cr,uid,ids,context) syntax. and the Record Style streamlines parameters, retains only self and args, and is shaped like Def (Self,args)

 __all__= [      'Environment',      'Meta','Guess','noguess',      'Model','Multi',' One',      'CR','Cr_context','Cr_uid','Cr_uid_context',      'cr_uid_id','Cr_uid_id_context','Cr_uid_ids','Cr_uid_ids_context',      'constrains','depends','onchange','returns',  ]

As you can see from the definitions in the api.py file, there are so many properties available. Next we'll look at their usage.

Environment:orm records the wrapper class, encapsulates attributes such as Cr,uid,context, and provides registration access, record caching, and management of recalculated data structures

Meta: Automatic decoration traditional style decoration class, while realizing the inheritance of returns decoration

Guess: This decorating method can be called either by the traditional style or by the record style.

Noguess: Stop all guess functions

Model: Decorate the Record-style method with self as the recordset

Multi: The same model, the difference is that the model in the equivalent of Traditional-style in the Model.method (Cr,uid,args,context=context), and Multi for Model.method (CR , Uid,ids,args,context=context)

One: The self in the Record-style method is a single instance, the decorated method loops through each record, returns a list result set, and returns the result of the connection if it is used with @returns.

CR: Decorative Traditional-style method that identifies the CR as a parameter

Cr_context: Decorating the Traditional-style method, identifying the Cr,context as a parameter

Cr_uid: Decorating the Traditional-style method, identifying the Cr,uid as a parameter

Cr_uid_context: Decorating the Traditional-style method, identifying the Cr,uid,context as a parameter

CR_UID_ID: Decorating the Traditional-style method, identifying the Cr,uid,id as a parameter

Cr_uid_id_context: Decorating the Traditional-style method, identifying the Cr,uid,id,context as a parameter

Cr_uid_ids: Decorating the Traditional-style method, identifying the Cr,uid,ids as a parameter

Cr_uid_ids_context: Decorating the Traditional-style method, identifying the Cr,uid,ids,context as a parameter

V7: Adornment method only supports Traditional-style API, new API method needs to rewrite a new method and decorate with V8

V8: The adornment method only supports the Record-style API, the old API method needs to rewrite a new method and decorate with V7

Constrains: Returns a field-dependent adorner that specifies a method that has a realistic field limit, each of which must be a field name

Depends: Returns a dependent adorner that specifies the compute method (or New Style function fields), each of which must be a string of field names separated by.

Onchagne: Returns an adorner for the onchange method of the given fields, each of which must be a field name

Returns (Model,downgrade=none): The adorner that returns a method that returns an instance of the parameter model, the parameter Model:model name or self (the current model), Parameter downgrade: The method to convert from Record-style to Traditional-style

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.