From e3a75860ea19ad4e5b396c6255b469085bba3217 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Sun, 25 Oct 2015 15:14:50 +0700 Subject: [PATCH] prevent duplicat staff --- netforce_clinic/migrations/restore_picking.py | 5 ++++- netforce_clinic/models/hd_case.py | 9 ++++++--- netforce_clinic/models/visit.py | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/netforce_clinic/migrations/restore_picking.py b/netforce_clinic/migrations/restore_picking.py index e1852a8..8c06148 100644 --- a/netforce_clinic/migrations/restore_picking.py +++ b/netforce_clinic/migrations/restore_picking.py @@ -28,6 +28,9 @@ class Migration(migration.Migration): for hdcase in get_model("clinic.hd.case").search_browse(dom): if not hdcase.pickings: print('gen picking for %s in %s'%(hdcase.number, hdcase.date)) - hdcase.make_pickings() + ctx={ + 'migrate':True, + } + hdcase.make_pickings(context=ctx) Migration.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 954f2dc..5a05eb8 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -819,9 +819,12 @@ class HDCase(Model): if patient.type_id.main_product: if len(prod_code)>1: prods=get_model('product').search_browse(['code','=',prod_code]) - if not prods: - raise Exception("Can not create good issue: product code %s is not found!"%prod_code) - prod=prods[0] + if not context.get('migrate'): + if not prods: + raise Exception("Can not create goods issue: product code %s is not found!"%prod_code) + prod=prods[0] + else: + continue if prod_ids and prod.id not in prod_ids or prod.id in prod_exist_ids: continue prod_exist_ids.append(prod.id) diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index fc9a2b3..c075edf 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -203,6 +203,9 @@ class Visit(Model): hd_case_id=None if obj.hd_cases: hd_case=obj.hd_cases[0] + # prevent duplicate staff: del old staff + for staff in hd_case.staffs: + staff.delete() hd_case.write(vals) hd_case_id=hd_case.id else: