Tuesday, December 10, 2019

create report in odoo 10



      In this blog we will explain how we can create report in odoo 10 (report generate by wizard)

      So to to that we have to follow the step blow , we will take payments report as an example

1/ create wizard python file in which we will add all fields that we want to use as filler to generate the report 

class paymentsReportWiz(models.TransientModel):
    _name = "payments.report.wiz"
    _description = "Payments Report"


    def get_year_range(self):
        year_list = []
        for i in range(2015, (fields.Date.from_string(fields.Date.today()).year)+5):
            year_list.append((str(i), str(i)))
        return year_list

    target_move = fields.Selection([('posted', 'All Posted Entries'),
        ('all', 'All Entries')], string='Target Moves', required=True, default='posted')
    year = fields.Selection(get_year_range, string='Year', default=str(fields.Date.from_string(fields.Date.today()).year))
 
@api.multi
    def print_report(self):
        """
            function to print the report
        """
        data = {}
        move_ids = self.get_move_ids()
        data['year'] = self.year
        data['move_ids'] = move_ids
        return self.env['report'].with_context({'portrait': 1}).get_action(self, 'module_name.payments_report_template', data=data)

    
    def get_move_ids(self):
        """
            Function to retrun moves base on selected moves type
        """
        move_object = self.env['account.move']
        move_ids = []
        if self.target_move == 'posted':
            move_ids = move_object.search([('state','=','posted')])
        else:
            move_ids = move_object.search([])
        return move_ids.ids



class PaymnetsReportDetails(models.AbstractModel):
    _name = "report.module_name.payments_report_template"

    @api.model
    def render_html(self, docids, data=None):
        """
            function to render the report
        """
        docids = docids
        current_company = self.env.user.company_id
        data['current_company'] = current_company
        return self.env['report'].render('module_name.payments_report_template', data)
 

2/ create the wizard form view file  , as bellow 


<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <data>

        <!-- """Create Wizard View""" -->

        <record id="view_payments_report_wiz_form" model="ir.ui.view">
            <field name="name">payments.report.wiz.form</field>
            <field name="model">payments.report.wiz</field>
            <field name="arch" type="xml">
                <form >
                    <sheet>
                        <group colspan="4" col="4">
                            <field name="target_move" widget="radio"/>
                            <field name="year" required="1"/>
                        </group>

                        <footer>
                            <button name="print_report" string="Print" type="object" default_focus="1" class="oe_highlight"/>
                            <button string="Cancel" special="cancel"/>
                        </footer>
                    </sheet>
                </form>
            </field>
        </record>



3/ create the report template as bellow 
 

<?xml version="1.0" encoding="utf-8" ?>
<odoo>

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

  <template id="payments_report_template">
    <t t-call="report.html_container">
      <div class="page">
        <b style="font-size:24px;">
          <span t-esc="current_company.name"/>
        </b>
        <b style="float:right;font-size:24px;color:#3a5d9c">
          Payments Report
        </b>
      </div>
    </t>
  </template>

<report
    id="payments_report_action"
    string="Payments Report"
    model="account.move.line"
    report_type="qweb-html"
    name="module_name.payments_report_template"
    menu="False"
    />

  </odoo>


Monday, December 9, 2019

how to edit view in odoo

ODOO

views

 

In this step we will continue with patient object by adding some new fields and design their view , so we have two steps today
  • add the fields 
          'name' which will contain the full name for the patient that will be concatenation of the four name , so 'name' field will be computed field
          'image' which is binary field that will contain the image of patient
          'gender' contain the gender of patient and it is selection field contain two values [male and female]
          'birth_day' the birthdate for the patient
          'met_doctor' which is boolean field that will be true if the patient met the doctor before 
          'last_meeting' the date of last meeting 

So we can add them as 

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ClinicPatient(models.Model):
    ###############################
    #Class for patient which is contain all patient data
    ###############################
    _name = 'clinic.patient'
    _description = "object contain all patient data"

    first_name = fields.Char(string='First Name', required=True)
    second_name = fields.Char(string='Second Name', required=True)
    third_name = fields.Char(string='Third Name', required=True)
    forth_name = fields.Char(string='Fourth Name', required=True)
    name = fields.Char(string="Name", readonly=True, compute='get_patient_name')
    image = fields.Binary(string='Image', copy=False)
    gender = fields.Selection([('male','Male'),('female','Female')], string='Gender',default='male')
    birth_day = fields.Date(string='Birthday', required=True)
    met_doctor = fields.Boolean(string='Met Doctor')
    last_meeting = fields.Date(string='Last Meeting')

    @api.one
    def get_patient_name(self):
        """
        function to calculate the full name for the patient
        """
        self.name = self.first_name+' '+self.second_name+' '+self.third_name+' '+self.forth_name

  • Edit view file as bellow 
<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>

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

        <record id="clinic_patient_form_view" model="ir.ui.view">
            <field name="name">clinic.patient.form</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <form string="Patient">
                    <sheet>
                        <div style="width:100%;">
                            <div style="width:20%;float:left;">
                                <field name="image" widget="image"/>
                            </div>
                            <div style="width:78%;float:right;">
                                <group colspan="2" col="2">
                                    <field name="name" nolabel="1" style="font-size:32px;"/>
                                </group>
                                <table style="width:100%;">
                                    <tr style="width:100%;">
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="first_name" placeholder="First Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="second_name" placeholder="Second Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="third_name" placeholder="Third Name"/>
                                        </td>
                                        <td style="width:25%;font-size:13px;padding:2px;">
                                            <field name="forth_name" placeholder="Fourth Name"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <br></br><br></br>
                        <group colspan="4" col="4">
                            <field name="gender"/>
                            <field name="birth_day"/>
                            <field name="met_doctor"/>
                            <field name="last_meeting" attrs="{'invisible':[('met_doctor','=',False)],'required':[('met_doctor','=',True)]}"/>
                        </group>
                    </sheet>
                </form>
            </field>
        </record>

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

        <record id="clinic_patient_tree_view" model="ir.ui.view">
            <field name="name">clinic.patient.tree</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <tree string="Patients">
                    <field name="first_name"/>
                    <field name="second_name"/>
                    <field name="third_name"/>
                    <field name="forth_name"/>
                </tree>
            </field>
        </record>

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

        <record id="clinic_patient_action_view" model="ir.actions.act_window">
            <field name="name">Patients</field>
            <field name="res_model">clinic.patient</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="clinic_patient_tree_view"/>
        </record>


        <!-- """Create the root menu """ -->

        <menuitem id="clinic_root_menu"
            name="Clinic Patient"
            sequence="1"
        />

        <!-- """Create the Configration menu """ -->

        <menuitem id="clinic_patient_main_menu"
            name="Patients" sequence="2"
            parent="clinic_root_menu"
        />

        <!-- """Create the Company's Projects menu""" -->

        <menuitem
            name="Patients"
            parent="clinic_patient_main_menu"
            action="clinic_patient_action_view"
            id="patients_action_menu"
            sequence="5"
        />

    </data>
</odoo>


Watch on YouTube


  PREVIOUS STEP            NEXT STEP

Saturday, December 7, 2019

object with simple view in odoo

ODOO

 

views

 

On this step we will create object with simple view
    As we decided we are going to design clinic erp system as today we will start to create patient model so as we know in our module structure we create models folder which is contain python files , also we will create views folder which will contain xml files so let us start …
First : create patient object in python file by name “clinic_patient.py” inside models folder which we must create inside our module just as bellow …

# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

class ClinicPatient(models.Model):
    _name = 'clinic.patient'
    _description = "object contain all patient data"

    first_name = fields.Char(string='First Name', required=True)
    second_name = fields.Char(string='Second Name', required=True)
    third_name = fields.Char(string='Third Name', required=True)
    forth_name = fields.Char(string='Fourth Name', required=True)


   Now we created new object with name "clinic.patient" which will create new table in the database by name "clinic_patient" which is also contain four fields (names) , then we must create view file for this model by name “clinic_patient_view.xml” inside views folder which we create inside our module as bellow …
 First : create new file inside view folder and save it by name "
clinic_patient_view.xml"
second : open it and and edit it as bellow ...

 <?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>

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

        <record id="clinic_patient_form_view" model="ir.ui.view">
            <field name="name">clinic.patient.form</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <form string="Patient">
                    <sheet>
                        <table style="width:100%;">
                            <tr style="width:100%;">
                                <td style="width:20%;">
                                    <b style="font-size:13px;">
                                        Name
                                    </b>
                                </td>
                                <td style="width:20%;font-size:13px;">
                                    <field name="first_name" placeholder="First Name"/>
                                </td>
                                <td style="width:20%;font-size:13px;">
                                    <field name="second_name" placeholder="Second Name"/>
                                </td>
                                <td style="width:20%;font-size:13px;">
                                    <field name="third_name" placeholder="Third Name"/>
                                </td>
                                <td style="width:20%;font-size:13px;">
                                    <field name="forth_name" placeholder="Fourth Name"/>
                                </td>
                            </tr>
                        </table>
                    </sheet>
                </form>
            </field>
        </record>

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

        <record id="clinic_patient_tree_view" model="ir.ui.view">
            <field name="name">clinic.patient.tree</field>
            <field name="model">clinic.patient</field>
            <field name="arch" type="xml">
                <tree string="Patients">
                    <field name="first_name"/>
                    <field name="second_name"/>
                    <field name="third_name"/>
                    <field name="forth_name"/>
                </tree>
            </field>
        </record>

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

        <record id="clinic_patient_action_view" model="ir.actions.act_window">
            <field name="name">Patients</field>
            <field name="res_model">clinic.patient</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="clinic_patient_tree_view"/>
        </record>


        <!-- """Create the root menu """ -->

        <menuitem id="clinic_root_menu"
            name="Clinic Patient"
            sequence="1"
        />

        <!-- """Create the Configration menu """ -->

        <menuitem id="clinic_patient_main_menu"
            name="Patients" sequence="2"
            parent="clinic_root_menu"
        />

        <!-- """Create the Company's Projects menu""" -->

        <menuitem
            name="Patients"
            parent="clinic_patient_main_menu"
            action="clinic_patient_action_view"
            id="patients_action_menu"
            sequence="5"
        />

    </data>
</odoo> 

 Whatch On YouTube 


 
  PREVIOUS STEP         NEXT STEP

Wednesday, December 4, 2019

View types in odoo

ODOO

 

Views



In this step we will explain
  • View types in odoo
  • How to create your first python class (python class structure)


View types :
 
Form view : show editable form for your object just like in the image bellow

List view (tree view) : show existing records for your models in the database as list with some fields , just like bellow

Kanban view : show existing records in card view just like in the image bellow 
 
Calendar view : view to display and edit information about dates and durations in your records in a visual way
 
Graph view : show your data in graph views as bar chart, line chart and pie chart
Pivot view : show your data in dynamic views
Search view : design search view with some attributes like (group by ,filters …) to make search more easy for the user 

Now how to create your first python class ?

We can define the class (object) structure as bellow
Import packages : here we will import all packages that we will use
Class class_name.. : here we define our class (class name and type)
Class attributes : here we define the attributes for the class
Class attributes :
_name = ‘the object name’ … eg : _name = ‘clinic.patient’
_description = ‘object description’
_order = ‘field_name’ … to order the records by this field
_rec_name = ‘field_name’… to show record in relational fields by this field
_inherit = ‘object.object’ … write the inherited here


Class body : will define as
Fields

Constraints

Functions

Watch On YouTube 



PREVIOUS STEP          NEXT STEP

Module's standard structure in odoo

ODOO

odoo module

 

On this step we will explain :
  • Field’s attributes
  • Module's standard structure 
     
To see field’s attributes click here

Module’s standard structure is just as bellow 
 
 module
    __init__.py
    __manifest__.py
    >< controllers
    >< models
    >< data
    >< i18n
    >< views
    >< security
    >< demo
    >< static
    >< wizard
    >< report
    >< doc
    >< test
Now let us explain them one by one :
Controllers : contains the code files for the website controllers, for modules which are providing that kind of feature .

Models : contains the backend code files, creating the Models and their business logic (contain the python files which create models)

Data : contains other data files with module initial data 

I18n : is where Odoo will look for the translation (contain translation file for many languages)

Views : contains the XML files for the user interface, with the actions, forms, lists, and so on

Security : contains the data files defining access control lists (contain files which define permissions)

Demo : contains data files with demonstration data

Static : is where all web assets are expected to be placed (contain web assets files such as css, js … files)

Wizard : Wizards describe stateful interactive sessions with the user through dynamic forms (contain all wizard files)

Report : contain reports files
 
Doc : contain documentation files

Test : contain the test files which are python file have names start with test_ "eg: test_patient.py"

Watch on YouTube 




PREVIOUS STEP           NEXT STEP

Tuesday, December 3, 2019

create module in odoo

ODOO

odoo mdule

 

 In this step we will explain how to build simple empty module and the data types in odoo

how to start build your module

odoo module is afolder that contain two files , so to create new module me must start with the steps bellow 

    - create new folder with name "module_name"
    - inside it create file with name "__init__.py"
    - inside it create another file with name "__manifest__.py"
now create  __manifest__.py as bellow 
    # -*- coding: utf-8 -*-
{
    'name' : 'clinic
',
    'version' : '1.1',
    'summary': 'clinic
erp system',
    'sequence': 10,
    'description': """
        manage
patient data 
        doctors data
        Patient dormitory data
     """,
    'category': 'Health',
    'author': 'Shilal,
    'website': 'https://shilalg.blogspot.com',
    'images' : [],
    'depends' : [],
    'data': [
    ],
    'demo': [
    ],
    'installable': True,
    'active': True,
}

 
Now let us explain what that is mean  
first __manifest__ file is contain the data of the module so 
  'name' : 'clinic', is define the name for our module
  'version' : '1.1', the current version for this module , I use it when I have more than one version for my module 
 'summary': short description for your module
 'description': description for your module and the tasks that your module do  
 'category': the category that your module belong to 
 'author': the company or the engineer who build the module
 'website': EG  the web site of the company or the engineer who build the module 
 'images' : the image for your module
 'depends' : any other module that must be installed in the system to make your module work (other modules name)
 'data': here we call the xml files in which we made our views 

now we will create empty file by name __init__.py , then our module will be created then we can install it by following the steps bellow 
  • restart the Odoo server (be sure that you call the directory which contain your modules with the run command by editing the addons path just like we explain) 
  • go to your browser and login to your database 
  • then go to setting to activate the developer mode 
  • the go to apps menu and click on update app list menu (load your module )
  • the search for your module by it's name in apps view and install it 


Data types :
Numeric : on which we are storing numbers and it has two types
     Integer > on which we store integers
     Float > on which we can store numbers with decimal part
Textual : on which we can store text data, and it has three types
     Char : on which we can store string maximum 255 characters
     Text : on which we can store string and it view as text area with unlimited characters
     Html : on which we can store string but it view as text editor
Date : on which we can store date and it has two types
     Date : on this field we can enter the date only without the time (month, day ,year)
     Datetime : on this field we can enter date and time too(month , day ,year hours ,minutes , seconds)
Boolean : has one type by name Boolean which can has True or False vale only
Binary : has one type too my name Binary in which we can store binary date (docs , images , sounds , videos …)
Selection : it also has one type by name selection and in it the user will select one value from the values in this field
Relational Fields : on this type we store the relation between objects , and we have three types of relational fields
    One2many > just when we say there are one record in object A will has relations with many records in object B just like (in the table of doctors one doctor will take care of more than one patient)
    Many2one > the reverse of One2many
    Many2many > in this type many records in object A will has relation with many records in object B just like (more than one medication will be given for many patients)
Now what is the syntax to define fields ?
All fields have one syntax just as
Field_name = fields.datatype(field attributes)

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