วันจันทร์ที่ 9 มิถุนายน พ.ศ. 2557

OpenERP : การสร้าง Report ใน OpenERP ตอนที่ 2 (สร้าง New Report)

ขั้นตอนในการสร้าง report ใน OpenERP อย่างง่ายมีอยู่ 3 ขั้นตอนดังนี้ครับ

1.สร้างไฟล์ RML (ใช้ OpenERP Plugin ชื่อว่า bass report designer + Open Office)
2.สร้างไฟล์ .py
3.Config OpenERP

ขั้นตอนที่ 1 : สร้างไฟล์ RML

1.เปิด Open Office แล้ว ไปที่ OpenERP Report Designer แล้ว connect เข้าไปที่ OpenERP Server



2.ไปที่ OpenERP Report Designer-->Open a new report


3.ทำการเลือก Module ที่ต้องการทำ Report ในที่นี้ผมเลือก Account


4.พิมพ์ ABC ลงไปแล้วทำการ Save ไฟล์เป็น .sxw



5.  ไปที่ OpenERP Report Designer --> Send to server


6. ทำการ Generate ไฟล์ RML โดยไปที่ OpenERP Report Designer--> Export to RML


10. เมื่อได้ไฟล์ .sxw และ .rml แล้วให้นำไปวางใน module : account ตาม path ที่ติดตั้ง



ขั้นตอนที่ 2 : สร้าง .py

1. สร้างไฟล์ account_print_invoice_example.py ขึ้นมา แล้ว copy code ไปวาง



import time
from openerp.report import report_sxw

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        self.localcontext.update({
            'time': time,
        })
report_sxw.report_sxw(
    'report.account.invoice_example',
    'account.invoice_example',
    'addons/account/report/account_print_invoice_example.rml',
    parser=account_invoice
)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:



การสร้าง report_sxw.report_sxw('attribute1','attribute2','attribute3','attribute')

attribute1 = report name
attribute2 = object name
attribute3 = path name
attribute4 = optional

ref::
https://www.odoo.com/forum/Help-1/question/what-attributes-should-be-put-in-report_sxwreport_sxw-36741


2. เพิ่ม report เข้าไปในไฟล์ __iniy__.py (*** เราไม่ต้องเพิ่มตรงนี้ก็ได้ครับ เป็นการเพิ่มชื่อ module เข้าไป ในที่นี้เราจะทดลองสร้างแค่ report เพราะหลังจากที่เรา restart แล้วจะทำให้ไม่สามารถเข้ามาใช้งาน OpenERP ได้ เพราะว่ามันหา module : account_print_invoice_example ไม่เจอ ***)





ขั้นตอนที่ 3 : Config OpenERP

1.ไปที่ Setting-->Technical-->Action-->reports



ทดสอบการเข้าใช้งาน



ไม่มีความคิดเห็น: