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.

0

creating a new module

By
sneha antony
on 4/23/14, 9:43 AM 1,367 views

I need to add sql constraint so that it prevent the duplication in customer name.The sql constraint cannot be added to the existing module as it cannot be edited.So a new module has to be created.How to create this module and how to inherit the features in my new module and add the new features. ?

0

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 4/23/14, 9:53 AM

Hi,

You can add the following code in your module to apply unique constraint for Customer :

class res_partner(osv.osv):
    _inherit = 'res.partner'

    _sql_constraints = [
        ('name_uniq', 'unique(name)', 'Customer Name must be unique!'),
    ]

Before installing the module, make sure that existing customers don't have duplicate names. If exists, rename those Customers, else constraints will not be applied.

How can a validation for the customer name be linked with the sale_order class?This should be inherited with res.partner isn't it?

sneha antony
on 4/23/14, 10:08 AM

I have updated my answer.

Nehal
on 4/23/14, 10:11 AM

so can i add the _sql_constraints to the default file that contains the class?

sneha antony
on 4/23/14, 10:19 AM

Instead of adding this in default file, better to create new module. You just need to create module with _init_.py , _openerp_.py and py file which includes the given code. This will add the constraint for Partner name.

Nehal
on 4/23/14, 10:31 AM

what about the code in _init_.py and _openerp_.py files?

sneha antony
on 4/23/14, 10:33 AM

Isn't .xml file necessary in the new module?

sneha antony
on 4/23/14, 10:34 AM

I installed a new module customer_validation for the above purpose and added the code in py file but now the issue is the validation does not work.Still I can add a name and save it which already exists.

sneha antony
on 4/24/14, 3:10 AM

Before installing the module, make sure that existing customers don't have duplicate names. If exists, rename those Customers, else constraints will not be applied.

Nehal
on 4/24/14, 5:55 AM

i had duplicate names when I installed the module.So i am going to uninstall the module,remove the duplicate names and then install the module again.Is that ok?

sneha antony
on 4/24/14, 6:07 AM

Yes it is ok if by upgrading module constraint is not applied.

Nehal
on 4/24/14, 6:16 AM

I tried both the ways.First by upgrading the module and then by uninstalling and then reinstalling it.But still the name validation is not working.

sneha antony
on 4/24/14, 6:28 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

0 follower(s)

Stats

Asked: 4/23/14, 9:43 AM
Seen: 1367 times
Last updated: 3/16/15, 8:10 AM