Technology IT

Odoo Report Development Guide

คู่มือเจาะลึกโครงสร้างและการพัฒนาระบบ Report ใน Odoo ตั้งแต่โครงสร้างพื้นฐานจนถึงเทคนิคขั้นสูง

Odoo Report Development Guide

ภาพรวมระบบ Report ของ Odoo

ระบบ Report ของ Odoo ใช้การผสมผสานระหว่าง QWeb (XML) เพื่อสร้างโครงสร้าง HTML, Python Logic เพื่อจัดการข้อมูล และ wkhtmltopdf เพื่อแปลงผลลัพธ์สุดท้ายเป็นเอกสาร PDF

องค์ประกอบเชิงเทคนิค

สัดส่วนความสำคัญของแต่ละส่วนประกอบในการสร้าง Report 1 ตัว

เปรียบเทียบความซับซ้อน

ความยากง่ายระหว่างการแก้ไข Report เดิม (Inherit) vs สร้างใหม่ (New)

1. สถาปัตยกรรม (Architecture)

กระบวนการทำงานเบื้องหลังเมื่อผู้ใช้สั่งพิมพ์เอกสาร ทำความเข้าใจ Flow เพื่อการ Debug ที่แม่นยำ

คลิกที่ขั้นตอนเพื่อดูรายละเอียด

11. Action Trigger

เมื่อผู้ใช้กดปุ่ม Print ระบบจะเรียก ir.actions.report ซึ่งเป็นตัวกำหนดว่าจะใช้ Report ตัวไหน Model อะไร และส่งออกเป็น Type ไหน (เช่น qweb-pdf)

2. องค์ประกอบหลัก (Core Components)

1 Report ประกอบด้วย 3 ส่วนหลัก เลือกหัวข้อเพื่อดูตัวอย่างโค้ดและคำอธิบาย

XML Action Definitionxml
<record id="action_report_sale_order_custom" model="ir.actions.report">
    <field name="name">Custom Sale Order</field>
    <field name="model">sale.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">my_module.report_name</field>
    <field name="report_file">my_module.report_name</field>
</record>

3. ขั้นตอนการพัฒนา (Workflow)

เลือกสถานการณ์ที่คุณต้องการพัฒนา เพื่อดูแนวทาง Best Practice

แนะนำที่สุด (Best Practice)

เหมาะสำหรับการเพิ่ม Logo, แก้ไข Layout เล็กน้อย หรือเพิ่ม Field ข้อมูลลงใน Standard Report

ขั้นตอนการทำ:

  1. หา External ID:

    หา ID ของ Report เดิมที่ต้องการแก้ (เช่น sale.report_saleorder_document)

  2. สร้างไฟล์ XML ใหม่:

    ใน Module ของคุณ ให้สร้าง template ที่ระบุ inherit_id

  3. ใช้ XPath:

    ระบุตำแหน่งที่ต้องการแก้ไขแม่นยำด้วย XPath Expression

ตัวอย่าง Code (XPath):

<template id="report_inherit" inherit_id="sale.report_saleorder_document"> <xpath expr="//div[@id='informations']" position="after"> <div class="col-12"> <strong>หมายเหตุ:</strong> สินค้าซื้อแล้วไม่รับคืน </div> </xpath> </template>

4. เทคนิคและคำแนะนำ (Expert Tips)

ทางลัดและวิธีแก้ปัญหาที่พบบ่อยในการทำ Report

🚀 การ Debug

อย่า Print PDF ตลอดเวลา

ใช้ URL Mode เพื่อแก้ CSS โดยไม่ต้องรอ Render PDF

/report/html/module.report_name/1
✂️ Page Break

แก้ปัญหาตัดหน้าไม่สวย

ใช้ CSS Class บังคับการตัดคำหรือขึ้นหน้าใหม่

page-break-inside: avoid;
🌍 Translations

เปลี่ยนภาษาตามลูกค้า

ต้องใส่ Attribute t-lang ใน Template เสมอ

t-lang="o.partner_id.lang"
📏 Paper Format

ขอบกระดาษ/Header ทับ

ตั้งค่าที่ Settings > Technical > Reporting > Paper Format

📱 Barcode

สร้าง Barcode ง่ายๆ

ใช้ URL Helper ของ Odoo ได้เลย

/report/barcode/?type=Code128&value=...
🎨 CSS Management

Bootstrap & SCSS

ใช้ Grid System ได้เลย และควรเขียน SCSS แยกไฟล์

5. Check List ก่อน Deploy

ตรวจสอบความเรียบร้อยก่อนนำขึ้นระบบจริง

Share this guide

Join the discussion

Comments 0

Join the discussion by signing in.

Loading comments...

Odoo Report Development Guide | เจาะลึกโครงสร้างและการพัฒนา