nurse payment

conv_bal
watcha.h 2014-10-26 15:48:51 +07:00
parent 7d6240a247
commit 1ca2e62554
20 changed files with 309 additions and 24 deletions

View File

@ -0,0 +1,7 @@
<action>
<field name="string">Cycle Items</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.cycle.item</field>
<field name="modes">list,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -0,0 +1,7 @@
<action>
<field name="string">Nurse Categories</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.nurse.categ</field>
<field name="modes">list,page,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -6,10 +6,8 @@
<field name="name"/> <field name="name"/>
<field name="duration"/> <field name="duration"/>
<field name="sequence"/> <field name="sequence"/>
<separator string="Labor Cost"/>
<field name="var_k"/>
<field name="var_x"/>
<related> <related>
<field name="cycle_items"/>
<field name="visits"/> <field name="visits"/>
<field name="hd_cases"/> <field name="hd_cases"/>
</related> </related>

View File

@ -0,0 +1,34 @@
<form model="clinic.cycle.item" attrs='{"readonly":[["state","in",["done"]]]}' show_company="1">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Create Journal" method="create_journal" states="draft"/>
</button>
</head>
<field name="cycle_id" required="1"/>
<field name="date"/>
<field name="var_k"/>
<field name="var_x"/>
<field name="total_pt"/>
<field name="total_amount"/>
<field name="lines" nolabel="1">
<list>
<field name="nurse_categ"/>
<field name="formular"/>
<field name="qty"/>
<field name="rate"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
</group>
<foot>
<button string="Compute" type="default" icon="refresh" method="compute" states="draft"/>
</foot>
<related>
<field name="hd_cases"/>
</related>
</form>

View File

@ -0,0 +1,6 @@
<list model="clinic.cycle.item">
<field name="cycle_id" required="1"/>
<field name="date"/>
<field name="var_k"/>
<field name="var_x"/>
</list>

View File

@ -3,6 +3,9 @@
<item string="Personals"> <item string="Personals">
<item string="Doctors" action="clinic_doctor"/> <item string="Doctors" action="clinic_doctor"/>
<item string="Nurses" action="clinic_nurse"/> <item string="Nurses" action="clinic_nurse"/>
<divider/>
<header string="CATEGORIES"/>
<item string="Nurse Categories" action="clinic_nurse_categ"/>
</item> </item>
<item string="Patients"> <item string="Patients">
<item string="Patients" action="clinic_patient"/> <item string="Patients" action="clinic_patient"/>
@ -16,7 +19,10 @@
<item string="Comorbidities" action="clinic_comorbidity"/> <item string="Comorbidities" action="clinic_comorbidity"/>
<item string="Morbidities" action="clinic_morbidity"/> <item string="Morbidities" action="clinic_morbidity"/>
</item> </item>
<item string="Cycles">
<item string="Cycles" action="clinic_cycle"/> <item string="Cycles" action="clinic_cycle"/>
<item string="Cycle Items" action="clinic_cycle_item"/>
</item>
<item string="Visits" action="clinic_visit"/> <item string="Visits" action="clinic_visit"/>
<item string="Treatments" action="clinic_hd_case"/> <item string="Treatments" action="clinic_hd_case"/>
<item string="Reports"> <item string="Reports">
@ -26,7 +32,7 @@
<header string="HD Madical"/> <header string="HD Madical"/>
<item string="Madical Summary" action="clinic_report_hd_madical"/> <item string="Madical Summary" action="clinic_report_hd_madical"/>
<header string="REPORT SETTINGS"/> <header string="REPORT SETTINGS"/>
<item string="Translate" action="clinic_translate"/> <item string="Topics" action="clinic_translate"/>
</item> </item>
<item string="Settings"> <item string="Settings">
<item string="Departments" action="clinic_department"/> <item string="Departments" action="clinic_department"/>

View File

@ -0,0 +1,6 @@
<form model="clinic.nurse.categ">
<field name="code"/>
<field name="name"/>
<field name="formular"/>
<field name="sequence"/>
</form>

View File

@ -0,0 +1,6 @@
<list model="clinic.nurse.categ">
<field name="code"/>
<field name="name"/>
<field name="formular"/>
<field name="sequence"/>
</list>

View File

@ -1,2 +1,4 @@
<form model="clinic.setting" title="Clinic Settings"> <form model="clinic.setting" title="Clinic Settings">
<separator string="Labor Cost"/>
<field name="var_k"/>
</form> </form>

View File

@ -0,0 +1,53 @@
import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class CycleItem(Model):
_name="clinic.cycle.item"
_string="Cycle Item"
def _get_x(self,ids,context):
res={}
for obj in self.browse(ids):
hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
pt=(hd_total or 0.0)
k=(obj.var_k or 0.0)
pt_k=pt*k
x=(pt_k + 1275)/13.5
res[obj.id]=x
return res
_fields={
'company_id': fields.Many2One("company", "Company"),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
'date': fields.Date("Date",search=True),
'var_k': fields.Float("K"),
'var_x': fields.Float("X", function="_get_x"),
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
'lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Lines'),
}
_defaults={
'state': 'draft',
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'var_k': 450,
}
def compute(self,ids,context={}):
for obj in self.browse(ids):
nurer_categ_ids=[line.nurse_categ.id for line in obj.lines]
vals={
'lines': [],
}
for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
vals['lines'].append(('create',{
'nurse_categ': nurse_categ.id,
'formular': nurse_categ.formular or "",
'qty': 1,
}))
pass
obj.write(vals)
CycleItem.register()

View File

@ -7,6 +7,7 @@ from . import graduation
from . import morbidity from . import morbidity
from . import nation from . import nation
from . import nurse from . import nurse
from . import nurse_categ
from . import address from . import address
from . import patient from . import patient
from . import patient_cause_line from . import patient_cause_line
@ -27,6 +28,8 @@ from . import dialyzer_line
from . import import_payment from . import import_payment
from . import file_sheet from . import file_sheet
from . import cycle from . import cycle
from . import cycle_item
from . import cycle_item_line
from . import gen_visit from . import gen_visit
from . import gen_visit_line from . import gen_visit_line
from . import report_hd_detail from . import report_hd_detail

View File

@ -12,9 +12,8 @@ class Cycle(Model):
'company_id': fields.Many2One("company", "Company"), 'company_id': fields.Many2One("company", "Company"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"), 'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"),
'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"), 'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"),
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
'var_k': fields.Float("K"), 'var_k': fields.Float("K"),
'var_x': fields.Float("X"),
} }
_defaults={ _defaults={

View File

@ -0,0 +1,96 @@
import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class CycleItem(Model):
_name="clinic.cycle.item"
_string="Cycle Item"
def _get_all(self,ids,context):
res={}
for obj in self.browse(ids):
hd_total=len([hd_case for hd_case in obj.hd_cases if hd_case.state=='completed']) # XXX
pt=(hd_total or 0.0)
k=(obj.var_k or 0.0)
pt_k=pt*k
x=(pt_k + 1275)/13.5
total=0.0
for line in obj.lines:
total+=line.amount
res[obj.id]={
'var_x': x,
'total_pt': hd_total,
'total_amount': hd_total*k,
'total': total,
}
return res
_fields={
'company_id': fields.Many2One("company", "Company"),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
'date': fields.Date("Date",search=True),
'var_k': fields.Float("K"),
'var_x': fields.Float("X", function="_get_all",function_multi=True),
'total_pt': fields.Float("PT", function="_get_all",function_multi=True),
'total_amount': fields.Float("PT*K", function="_get_all",function_multi=True),
'total': fields.Float("Total", function="_get_all",function_multi=True),
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
'lines': fields.One2Many('clinic.cycle.item.line', 'cycle_item_id', 'Lines'),
}
_defaults={
'state': 'draft',
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
'var_k': 450,
}
def compute(self,ids,context={}):
for obj in self.browse(ids):
#nurer_categ_ids=[line.nurse_categ.id for line in obj.lines]
# XXX
vals_dict={}
for hd_case in obj.hd_cases:
if hd_case.state=='completed':
nurse_code=hd_case.nurse_id.categ_id.code or ""
print("nurse_code ", nurse_code)
if not vals_dict.get(nurse_code):
vals_dict[nurse_code]=0
vals_dict[nurse_code]+=1
for line in obj.lines:
line.delete()
vals={
'lines': [],
}
print(vals_dict)
for nurse_categ in get_model("clinic.nurse.categ").search_browse([]):
formular=nurse_categ.formular or ""
rate=0
try:
var_x="%s"%(round(obj.var_x,2))
formulared=formular.replace("x",var_x)
rate=eval(formulared)
except:
rate=0
vals['lines'].append(('create',{
'nurse_categ': nurse_categ.id,
'formular': formular,
'qty': vals_dict.get(nurse_categ.code,0),
'rate': rate,
}))
obj.write(vals)
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': obj.id,
},
'flash': 'Compute OK',
}
CycleItem.register()

View File

@ -0,0 +1,31 @@
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class CycleItemLine(Model):
_name="clinic.cycle.item.line"
_string="Cycle Item Line"
def all_amount(self,ids,context={}):
res={}
for obj in self.browse(ids):
res[obj.id]={
'amount': (obj.qty or 0) * (obj.rate or 0.0),
}
return res
_fields={
'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
'nurse_categ': fields.Many2One("clinic.nurse.categ", "Nurse Category"),
'formular': fields.Char("Formular", size=100),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate"),
'amount': fields.Float("Amount",function="all_amount", function_multi=True),
'company_id': fields.Many2One('company','Company'),
}
_defaults={
"company_id": lambda *a: get_active_company(),
}
CycleItemLine.register()

View File

@ -133,6 +133,7 @@ class GenVisit(Model):
dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')]) dom.append(['time_start','>=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')]) dom.append(['time_stop','<=','%s %s'%(tmp.strftime(FMT_DATE)[0:10],' 23:59:59')])
dom.append(['patient_id', '=', line.patient_id.id]) dom.append(['patient_id', '=', line.patient_id.id])
dom.append(['cycle_id', '=', obj.cycle_id.id]) #XXX
dom.append(['state','=','draft']) dom.append(['state','=','draft'])
vids=visit_obj.search(dom) vids=visit_obj.search(dom)
visit_obj.delete(vids) visit_obj.delete(vids)

View File

@ -68,6 +68,7 @@ class HDCase(Model):
'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"),
"cycle_item_id": fields.Many2One("clinic.cycle.item","Cycle Item"), # compute labor cost
'pay_amount': fields.Float("Amount",function="get_pay_amount"), 'pay_amount': fields.Float("Amount",function="get_pay_amount"),
'pay_date': fields.Date("Pay Date"), 'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"), 'pay_account_id': fields.Many2One("account.account","Account"),
@ -462,11 +463,30 @@ class HDCase(Model):
}) })
return True return True
def create_cycle_item(self,ids,context={}):
for obj in self.browse(ids):
cycle_item=get_model("clinic.cycle.item")
datenow=time.strftime('%Y-%m-%d')
cycle_id=obj.cycle_id.id
cycle_item_ids=cycle_item.search([['date','=',datenow],['cycle_id','=',cycle_id]])
cycle_item_id=None
if cycle_item_ids:
cycle_item_id=cycle_item_ids[0]
else:
cycle_item_id=cycle_item.create({
'cycle_id': obj.cycle_id.id,
})
obj.write({
'cycle_item_id': cycle_item_id,
})
return True
def complete(self,ids,context={}): def complete(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
obj.make_invoices() obj.make_invoices()
obj.post_invoices() obj.post_invoices()
obj.update_usetime() obj.update_usetime()
obj.create_cycle_item()
obj.write({ obj.write({
"state":"completed", "state":"completed",
}) })
@ -551,6 +571,7 @@ class HDCase(Model):
payment.delete() payment.delete()
for pm_line in obj.payment_lines: for pm_line in obj.payment_lines:
pm_line.delete() pm_line.delete()
state=context.get("state","in_progress") #force state state=context.get("state","in_progress") #force state
obj.write({ obj.write({
'state': state, 'state': state,

View File

@ -51,6 +51,7 @@ class HDCasePayment(Model):
if obj.pay_amount: if obj.pay_amount:
hd_case.make_payment(context=context) hd_case.make_payment(context=context)
if obj.complete: if obj.complete:
hd_case.create_cycle_item()
hd_case.write({ hd_case.write({
'state': 'completed', 'state': 'completed',
}) })
@ -71,6 +72,7 @@ class HDCasePayment(Model):
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id) hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.make_invoices() hd_case.make_invoices()
hd_case.post_invoices() hd_case.post_invoices()
hd_case.create_cycle_item()
#if obj.complete: #if obj.complete:
hd_case.write({ hd_case.write({
'state': 'completed', 'state': 'completed',

View File

@ -44,7 +44,7 @@ class Nurse(Model):
"user_id": fields.Many2One("base.user","User"), "user_id": fields.Many2One("base.user","User"),
'picture': fields.File("Picture"), 'picture': fields.File("Picture"),
'note': fields.Text("Note"), 'note': fields.Text("Note"),
'categ_id': fields.Many2One("product.categ","Category"), 'categ_id': fields.Many2One("clinic.nurse.categ","Category"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):

View File

@ -0,0 +1,22 @@
from netforce.model import Model, fields
from netforce.access import get_active_company
class NurseCateg(Model):
_name="clinic.nurse.categ"
_string="Nurse Categ"
_fields={
"name": fields.Char("Name",required=True,search=True),
"code": fields.Char("Code",required=True,search=True),
'formular': fields.Text("Formular"),
'sequence': fields.Integer("Sequence"),
}
_defaults={
"company_id": lambda *a: get_active_company(),
'sequence': 0,
}
_order="sequence"
NurseCateg.register()

View File

@ -1,25 +1,10 @@
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
from netforce.access import get_active_company
class ClinicSetting(Model): class ClinicSetting(Model):
_name="clinic.setting" _name="clinic.setting"
_string="Setting" _string="Setting"
_fields={ _fields={
"mg_partner_id": fields.Many2One("partner","Partner Medical Govement"), "var_k": fields.Float("K"),
"ar_mg_id": fields.Many2One("account.account","Account Receivable Medical Govement"),
"ap_mg_id": fields.Many2One("account.account","Account Payment Medical Govement"),
"nhso_partner_id": fields.Many2One("partner","Partner NHSO 30B"),
"ar_nhso_id": fields.Many2One("account.account","Account Receiveble NHSO 30B"),
"ap_nhso_id": fields.Many2One("account.account","Account Payment NHSO 30B"),
"sc_partner_id": fields.Many2One("partner","Partner Social Security"),
"ar_sc_id": fields.Many2One("account.account","Account Receiveble Social Security"),
"ap_sc_id": fields.Many2One("account.account","Account Payment Social Security"),
#"ori_str": fields.Char("ori_str","Original String"),
#"translate": fields.Char("translate","Translation"),
} }
ClinicSetting.register() ClinicSetting.register()