Odoo 16 模块迁移到 17 检查表

Model [Python]

●manifest version == 17.0.x.y.z

版本升级到 17 ; 如果是 3 位版本号, 忽略

●Fields属性不再支持 states 字典

Fields 属性展开为 [readonly | invisible | required] = python expr;以在 view 上用 [readonly | invisible | required]= python expr 以及 column_invisible 设置相应的状态属性

●message_post_with_template( ) 方法更换为message_post_with_source( )

同时参数 改为 record 而不再是 record.id

●name_get( ) 方法 更换为 _compute_display_name( )

●Hook function 只有一个参数 env ,不再是2个参数: cr 和 registry

例如

def uninstall_hook(env): # pragma: no cover

# Remove unapproved pages

_logger.info("Deleting unapproved Change Requests.")

env.cr.execute("DELETE FROM document_page_history WHERE state != 'approved'")

   

   

View [xml]

●XML 文件 不需要 encoding="utf-8"

●View 里面的 attrs 需要展开,并且 domain 改写为 python 表达式

1.View 里面的 attrs 需要改写为 [readonly | invisible | required] ="python expr"

2.View 里面的 attributes 需要改写为 [readonly | invisible | required] ="python expr"

3.View 里面的 column_invisible 需要改写为 column_invisible ="python expr"

   

例如

[readonly | invisible | required]

<group string="Taxes" invisible="not tax_line_id and not tax_ids">

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

<field name="tax_ids" widget="many2many_tags" readonly="1" invisible="not tax_ids"/>

<field name="tax_tag_invert" readonly="1" groups="base.group_no_one"/>

</group>

   

column_invisible

<field name="is_landed_costs_line" string="Landed Costs" column_invisible="parent.move_type != 'in_invoice'" readonly="product_type != 'service'" optional="show" groups="stock.group_stock_manager"/>

   

   

attributes

<xpath expr="//label[@for='delay_count']" position="attributes">

<attribute name="invisible">chaining_type == 'suggest' and not suggested_next_type_ids or chaining_type == 'trigger' and not triggered_next_type_id</attribute>

</xpath>

   

 

●View 里面的 states 不再支持

改写为 invisible 以及 column_invisible

●Tree 里面不再支持 invisible, 只支持 column_invisible

domain 改写为 python expr

●Calendar 里面 quick_add 改为 quick_create

●root 层级的 Tag 不再支持 groups

●res.config.settings 页面结构,使用 app, block 和 setting

例如:

<app

data-string="Knowledge"

string="Knowledge"

name="document_knowledge"

>

<block

name="maintenance_mode_setting"

title="Knowledge and Documents Management"

>

<setting>

<field name="module_attachment_indexation" />

</setting>

<setting>

<field name="group_ir_attachment_user" />

</setting>

<setting>

<field name="module_document_page" />

</setting>

<setting>

<field name="module_document_page_approval" />

</setting>

</block>

</app>

   

   

Web [JavaScript]

因为Odoo SA基于 owl 做了大量重构 ,所以改动挺大

   

●patch

取消 registerPatch 改为使用 patch 为已有的组件打补丁 , 例如

patch(Chatter.prototype, {

   

_onAddUrl(event) {

event.preventDefault();

event.stopPropagation();

this.env.services.action.doAction(

"document_url.action_ir_attachment_add_url",

{

additionalContext: {

active_id: this.state.thread.id,

active_ids: [this.state.thread.id],

active_model: this.state.thread.model,

},

onClose: this._onAddedUrl.bind(this),

}

);

},

_onAddedUrl() {

this.load(this.state.thread);

},

get attachmentUrl() {

return url("/web/content", {

id: this.AttachmentList.attachment.id,

download: true,

});

},

   

});

   

   

●extends

使用 extends 继承现有组件 , 扩展为新组件

export class DocumentPageHtmlField extends HtmlField {

events = Object.assign({}, HtmlField.prototype.events, {

"click .oe_direct_line": "_onClickDirectLink",

});

   

_onClickDirectLink = function (event) {

var self = this;

event.preventDefault();

event.stopPropagation();

var element = $(event.target).closest(".oe_direct_line")[0];

var default_reference = element.name;

var model = $(event.target).data("oe-model");

var id = $(event.target).data("oe-id");

var context = this.record.getContext(this.recordParams);

if (default_reference) {

context.default_reference = default_reference;

}

this._rpc({

model: model,

method: "get_formview_action",

args: [[parseInt(id, 10)]],

context: context,

}).then(function (action) {

self.trigger_up("do_action", { action: action });

});

};

   

};

   

export const documentPageHtmlField = {

...htmlField,

component: DocumentPageHtmlField,

displayName: _t("Reference"),

supportedOptions: [...htmlField.supportedOptions],

extractProps({ attrs, options }) {

const props = htmlField.extractProps(...arguments);

props.filterTemplates = options.filterTemplates;

props.inlineField = options['inline-field'];

props.iframeHtmlClass = attrs.iframeHtmlClass;

return props;

},

};

   

registry.category("fields").add("document_page_reference", documentPageHtmlField);

   

●odoo module

尽管odoo.define()还能使用,尽量使用 /** @odoo-module **/ 来声明模块

   

   

 

Web [Qweb]

●使用 t-debug="" 设置断点

备注:

● this.state 可以取得 组件对象的信息

例如 chatter 包含的 thread 信息

patch(Chatter.prototype, {

   

_onAddUrl(event) {

event.preventDefault();

event.stopPropagation();

this.env.services.action.doAction(

"document_url.action_ir_attachment_add_url",

{

additionalContext: {

active_id: this.state.thread.id,

active_ids: [this.state.thread.id],

active_model: this.state.thread.model,

},

onClose: this._onAddedUrl.bind(this),

}

);

},

})