Tuesday, January 28, 2020

design report in odoo

ODOO

reports

 
In this step we will show how to design report bellow 


You can design this report by adding the template 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">
                        <header>
                            <div style="float:left;border-bottom: 2px solid black;border-color:#1f7b91 ! important;width:70%;">
                                <b style="font-size:32px;color:#1f7b91 ! important;">
                                    Shilal Software Company
                                </b>
                                <br></br>
                                <b style="font-size:22px;color:#1f7b91 !important;">
                                    Clinic Managment System
                                </b>
                            </div>
                            <div style="float:right;">
                                <!-- <img src=\"/logo.png?company=${company.id}\"/> -->
                                <img src="/clinic/static/img/shilal.png" style="width:160px;height:100px;"/>
                            </div>
                        </header>
                        <br></br><br></br><br></br><br></br><br></br><br></br><br></br>
                        <div>
                            <center>
                                <u>
                                    <b style="font-size:20px;">
                                        Clinic Booking Report
                                    </b>
                                </u>
                            </center>
                        </div>
                        <br></br><br></br>
                        <div style="width:50%;float:left;font-size:14;">
                            <t t-if="doctor_id != 'no'">
                                <b>
                                    Doctor :
                                </b>
                                <span t-esc="doctor_id" />
                                <br></br>
                            </t>
                            <t t-if="patient_id != 'no'">
                                <b>
                                    Patient :
                                </b>
                                <span t-esc="patient_id" />
                                <br></br>
                            </t>
                            <t t-if="meeting_date != 'no'">
                                <b>
                                    Meeting Date :
                                </b>
                                <span t-esc="meeting_date" />
                                <br></br>
                            </t>
                            <br></br>
                        </div>
                        <div style="width:50%;float:right;font-size:14;">
                            <t t-if="date != 'no'">
                                <b>
                                    Date :
                                </b>
                                <span t-esc="date" />
                                <br></br>
                            </t>
                            <t t-if="state != 'no'">
                                <b>
                                    State :
                                </b>
                                <span t-esc="state" />
                                <br></br>
                            </t>
                        </div>
                        <table style="width:100%;">
                            <tr style="font-size:18px; border: 2px solid black;text-align: center;background-color:#d6d6c2 !important;">
                                <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>
                        <br></br><br></br>
                        <div>
                            <b style="font-size:14px;width:50%;float:left;">
                                Print By : <span t-esc="request.env.user.partner_id.name" />
                                <br></br>
                                Signiture : _____________________________
                            </b>
                        </div>
                        <div>
                            <b style="font-size:14px;width:50%;float:right;">
                                Print On : <span t-esc="context_timestamp(datetime.datetime.now()).strftime('%A %d-%B-%Y')"/>
                            </b>
                        </div>
                    </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="False"
        />
         <record id="paperformat_euro_no_margin" model="report.paperformat">
            <field name="name">European A5</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">5</field>
            <field name="margin_bottom">5</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>



PREVIOUS STEP            NEXT STEP

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

Thursday, January 16, 2020

explain reports in odoo

In this step we will explain reports in odoo 

There are many types of reports in odoo and we can classified these type depends on many bases so we can say 
  • we have reports that it's data passed to doc file (pdf reports , xls reports) 
  • we have report show data in the screen (graphic reports, pivot) 
  • we have reports that we can edit it's data 
Now we will start with pdf report :
actually Odoo uses a report engine based on QWeb, Twitter Bootstrap and Wkhtmltopdf.
and to create pdf report for one record in the database we can do it as bellow

(create pdf report for clinic.booking object as an example) 

  • create report template as bellow

        <template id="clinic_booking_report_temp">
            <t t-call="web.html_container">
                <t t-foreach="docs" t-as="doc">
                    <t t-call="web.external_layout">
                        <div class="page">  
                        </div>
                    </t>
                </t>
            </t>
        </template>

 
  • create report record which will call the template as bellow
       <report
            id="clinic_booking_report_action"
            string="Booking Report"
            model="clinic.booking"
            report_type="qweb-pdf"
            name="clinic.clinic_booking_report_temp"
            menu="True"
        /> 
  • define paper format (optional)
       <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>


Watch On YouTube


PREVIOUS STEP             NEXT STEP

Wednesday, January 8, 2020

buttons in odoo

ODOO

Buttons

 
On this step we will explain button's types in odoo , there are many types of buttons in odoo just as :

  • object buttons : this type of button is created to call python function
  • action buttons : this type of button is created to call view " to open new view when the user click it'
  • Smart button : actually it's action button but beside open new view it also used to show some information about some objects "we show some fields with this button 
Now let us give an examples to create any type of buttons 

_ object button : let us say that we have a function by name "get_operation_start" and we want to call this function by click on some button , so we can make that button inside our view just as bellow 

<button name="get_operation_start" type="object" string="Start" class="oe_highlight" />

to explain what we did :

name="" here we pass the name of the function that we want to call when we click on this button 
type="" here we defined the type of this button 'object or action'
string="" here we defined the label for this button 
class="" here we defined the class for this button

_ action button : we can define it as bellow 

<button name="module_name.view_button_action" icon="fa-check" type="action" string="Graduated Students" />

now we have to create view_button_action which will call some view as bellow 

@api.multi

def view_button_action(self):

     return {
            'name': _('ModelName'),
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'model.model',
            'view_id': False,
            'type': 'ir.actions.act_window',
            'domain': [],
        }

_ smart button : smart button is that button which contain some fields which are display with this button , and for example we can give the smart button that show the available quantity of the product in the stock which is defined as bellow 

<button class="oe_stat_button"
         name="product_open_quants"
         icon="fa-building-o"
         type="object" attrs="{'invisible':[('type', '!=', 'product')]}">
                 <field name="qty_available" widget="statinfo" string="On Hand"/></button>
 

Watch On YouTube



PREVIOUS STEP            NEXT STEP

Thursday, January 2, 2020

workflow in odoo

ODOO

 

Workflow 


 
In this step we will continue with clinic booking work flow , so we will

  • add booking data for ‘clinic.booking’ object as bellow

state = fields.Selection([('draft','Draft'),('wait_d_meeting','Wait Doctor Meeting'),('stay_on_ward','Stay On Ward'),('medical_bill','Medical Bill')], string='State', default='draft')

patient_id = fields.Many2one('clinic.patient', string='Patient', required=True)

doctor_id = fields.Many2one('clinic.doctor', string='Doctor', required=True)

date = fields.Date(string="Date", default=fields.date.today())

meeting_date = fields.Date(string="Meeting Date", required=True)

paid_fees = fields.Boolean(string="Paid Fees")

note = fields.Html(string="Note")

  • create clinic booking views as bellow
<!-- """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>



  • edit work flow function as bellow

@api.one

def action_to_wait_d_meeting(self):

"""

function to be sure that the paient had registered to meet doctor

"""

if self.paid_fees == False:

raise ValidationError(_("The Patient did not paid fees yet !"))

self.state = 'wait_d_meeting'





@api.one

def clinic_ward_action(self):

"""

function will call if the doctor decied that the patient must stay for sometime in clinin's ward

"""

self.patient_id.write({'met_doctor': True})

self.patient_id.write({'last_meeting': self.meeting_date})

self.state = 'stay_on_ward'



@api.one

def medical_bill_action(self):

"""

function will call if the doctor give the patient a medical bill

"""

self.patient_id.write({'met_doctor': True})

self.patient_id.write({'last_meeting': self.meeting_date})

self.state = 'medical_bill'

Watch On YouTube



 PREVIOUS STEP              NEXT STEP

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...