conv_bal
watcha.h 2014-11-28 11:54:21 +07:00
parent 4687c318ee
commit 6176f0c89f
6 changed files with 170 additions and 109 deletions

View File

@ -48,7 +48,7 @@
<group span="12" form_layout="stacked"> <group span="12" form_layout="stacked">
<field name="lines" count="3" nolabel="1"> <field name="lines" count="3" nolabel="1">
<list> <list>
<field name="type"/> <field name="type" onchange="onchange_type"/>
<field name="product_id" onchange="onchange_product"/> <field name="product_id" onchange="onchange_product"/>
<field name="description"/> <field name="description"/>
<field name="qty" onchange="onchange_line"/> <field name="qty" onchange="onchange_line"/>
@ -59,11 +59,16 @@
</field> </field>
</group> </group>
<group span="8" form_layout="stacked"> <group span="8" form_layout="stacked">
<field name="invoice_policy"/> <field name="invoice_policy" onchange="onchange_policy"/>
<newline/>
<group attrs='{"invisible":[["invoice_policy","in",["","fee"]]]}'>
<field name="invoice_option"/>
</group>
</group> </group>
<group span="4" columns="1"> <group span="4" columns="1">
<field name="total"/> <field name="total"/>
<field name="fee_amount"/> <field name="fee_amount"/>
<field name="mdc_amount"/>
<field name="payment_lines" nolabel="1"> <field name="payment_lines" nolabel="1">
<template> <template>
{{#each context.data}} {{#each context.data}}
@ -112,7 +117,6 @@
<button string="Done" type="success" icon="ok" method="done" states="in_progress"/> <button string="Done" type="success" icon="ok" method="done" states="in_progress"/>
<button string="Discontinue" type="danger" icon="remove" action="clinic_hd_case_distcont" states="in_progress"/> <button string="Discontinue" type="danger" icon="remove" action="clinic_hd_case_distcont" states="in_progress"/>
<button string="Pay" type="success" icon="ok" action="clinic_payment" states="waiting_payment" /> <button string="Pay" type="success" icon="ok" action="clinic_payment" states="waiting_payment" />
<!--<button string="Undo" type="default" icon="repeat" method="undo" states="completed"/>-->
</foot> </foot>
<related> <related>
<field name="invoices" click_action="view_invoice"> <field name="invoices" click_action="view_invoice">

View File

@ -29,10 +29,12 @@
<list> <list>
<field name="patient_type"/> <field name="patient_type"/>
<field name="invoice_policy"/> <field name="invoice_policy"/>
<field name="invoice_option"/>
</list> </list>
<form> <form>
<field name="patient_type"/> <field name="patient_type"/>
<field name="invoice_policy"/> <field name="invoice_policy"/>
<field name="invoice_option"/>
</form> </form>
</field> </field>
</tab> </tab>

View File

@ -30,6 +30,41 @@ class HDCase(Model):
res[obj.id]=obj.amount res[obj.id]=obj.amount
return res return res
def _get_total(self,ids,context={}):
vals={}
for obj in self.browse(ids):
total=0
due_amt=0
fee_amt=0
mdc_amt=0
for line in obj.lines:
if line.type=='fee':
fee_amt+=line.amount or 0.0
elif line.type=='medicine':
mdc_amt+=line.amount or 0.0
total+=line.amount or 0.0
# TODO need to check with invoice policy
# government pay for :
# - fee -> create invoice with fee type on state waiting to payment
# - fee & medicine -> create 2 invoice for fee and medicine type
if obj.invoice_policy=='fee':
due_amt=total-fee_amt
elif obj.invoice_policy=='fee_mdc':
due_amt=total-(fee_amt+mdc_amt)
else:
due_amt=total
for line in obj.payment_lines:
due_amt-=line.amount or 0.0
vals[obj.id]={
"total": total,
"amount": due_amt,
'fee_amount': fee_amt,
'mdc_amount': mdc_amt,
}
return vals
_fields={ _fields={
"number": fields.Char("Number",required=True,search=True), "number": fields.Char("Number",required=True,search=True),
"time_start": fields.DateTime("Time Start",required=True,search=True), "time_start": fields.DateTime("Time Start",required=True,search=True),
@ -55,8 +90,6 @@ class HDCase(Model):
"lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"), "lines": fields.One2Many("clinic.hd.case.line","hd_case_id","Lines"),
"staffs": fields.One2Many("clinic.hd.case.staff","hd_case_id","Staffs"), "staffs": fields.One2Many("clinic.hd.case.staff","hd_case_id","Staffs"),
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"), "comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
"amount": fields.Float("Due Amount",function="get_total",readonly=True,function_multi=True),
"total": fields.Float("Total",function="get_total",readonly=True,function_multi=True),
"reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True), "reconcile_id": fields.Many2One("account.reconcile","Reconcile Id",readonly=True),
"invoices": fields.One2Many("account.invoice","related_id","Invoices"), "invoices": fields.One2Many("account.invoice","related_id","Invoices"),
"pickings": fields.One2Many("stock.picking","related_id","Pickings"), "pickings": fields.One2Many("stock.picking","related_id","Pickings"),
@ -64,8 +97,11 @@ class HDCase(Model):
"payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"), "payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"),
'visit_id': fields.Many2One("clinic.visit", "Visit"), 'visit_id': fields.Many2One("clinic.visit", "Visit"),
'duration': fields.Integer("Duration (hrs)",function="get_hrs"), 'duration': fields.Integer("Duration (hrs)",function="get_hrs"),
"total": fields.Float("Total",function="_get_total",readonly=True,function_multi=True),
"fee_amount": fields.Float("Fee",function="_get_total",readonly=True,function_multi=True),
"mdc_amount": fields.Float("Medicine",function="_get_total",readonly=True,function_multi=True),
"amount": fields.Float("Due Amount",function="_get_total",readonly=True,function_multi=True),
'fee_partner_id': fields.Many2One("partner","Contact Fee"), 'fee_partner_id': fields.Many2One("partner","Contact Fee"),
"fee_amount": fields.Float("Fee",function="get_total",readonly=True,function_multi=True),
'fee_paid': fields.Boolean("Fee Paid"), 'fee_paid': fields.Boolean("Fee Paid"),
'note': fields.Text("Note"), 'note': fields.Text("Note"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"), "cycle_id": fields.Many2One("clinic.cycle","Cycle"),
@ -79,7 +115,8 @@ class HDCase(Model):
"total_nurse": fields.Integer("Total Nurse",function="get_staff",function_multi=True), "total_nurse": fields.Integer("Total Nurse",function="get_staff",function_multi=True),
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']],function="get_staff",function_multi=True), 'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']],function="get_staff",function_multi=True),
'nu': fields.Char("N/U"), 'nu': fields.Char("N/U"),
"invoice_policy": fields.Selection([("fee","Only fee"),("fee_med","Fee & Medicine")],"Invoice Policy"), "invoice_policy": fields.Selection([("fee","Only Fee"),("fee_mdc","Fee & Medicine")],"Government pay for:"),
"invoice_option": fields.Selection([("fee_mdc_plus","Combine Fee & Medicine"),("fee_mdc_split","Split Fee & Medicine")],"Invoice:"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):
@ -106,6 +143,8 @@ class HDCase(Model):
'hct': 0, 'hct': 0,
'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์", 'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์",
'fee_paid': False, 'fee_paid': False,
'invoice_option': 'fee',
'invoice_policy': 'fee',
} }
_order="date desc,number desc" _order="date desc,number desc"
@ -278,12 +317,13 @@ class HDCase(Model):
if not uom: if not uom:
raise Exception("Unit not found in uom") raise Exception("Unit not found in uom")
obj=self.browse(ids[0]) obj=self.browse(ids[0])
due_date=obj.date[0:10] due_date=obj.date[0:10] # XXX
# cash, credit # cash, credit
make_invoice=context.get('make_invoice',True) make_invoice=context.get('make_invoice',True)
context['type']='out' context['type']='out'
context['inv_type']='invoice' context['inv_type']='invoice'
fee_lines=[] fee_lines=[]
mdc_lines=[]
if obj.lines: if obj.lines:
vals={ vals={
"type": "out", "type": "out",
@ -301,6 +341,7 @@ class HDCase(Model):
if not partner: if not partner:
raise Exception("No contact for patient %s"%obj.patient_id.name) raise Exception("No contact for patient %s"%obj.patient_id.name)
vals["partner_id"]=partner.id vals["partner_id"]=partner.id
for line in obj.lines: for line in obj.lines:
if line.product_id: if line.product_id:
account_id=line.product_id.sale_account_id.id or account_receivable_id account_id=line.product_id.sale_account_id.id or account_receivable_id
@ -315,17 +356,27 @@ class HDCase(Model):
"amount": line.amount, "amount": line.amount,
'account_id': account_id, 'account_id': account_id,
} }
if obj.invoice_policy=='fee':
if line.type=='fee': if line.type=='fee':
fee_lines.append(inv_line) fee_lines.append(inv_line)
else: else:
vals['lines'].append(('create',inv_line)) vals['lines'].append(('create',inv_line))
elif obj.invoice_policy=='fee_mdc':
if line.type=='fee':
fee_lines.append(inv_line)
elif line.type=='medicine':
mdc_lines.append(inv_line)
else:
vals['lines'].append(('create',inv_line))
else:
vals['lines'].append(('create',inv_line))
if obj.amount and make_invoice: ## not pay yet if obj.amount and make_invoice: ## not pay yet
inv_id=get_model("account.invoice").create(vals,context) get_model("account.invoice").create(vals,context)
# create picking # check if type of product is stockable then create picking
obj.make_pickings() obj.make_pickings()
if fee_lines and not obj.fee_paid:
vals={ vals={
"type": "out", "type": "out",
"inv_type": "invoice", "inv_type": "invoice",
@ -338,20 +389,39 @@ class HDCase(Model):
"lines": [], "lines": [],
"company_id": company_id, "company_id": company_id,
} }
vals["partner_id"]=obj.fee_partner_id.id
if obj.invoice_option=='fee_mdc_plus':
fee_lines+=mdc_lines
mdc_lines=[]
if mdc_lines:
inv_vals=vals.copy()
inv_vals["partner_id"]=obj.fee_partner_id.id
account_id=account_receivable_id account_id=account_receivable_id
patient_type=obj.patient_id.type patient_type=obj.patient_id.type
if patient_type=='mg': if patient_type=='sc':
account_id=setting.ar_mg_id.id
elif patient_type=='sc':
account_id=setting.ar_sc_id.id account_id=setting.ar_sc_id.id
elif patient_type=='uc': elif patient_type=='uc':
account_id=setting.ar_uc.id account_id=setting.ar_uc_id.id
for mdc_line in mdc_lines:
mdc_line['account_id']=account_id
inv_vals['lines'].append(('create',mdc_line))
get_model("account.invoice").create(inv_vals,context)
if fee_lines and not obj.fee_paid:
inv_vals=vals.copy()
inv_vals["partner_id"]=obj.fee_partner_id.id
account_id=account_receivable_id
patient_type=obj.patient_id.type
if patient_type=='sc':
account_id=setting.ar_sc_id.id
elif patient_type=='uc':
account_id=setting.ar_uc_id.id
for fee_line in fee_lines: for fee_line in fee_lines:
fee_line['account_id']=account_id fee_line['account_id']=account_id
vals['lines'].append(('create',fee_line)) inv_vals['lines'].append(('create',fee_line))
inv_id=get_model("account.invoice").create(vals,context) get_model("account.invoice").create(inv_vals,context)
obj.write({ obj.write({
'fee_paid': True, 'fee_paid': True,
}) })
@ -485,40 +555,6 @@ class HDCase(Model):
'flash': '%s is completed'%obj.number, 'flash': '%s is completed'%obj.number,
} }
def journal_report(self,ids,context={}):
obj=self.browse(ids[0])
move_id = get_model("account.move").search([["narration","=",obj.number]])
if not move_id:
raise Exception("Order is not post or nove have jounal entry.")
return {
"next": {
"name": "journal_entry",
"mode":"form",
"active_id":move_id[0],
}
}
def get_total(self,ids,context={}):
vals={}
for obj in self.browse(ids):
total=0
due_amt=0
fee_amt=0
for line in obj.lines:
if line.type=='fee':
fee_amt+=line.amount or 0.0
total+=line.amount or 0.0
due_amt=total-fee_amt
for line in obj.payment_lines:
due_amt-=line.amount or 0.0
vals[obj.id]={
"total": total,
"amount": due_amt,
'fee_amount': fee_amt,
}
return vals
def delete(self,ids,context={}): def delete(self,ids,context={}):
for obj in self.browse(ids): for obj in self.browse(ids):
if obj.state != 'draft': if obj.state != 'draft':
@ -741,15 +777,66 @@ class HDCase(Model):
break break
return vals return vals
def get_invoice_policy(self,vals,patient_id=None):
if patient_id:
patient=get_model("clinic.patient").browse(patient_id)
st=get_model("clinic.setting").browse(1)
for pl in st.invoice_policies:
policy=pl.invoice_policy
patient_type=pl.patient_type
opt=pl.invoice_option
if patient.type==patient_type:
vals['invoice_policy']=policy
vals['invoice_option']=opt
break
return vals
def create(self,vals,**kw): def create(self,vals,**kw):
patient_id=vals['patient_id'] patient_id=vals['patient_id']
vals=self.get_staff_line(vals,patient_id) vals=self.get_staff_line(vals,patient_id)
vals=self.get_invoice_policy(vals,patient_id)
new_id=super().create(vals,**kw) new_id=super().create(vals,**kw)
return new_id return new_id
def write(self,ids,vals,**kw): def write(self,ids,vals,**kw):
patient_id=vals.get('patient_id') patient_id=vals.get('patient_id')
vals=self.get_staff_line(vals,patient_id) vals=self.get_staff_line(vals,patient_id)
vals=self.get_invoice_policy(vals,patient_id)
super().write(ids,vals,**kw) super().write(ids,vals,**kw)
def onchange_type(self,context={}):
data=self.onchange_policy(context)
return data
def onchange_policy(self,context={}):
data=context['data']
inv_pol=data['invoice_policy']
total=0.0
fee=0.0
mdc=0.0
due_amt=0.0
for line in data['lines']:
amt=line['amount'] or 0.0
total+=amt
ltype=line['type']
if ltype=='fee':
fee+=amt
elif ltype=='medicine':
mdc+=amt
elif ltype=='others':
pass
if inv_pol=='fee':
due_amt=total-fee
data['invoice_option']=''
elif inv_pol=='fee_mdc':
due_amt=total-fee-mdc
data['invoice_option']='fee_mdc_split'
else:
due_amt=total
data['total']=total
data['fee_amount']=fee
data['mdc_amount']=mdc
data['amount']=due_amt
return data
HDCase.register() HDCase.register()

View File

@ -48,7 +48,7 @@ class Patient(Model):
"app_no": fields.Char("Application No."), "app_no": fields.Char("Application No."),
"salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"), "salary": fields.Selection([["20000","5,001-20,000"],["50000","20,001-50,000"],["100000","50,001-100,000"],["100001","100,000+"]], "Salary"),
"addresses": fields.One2Many("address","patient_id","Addresses"), "addresses": fields.One2Many("address","patient_id","Addresses"),
"gender": fields.Selection([("male","Male"),("female","Female")],"Gender",required=False), "gender": fields.Selection([("male","Male"),("female","Female")],"Gender",search=True),
"marital_status": fields.Selection([("single","Single"),("marry","Marry"),("divorce","Divorce"),("separated","Saparated"),("widowed","Widowed")],"Marital Status",required=False), "marital_status": fields.Selection([("single","Single"),("marry","Marry"),("divorce","Divorce"),("separated","Saparated"),("widowed","Widowed")],"Marital Status",required=False),
"nation_id": fields.Many2One("clinic.nation","Nationality"), "nation_id": fields.Many2One("clinic.nation","Nationality"),
"race_id": fields.Many2One("clinic.race","Race"), "race_id": fields.Many2One("clinic.race","Race"),
@ -114,47 +114,6 @@ class Patient(Model):
} }
_order="resign_date desc,number desc" _order="resign_date desc,number desc"
def void(self,ids, context={}):
obj=self.browse(ids)[0]
obj.write({"state":"voided"})
def get_partner_id( self,patient_type,data):
partner_obj=get_model("partner")
categ_name=PATIENT_TYPE.get(patient_type)
categ_ids=get_model("partner.categ").search([['name','=',categ_name]])
if not categ_ids:
raise Exception("Category: %s not found"%categ_name)
partner_id=None
if patient_type in ("mg","sc","uc"):
partner_obj=get_model("partner")
for partner in partner_obj.search_browse([]):
if partner.categ_id.id in categ_ids:
partner_id=partner.id
print("Found partner ", partner.name, " ", partner.id)
break
if not partner_id:
name=data.get("name","")
partner_ids=partner_obj.search([['name','=',name]])
if not partner_ids:
partner_id=partner_obj.create({
'name': name,
'last_name': name,
'type': 'person'
})
print("create new partner ", name)
else:
partner_id=partner_ids[0]
return partner_id
def onchange_type(self,context={}):
data=context['data']
patient_type=data['type']
partner_id=None
if patient_type:
partner_id=self.get_partner_id(patient_type,data)
data['partner_id']=partner_id
return data
def create(self, vals,**kw): def create(self, vals,**kw):
obj_id=super(Patient,self).create(vals,**kw) obj_id=super(Patient,self).create(vals,**kw)
obj=self.browse(obj_id) obj=self.browse(obj_id)

View File

@ -7,7 +7,14 @@ class SettingPolicy(Model):
_fields={ _fields={
"setting_id": fields.Many2One("clinic.setting","Setting"), "setting_id": fields.Many2One("clinic.setting","Setting"),
"patient_type": fields.Selection([("sc","Social Security"),("uc","UC"),("others","Others")],"Type",required=True), "patient_type": fields.Selection([("sc","Social Security"),("uc","UC"),("others","Others")],"Type",required=True),
"invoice_policy": fields.Selection([("fee","Only fee"),("fee_med","Fee & Medicine")],"Invoice Policy"), "invoice_policy": fields.Selection([("fee","Only fee"),("fee_mdc","Fee & Medicine")],"Policy"),
"invoice_option": fields.Selection([("fee_mdc_plus","Combine Fee & Medicine"),("fee_mdc_split","Split Fee & Medicine")],"Option"),
} }
def _write(self,ids,vals,**kw):
obj=self.browse(ids)[0]
if obj.invoice_policy=='fee':
vals['invoice_option']=''
super().write(ids,vals,**kw)
SettingPolicy.register() SettingPolicy.register()

View File

@ -1,3 +1,5 @@
bug:
มีปัญหาการสร้าง address ของ contact จากผู้ป่วยโดยอัตโนมัติ เพราะมันไม่ได้ถูกเก็บไว้ที่ form
===== =====
first: first:
match payment match payment