Odoo Help

4

How to create a Duplicate button.

By
Dale E. Moore
on 3/30/13, 8:41 PM 5,835 views

Settings, Companies, Companies, Bank Accounts does not have a duplicate button.

How would I create a push button that would duplicate a Bank Account like exists for Customers, Products, Projects, and so many other objects in OpenERP?

I've heard you "put a button on list view of o2m bank and call copy()!" Because "copy() does it all (default values + new values + translations)!" So this goes in my view.xml:

<record id="view_partner_bank_form_inherit_dale" model="ir.ui.view">
    <field name="name">Dale Bank Accounts - Journal</field>
    <field name="model">res.partner.bank</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="base.view_partner_bank_form"/>
    <field name="arch" type="xml">
    <group name="bank" position="after">
    <group name="accounting" col="2" colspan="2" attrs="{'invisible': [('company_id','=', False)]}" groups="base.group_extended">
        <separator string="Duplicate" colspan="2"/>
        <button name="copy_bank" type="object" string="Duplicate"/>
    </group>
    </group>
    </field>
</record>

The button size is a bit large and I hear that "col, colspan; will adjust the size" then this goes in my bank.py:

class bank(osv.osv):
    _inherit = "res.partner.bank"

    def copy_bank(self, cr, uid, ids, context=None):
        for rec in self.browse(cr, uid, ids, context):
            self.copy(cr,uid, rec.id , {},context)
        return True
bank()

and everything works lovely.

I'd just like to move the Duplicate button up onto the same line with the Close button.

Hi Dale, you should not use the reserved keyword "copy" as a name of your method. Secondly it will be nice if you can post the python code that you have written for this method.

Naresh Soni (nch)
on 4/2/13, 5:05 AM
2
Parth Gajjar
On 4/2/13, 5:19 AM

Duplicate Button Generate Automatically

Duplicate Button will generate automatically in every form.

image description

You just need to override copy function if you want some changes in default copy function.

def copy(self, cr, uid, id, default=None, context=None):
    #your changes
    default_return_value=super("your parent class", self).copy(cr, uid, id, default, context)
    #your changes in "default_return_value"
    return default_return_value

I'm doing just that to prevent a constraint which doesn't allow two objects with the same name to exist for my current class. But when I try to duplicate, the constraint error rise anyway. Should I overload something in the form view to make the button call my overloaded _copy_ method?

Mathieu Stumpf
on 1/23/14, 11:29 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 3/30/13, 8:41 PM
Seen: 5835 times
Last updated: 3/16/15, 8:10 AM