首先要创建文件夹wizard,其下包含:
wizard.py
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class Wizard(models.TransientModel):
_name = '模型名'
字段名1 = fields.Char()
字段名2 = fields.Char()
字段名3 = fields.Char()
@api.multi
def 方法名(self):
active_ids = self._context.get('active_ids') # 读取列表中选中记录的ID
for active_id in active_ids: # 遍历ID
print(self.comment) # 查看向导的值
self.env['修改记录的模型名'].search([('id', '=', active_id)]).write({
'修改记录的模型的字段名': self.字段名1,
'修改记录的模型的字段名': self.字段名2,
'修改记录的模型的字段名': self.字段名3,
})
views.xml(需要在__manifest__.py中添加)
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="自定义1">
<field name="name">自定义2</field>
<field name="model">向导模型名</field>
<field name="arch" type="xml">
<form string="自定义3">
<group>
<field name="字段名1"/>
<field name="字段名2"/>
<field name="字段名3"/>
</group>
<!--按钮设置↓-->
<footer>
<button name="向导模型的方法名" type="object"
string="自定义4" class="oe_highlight"/>
or
<button special="cancel" string="Cancel"/>
</footer>
</form>
</field>
</record>
<act_window id="launch_session_wizard"
name="自定义5"
src_model="要嵌入的模型名"
res_model="向导模型名"
view_type="tree"
view_mode="form"
target="new"
key2="client_action_multi"/><!--key2必须加不然只能显示在form视图中-->
</data>
</odoo>
__init__.py
# -*- coding: utf-8 -*-
from . import wizard
补充:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class TAW(models.TransientModel):
_name = 'a.w'
def _default_line_ids(self):
records = self.env['t.t'].browse(self.env.context.get('active_ids', []))
line_list = []
for record in records:
result = {'name': record.name, 'time': record.time, 'version': record.version}
line_list.append((0, 0, result))
return line_list
line_ids = fields.One2many('a.l', 'a_id', readonly=True, default=_default_line_ids)
class TAL(models.TransientModel):
_name = 'a.l'
name = fields.Char(string='Name')
time = fields.Datetime(string='', readonly=True)
version = fields.Char(string='', readonly=True)
a_id = fields.Many2one('a.w', readonly=True)