Tuesday, August 20, 2019

domain to field in odoo

ODOO

we can add domain for field in both python file and xml file as bellow 
E.G : let us say we have department_id file which it's domain must be the company 

in python file :

department_id = fields.Many2one('hr.department', domain="[('company_id', '=', company_id)]", string="Department")

// the department object must has field call company_id and the current object too 

in xml file : 

<field name="department_id" domain="[('company_id','=',company_id)]"/>

module icon in odoo

ODOO

 

to add icon to our module we can add the icon path to the main menu of our module by using web_icon attribute as bellow 

in odoo 9 :
<menuitem id="main_menu_id" 
            name="Menu String"
            web_icon="module_name,static/description/icon_name.png"
/>

in odoo 11 : 
<menuitem id="main_menu_id"
            name="Menu String"
            web_icon="module_name,static/description/icon.png"
/>
//here the name of your image must be icon

overwrite form view in odoo

ODOO

we can change the form view after inherit the main view by using xpath as bellow

<xpath expr='//form' position="replace">
      <form string="new form string ">
              new form body
      </form.
</xpath>

email validation in odoo

ODOO

we must make validation for the email field to be sure that the email which input by the user is an invalid email , and we can do that as bellow 

E.G .
let us say that we have email field as 

email = fields.Char(string="Email")

then we can make validation by adding the function bellow 

@api.constrains('email')
    def _validate_email(self):
        for rec in self:
            if self.email and not tools.single_email_re.match(rec.email):
                raise Warning(_("Please enter a valid email address."))
        return True

* to make this function work we must import tool and exceptions as bellow 

from odoo.exceptions import ValidationError
from odoo import api , fields, exceptions, tools, models,_

constrant unique to field in odoo

ODOO

sql constraint work on the database and called when we want to create new record in database table 
we can make field unique as bellow 
 
_sql_constraints = [
        ('unique_code', 'unique(code)', 'Employee code must be unique !')
    ]

here we make constraint unique for employee code

create compute field in odoo

odoo

compute field is that field which it's value computed by function , so we can make it by the following steps
  • create the field and link it with function that will compute it's value 
E.G .

student_number = fields.Integer(string="Student Number", compute='get_student_number') 

  • create the function to compute the value 

E.G .

@api.one
def  get_student_number(self):
       student_ids = self.env['student.student'].search([])
       counter = 1
       for rec in student_ids:
             counter = counter+1
       self.student_number = counter

* the function will call automatically when we create record 

Watch On YouTube


Wednesday, August 7, 2019

activities log in odoo

ODOO


 

activities log helps us to save all changes that made in our objects , and we can make it as bellow 
  • inherit mail thread object 
_inherit = 'mail.thread' 
  • make track to fields that we want to save it's change , as bellow 
E.G : 
say we have field called name , so we can make track for it as bellow 

name = fields.Char(string="Name", required=True, track_visibility='onchange') 

  • show the activities log with xml file as footer for our view ,as bellow 
<footer>
      <div class="oe_chatter">
             <field name="message_follower_ids" widget="mail_followers"                                       groups="base.group_user"/>
             <field name="message_ids" widget="mail_thread"/>
      </div>
</footer>

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