Odoo Help

0

Prevent Duplication of Customer Name

By
sneha antony
on 4/24/14, 8:49 AM 2,261 views

I had the issue of duplicated customer names in Openerp..I'm trying to create a module for OpenERP 7 that prevents double partner records. For instance if I create a contact with the name: "Ajay."; I want an error prompt to come up when I make another contact with the exact same name, and saving is prevented.

After reading up on the web and the help section here, the best way to accomplish this seemed to use an sql constraint. In some of the topics I've read it was recommended to create a new module just for this.

I have created a module, which I named Customer_validation and I am able to install it on my database on the server. However, my code does not seem to be working - I can still enter double partner names without validation.

This is my first module, so I may have very well made a mistake. Is there something that is missing from my code, or if I forgot something in my module?

Folder name: "Customer_validation" Folder contains: 3 files

    **__init__.py**
     import crm

**__openerp__.py**
{
  "name" : "customer_validation",
  "version" : "0.1",
  "description" : """
  Adds partner validation
   """,
   "author" : "Sneha",
  "depends" : ['crm'],
  "category" : "Generic Modules/Base",
  "init_xml" : [],
  "demo_xml" : [],
  "active": False,
  "installable": True
  }

 **Customer_validation.py**
from osv import fields, osv

class res_partner(osv.osv): 
  _inherit = 'res.partner' 
  _sql_constraints = [ 
  ('name', 'UNIQUE (name)', 'The name of the partner must be unique !') 
   ]
 res_partner()
3

Dhinesh - Technical Consultant, Sodexis Inc

--Dhinesh - Technical Consultant, Sodexis Inc--
3722
| 5 4 9
Pondicherry, India
--Dhinesh - Technical Consultant, Sodexis Inc--

Passionate coder in Python/OpenERP. Knows Django/Flask MVC frameworks. Did code in Java, PHP.

Contact me at: dvdhinesh.mail@gmail.com

Dhinesh - Technical Consultant, Sodexis Inc
On 4/24/14, 8:58 AM

Hi, Change this in your files...

 **__init__.py**
     import Customer_validation.py

**__openerp__.py**
{
  "depends" : ['base','crm'],
  }

I changed and upgraded the module.But the result is still the same.No validation is working.

sneha antony
on 4/24/14, 9:19 AM
1

Nehal

--Nehal--
2108
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 4/24/14, 8:56 AM

Hi,

Change the following :

  1. import Customer_validation instead of import crm
  2. "depends" : ['base'],

I tried but still the same.validation is not working.

sneha antony
on 4/24/14, 9:20 AM

check your customers and partners as well. There may be possibility of existing records with same names.

Nehal
on 4/24/14, 9:23 AM

I tried by removing the filters and thoroughly checked for duplicated records and removed/edited those which were found.then the module was upgraded and tried adding an already existing name.Still no validation is working for the name entered.

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

0 follower(s)

Stats

Asked: 4/24/14, 8:49 AM
Seen: 2261 times
Last updated: 3/16/15, 8:10 AM