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

Monday, December 30, 2019

design workflow in odoo

      In this step we will design work flow for clinic booking process as we had explain in the previous step so to make it we have to 
  • create new object by name ('clinic.booking') as bellow with workflow functions 
# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError

class ClinicBooking(models.Model):
    ###############################
    #Class for Booking data
    ###############################
    _name = 'clinic.booking'
    _description = "object contain all doctor data"

    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')


    @api.one
    def action_to_wait_d_meeting(self):
        """
        function to be sure that the paient had registered to meet doctor
        """
        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.state = 'stay_on_ward'

    @api.one
    def medical_bill_action(self):
        """
        function will call if the doctor give the patient a medical bill
        """
        self.state = 'medical_bill'
  • 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>
                    </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="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>
 


Watch On YouTube



PREVIOUS STEP           NEXT STEP

Tuesday, December 24, 2019

explain workflow in odoo

ODOO 

Workfow 

 

In this step we are going to start workflow in odoo , so we have to ask some Qs 
  • What is workflow ?
Workflow is away that we use to define all steps to do some tasks or activities in our organization , and it's away to make our work clear and easy 
Workflow is consist of some activities and some actions which are depends on activities "eg : to migrate student from first class to the second one , he must study at the first one"
  •  How to make workflow in odoo ? 
To design workflow in odoo we have tow main steps 

1- logical design : in this step we define all steps of the task that we want to do , also we define which step must be first and which one must be after which one , also we design the action that must be happened to change from the first step to the second one , also we have to define the user's permissions "which user is allowed to take that action in this workflow" finally we have to design workflow diagram that summarizes our logical design "EG : the diagram bellow "



2- technical design : in this step we write down our logical design as code , to do that we have to 
  • Create state field which is selection field that contain all states of our workflow as bellow       
state = fields.Selection([('draft','Draft'),('unit_manager_approv','Unit Manager Approve'),('general_manager_approv','General Manager Approve')], string="draft", default='draft')

  • Create our functions , and in every one we must put all actions that will be happen in one state , and also every function will change the state from one state to another
Watch On YouTube 


PREVIOUS STEP            NEXT STEP

Monday, December 23, 2019

create notebook view, kanban view in odoo

ODOO

notebook

kanban

 
 
In this step we will create some view 
  • create notebook view
  • create kanban view
Notebook is away to view fields as note that contains many pages , so as example we will create notebook view for 'clinic.doctor' consist of two page ' patients page ' & 'doctor's qualifications' so we will go to 'clinic.doctor' object and add the field of qualifications & specialty as bellow 

qualifications = fields.Html(string="Qualifications")
specialty = fields.Many2one('doctor.specialty', string="Specialty")
academic_degree

and in the 'clinic_doctor.py' file we will add new class by name 'DoctorSpecialty' which will contain all specialties for the doctors 'name field only', just as bellow 

class DoctorSpecialty(models.Model):
    _name = "
doctor.specialty"
    _description = "
Doctor Specialty
      
     name = field.Char(string="Name")

Then we have to go to 'clinic_doctor_view.xml' file and add the notenook view as bellow ..

<notebook>
    <page string="Patients">
         <group colspan="2" col="2">
             <field name="patient_ids" nolabel="1"/>
         </group>
    </page> 
    <page string="Qualifications">
         <group colspan="4" col="4">
              <field name="specialty"/>
              <field name="academic_degree"/>
              <field name="university"/>
              <field name="graduate_year"/>
         </group>
         <group colspan="2" col="2">
             <field name="qualifications" nolabel="1"/>
         </group>
    </page>
</notebook>

Then we will create kanban view for 'clinic.doctor' object in which we will put just the important fields for the doctor just as "name, specialty, image"

Now we will create kanban view for the 'clinic.doctor' object by adding the code bellow to the 'clinic_doctor_view.xml' file

<!-- """Create kanban View""" -->

        <record id="clinic_doctor_kanban_view" model="ir.ui.view">
            <field name="name">clinic.doctor.kanban</field>
            <field name="model">clinic.doctor</field>
            <field name="arch" type="xml">
                <kanban >
                    <field name='id'/>
                    <field name="image"/>
                    <field name="specialty"/>
                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_kanban_global_click" style=" border: 1px solid #d9d7d7; border-radius: 5px !important;">
                                <div class="o_kanban_image">
                                    <img t-att-src="kanban_image('clinic.doctor','image',record.id.raw_value)" alt="Image"/>
                                </div>
                                <div class="oe_kanban_details">
                                    <ul>
                                        <li style="font-size:16px;color:blue !important;"><b>Name :</b> <field name="name"/></li>
                                        <li><b>Specialty :</b> <field name="specialty"/></li>
                                    </ul>
                                </div>
                                <div class="o_kanban_record_bottom">
                                    <div class="oe_kanban_bottom_left" style="margin-left:8px;">
                                        <b> A.D :</b> <field name="academic_degree"/>
                                    </div>
                                    <div class="oe_kanban_bottom_right" style="margin-right:40px;">
                                        <b> Age :</b> <field name="age_year"/>
                                    </div>
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>


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