diff --git a/netforce_clinic/actions/clinic_report_account_shop.xml b/netforce_clinic/actions/clinic_report_account_shop.xml new file mode 100644 index 0000000..dd48fe1 --- /dev/null +++ b/netforce_clinic/actions/clinic_report_account_shop.xml @@ -0,0 +1,8 @@ + + Report Shop + report + clinic.report.shop + report_shop + report_shop + account_menu + diff --git a/netforce_clinic/actions/clinic_report_shop.xml b/netforce_clinic/actions/clinic_report_shop.xml new file mode 100644 index 0000000..f831b6a --- /dev/null +++ b/netforce_clinic/actions/clinic_report_shop.xml @@ -0,0 +1,8 @@ + + Report Shop + report + clinic.report.shop + report_shop + report_shop + clinic_menu + diff --git a/netforce_clinic/layouts/clinic_account_menu.xml b/netforce_clinic/layouts/clinic_account_menu.xml index 614404b..f6558c2 100644 --- a/netforce_clinic/layouts/clinic_account_menu.xml +++ b/netforce_clinic/layouts/clinic_account_menu.xml @@ -8,6 +8,7 @@
+ diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml index f588be3..42a4826 100644 --- a/netforce_clinic/layouts/clinic_menu.xml +++ b/netforce_clinic/layouts/clinic_menu.xml @@ -46,6 +46,7 @@ + diff --git a/netforce_clinic/layouts/clinic_report_shop.xml b/netforce_clinic/layouts/clinic_report_shop.xml new file mode 100644 index 0000000..44d9fca --- /dev/null +++ b/netforce_clinic/layouts/clinic_report_shop.xml @@ -0,0 +1,8 @@ +
+ + + + + + + diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index a1a7d1f..9d8f5fa 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -124,3 +124,4 @@ from . import name_title from . import compute_labor_cost from . import login from . import sequence +from . import report_shop diff --git a/netforce_clinic/models/report_shop.py b/netforce_clinic/models/report_shop.py new file mode 100644 index 0000000..d3d88a9 --- /dev/null +++ b/netforce_clinic/models/report_shop.py @@ -0,0 +1,147 @@ +import time +from calendar import monthrange + +from netforce.model import Model, fields, get_model +from netforce.access import get_active_company + +class ReportShop(Model): + _name="clinic.report.shop" + _string="Report Shop" + _transient=True + + _fields={ + "date": fields.Date("Month", required=True), + "date_from": fields.Date("From", required=True), + "date_to": fields.Date("To", required=True), + 'branch_id': fields.Many2One("clinic.branch","Branch"), + 'department_id': fields.Many2One("clinic.department","Departments"), + 'product_id': fields.Many2One("product","Product"), + } + + def default_get(self,field_names=None,context={},**kw): + defaults=context.get("defaults",{}) + date=defaults.get('date',time.strftime("%Y-%m-%d")) + year,month=time.strftime("%Y-%m").split("-") + weekday, total_day=monthrange(int(year), int(month)) + date_from=defaults.get('date_from','%s-%s-01'%(year,month)) + date_to=defaults.get('date_to',"%s-%s-%s"%(year,month,total_day)) + date_from=defaults.get('date',date) + date_to=defaults.get('date',date) + product_id=defaults.get('product_id') + + branch_id=defaults.get('branch_id',None) + print('defaults ', defaults) + if branch_id: + branch_id=int(branch_id) + department_id=defaults.get('department_id',None) + if department_id: + department_id=int(department_id) + select_dpt=get_model('select.company').get_select() + print('select_dpt ', select_dpt) + if select_dpt: + if not branch_id: + branch_id=select_dpt['branch_id'] + if not department_id: + if select_dpt.get('department_ids'): + department_id=select_dpt['department_ids'][0] + else: + department_id=select_dpt['department_id'] + res={ + 'date': date, + 'date_from': date_from, + 'date_to': date_to, + 'branch_id': branch_id, + 'department_id': department_id, + 'product_id': product_id, + } + return res + + def get_report_data(self,ids,context={}): + company_id=get_active_company() + company=get_model("company").browse(company_id) + defaults=self.default_get(context=context) + date_from=defaults.get("date_from") + date_to=defaults.get("date_to") + date=defaults.get("date") + branch_id=defaults.get("branch_id") + department_id=defaults.get("department_id") + product_id=defaults.get('product_id') + if ids: + obj=self.browse(ids)[0] + branch_id=obj.branch_id.id + department_id=obj.department_id.id + date=obj.date + date_from=obj.date_from + date_to=obj.date_to + product_id=obj.product_id.id + ctx={ + 'date_from': date_from, + 'date_to': date_to, + 'branch_id': branch_id, + 'department_id': department_id, + 'product_id': product_id, + } + lines=get_model('clinic.shop').get_shop_data(context=ctx)['records'] + company_name=company.name or "" + if department_id: + company_name+=' (%s)'%get_model('clinic.department').browse(department_id).name or "" + elif branch_id: + company_name+=' (%s)'%get_model('clinic.branch').browse(branch_id).name or "" + total_fee=0 + total_srv=0 + total_epo=0 + total_lab=0 + total_dlz=0 + total_misc=0 + total_mdc=0 + slines=[] + no=1 + for line in sorted(lines, key=lambda x: (x['date'])): + total_fee+=line.get('fee',0) + total_srv+=line.get('srv',0) + total_epo+=line.get('epo',0) + total_mdc+=line.get('mdc',0) + total_lab+=line.get('lab',0) + total_misc+=line.get('misc',0) + total_dlz+=line.get('dlz_price',0) + line['no']=no + slines.append(line) + no+=1 + data={ + 'company_name': company_name, + 'branch_id': branch_id, + 'department_id': department_id, + 'date': date, + 'date_from': date_from, + 'date_to': date_to, + 'lines': slines, + 'total_fee': total_fee, + 'total_srv': total_srv, + 'total_epo': total_epo, + 'total_mdc': total_mdc, + 'total_lab': total_lab, + 'total_misc': total_misc, + 'total_dlz': total_dlz, + } + 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_branch(self,context={}): + data=context['data'] + data['department_id']=None + return data + + def onchange_datefrom(self,context={}): + data=context['data'] + data['date_to']=data['date_from'] + return data + +ReportShop.register() diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py index b015843..a73a922 100644 --- a/netforce_clinic/models/shop.py +++ b/netforce_clinic/models/shop.py @@ -816,6 +816,11 @@ class Shop(Model): ['date','<=',context['date_to']], ['state','not in',['draft','cancelled']], ] + product_id=context.get('product_id') + if product_id: + dom.append([ + 'product_id','=',product_id, + ]) branch_id=context.get('branch_id') if branch_id: dom.append([ @@ -826,7 +831,6 @@ class Shop(Model): dom.append([ 'department_id','=',department_id, ]) - print('#shop.dom' , dom) for shop in get_model("clinic.shop").search_browse(dom): patient=shop.patient_id pm_id=None @@ -854,7 +858,7 @@ class Shop(Model): lab=0 misc=0 fee=0 - dlz_price=0 + dlz=0 mdc_names=[] if categ.parent_id: if categ.parent_id.code=='MDC': @@ -867,7 +871,7 @@ class Shop(Model): misc+=amount continue if categ.code=='DLZ': - dlz_price+=amount + dlz+=amount elif categ.code=='FEE': fee+=amount elif categ.code=='LAB': @@ -877,36 +881,30 @@ class Shop(Model): vals={ 'is_shop': True, 'hdcase_id': None, - 'number': None, #XXX 'date': shop.date, - 'hct': 0, + 'pay_type': shop.ptype, 'epo_name': "", - 'ptype': "Shop", #XXX 'ptype_color': "warning", 'dname': "", - 'cycle': "", - 'cid': 0, #XXX 'pname': patient.name or "", 'hn': patient.hn or "", 'idcard': patient.card_no or "", - 'cseq': 0, - 'cycle_item_id': "", 'pm_id': pm_id, 'pm_number': pm_number, 'inv_number': inv_number, 'inv_id': inv_number, 'inv_ref': inv_ref, + 'inv_id': inv_id, 'fee': fee, 'mdc': mdc, 'mdc_name': ','.join([n for n in mdc_names]), 'dlz_name': "", #XXX 'dlz_id': "", - 'dlz_price': dlz_price, + 'dlz': dlz, 'lab': lab, 'misc': misc, 'pick_ref': pick_number, 'pick_id': pick_id, - 'reimbursable': 'no', } records.append(vals) data={ diff --git a/netforce_clinic/reports/report_shop.xlsx b/netforce_clinic/reports/report_shop.xlsx new file mode 100644 index 0000000..2c3e1b2 Binary files /dev/null and b/netforce_clinic/reports/report_shop.xlsx differ diff --git a/netforce_clinic/templates/report_shop.hbs b/netforce_clinic/templates/report_shop.hbs new file mode 100644 index 0000000..01f190a --- /dev/null +++ b/netforce_clinic/templates/report_shop.hbs @@ -0,0 +1,75 @@ +
+

+ {{company_name}}
+

+

+ From {{date_from}} To {{date_to}} +

+
+ + + + + + + + + + + + + + + + + + + {{#each lines}} + + + + + {{#ifeq ptype "credit"}} + + {{else}} + + {{/if}} + + + + + + + + + + {{/each}} + + + + + + + + + + + + + + + +
DateNameReceipt#Invoice#ชื่อยาค่าฟอกค่ายาLabMisc.DlzRef.Inv#Picking#
{{date}}{{pname}}{{pm_number}} + {{view "link" string=inv_number action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}} + + {{view "link" string=pm_number action="payment" action_options="mode=form" active_id=pm_id}} + {{mdc_name}}{{currency fee zero=""}}{{currency mdc zero=""}}{{currency lab zero=""}}{{currency misc zero=""}}{{currency dlz zero=""}} + {{view "link" string=inv_ref action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}} + + {{#if pick_id}} + {{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}} + {{else}} + - + {{/if}} +
{{currency total_fee zero=""}}{{currency total_mdc zero=""}}{{currency total_lab zero=""}}{{currency total_misc zero=""}}{{currency total_dlz zero=""}}
+