跳至內容
選單
此問題已被標幟
1 回覆
3457 瀏覽次數

How to create a save and new button in a wizard, which does the same functionality like save and new button when creating sub contacts for a parent in odoo 10.


頭像
捨棄
最佳答案

Hi

XML

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="sub_contacts_view_form" model="ir.ui.view">
 
      <field name="name">sub.contacts.view.form</field>
        <field name="model">sub.contacts</field>
        <field name="arch" type="xml">
            <form string="Sub Contacts">
                <group>
                    <field name="name"/>
                    <field name="email"/>
                </group>
                // you can add the fields here
                <footer>
                    <button string="Save" name="action_sub_contacts" type="object" class="oe_highlight"/>
                    or
                    <button string="Cancel" class="oe_link" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="sub_contacts_action" model="ir.actions.act_window">
        <field name="name">Sub Contacts</field>
        <field name="res_model">sub.contacts</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="sub_contacts_view_form"/>
        <field name="target">new</field>
    </record>
</odoo>


py

from odoo import api, fields, models


class SubContacts(models.TransientModel):

_name =
"sub.contacts"
_description =
"Sub Contacts"

name = fields.Char(string=
'Name')
    
@api.multi
def action_sub_contacts(self):
   
self.ensure_one()
    vals = {
       
// add values here
        }
    new_rec =
self.env['res.partner'].create(vals)
   
return {'type': 'ir.actions.act_window_close'}

Hope it helps

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
7月 25
4440
2
12月 24
7626
2
11月 24
28395
2
5月 24
7362
3
3月 24
6793