【odoo15】从代码返回视图,从向导窗体返回视图窗体

功能:点击创建后返回到mysale.mysale的form视图。

 代码:视图文件:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record model="ir.actions.act_window" id="action_appointment">
        <field name="name">创建 appointment</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">create.appointment.wizard</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="action_appointment_form"/>
        <field name="target">new</field>
    </record>

    <record model="ir.ui.view" id="action_appointment_form">
        <field name="name">mykid_form</field>
        <field name="model">create.appointment.wizard</field>
        <field name="arch" type="xml">
            <form>
                <form string="创建一个新预约">
                    <group>
                        <field name="product_id"/>
                        <field name="date_test1"/>
                    </group>
                    <footer>
                        <button name="action_createaption" string="创建" type="object" class="btn-primary"/>
                        <button string="取消" class="btn-secondary" special="cancel"/>
                    </footer>
                </form>
            </form>
        </field>
    </record>

    <menuitem id="menu_1_list3"
              name="appointment"
              parent="menu_1_list"
              action="action_appointment"
              sequence="30"/>
</odoo>

模型文件:

from odoo import fields, models, api, _


class CreateAppointmentWizard(models.TransientModel):
    _name = "create.appointment.wizard"
    _description = "这是一个瞬态模型,信息不会记录到数据库"
    product_id = fields.Many2one('product.template', string="产品")
    date_test1 = fields.Date(string="日期")

    def action_createaption(self):
        print("创建成功")
        vals = {
            'product_id': self.product_id.id,
            'date_test1': self.date_test1
        }
        self.env['mysale.mysale'].create(vals)
        return {
            'name': _('Appointment'),
            'type': 'ir.actions.act_window',
            'view_mode': 'form',
            'res_id': self.product_id.id,
            'res_model': 'mysale.mysale',
            'target': 'new',
        }

需要注意的是:

 1.   product_id是一个many2one,拿到后是个元组,所以我们要的值是它的ID

 2.   res_model 为返回到哪个模型的视图。这里我们返回mysale的模型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值