Odoo Help

Welcome!

This community 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.

4

How to create a Duplicate button.

By
Dale E. Moore
on 3/30/13, 8:41 PM 4,154 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

--Parth Gajjar--
1484
| 3 3 5
Ahmadabad, India
--Parth Gajjar--
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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