From 096cbcbb13862dd0213ce50c02d07213da3a64dc Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Sat, 22 Nov 2014 13:08:42 +0700 Subject: [PATCH] remain hd case number --- netforce_clinic/models/visit.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py index 7bc0884..11aec03 100644 --- a/netforce_clinic/models/visit.py +++ b/netforce_clinic/models/visit.py @@ -174,7 +174,15 @@ class Visit(Model): vals['fee_partner_id']=partner_id break - hd_case_id=hd_case_obj.create(vals) + # use exist hd_case (in case set to draft) + hd_case_id=None + if obj.hd_cases: + hd_case=obj.hd_cases[0] + hd_case.write(vals) + hd_case_id=hd_case.id + else: + hd_case_id=hd_case_obj.create(vals) + if context.get("called"): #XXX call outside return hd_case_id @@ -327,11 +335,12 @@ class Visit(Model): def to_draft(self,ids,context={}): obj=self.browse(ids)[0] for hd_case in obj.hd_cases: - # XXX - hd_case.write({ - 'state': 'draft', - }) - hd_case.delete() + hd_case.to_draft() + for line in hd_case.lines: + line.delete() + for ps in hd_case.personals: + ps.delete() + #hd_case.delete() obj.write({ 'state': 'draft', })