Tuesday, July 30, 2019

add item to top right menu in odoo

 

ODOO

menus

top right menu 

 

 

we can add item to user drop down menu in odoo by following the steps bellow
  • create web page as we explain before 
  • then we can add the item to the list as bellow 
<?xml version="1.0" encoding="utf-8"?>
 <templates id='template' xmlspace='preserve'>

  <!--Extends UserMenu -->
   <t t-extend="UserMenu" t-name="UserMenu">

     <t t-jquery="li.divider" t-operation="after">
        <li><a href="/new_item" >New Item</a></li>
     </t>
   </t>

</templates>

// here we have to create the web page by "/new_item" link

how to start new page in report in odoo

ODOO

reports


you can start new page in odoo by adding

<div style="page-break-before: always;">

 also you can use &#160; many time to add spaces unit you can start new page

How to make user choose the language of report

ODOO

reports

 

we can let the user choose the language for report with out change his language as bellow
  • define languages field as bellow 
report_language = fields.Many2one('res.lang','Report Language', required=True)
  • define the external template in which we call the language that entered by the user as bellow 
<template id="report_main_temp">
      <t t-call="report.html_container">
        <t t-foreach="docs" t-as="doc">
          <t t-call="certifications.student_file_template" t-lang="doc.certification_language.code"/>
        </t>
      </t>
    </template>  
  • the we will add internal template in which we will define report body for each language we installed in our system 
 EG : for English language 

<template id="report_file_template">
      <!-- <t t-foreach="docs" t-as="o" > -->
        <t t-set="doc" t-value="doc.with_context({'lang':doc.report_language.code})" />
<t t-if="line(data)[0]['c_language'].code == 'en_US'">
""" the report body in English language """
</t>
</t>
</template>

Tuesday, July 23, 2019

many views for one model in odoo

ODOO

views

 

To explain this let us say we have the student object in which we have the level field which is a selection field as bellow 

level = fields.Selection([('first','First'),('second','Second'),('third','Third')], string="Level")

and we want to put each level's students in single view , so we can do it as bellow 

for each level we have to 
  • add the action record
<record model="ir.actions.act_window" id="first_level_student_action">
            <field name="name">The First Level Students</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">student.student</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
              <field name="domain">[('level','=','first')]</field>
              <field name="context">{}</field>
              <field name="search_view_id" ref="module_name.view_student_search" />
        </record>

// this will only get the students of the first level 
  • add the form view 
<record model="ir.actions.act_window.view" id="first_level_student_action_form">
            <field name="act_window_id" ref="first_level_student_action" />
            <field name="sequence" eval="10" />
            <field name="view_mode">form</field>
            <field name="view_id" ref="module_name.view_first_level_student_form" />
        </record>
  • add the tree view 
<record model="ir.actions.act_window.view" id="first_level_student_action_tree">
            <field name="act_window_id" ref="first_level_student_action" />
            <field name="sequence" eval="20" />
            <field name="view_mode">form</field>
            <field name="view_id" ref="module_name.view_first_level_student_tree" />
        </record>
  • add the menuitem
<menuitem id="first_level_menu" sequence="10" parent="module_name.root_menu"
         action="first_level_student_action" />

how to add barcodes to reports in odoo


ODOO

reports

barcodes

 

 

we can generate two types of barcodes in odoo as the image show , so let us show how we can add any one to our reports

we will start with code (1) and we can add it by following steps
  • add the barcode field in our python file as bellow
barcode = fields.Char('Barcode', size=20)
  • add sql constraints to make barcode unique for each report
 _sql_constraints = [
        ('unique_name_barcode',
         'unique(barcode)',
         'Barcode must be unique per Report!'),
    ]
  • add create function which will create the barcode automatically when we create report 
@api.model
    def create(self,vals):
        """
        Method to create sequence for report barcode
        """
        vals['barcode'] = self.env['ir.sequence'].get('student.student')
        return super(student_student, self).create(vals) 
// student.student is the model which is contain the barcode field 
// student_student the of the class that is contain the barcode field
// this function will create the sequence with the barcode 
  • add the barcode to our report as bellow 
<img t-att-src="'data:image/png;base64,%s'% (get_barcode('Code128',doc.barcode))"/>

Now we  will code the barcode (2) by following the same steps but in our report template we must show the barcode as bellow 

<img t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', doc.barcode, 50, 50)" style="width:150px;height:150px;"/>

Monday, July 22, 2019

how to create sequence in odoo

ODOO

fields

 

Sequence is that field which generated automatically by the system and it's unique for each record in the table in the database and we can create it by following these steps 


  • define the sequence field as bellow 
        reference = fields.Char('Reference', readonly=True)
  • define the function which will create the sequence when we create the record as bellow 
      @api.model
       def create(self,vals):
           vals['reference'] = self.env['ir.sequence'].get('academic.year')
           return super(academic_year, self).create(vals)     
  • define the sequence related model and the name of the sequence and other attributes as bellow 
      <record id="student_reference" model="ir.sequence">
          <field name="name">Student Reference</field>
          <field name="prefix">Stu_</field>
          <field name="padding">6</field>
          <field name="code">student.student</field>
       </record>
  • at last we have to add our field to the tree view or other view we want

Saturday, July 20, 2019

fields attributes in odoo

ODOO

fields

attributes 

 

Here we are going to explain odoo field's attributes one by one , so let as start 

  • String

this attribute allow me to control the label of the field in the GUI 
Eg : name = fields.Char(string="Employee Name")// the label of this field will be Employee Name 

  • Required

this attribute defines that the field must be have an inputed value from the user or not in any created record , so it can be set for true or false
Eg :  name = fields.Char(string="Employee Name", required=True) // here we can't create record of this field if we don't insert a value for it 

  • Domain 

this with define the domain to insert a value for this field 
Eg : employee_id = fields.Many2one('employee.employee', string="Employee", domain=[('age','=',25)])// this will allows me to choose from employees with 25 years old only 

  • Default 

this attribute will give default value for the field 
Eg : gender = fields.Selection([('mail','Mail'),('femail','Femail')], default='mail', string="Gender") //  the make the gender = mail as default 

  • Readonly 

this attribute make the user cann't give a value the field , so it show the field just as label "uneditable" and it can take boolean value as true or false
Eg :  gender = fields.Selection([('mail','Mail'),('femail','Femail')], default='mail', string="Gender", readonly=True)// the user cann't choose the gender here

  • Digits 

this attribute is only use with float fields to control precision of a value to set how value will display 
Eg : price = fields.Float(string="Price", digits=(10,3)) // this will show the price as number of 10 integer digits and 3 decimal digits

  • Store

this attribute will save the value of the field forcefully in the database and it take boolean value "true or flase  

  • help

this attribute uesd to make the field more freindly by adding helping message which will show when the user put the mouse cursor over the field 

  •  Compute 

this attribute make the value of the field computed from a function
Eg : name = fields.Char(string="Name", compute="get_name") // this make the value of name field computed from get_name function which can be defined as 

@api.one
def get_name(self):
      self.name = "ABCD" // the function put ABCD as value for the field

  • Copy

this attribute  takes boolean value to control that if the value of the field will copy or not if we duplicate the record
  • Index

this attribute takes boolean value to control that if the field's index will create in the database or not " the field index help us to search for the field in the database directly "

  •  Inverse

this attribute help us to call function when the vlaue of the field changed 
Eg : age  = fields.Integer(string="Age", inverse="get_full_name") // that means the get_full_name function will call when we  change the value of the age field

  • translate

this attribute make you can translate the value of the field into another language 
Eg : name = fields.Char(string="Name", translate=True) 

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