Saturday, January 18, 2020

report in odoo

ODOO

 

  
 In this step we will design report for clinic.booking object by wizard so
  • first we have to create wizard in which the user will inter important data to print the report he want as bellow
# -*- coding: utf-8 -*-
##############################################################

from odoo import fields, models, api, _
import time
from datetime import date
from odoo.exceptions import ValidationError ,UserError

class ClinicBookingWiz(models.TransientModel):
    _name = "clinic.booking.report.wiz"

    state = fields.Selection([('draft','Draft'),('wait_d_meeting','Wait Doctor Meeting'),('stay_on_ward','Stay On Ward'),('medical_bill','Medical Bill')], string='State')
    patient_id = fields.Many2one('clinic.patient', string='Patient')
    doctor_id = fields.Many2one('clinic.doctor', string='Doctor')
    date = fields.Date(string="Date")
    meeting_date = fields.Date(string="Meeting Date")

    @api.multi
    def print_booking_report(self):
        """
        This Function Get The Data For Booking Reports
        """
        booking_ids = self.env['clinic.booking'].search([])
        data = {}
        booking_list = []

        if self.state:
            for rec in booking_ids:
                if rec.state == self.state:
                    booking_list.append(rec.id)
            booking_ids = booking_ids.search([('id','in',booking_list)])
            booking_list = []

        if self.patient_id:
            for rec in booking_ids:
                if rec.patient_id == self.patient_id:
                    booking_list.append(rec.id)
            booking_ids = booking_ids.search([('id','in',booking_list)])
            booking_list = []  

        if self.doctor_id:
            for rec in booking_ids:
                if rec.doctor_id == self.doctor_id:
                    booking_list.append(rec.id)
            booking_ids = booking_ids.search([('id','in',booking_list)])
            booking_list = []

        if self.date:
            for rec in booking_ids:
                self_date = str(self.date)
                rec_date = str(rec.date)
                if self_date == rec_date:
                    booking_list.append(rec.id)
            booking_ids = booking_ids.search([('id','in',booking_list)])
            booking_list = []

        if self.meeting_date:
            for rec in booking_ids:
                self_meeting_date = str(self.meeting_date)
                rec_meeting_date = str(rec.meeting_date)
                if self_meeting_date == rec_meeting_date:
                    booking_list.append(rec.id)
            booking_ids = booking_ids.search([('id','in',booking_list)])
            booking_list = []

        for rec in booking_ids:
            booking_list.append(rec.id)
        data = {'booking_ids':booking_list}
        return self.env.ref('clinic.booking_custom_report_action').report_action(self, data=data)


class ClinicBookingReportDetails(models.AbstractModel):
    _name = "report.clinic.booking_custom_report_temp"

    @api.model
    def get_report_values(self, docids, data=None):
        booking_ids = self.env['clinic.booking'].search([('id','=',data['booking_ids'])])
        docids = docids
        # self.get_menus_skel(docids, data)
      
        return {
            'data': booking_ids
            }
  • then we have to create view for this object as bellow
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>

        <!-- """Create Form View""" -->

        <record id="clinic_booking_form_view" model="ir.ui.view">
            <field name="name">clinic.booking.form</field>
            <field name="model">clinic.booking</field>
            <field name="arch" type="xml">
                <form string="Doctor">
                    <header>
                        <button name="action_to_wait_d_meeting" states="draft" string="Confirm" type="object" class="oe_highlight" style="margin-left:2px;"/>
                        <button name="clinic_ward_action" states="wait_d_meeting" string="Stay On Ward" type="object" class="oe_highlight" style="margin-left:2px;"/>
                        <button name="medical_bill_action" states="wait_d_meeting" string="Medical Bill" type="object" class="oe_highlight" style="margin-left:2px;"/>
                        <field name="state" widget="statusbar" readonly="1"/>
                    </header>
                    <sheet>
                        <group colspan="4" col="4">
                            <field name="patient_id" />
                            <field name="doctor_id" />
                            <field name="date" />
                            <field name="meeting_date" />
                            <field name="paid_fees" />
                        </group>
                        <group colspan="4" col="4" string="Note">
                            <field name="note" nolabel="1"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

        <!-- """Create Tree View""" -->

        <record id="clinic_booking_tree_view" model="ir.ui.view">
            <field name="name">clinic.booking.tree</field>
            <field name="model">clinic.booking</field>
            <field name="arch" type="xml">
                <tree string="doctors">
                    <field name="patient_id" />
                    <field name="doctor_id" />
                    <field name="date" />
                    <field name="meeting_date" />
                    <field name="paid_fees" />
                    <field name="state"/>
                </tree>
            </field>
        </record>

        <!-- """Create Action View""" -->

        <record id="clinic_booking_action_view" model="ir.actions.act_window">
            <field name="name">Booking</field>
            <field name="res_model">clinic.booking</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="clinic_booking_tree_view"/>
        </record>

        <!-- """Create the Booking Root menu """ -->

        <menuitem id="clinic_booking_root_menu"
            name="Booking" sequence="1"
        />

        <!-- """Create the Booking Mani menu""" -->

        <menuitem
            name="Booking"
            parent="clinic_booking_root_menu"
            action="clinic_booking_action_view"
            id="clinic_booking_action_menu"
            sequence="2"
        />

    </data>
</odoo>

  • last thing we have to create report template file as bellow
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

        <!-- ...Define Template... -->

        <template id="booking_custom_report_temp">
            <t t-call="web.html_container">
                <t t-call="web.external_layout">
                    <div class="page">
                        <table style="width:100%;">
                            <tr style="font-size:18px; border: 2px solid black;text-align: center;">
                                <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                    <b>
                                        Doctor
                                    </b>
                                </td>
                                <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                    <b>
                                        Paient
                                    </b>
                                </td>
                                <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                    <b>
                                        Booking Date
                                    </b>
                                </td>
                                <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                    <b>
                                        Meeting Date
                                    </b>
                                </td>
                                <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                    <b>
                                        State
                                    </b>
                                </td>
                            </tr>
                            <t t-foreach="data" t-as="object_line">
                                <tr style="font-size:18px; border: 2px solid black;text-align: center;">
                                    <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                        <n>
                                            <span t-esc="object_line.doctor_id.name" />
                                        </n>
                                    </td>
                                    <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                        <n>
                                            <span t-esc="object_line.patient_id.name" />
                                        </n>
                                    </td>
                                    <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                        <n>
                                            <span t-esc="object_line.date" />
                                        </n>
                                    </td>
                                    <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                        <n>
                                            <span t-esc="object_line.meeting_date" />
                                        </n>
                                    </td>
                                    <td style="font-size:14px; border: 2px solid black;padding-top:5px;padding-bottom:5px;">
                                        <n>
                                            <span t-esc="object_line.state" />
                                        </n>
                                    </td>
                                </tr>
                            </t>
                        </table>
                    </div>
                </t>
            </t>
        </template>

        <!-- """create report """ -->

        <report
            id="booking_custom_report_action"
            string="Booking Report"
            model="clinic.booking"
            report_type="qweb-pdf"
            name="clinic.booking_custom_report_temp"
            menu="True"
        />
         <record id="paperformat_euro_no_margin" model="report.paperformat">
            <field name="name">European A4</field>
            <field name="default" eval="True" />
            <field name="format">A4</field>
            <field name="page_height">0</field>
            <field name="page_width">0</field>
            <field name="orientation">Portrait</field>
            <field name="margin_top">40</field>
            <field name="margin_bottom">28</field>
            <field name="margin_left">7</field>
            <field name="margin_right">7</field>
            <field name="header_line" eval="False" />
            <field name="header_spacing">0</field>
            <field name="dpi">90</field>
        </record>

</odoo>

Watch On YouTube



PREVIOUS STEP            NEXT STEP

2 comments:

  1. استاذنا الغالى
    ال فيو المشروح هنا غير الذى بالفيديو
    حيث ان الفيو الموجود بالبلوج



    اما الموجود بالفيديو



    عليه عند المحاولة للتطبيق حدث خطا

    شكرا لمجهوداتك يا غالى

    ReplyDelete
  2. ممكن ترسل لي الخظأ البيظهر معك شان نحل هذه المشكلة

    ReplyDelete

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...