labor cost + pharmacy

conv_bal
watcha.h@almacom.co.th 2015-01-22 17:40:05 +07:00
parent 2323d058b9
commit e5171ba0d7
17 changed files with 184 additions and 58 deletions

View File

@ -4,7 +4,7 @@
<field name="item_copy_id" domain='[["department_id","=",department_id]]' onchange="onchange_item" attrs='{"required":[["choice","=","item"]]}' span="4"/>
<field name="schd_copy_id" domain='[["department_id","=",department_id]]' onchange="onchange_item" attrs='{"required":[["choice","=","schd"]]}' span="4"/>
<field name="cycle_item_id" span="2" invisible="1"/>
<field name="department_id" span="2" invisible="1"/>
<field name="department_id" span="3" invisible="1"/>
</group>
<field name="lines" nolabel="1">
<list noadd="1">

View File

@ -1,4 +1,9 @@
<form model="clinic.department" show_company="1">
<head>
<button string="Options" dropdown="1">
<!--<item string='Create Sickbed' action="clinic_create_sickbed"/>-->
</button>
</head>
<field name="name"/>
<field name="code"/>
<field name="parent_id"/>

View File

@ -1,4 +1,4 @@
<form model="clinic.hd.case" attrs='{"readonly":[["state","in",["cancelled","paid"]]]}' show_company="1">
<form model="clinic.hd.case" attrs='{"readonly":[["state","in",["cancelled","paid","waiting_payment"]]]}' show_company="1">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
@ -12,10 +12,10 @@
<field name="patient_id" span="2" onchange="onchange_patient"/>
<field name="patient_type_id" span="2"/>
<field name="cycle_id" span="2" required="1" onchange="onchange_cycle"/>
<field name="department_id" span="2"/>
<field name="cycle_item_id" span="2" domain="[['cycle_id','=',cycle_id]]"/>
<field name="visit_id" span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" span="2"/>
<field name="req_fee" span="2" invisible="1"/>
<field name="company_id" span="2" invisible="1"/> <!-- to show company name, don't remove -->
<field name="hct_include" span="2" invisible="1"/>

View File

@ -2,33 +2,49 @@
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Create Journal Entry"/>
<!--<item string="Create Journal Entry"/>-->
<item string="TODO"/>
</button>
</head>
<field name="date" span="3" mode="month"/>
<group form_layout="stacked">
<!--<field name="name" span="2"/>-->
<field name="date" onchange="onchange_date" mode="month" span="2"/>
<field name="date_from" span="2"/>
<field name="date_to" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
</group>
<tabs>
<tab string="General">
<field name="lines" nolabel="1">
<tab string="Doctors">
<field name="doctor_lines" nolabel="1">
<list>
<field name="staff_id"/>
<field name="type"/>
<field name="department_id"/>
<field name="qty" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</list>
<form>
</field>
<field name="dcost" string="Total" span="3" offset="9"/>
</tab>
<tab string="Nurses">
<field name="nurse_lines" nolabel="1">
<list>
<field name="staff_id"/>
<field name="type"/>
<field name="qty"/>
<field name="rate"/>
<field name="department_id"/>
<field name="qty" string="PT" onchange="onchange_line"/>
<field name="rate" onchange="onchange_line"/>
<field name="amount"/>
</form>
</list>
</field>
<field name="total_amt" span="3" offset="9"/>
<field name="ncost" string="Total" span="3" offset="9"/>
</tab>
<tab string="Approval">
<group form_layout="stacked">
<field name="user_id" span="3"/>
<button string="Approve" icon="ok" size="small"/>
</group>
</tab>
<tab string="Note">

View File

@ -1,5 +1,11 @@
<list model="clinic.labor.cost.entry" colors='{"#cfc":[["state","=","approved"]],"#dbdbdb":[["state","=","cancelled"]]}'>
<field name="name"/>
<field name="note"/>
<!--<field name="name"/>-->
<field name="date_from"/>
<field name="date_to"/>
<field name="branch_id"/>
<field name="department_id"/>
<field name="dcost"/>
<field name="ncost"/>
<field name="total"/>
<field name="state"/>
</list>

View File

@ -1,5 +1,6 @@
<list model="clinic.labor.cost">
<field name="cycle_item_id"/>
<field name="var_pt"/>
<field name="total_dcost"/>
<field name="total_ncost"/>
<!--<field name="total_stcost"/>-->

View File

@ -1,11 +1,11 @@
<inherit inherit="account_menu">
<item string="Settings" position="before">
<item string="Ratchawat">
<item string="Labor Cost" action="clinic_labor_cost"/>
<item string="Labor Cost Items" action="clinic_labor_cost_item"/>
<item string="Labor Costs" action="clinic_labor_cost"/>
<!--<item string="Labor Cost Items" action="clinic_labor_cost_item" perm="clinic_labor_cost_item"/>-->
<item string="Labor Cost Entries" action="clinic_labor_cost_entry"/>
<item string="Matching Payment(Old)" action="clinic_report_payment_matching"/>
<item string="Matching Payment" action="clinic_matching_payment"/>
<!--<item string="Matching Payment(Old)" action="clinic_report_payment_matching"/>-->
<item string="Matching Payments" action="clinic_matching_payment"/>
<item string="HD Case Expenses" action="clinic_hd_case_expense"/>
<divider/>
<header string="REPORTS"/>

View File

@ -10,6 +10,10 @@
<field name="date" span="2"/>
<field name="patient_id" required='1' span="2"/>
<field name="ref" span="2"/>
<field name="branch_id" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<tabs>
<tab string="General">
<field name="lines" nolabel="1">
<list>
<field name="product_id" onchange="onchange_product"/>
@ -20,11 +24,15 @@
<field name="amount"/>
</list>
</field>
</group>
<group span="9" columns="1">
</tab>
<tab string="Other">
<group form_layout="stacked">
<field name="user_id" span="3"/>
</group>
</tab>
</tabs>
</group>
<group span="9" columns="1">
</group>
<group span="3" columns="1">
<field name="total"/>
@ -33,8 +41,8 @@
<button string="Pay" type="success"/>
</foot>
<related>
<field name="orders"/>
<field name="invoices"/>
<field name="payments"/>
<field name="pickings"/>
</related>
</form>

View File

@ -2,6 +2,8 @@
<field name="number"/>
<field name="date"/>
<field name="patient_id"/>
<field name="branch_id"/>
<field name="department_id"/>
<field name="user_id"/>
<field name="state"/>
</list>

View File

@ -91,3 +91,4 @@ from . import make_apt_line
from . import matching_payment
from . import pharmacy
from . import pharmacy_line
from . import sale_order

View File

@ -1,4 +1,5 @@
import time
from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.database import get_connection
@ -11,53 +12,99 @@ class LaborCostEntry(Model):
_name="clinic.labor.cost.entry"
_string="Labor Cost Entry"
_multi_company=True
_key=['name']
#_key=['name']
def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
total_amt=0.0
total=0.0
total_qty=0
dcost=0
ncost=0
for line in obj.lines:
total_qty+=line.qty or 0
total_amt+=line.amount or 0.0
amt=line.amount or 0
qty=line.qty or 0
if line.type=='nurse':
ncost+=amt
else:
dcost+=amt
total_qty+=qty
total+=amt
res[obj.id]={
'total_amt':total_amt,
'total':total,
'total_qty': total_qty,
'dcost': dcost,
'ncost': ncost,
}
return res
_fields={
'name': fields.Char("Name", search=True),
'name': fields.Char("Name", required=True,search=True),
'date': fields.Date("Month",required=True),
'total_amt': fields.Float("Total", function="_get_all",function_multi=True),
'date_from': fields.Date("From",required=True),
'date_to': fields.Date("To",required=True),
'total': fields.Float("Total (Baht)", function="_get_all",function_multi=True),
'total_qty': fields.Float("Total Qty", function="_get_all",function_multi=True),
'dcost': fields.Float("Doctor Cost", function="_get_all",function_multi=True),
'ncost': fields.Float("Nurse Cost", function="_get_all",function_multi=True),
"lines": fields.One2Many("clinic.labor.cost.entry.line", "entry_id", "Lines"),
"nurse_lines": fields.One2Many("clinic.labor.cost.entry.line", "entry_id", "Nurse Lines",domain=[['type','=','nurse']]),
"doctor_lines": fields.One2Many("clinic.labor.cost.entry.line", "entry_id", "Doctor Lines",domain=[['type','=','doctor']]),
'state': fields.Selection([['draft','Draft'],['approved','Approved']],"State"),
'user_id': fields.Many2One("base.user","Approver"),
'user_id': fields.Many2One("base.user","Approver",search=True),
'note': fields.Text("Note"),
'company_id': fields.Many2One("company","Company"),
'department_id': fields.Many2One("clinic.department","Department",search=True),
'branch_id': fields.Many2One("clinic.branch","Branch",search=True),
}
def _get_date_from(self,context={}):
year,month=time.strftime("%Y-%m").split("-")
return '%s-%s-01'%(year,month)
def _get_date_to(self,context={}):
year,month,day=time.strftime("%Y-%m-%d").split("-")
weekday, total_day=monthrange(int(year), int(month))
return "%s-%s-%s"%(year,month,total_day)
_defaults={
'state': 'draft',
'name': '/',
'date': lambda *a: time.strftime("%Y-%m-%d"),
'date_from': _get_date_from,
'date_to': _get_date_to,
'user_id': lambda *a: get_active_user(),
'company_id': lambda *a: get_active_company(),
}
_order="date_from desc,branch_id,department_id"
def compute(self,ids,context={}):
obj=self.browse(ids)[0]
year,month,day=obj.date.split("-")
db=get_connection()
line_ids=[r['id'] for r in db.query("select id from clinic_labor_cost_line where extract(month from date)=%s",int(month))]
line_ids=[]
dom=[
['date','>=',obj.date_from],
['date','<=',obj.date_to],
]
if obj.branch_id:
dom.append(['labor_cost_id.cycle_item_id.branch_id','=',obj.branch_id.id])
if obj.department_id:
dom.append(['labor_cost_id.cycle_item_id.department_id','=',obj.department_id.id])
for lc_id in get_model("clinic.labor.cost.line").search(dom):
line_ids.append(lc_id)
staffs={}
for line in get_model("clinic.labor.cost.line").browse(line_ids):
staff=line.staff_id
qty=line.qty
amt=line.amount
dpt=staff.department_id
if not dpt:
dpt=line.labor_cost_id.cycle_item_id.department_id
if not staffs.get(staff.id):
staffs[staff.id]={
'department_id': dpt.id,
'qty': 0,
'amt': 0,
'rate': 0, # XXX for special nurse
@ -79,6 +126,7 @@ class LaborCostEntry(Model):
'amount': amt,
'date': timenow,
'rate': rate,
'department_id': vals['department_id'],
}))
for line in obj.lines:
@ -110,14 +158,6 @@ class LaborCostEntry(Model):
vals['name']=utils.date2thai(obj.date,format='%(BY)s/%(m)s')
super().write(ids,vals,**kw)
def onchange_line(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
data=self.update_amount(context)
return data
def update_amount(self,context={}):
data=context['data']
total_amt=0.0
@ -126,4 +166,26 @@ class LaborCostEntry(Model):
data['total_amt']=total_amt
return data
def onchange_date(self,context={}):
data=context['data']
date=data['date']
year,month,day=date.split("-")
weekday, total_day=monthrange(int(year), int(month))
data['date_from']="%s-%s-01"%(year,month)
data['date_to']="%s-%s-%s"%(year,month,total_day)
return data
def onchange_line(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
line['amount']=(line['qty'] or 0) * (line['rate'] or 0.0)
data=self.update_amount(context)
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
LaborCostEntry.register()

View File

@ -17,6 +17,7 @@ class LaborCostEntryLine(Model):
'rate': fields.Float("Rate Avg."),
'amount': fields.Float("Amount"),
'company_id': fields.Many2One("company","Company"),
'department_id': fields.Many2One("clinic.department","Department"),
"type": fields.Selection([['staff','Staff'],["doctor","Doctor"],["nurse","Nurse"]],"Type"),
}

View File

@ -21,19 +21,33 @@ class Pharmacy(Model):
"ref": fields.Char("Ref",search=True),
'date': fields.Date("Date",search=True),
'patient_id': fields.Many2One('clinic.patient','Patient',search=True),
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'lines': fields.One2Many('clinic.pharmacy.line','pharmacy_id','Lines'),
'total': fields.Float("Total",function="_get_all",function_multi=True),
'user_id': fields.Many2One("base.user","Pharmacist"),
'state': fields.Selection([['draft','Draft'],['waiting_payment','Waiting Payment'],['paid','Paid']],'State'),
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
"invoices": fields.One2Many("account.invoice","related_id","Invoices"),
"payments": fields.One2Many("account.payment","related_id","Payments"),
"orders": fields.One2Many("sale.order","pharmacy_id","Orders"),
}
def _get_branch(self,context={}):
b_ids=get_model('clinic.branch').search([])
if b_ids:
return b_ids[0]
def _get_department(self,context={}):
dpt_ids=get_model('clinic.department').search([])
if dpt_ids:
return dpt_ids[0]
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d"),
'number': '/',
'date': lambda *a: time.strftime("%Y-%m-%d"),
'user_id': lambda *a: get_active_user(),
'branch_id': _get_branch,
'department_id': _get_department,
'state': 'draft',
}

View File

@ -0,0 +1,10 @@
from netforce.model import Model, fields
class SaleOrder(Model):
_inherit="sale.order"
_fields={
"pharmacy_id": fields.Many2One("clinic.pharmacy","Pharmacy"),
}
SaleOrder.register()

View File

@ -91,10 +91,8 @@ class ClinicSetting(Model):
return True
def run_script(self,ids,context={}):
db=get_connection
for item in get_model("clinic.cycle.item").search_browse([]):
res=db.query('select create_time from clinic_cycle_item')
print(res)
db=get_connection()
db.execute('update clinic_cycle_item set date_validate=write_time;')
print("Done!")
def reset_last_import(self,ids,context={}):

View File

@ -338,4 +338,5 @@ class VisitBoard(Model):
}
}
VisitBoard.register()

View File

@ -2,10 +2,11 @@ todo:
- report
- doctor labort cost detail ***
- matching payment ***
- popup messagging -> Ask DJ
- modify message of log -> Ask DJ
- show image of staff
- copy old nurse from previous cycle item -> fixing
- show image of staff ->
- copy old nurse from previous cycle item -> ok
- multi confirm on visit board **** -> ok
=======
generate visit ใหม่ -> ok