diff --git a/netforce_clinic/layouts/clinic_cycle_item_copy.xml b/netforce_clinic/layouts/clinic_cycle_item_copy.xml
index 48e9ef3..5f56003 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_copy.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_copy.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_department_form.xml b/netforce_clinic/layouts/clinic_department_form.xml
index 2fb9510..43c8034 100644
--- a/netforce_clinic/layouts/clinic_department_form.xml
+++ b/netforce_clinic/layouts/clinic_department_form.xml
@@ -1,4 +1,9 @@
+
-
+
+
diff --git a/netforce_clinic/layouts/clinic_labor_cost_entry_list.xml b/netforce_clinic/layouts/clinic_labor_cost_entry_list.xml
index 0c1016f..a5d2069 100644
--- a/netforce_clinic/layouts/clinic_labor_cost_entry_list.xml
+++ b/netforce_clinic/layouts/clinic_labor_cost_entry_list.xml
@@ -1,5 +1,11 @@
-
-
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_labor_cost_list.xml b/netforce_clinic/layouts/clinic_labor_cost_list.xml
index 1f43dfa..e1ecbb8 100644
--- a/netforce_clinic/layouts/clinic_labor_cost_list.xml
+++ b/netforce_clinic/layouts/clinic_labor_cost_list.xml
@@ -1,5 +1,6 @@
+
diff --git a/netforce_clinic/layouts/clinic_menu_inherit.xml b/netforce_clinic/layouts/clinic_menu_inherit.xml
index a63136f..51b561d 100644
--- a/netforce_clinic/layouts/clinic_menu_inherit.xml
+++ b/netforce_clinic/layouts/clinic_menu_inherit.xml
@@ -1,11 +1,11 @@
-
-
-
-
+
+
-
-
+
+
diff --git a/netforce_clinic/layouts/clinic_pharmacy_form.xml b/netforce_clinic/layouts/clinic_pharmacy_form.xml
index 70e6c49..c4a24a6 100644
--- a/netforce_clinic/layouts/clinic_pharmacy_form.xml
+++ b/netforce_clinic/layouts/clinic_pharmacy_form.xml
@@ -10,21 +10,29 @@
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
@@ -33,8 +41,8 @@
+
-
diff --git a/netforce_clinic/layouts/clinic_pharmacy_list.xml b/netforce_clinic/layouts/clinic_pharmacy_list.xml
index 2b08b1d..d7750f5 100644
--- a/netforce_clinic/layouts/clinic_pharmacy_list.xml
+++ b/netforce_clinic/layouts/clinic_pharmacy_list.xml
@@ -2,6 +2,8 @@
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 91986da..6e3c2f1 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -91,3 +91,4 @@ from . import make_apt_line
from . import matching_payment
from . import pharmacy
from . import pharmacy_line
+from . import sale_order
diff --git a/netforce_clinic/models/labor_cost_entry.py b/netforce_clinic/models/labor_cost_entry.py
index 6ec1a92..f1d370b 100644
--- a/netforce_clinic/models/labor_cost_entry.py
+++ b/netforce_clinic/models/labor_cost_entry.py
@@ -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()
diff --git a/netforce_clinic/models/labor_cost_entry_line.py b/netforce_clinic/models/labor_cost_entry_line.py
index ee52e88..b0f2ccf 100644
--- a/netforce_clinic/models/labor_cost_entry_line.py
+++ b/netforce_clinic/models/labor_cost_entry_line.py
@@ -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"),
}
diff --git a/netforce_clinic/models/pharmacy.py b/netforce_clinic/models/pharmacy.py
index c4cbdaf..2b759cd 100644
--- a/netforce_clinic/models/pharmacy.py
+++ b/netforce_clinic/models/pharmacy.py
@@ -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',
}
diff --git a/netforce_clinic/models/sale_order.py b/netforce_clinic/models/sale_order.py
new file mode 100644
index 0000000..517c360
--- /dev/null
+++ b/netforce_clinic/models/sale_order.py
@@ -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()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 138c53a..ebfe714 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -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={}):
diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py
index f2f59b1..b277a5f 100644
--- a/netforce_clinic/models/visit_board.py
+++ b/netforce_clinic/models/visit_board.py
@@ -338,4 +338,5 @@ class VisitBoard(Model):
}
}
+
VisitBoard.register()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 32076ac..964a35f 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -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