3

I have simple code.

python:

class Test(osv.osv):
    _name= 'test.name'
    _columns= {
        'name' = fields.char('Name')
}

xml:

<record model="ir.ui.view" id="test_form_view">
    <field name="name">Test</field>
    <field name="model">test.name</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form version="7.0">
            <sheet>
                <group>
                    <field name="name"/>
                </group>
            </sheet>
        </form>
    </field>
</record>

I'd like to open a form view, same as after clicking one2many field (with buttons save&close, save&new, discard), so I could hit save&new button and directly add new entry without closing and reopening new form.

Is there any chance to do this? (without manually creating form that has custom buttons)

CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • As far as i know, there is no build-in wizard/popup for that. But you can use editable tree views, if your model doesn't have so many fields. Just Off-topic: why do you use OpenERP/Odoo V7 instead of one of the newer ones? – CZoellner May 30 '16 at 14:14
  • @CZoellner this could help to fill "name" field multiple times without closing and reopening, but that's not what I'm looking for (I need view with buttons...). Thanks anyways. Answering your question: using OpenERP/Odoo V7 in not the choice of mine. – Irakli Mchedlishvili May 31 '16 at 08:16

1 Answers1

0

Unfortunately, you cannot overwrite ORM methods like create to make them call other form, so what I recommend you is to try the following:

Create a new transient model which is like your model test.name, this way:

class YourAbstractModel(osv.TransientModel):
    _name= 'your.abstract.model'
    _columns= {
        'name': fields.char('Name')
    }

    def create_test_name(self, cr, uid, ids, context):
        wizard_info = self.browse(cr, uid, ids)[0]
        vals = {
            'name': wizard_info.name or False
        }
        self.pool.get('test.name').create(cr, uid, vals, context=context)
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'your.abstract.model',
            'view_mode': 'form',
            'view_type': 'form',
            'views': [(False, 'form')],
            'target': 'new',
        }

And also create its own view:

<record model="ir.ui.view" id="your_abstract_model_form_view">
    <field name="name">Your abstract model form</field>
    <field name="model">your.abstract.model</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form version="7.0">
            <sheet>
                <group>
                    <field name="name"/>
                </group>
                <footer>
                    <button name="create_test_name" string="Create" type="object" class="oe_highlight"/> or 
                    <button special="cancel" string="Cancel" class="oe_link"/>
                </footer>
            </sheet>
        </form>
    </field>
</record>

Then modify the menuitem which showed the view you wrote in your question and make it call the new view I wrote here.

I guess you can manage your purpose if I understood well the question.

forvas
  • 9,801
  • 7
  • 62
  • 158
  • thanks for answer. This approach works fine, unless what about the very first time you hit the create button? (Thats the reason why I wanted to get that kind of view directly after hitting create button) Besides, I have had done something very similar, with just defining methods that return views I want, but in same class and calling them with buttons form xml. And it was working pretty much in the same way as the one you suggest. So what's the actual benefit of making new transient model which is then writing things in my test model? – Irakli Mchedlishvili May 31 '16 at 07:30
  • I have not tried it, I guess you can get the same result without creating an abstract model, if you open your wizard hiding the action buttons (`'flags': {'form': {'action_buttons': False, }, }`) and create your own ones (which call a non-ORM method which calls an ORM method), – forvas May 31 '16 at 07:44