From ebb102e60268387d2e62f837ef5ace997edcf40e Mon Sep 17 00:00:00 2001 From: "watcha.h@almacom.co.th" Date: Tue, 31 Mar 2015 08:38:56 +0700 Subject: [PATCH] report shop --- .../actions/clinic_report_account_shop.xml | 8 + .../actions/clinic_report_shop.xml | 8 + .../layouts/clinic_account_menu.xml | 1 + netforce_clinic/layouts/clinic_menu.xml | 1 + .../layouts/clinic_report_shop.xml | 8 + netforce_clinic/models/__init__.py | 1 + netforce_clinic/models/report_shop.py | 147 ++++++++++++++++++ netforce_clinic/models/shop.py | 22 ++- netforce_clinic/reports/report_shop.xlsx | Bin 0 -> 5253 bytes netforce_clinic/templates/report_shop.hbs | 75 +++++++++ 10 files changed, 259 insertions(+), 12 deletions(-) create mode 100644 netforce_clinic/actions/clinic_report_account_shop.xml create mode 100644 netforce_clinic/actions/clinic_report_shop.xml create mode 100644 netforce_clinic/layouts/clinic_report_shop.xml create mode 100644 netforce_clinic/models/report_shop.py create mode 100644 netforce_clinic/reports/report_shop.xlsx create mode 100644 netforce_clinic/templates/report_shop.hbs 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 0000000000000000000000000000000000000000..2c3e1b242864771b99db4a4b0cdb2a2ba328daff GIT binary patch literal 5253 zcmaJ_1yodPyCwu_q)TZKBu5ZNQs9syLrUiWGUSi~Qc8EHl(a*4cOxLB)JRE4O1H?* zcABJ z!wTqtJApf%AyMuwHDrI8RyGHXq{w-`N*erOESStoQH3Cok63gJ5GJ!73252&mN55!hMRA?5 z$?)(s5h)G-rS|MCHMr55$K}i&jKwygTfPuvpH`<{8J5)QEK(onkS0#@)vx4-FcW15n4Ke!v7H^a ztBrNq$dDx(fD~iFGlTI~Enjd5V@z;WT#4Tcz_td&K~`;F)y)6XdNY&ffDA1h_as0n6`??MQBxG>?)fwU<(uu|s z%Cm+So>^Gkv*hdABAZB3;w13>w0rkxje%a*uH`u|!!7hYd2jklvRaDoJeFBM<}}65 ztqRgfJ^xyHxhdh$ZYv>@w_K#56`APnKDc|HU2fL+X4{4`zq3j^wsBS2+{;I%M$cY6 zLo|FM`8mUsDD%|z<9%EtF*~H+a1qzrHb(suF+?|sF@ZUlA(^p>)>rDJCk@!SB*Q=9 z${h%cNzjMB$PMnVfi^K6P7w{rzA8qvQZy8UD}@PmIy+yh@emXYA1^fVH%R2LsbK0P zX>628q#Ql;ev(Y6SKA~=P3?3ml6 z778%zVW)+x3t88nuHIWH;M^(qY15?zf;&EgWt=o>AgVKIo3audyoYa}T*s@#E)Pu` zyZ1p`l3uhzK(>F%8cXV$Zz2g0PYN(7!+)%_+q*en>0!z3eEtA6=+jr3cXn;)RobK@ zW}e9eND5gHP7F<=>l`Gg1}%_ zNUHzN(`ZGjPF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LK{EbQ;|Z9Tniu`zobk z5QkH5ZI^hUhKJy`j49a7r_eL880<)*rS|%4OVoFAmF}(%Xxmu+9b*wE1_(~K++kT= zUIR!JQ5=2qkW!Gh*B#PEcw+AVhF>{WR2js;i@P7rX9r9!gw#aowRjy8EZBA^g>){L@8;t17|}ym-w!nph1y zHI-R%zQFF0EGVIF=+WlW0jDBqa{S<6#O3*@!e>IGz%=H4mB^iFowQab@HXHtP|L?| z&Pkl+%$ajVI2~O{3wKorUJIryE$A{tC8M;p2onbp0xeu_j?A@9zA#IW9*5kvml1s_ zL5*{-%+ENsTa5l=x%Bb}vjY+FA)zt@I?9AaZ{RzNqIS^3MgmbfIW!?76*^snY_q|m ziN*2uD4&)q?6kfX6mzE)7?Hod6pW(GdwZL zAE%>nc)lo>vsqbOACHmlrJMS+-l{4k0o2U)VO0m9-r6G}KdRT!6VL~jhoIV5$gT^@ zK-ex8*tV^O;+4=9c|uhRQU$A{^1M6Hwr#57NxF?KFt7xVL;zrZ$YkGlE|aKp+!?oM zd%u{Y_+3z-wdryh)`39w~xJ5(r-Ab>1>VP~=hOy-9-gEGez2|kIMA4Ok z**cloIvJ|F*_k=&BiqjAxOPw{FKN%t1&2b(Sl$6W#rGOW|LCs9Q>eAX-*4cAFE06!u;Ahx4^U&m!XDOzyPz-sLc8c}U1QkQ zIeg!6&s(*BFEh#WC+QH<&b$2Aq-)+nrV=U|Dax;j(an(wa$@wqabte;yW!1|0&=4A z3sl#C_4|C~ck7!<898?Ng@@OX@vrqiLx|taZ^}ueoc@Jm^goH~-`BY*g^=R&7b>s0 zx)$mGM~eQw!p*}SDVcsj9P{T2|5ZT!zRJyFhin9Xq4e4*$oKfSE%@E^W=0{a;V-NZ r{QCm`)W+Y9Z$<_(>3*T{+Nb{|1(iV<*V{rt!M^^8Uwev|82R)cIBoRe literal 0 HcmV?d00001 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=""}}
+