1. ทำการเพิ่ม Code นี้ ในไฟล์ที่ชื่อ amount_to_text.py ไฟล์นี้จะถูกเก็บอยู่ในโฟลเดอร์ openerp/tools
โค้ด: เลือกทั้งหมด
#---------------------------------------------------------------------
# Thai_Number to Word #
#---------------------------------------------------------------------
def conto(val):
lek = ("ศูนย์","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า")
luk = ("สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน")
text = ''
def thainumtext(val):
i=0
n,l = len(val),len(val)
text = ''
temp_int = 0
while n>0:
temp_int = int(val[i])
if (temp_int>0):
if ((n==1) and temp_int ==1 and l > 1):
text = text + 'เอ็ด'
elif ((2==n) and temp_int ==1):
pass
elif ((2==n) and temp_int ==2):
text = text + 'ยี่'
else:
text = text + lek[temp_int]
if n > 1:
text = text + luk[n-2]
n=n-1
i+=1
return text
n = len(val)
if n == 1: return lek[int(val)]
nlist = []
n=6
temp = ''
for i in reversed(val):
temp = i+temp
n = n-1
if n == 0:
nlist.append(temp)
temp = ''
n = 6
else:
if temp <> '': nlist.append(temp)
n = 1
for i in (nlist):
if n:
text = thainumtext(i) + text
n=0
else:
text = thainumtext(i) +'ล้าน' + text
return text
def amount_to_text_th(number,currency):
number = '%.2f' % float(number)
units_name=currency
list=str(number).split('.')
start_word=conto(list[0])
end_word=conto(list[1])
cents_number = int(list[1])
if cents_number == 0:
cents_name='ถ้วน'
else:
cents_name=(cents_number>1) and 'สตางค์' or 'สตางค์'
final_result = start_word+units_name+end_word+cents_name
return final_result2. ทำการแก้ไขไฟล์ sale_order.py ไฟล์นี้จะเก็บอยู่ในโฟลเดอร์ openerp/addons/sale/report ให้เป็นดังนี้
โค้ด: เลือกทั้งหมด
import time
from tools.translate import _
from tools import amount_to_text
from tools.amount_to_text import amount_to_text_th
from openerp.report import report_sxw
class order(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context=None):
super(order, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
'amount_to_text_th': amount_to_text_th,
'show_discount':self._show_discount,
}) 3. หลังจากนั้นก็ทำการเรียกใช้ฟังฟังก์ชันใน Report ด้วยการเพิ่มคำสั่ง
โค้ด: เลือกทั้งหมด
<para style="terp_default_Bold_9">([[ amount_to_text_th(o.amount_total,'บาท') ]])</para>เข้าไปที่ไฟล์ sale_order.rml ที่อยู่ในโฟล์เดอร์ openerp/addons/sale/report
เท่านี้ก็จะสามารถแสดงจำนวนเงินเป็นตัวอักษรใน ใบเสนอราคา และ ใบสั่งขาย ครับ
Log in with LINE

