prevent duplicate contact name
parent
4fa63302e1
commit
1b79fdc191
|
@ -7,3 +7,4 @@
|
||||||
#from . import restore_picking
|
#from . import restore_picking
|
||||||
#from . import rename_dbl_hdcase_number
|
#from . import rename_dbl_hdcase_number
|
||||||
#from . import reset_hdcase_number
|
#from . import reset_hdcase_number
|
||||||
|
from . import remove_dbl_contact
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
from netforce.model import get_model
|
||||||
|
from netforce import migration
|
||||||
|
from netforce.access import set_active_user, set_active_company
|
||||||
|
|
||||||
|
class Migration(migration.Migration):
|
||||||
|
_name="clinic.remove.dbl.contact"
|
||||||
|
_version="2.12.3"
|
||||||
|
|
||||||
|
def migrate(self):
|
||||||
|
set_active_company(1)
|
||||||
|
set_active_user(1)
|
||||||
|
contacts={}
|
||||||
|
context={
|
||||||
|
'active_test': False, #find archive also
|
||||||
|
}
|
||||||
|
for partner in get_model("partner").search_browse([],context=context):
|
||||||
|
contacts.setdefault(partner.name,{'name': partner.name,'lines': []})
|
||||||
|
contacts[partner.name]['lines'].append(partner.id)
|
||||||
|
cnames={}
|
||||||
|
for contact_name, vals in contacts.items():
|
||||||
|
lines=vals['lines']
|
||||||
|
if len(lines) > 1:
|
||||||
|
for contact_id in lines:
|
||||||
|
contact=get_model('partner').browse(contact_id)
|
||||||
|
if contact.is_patient:
|
||||||
|
res=get_model("clinic.patient").search([['partner_id','=',contact_id]])
|
||||||
|
if not res:
|
||||||
|
try:
|
||||||
|
print(contact_name,' not use, will delete')
|
||||||
|
get_model('partner').delete([contact_id])
|
||||||
|
except Exception as e:
|
||||||
|
print("Can not delete contact_id ", contact_id)
|
||||||
|
print("ERROR ", e)
|
||||||
|
else:
|
||||||
|
res=get_model("account.invoice").search_read([['partner_id','=',contact_id]],['number'])
|
||||||
|
if not res:
|
||||||
|
print(contact_name,' not use, will delete')
|
||||||
|
get_model('partner').delete([contact_id])
|
||||||
|
else:
|
||||||
|
if contact_name not in cnames.keys():
|
||||||
|
cnames[contact_name]=contact_id
|
||||||
|
else:
|
||||||
|
for r in res:
|
||||||
|
inv=get_model('account.invoice').browse(r['id'])
|
||||||
|
inv.write({
|
||||||
|
'partner_id': cnames[contact_name],
|
||||||
|
})
|
||||||
|
get_model('partner').delete([contact_id])
|
||||||
|
print("del ", contact_name)
|
||||||
|
print("#"*80)
|
||||||
|
|
||||||
|
|
||||||
|
Migration.register()
|
|
@ -2,6 +2,8 @@ from netforce.model import Model, fields
|
||||||
|
|
||||||
class Partner(Model):
|
class Partner(Model):
|
||||||
_inherit="partner"
|
_inherit="partner"
|
||||||
|
#_key=["code","name"]
|
||||||
|
_key=["name"]
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
'walkin_cust': fields.Boolean("Walkin Customer"),
|
'walkin_cust': fields.Boolean("Walkin Customer"),
|
||||||
|
@ -9,6 +11,10 @@ class Partner(Model):
|
||||||
'is_staff': fields.Boolean("Is Staff"),
|
'is_staff': fields.Boolean("Is Staff"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_sql_constraints=[
|
||||||
|
("contact_uniq","unique (name)","The name of contact must be unique!"),
|
||||||
|
]
|
||||||
|
|
||||||
def name_get(self,ids,context={}):
|
def name_get(self,ids,context={}):
|
||||||
vals=[]
|
vals=[]
|
||||||
for obj in self.browse(ids):
|
for obj in self.browse(ids):
|
||||||
|
|
Loading…
Reference in New Issue