odoo10关于向导的编写

本文介绍如何在Odoo中创建自定义向导和视图,包括使用Python和XML进行模型定义、字段设置及按钮操作。通过具体代码示例,详细解释了向导的创建过程和视图的嵌入方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先要创建文件夹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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

轮舞之翼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值