2014-12-04 14:08:29 +00:00
|
|
|
import time
|
|
|
|
|
2014-12-14 11:15:14 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2014-12-04 17:32:39 +00:00
|
|
|
from netforce.access import get_active_company
|
2014-12-04 14:08:29 +00:00
|
|
|
|
|
|
|
class HDCaseExpense(Model):
|
|
|
|
_name="clinic.hd.case.expense"
|
|
|
|
_string="Expense"
|
2014-12-04 17:32:39 +00:00
|
|
|
_multi_company=True
|
2014-12-04 16:48:38 +00:00
|
|
|
|
|
|
|
def _get_patient_conflict(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
hd_case=obj.hd_case_id
|
|
|
|
patient=hd_case.patient_id
|
|
|
|
conflict=False
|
|
|
|
if obj.patient_id.id!=patient.id:
|
|
|
|
conflict=True
|
|
|
|
res[obj.id]=conflict
|
|
|
|
return res
|
|
|
|
|
2015-02-18 18:50:15 +00:00
|
|
|
def _get_store(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
pt=obj.patient_id
|
|
|
|
name='%s,%s,%s,%s'%(obj.date, pt.hn_no or '', pt.card_no or '', pt.name)
|
|
|
|
res[obj.id]=name
|
|
|
|
return res
|
|
|
|
|
2014-12-04 14:08:29 +00:00
|
|
|
_fields={
|
2015-08-02 12:57:24 +00:00
|
|
|
'name': fields.Char("Name", size=256, function="_get_store",store=True),
|
2014-12-04 16:48:38 +00:00
|
|
|
'date': fields.Date("Date",required=True,search=True),
|
2015-03-02 04:03:07 +00:00
|
|
|
'patient_id': fields.Many2One("clinic.patient","Patient",domain=[['state','=','admit']], required=True,search=True),
|
2014-12-04 16:48:38 +00:00
|
|
|
'hd_case_id': fields.Many2One("clinic.hd.case","HD Case",required=True,search=True),
|
2014-12-04 15:26:20 +00:00
|
|
|
'payment_id': fields.Many2One("account.payment","Payment",search=True),
|
2014-12-14 11:15:14 +00:00
|
|
|
"invoices": fields.One2Many("account.invoice","clinic_expense_id","Invoices"),
|
|
|
|
'fee_amt': fields.Float("Fee"),
|
|
|
|
'mdc_amt': fields.Float("Medicine"), # EPOadm
|
|
|
|
'srv_amt': fields.Float("Service"), # Allow
|
|
|
|
'fee': fields.Boolean("Fee"),
|
|
|
|
'medicine': fields.Boolean("Medicine"),
|
|
|
|
'service': fields.Boolean("Service"),
|
2014-12-21 17:24:08 +00:00
|
|
|
'state': fields.Selection([['draft','Draft'],['waiting_matching','Waiting Matching'],['match','Match'],['unmatch','Unmatch'],['completed','Completed']],'State'),
|
2014-12-04 16:48:38 +00:00
|
|
|
'note': fields.Text("Note"),
|
|
|
|
'pt_conflict': fields.Boolean("Patient Conclict",function="_get_patient_conflict"),
|
2014-12-04 17:32:39 +00:00
|
|
|
'company_id': fields.Many2One("company","Company"),
|
2014-12-16 09:53:36 +00:00
|
|
|
'match_id': fields.Many2One("clinic.report.payment.matching","Match"),
|
2014-12-21 13:29:25 +00:00
|
|
|
'invno': fields.Char("Invoice No"),
|
2014-12-21 17:24:08 +00:00
|
|
|
'ok': fields.Boolean("OK"),
|
2014-12-04 14:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'state': 'draft',
|
|
|
|
'date': time.strftime("%Y-%m-%d"),
|
2014-12-04 17:32:39 +00:00
|
|
|
"company_id": lambda *a: get_active_company(),
|
2014-12-04 14:08:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_order="date desc"
|
|
|
|
|
2014-12-14 11:15:14 +00:00
|
|
|
def create(self,vals,**kw):
|
|
|
|
new_id=super().create(vals,**kw)
|
|
|
|
hd_case_id=vals['hd_case_id']
|
|
|
|
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
|
|
|
|
for inv in hd_case.invoices:
|
|
|
|
inv.write({
|
|
|
|
'clinic_expense_id': new_id,
|
|
|
|
})
|
2015-02-18 18:50:15 +00:00
|
|
|
self.function_store([new_id])
|
2014-12-14 11:15:14 +00:00
|
|
|
return new_id
|
|
|
|
|
2015-02-18 18:50:15 +00:00
|
|
|
def write(self,ids,vals,**kw):
|
|
|
|
self.function_store(ids)
|
|
|
|
super().write(ids,vals,**kw)
|
|
|
|
|
2014-12-21 17:24:08 +00:00
|
|
|
def complete(self,ids,context={}):
|
2014-12-04 14:08:29 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
2014-12-21 17:24:08 +00:00
|
|
|
'state': 'completed',
|
2014-12-04 14:08:29 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
def to_draft(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'draft',
|
2014-12-21 17:24:08 +00:00
|
|
|
'ok': False,
|
2014-12-04 14:08:29 +00:00
|
|
|
})
|
|
|
|
|
2014-12-04 15:26:20 +00:00
|
|
|
def delete(self,ids,context={}):
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
if obj.state!='draft':
|
2014-12-14 11:15:14 +00:00
|
|
|
continue #XXX migration
|
2014-12-04 15:26:20 +00:00
|
|
|
raise Exception("Status is not draft!")
|
|
|
|
super().delete(ids,context)
|
|
|
|
|
|
|
|
def do_match(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'match',
|
2014-12-21 17:24:08 +00:00
|
|
|
'ok':True,
|
2014-12-04 15:26:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
def do_unmatch(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'unmatch',
|
2014-12-21 17:24:08 +00:00
|
|
|
'ok': False,
|
2014-12-04 15:26:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
def cancel(self,ids,context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'cancelled',
|
|
|
|
})
|
|
|
|
|
2014-12-04 14:08:29 +00:00
|
|
|
HDCaseExpense.register()
|