conv_bal
watcha.h@almacom.co.th 2015-03-26 14:11:04 +07:00
parent f3968d0fea
commit e0a27017d8
12 changed files with 227 additions and 45 deletions

View File

@ -0,0 +1,6 @@
<action>
<field name="type">report_odt2</field>
<field name="model">clinic.shop</field>
<field name="method">get_invoice_data</field>
<field name="template">cust_invoice</field>
</action>

View File

@ -1,6 +1,6 @@
<action>
<field name="type">report_odt2</field>
<field name="model">clinic.shop</field>
<field name="method">get_data</field>
<field name="method">get_receipt_data</field>
<field name="template">cust_payment</field>
</action>

View File

@ -6,6 +6,7 @@
<field name="tabs">[
["All",[]],
["Draft",[["state","=","draft"]]],
["Waiting Payment",[["state","=","waiting_payment"]]],
["Paid",[["state","=","paid"]]],
["Cancelled",[["state","=","cancelled"]]]
]

View File

@ -2,10 +2,12 @@
<head>
<field name="state"/>
<button string="Print" dropdown="1" icon="print">
<item string="Receipt" action="clinic_cust_print" action_options="convert=pdf"/>
<item string="Receipt" action="clinic_receipt_print" action_options="convert=pdf"/>
<item string="Invoice" action="clinic_invoice_print" action_options="convert=pdf"/>
</button>
<button string="Options" dropdown="1">
<item string="To Draft" method="to_draft" states="paid"/>
<item string="To Draft" method="to_draft" states="waiting_payment,paid"/>
<item string="Void" method="void" states="waiting_payment,paid" confirm="Are you sure?"/>
</button>
</head>
<group form_layout="stacked">
@ -17,10 +19,10 @@
<field name="pay_type" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2" required="1"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' required="1" span="2"/>
<field name="pay_date" span="2"/>
<field name="cheque_no" span="2"/>
<field name="bank_name" span="2"/>
<field name="bank_branch" span="2"/>
<field name="pay_date" attrs='{"invisible":[["pay_type","=","credit"]]}' span="2"/>
<field name="cheque_no" attrs='{"invisible":[["pay_type","=","credit"]]}' span="2"/>
<field name="bank_name" attrs='{"invisible":[["pay_type","=","credit"]]}' span="2"/>
<field name="bank_branch" attrs='{"invisible":[["pay_type","=","credit"]]}' span="2"/>
<field name="hd_case_call" invisible="1"/>
<field name="shop_categs" invisible="1"/>
<field name="company_id" invisible="1"/>
@ -43,19 +45,19 @@
<field name="total"/>
</group>
</tab>
<tab string="Note">
<field name="note" nolabel="1"/>
<tab string="Accounting">
<field name="due_date" span="3"/>
</tab>
<tab string="Other">
<field name="related_id" span="3"/>
<field name="user_id" span="3"/>
<field name="note"/>
</tab>
</tabs>
</group>
<foot>
<button string="Pay" method="pay" states="draft" type="success"/>
<!--<button string="Cash" method="pay_cash" states="draft" type="success"/>-->
<!--<button string="Credit" method="pay_credit" states="draft" type="default"/>-->
<button string="Pay" method="pay" states="draft" attrs='{"invisible":[["pay_type","=","credit"]]}' type="success"/>
<button string="Approve" method="approve" states="draft" attrs='{"invisible":[["pay_type","=","cash"]]}' type="success"/>
</foot>
<related>
<field name="invoices"/>

View File

@ -9,7 +9,6 @@
<field name="branch_id"/>
<field name="department_id"/>
<field name="pay_type"/>
<field name="related_id"/>
<field name="user_id"/>
<field name="state"/>
</list>

View File

@ -94,9 +94,15 @@ class HDCase(Model):
fee=0
lab=0
misc=0
dlz_price=0
#sign=1
#if obj.state=='waiting_payment':
#sign=-1
for dline in obj.dialyzers:
dlz=dline.dialyzer_id
prod=dlz.product_id
dlz_price+=prod.sale_price or 0
for line in obj.lines:
amt=line.amount or 0
prod=line.product_id
@ -108,12 +114,14 @@ class HDCase(Model):
sign=-1
if categ.code=='EPO':
name=prod.name or ""
name=name.split("-") #XXX
name=name.split("-")
if name:
name=name[0].title()
names.append(name)
elif categ.code=='FEE':
fee+=amt*sign
elif categ.code=='DLZ':
dlz_price+=prod.sale_price or 0
elif categ.code=="LAB":
lab+=amt
else:
@ -124,6 +132,7 @@ class HDCase(Model):
'lab': lab,
'misc': misc,
'dlz_id': dlz_id,
'dlz_price': dlz_price,
'dlz_name': dlz_name,
'dlz_use': dlz_use,
'dlz_max': dlz_max,
@ -172,6 +181,7 @@ class HDCase(Model):
"lab": fields.Float("Fee",function="_get_expense",function_multi=True),
"misc": fields.Float("Fee",function="_get_expense",function_multi=True),
"dlz_name": fields.Float("DZ",function="_get_expense",function_multi=True),
"dlz_price": fields.Float("DZ",function="_get_expense",function_multi=True),
"dlz_use": fields.Float("DZ Use",function="_get_expense",function_multi=True),
"dlz_max": fields.Float("DZ Max",function="_get_expense",function_multi=True),
"dlz_id": fields.Float("DZ ID",function="_get_expense",function_multi=True),
@ -518,9 +528,10 @@ class HDCase(Model):
def cancelled(self,ids,context={}):
obj=self.browse(ids)[0]
obj.sickbed_id.write({
'available': True,
})
if obj.sickbed_id:
obj.sickbed_id.write({
'available': True,
})
obj.write({"state":"cancelled"})
def make_invoices(self,ids,context={}):

View File

@ -122,9 +122,11 @@ class ReportAccountHDCaseSummary(Model):
pm_number=','.join([pm.number for pm in hdcase.payments if pm.number])
inv_number=""
inv_ref=""
inv_id=None
for inv in hdcase.invoices:
inv_number+=inv.number or ""
inv_ref+=inv.ref or ""
inv_id=inv.id
pick_ref=""
pick_id=None
for pick in hdcase.pickings:
@ -157,9 +159,11 @@ class ReportAccountHDCaseSummary(Model):
'cycle_item_id': cycle_item.id,
'pm_number': pm_number and pm_number or "-",
'inv_number': inv_number and inv_number or "-",
'inv_id': inv_id,
'mdc_name': mdc_name,
'dlz_name': hdcase.dlz_name,
'dlz_id': hdcase.dlz_id.id,
'dlz_price': hdcase.dlz_price or 0,
'lab': hdcase.lab,
'misc': hdcase.misc,
'inv_ref': inv_ref and inv_ref or "-",
@ -195,6 +199,7 @@ class ReportAccountHDCaseSummary(Model):
total_srv=0
total_epo=0
total_lab=0
total_dlz=0
total_misc=0
slines=[]
no=1
@ -214,6 +219,7 @@ class ReportAccountHDCaseSummary(Model):
total_epo+=line.get('epo',0)
total_lab+=line.get('lab',0)
total_misc+=line.get('misc',0)
total_dlz+=line.get('dlz_price',0)
line['no']=no
cid=line['cid']
@ -252,6 +258,7 @@ class ReportAccountHDCaseSummary(Model):
'total_epo': total_epo,
'total_lab': total_lab,
'total_misc': total_misc,
'total_dlz': total_dlz,
'total_qty': total_qty,
'types': types,
'reimbursable': reimbursable,
@ -264,7 +271,6 @@ class ReportAccountHDCaseSummary(Model):
data['title']='Report - Claim'
else:
data['title']='Report - No Claim'
print('>>', data['reimbursable'])
return data
def onchange_date(self,context={}):

View File

@ -30,14 +30,15 @@ class Shop(Model):
"number": fields.Char("Number",required=True,search=True),
"ref": fields.Char("Customer Name",search=True),
'date': fields.Date("Date",search=True),
'due_date': fields.Date("Due Date",search=True),
'patient_id': fields.Many2One('clinic.patient','Patient',search=True,domain=[['state','=','admit']]),
'contact_id': fields.Many2One('partner','Contact',search=True),
'department_id': fields.Many2One("clinic.department","Department",search=True),
'branch_id': fields.Many2One("clinic.branch","Branch",search=True),
'lines': fields.One2Many('clinic.shop.line','shop_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'),
'user_id': fields.Many2One("base.user","Sale Man"),
'state': fields.Selection([['draft','Draft'],['waiting_payment','Waiting Payment'],['paid','Paid'],['cancelled','Cancelled']],'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"),
@ -121,6 +122,7 @@ class Shop(Model):
_defaults={
'number': '/',
'date': lambda *a: time.strftime("%Y-%m-%d"),
'due_date': lambda *a: time.strftime("%Y-%m-%d"),
'user_id': lambda *a: get_active_user(),
'company_id': lambda *a: get_active_company(),
'branch_id': _get_branch,
@ -270,7 +272,6 @@ class Shop(Model):
if obj.invoices:
for inv in obj.invoices:
inv.void()
due_date=obj.date[1:10] # XXX
context['type']='out'
context['inv_type']='invoice'
context['branch_id']=obj.branch_id.id
@ -281,7 +282,7 @@ class Shop(Model):
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
'due_date': due_date,
'due_date': obj.due_date,
"ref": obj.number or "",
'department_id': obj.department_id.id,
"related_id": "clinic.shop,%s"%obj.id,
@ -316,7 +317,7 @@ class Shop(Model):
inv.post()
obj.make_pickings()
obj.write({
'state': 'paid',
'state': 'waiting_payment',
'pay_type': 'credit',
})
@ -491,7 +492,117 @@ class Shop(Model):
},
}
def get_page(self,context={}):
def get_invoice_page(self,context={}):
if not context.get('refer_id'):
return {}
shop_id=int(context['refer_id'])
shop=self.browse(shop_id)
comp_id=get_active_company()
comp=get_model('company').browse(comp_id)
context['branch_id']=shop.branch_id.id
st=get_model('settings').browse(1,context=context)
cst=get_model('clinic.setting').browse(1)
cust=shop.contact_id
cust_tax_no=cust.tax_no or ''
cust_name=cust.name or ''
cust_addr=''
if cust.addresses:
cust_addr=cust.addresses[0].address_text
if 'your' in cust_addr:
cust_addr=''
if cust.walkin_cust:
cust_name=shop.ref or ''
no=1
sub_total=0
amount_total=0
lines=[]
for line in shop.lines:
amt=line.amount or 0
prod=line.product_id
lines.append({
'no': no,
'product_name': prod.name or '',
'description': line.description or '',
'uom_name': line.uom_id.name or '',
'qty': line.qty or 0,
'price': line.price or 0,
'amount': amt,
})
sub_total+=amt
no+=1
amount_total=sub_total #XXX
is_draft=shop.state=='draft' and True or False
is_cheque=False
pay_type=shop.pay_type or ''
user_id=get_active_user()
user=get_model("base.user").browse(user_id)
comp_name=comp.name or ""
if st.default_address_id.company:
comp_name=st.default_address_id.company or ""
number="/"
ref=""
payment_terms=''
currency_code=''
due_date=shop.due_date
for inv in shop.invoices:
number=inv.number or ""
ref=shop.number or ""
payment_terms=inv.payment_terms or ""
currency_code=inv.currency_id.code or ""
due_date=inv.due_date
add=st.default_address_id
data={
'partner_name': cust_name,
'partner_address': cust_addr,
'partner_tax_no': cust_tax_no,
'due_date': due_date,
'currency_code': currency_code,
'payment_terms': payment_terms,
'comp_name': comp_name,
'add_address': add.address or '',
'add_address2': add.address2 or '',
'add_province_name': add.province_id.name or '',
'add_district_name': add.district_id.name or '',
'add_subdistrict_name': add.subdistrict_id.name or '',
'add_city': add.city or '',
'add_postal_code': add.postal_code or '',
'add_phone': add.phone or '',
'add_fax': add.fax or '',
'tax_no': st.tax_no or '',
'number': number,
'ref': ref,
'date': shop.date,
'datenow': shop.date or time.strftime("%d/%m/%Y"),
'dateprint': shop.date or time.strftime("%d/%m/%Y %H:%M:%S"),
'note': shop.note or '',
'lines':lines,
'amount_subtotal': sub_total,
'amount_total': amount_total,
'total_text': utils.num2word(amount_total),
'is_cheque': is_cheque,
'is_draft': is_draft,
'user_name': user.name or "",
'state': shop.state or "",
}
blank_dot=''
if pay_type=='cash':
data['pay_type']='Cash'
if shop.cheque_no:
data['is_cheque']=True
data['bank_name']=shop.bank_name or blank_dot
data['branch_name']=shop.branch_name or blank_dot
data['cheque_no']=shop.cheque_no or blank_dot
data['cheque_date']=shop.pay_date or blank_dot
else:
data['pay_type']='Credit'
if st.logo:
data['logo']=get_file_path(st.logo)
if cst.signature:
data['signature']=get_file_path(cst.signature)
return data
def get_receipt_page(self,context={}):
if not context.get('refer_id'):
return {}
shop_id=int(context['refer_id'])
@ -538,17 +649,11 @@ class Shop(Model):
comp_name=comp.name or ""
if st.default_address_id.company:
comp_name=st.default_address_id.company or ""
number=shop.number or ""
ref=shop.ref or ""
if shop.pay_type=="cash":
for pm in shop.payments:
number=pm.number or ""
ref=shop.number or ""
else:
for inv in shop.invoices:
number=inv.number or ""
ref=shop.number or ""
number="/"
ref=""
for pm in shop.payments:
number=pm.number or ""
ref=shop.number or ""
add=st.default_address_id
data={
'comp_name': comp_name,
@ -596,15 +701,51 @@ class Shop(Model):
data['signature']=get_file_path(cst.signature)
return data
def get_data(self,ids,context={}):
def is_pay_by_cheque(self,ids,context={}):
obj=self.browse(ids)[0]
res=obj.pay_type or obj.pay_by or obj.pay_date or obj.bank_name or obj.bank_branch or False
return res
def get_receipt_data(self,ids,context={}):
settings=get_model('settings').browse(1)
pages=[]
for obj in get_model('clinic.shop').browse(ids):
context['refer_id']=obj.id
data=get_model('clinic.shop').get_page(context=context)
data=get_model('clinic.shop').get_receipt_page(context=context)
limit_item=13
if obj.is_pay_by_cheque(context=context):
limit_item-=1
if data['state']=='draft':
limit_item=10
limit_item-=3
for i in range(len(data['lines']),limit_item):
data['lines'].append({
'no': '',
'product_name': '',
'description': '',
'uom_name': '',
'qty': None,
'price': None,
'amount': None,
})
pages.append(data)
if pages:
pages[-1]["is_last_page"]=True
return {
"pages": pages,
"logo": get_file_path(settings.logo),
}
def get_invoice_data(self,ids,context={}):
settings=get_model('settings').browse(1)
pages=[]
for obj in get_model('clinic.shop').browse(ids):
context['refer_id']=obj.id
data=get_model('clinic.shop').get_invoice_page(context=context)
limit_item=13
if obj.is_pay_by_cheque(context=context):
limit_item-=1
if data['state']=='draft':
limit_item-=3
for i in range(len(data['lines']),limit_item):
data['lines'].append({
'no': '',
@ -628,11 +769,15 @@ class Shop(Model):
obj=self.browse(ids)[0]
if not obj.lines:
raise Exception("No item")
res=obj.pay_cash()
return res
if obj.pay_type=='cash':
res=obj.pay_cash()
else:
res=obj.pay_credit()
def approve(self,ids,context={}):
res={}
obj=self.browse(ids)[0]
if not obj.lines:
raise Exception("No item")
res=obj.pay_credit()
return res
def onchange_branch(self,context={}):
@ -640,4 +785,10 @@ class Shop(Model):
data['department_id']=None
return data
def void(self,ids,context={}):
for obj in self.browse(ids):
obj.write({
'state': 'cancelled',
})
Shop.register()

Binary file not shown.

View File

@ -59,6 +59,7 @@
<th>ค่าฟอก</th>
<th>ค่ายา</th>
<th>ค่าบริการฉีดยา</th>
<th>Inv#</th>
<th>Picking#</th>
<th>แพทย์</th>
<th>พยาบาล</th>
@ -85,7 +86,7 @@
<td>{{currency epo zero=""}}</td>
<td>{{currency lab zero=""}}</td>
<td>{{currency misc zero=""}}</td>
<td>{{dlz_name}}</td>
<td>{{currency dlz_price zero=""}}</td>
<td>{{inv_ref}}</td>
<td>
{{#if pick_id}}
@ -109,6 +110,9 @@
<td>{{currency fee zero=""}}</td>
<td>{{currency epo zero=""}}</td>
<td>{{currency srv zero=""}}</td>
<td>
{{view "link" string=inv_number action="cust_invoice" action_options="form_view_xml&cust_invoice_form&mode=form" active_id=inv_id}}
</td>
<td>
{{#if pick_id}}
{{view "link" string=pick_ref action="pick_out" action_options="mode=form" active_id=pick_id}}
@ -140,7 +144,7 @@
<th>{{currency total_epo zero=""}}</th>
<th>{{currency total_lab zero=""}}</th>
<th>{{currency total_misc zero=""}}</th>
<th></th>
<th>{{currency total_dlz zero=""}}</th>
<th></th>
{{else}}
<th></th>

View File

@ -1 +1,3 @@
testing script generate
> script:
merge staff, patient
> invoice payment on rd shop