Saturday, July 20, 2019
install odoo 9 on ubuntu
ODOO
install
In order to install odoo 9 on ubuntu you have to open your terminal and write the following commands one by one
- sudo apt-get update // in order to update your system
- sudo apt-get upgrade // in order to upgrade your system's packages
sudo apt-get install python-dateutil python-docutils python-feedparser python-jinja2 python-ldap python-libxslt1 python-lxml python-mako python-mock python-openid python-psycopg2 python-psutil python-pybabel python-pychart python-pydot python-pyparsing python-reportlab python-simplejson python-tz python-unittest2 python-vatnumber python-vobject python-webdav python-werkzeug python-xlwt python-yaml python-zsi poppler-utils python-pip python-pyPdf python-passlib python-decorator
// in order to
install all python dependencies for odoo
sudo apt-get install gcc python-dev mc bzr python-setuptools python-markupsafe python-reportlab-accel python-zsi python-yaml python-argparse python-openssl python-egenix-mxdatetime python-usb python-serial python-jinja2 python-unittest2 python-mock python-docutils lptools make python-pydot python-psutil python-paramiko poppler-utils python-pdftools antiword
//in order to install all
supporting packages for Odoo
sudo apt-get install -y npm &
sudo ln -s /usr/bin/nodejs /usr/bin/node &
// in order to install allsudo npm install -g less less-plugin-clean-css
web dependencies for odoo
sudo apt-get install python-software-properties &
sudo apt-get update &
sudo apt-get install postgresql
//
in order to installpostgresql
sudo su postgres
cd
createuser -s odoo
createuser -s your_system_name
exit
// by writing this 5 commands we will create two users for the database by names " odoo and your system name"
To run the server open your terminal and go to your server folder path and the write
./odoo.py // this will run the server with the default addons , then you have to open your browser and write "localhost:8069" to the database creating window as bellow
Now we gonna install the GUI for the database "Pgadmin3" by writing the following command
sudo apt-get install pgadmin3
To login the dadabase with user odoo we can use the command
- sudo -u odoo psql
and if we forgot the password for this user , we can change it by the command
- ALTER USER odoo PASSWORD "your_new_password"
Friday, July 19, 2019
controllers in odoo
Controllers is a way to make
web pages and define unique path "unique URL" for any page
So to create web pages you have to follow these
steps
-
create the controller
-
create the web page template
Example
:-
Let
us say we wanna create login page so we will start with creating
controller by create python file with name user_login.py and inside
it create the controller as bellow
from odoo import http
class user_login(http.Controller):
@http.route('/user_login_page', type='http', auth='public', website=True)
def render_login_page(self, **kw):
user_ids = http.request.env['user.user'].search([])
check_value = 0
if kw.get('longin_password') and kw.get('login_email'):
for rec in user_ids:
if rec.passwprd == kw['longin_password'] and rec.email == kw['login_email']:
check_value = check_value+1
return http.request.render('module_name.login_page_temp', {'docs': rec})
if check_value == 0:
return http.request.render('module_name.login_error_temp', {})
@http.route('/user_login_page', type='http', auth='public', website=True)
def render_login_page(self, **kw):
user_ids = http.request.env['user.user'].search([])
check_value = 0
if kw.get('longin_password') and kw.get('login_email'):
for rec in user_ids:
if rec.passwprd == kw['longin_password'] and rec.email == kw['login_email']:
check_value = check_value+1
return http.request.render('module_name.login_page_temp', {'docs': rec})
if check_value == 0:
return http.request.render('module_name.login_error_temp', {})
Now
let us explain what we did :
class
user_login(http.Controller): // define class user_login as controller
class
@http.route('/user_login_page',
type='http', auth='public', website=True)
http.route
// to define that we want to make routing
/user_login_page
// this will be the url of our web page
"localhost:8069/web/user_login_page"
type='http'
// to define that our page will run in http
auth='public'
// define the page four pubic user
website=True
//
to link the page
then
inside the function we take the email end the password from the web
page " if kw.get('longin_password') and kw.get('login_email'): "
and compare them with which saved in the database " if
rec.passwprd == kw['longin_password'] and rec.email ==
kw['login_email']:" and return true if it's true or return error
page "return http.request.render('module_name.login_error_temp',
{})" if it's wrong
then
we will create template with name user_login_page to design the web
page as bellow
<?xml
version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="user_login_page_id" name="User Login Page" page="True">
<t t-call="website.layout">
<div class="oe_structure oe_empty">
<div class="container">
<center>
<br></br><br></br><br></br>
<form class="oe_login_form" role="form" t-attf-action="/user_login_page{{ '?debug' if debug else '' }}" method="post" >
<div class="form-group form-field o_website_form_required_custom">
<label class="col-md-4 col-sm-5 control-label" for="login_email" style="color:#6666ff;">
</label>
<div class="col-md-5 col-sm-6">
<input type="text" class="form-control o_website_form_input" name="login_email" required="1" style="width:250px;text-align:center;border-color:#e67300;" placeholder="Email"/>
</div>
<br></br><br></br>
<label class="col-md-4 col-sm-5 control-label" for="longin_password" style="color:#6666ff;">
</label>
<div class="col-md-5 col-sm-6">
<input type="longin_password" class="form-control o_website_form_input" name="longin_password" required="1" style="width:250px;text-align:center;border-color:#e67300;" placeholder="password"/>
</div>
</div>
<br></br><br></br>
<div class="form-group">
<div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7">
<input type="hidden" name="redirect" t-att-value="redirect"/>
<button type="submit" class="btn" style="background-color:#e67300;">Login</button>
</div>
</div>
</form>
</center>
</div>
</div>
</t>
</template>
</data>
</openerp>
<openerp>
<data>
<template id="user_login_page_id" name="User Login Page" page="True">
<t t-call="website.layout">
<div class="oe_structure oe_empty">
<div class="container">
<center>
<br></br><br></br><br></br>
<form class="oe_login_form" role="form" t-attf-action="/user_login_page{{ '?debug' if debug else '' }}" method="post" >
<div class="form-group form-field o_website_form_required_custom">
<label class="col-md-4 col-sm-5 control-label" for="login_email" style="color:#6666ff;">
</label>
<div class="col-md-5 col-sm-6">
<input type="text" class="form-control o_website_form_input" name="login_email" required="1" style="width:250px;text-align:center;border-color:#e67300;" placeholder="Email"/>
</div>
<br></br><br></br>
<label class="col-md-4 col-sm-5 control-label" for="longin_password" style="color:#6666ff;">
</label>
<div class="col-md-5 col-sm-6">
<input type="longin_password" class="form-control o_website_form_input" name="longin_password" required="1" style="width:250px;text-align:center;border-color:#e67300;" placeholder="password"/>
</div>
</div>
<br></br><br></br>
<div class="form-group">
<div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7">
<input type="hidden" name="redirect" t-att-value="redirect"/>
<button type="submit" class="btn" style="background-color:#e67300;">Login</button>
</div>
</div>
</form>
</center>
</div>
</div>
</t>
</template>
</data>
</openerp>
The
last important thing
that we have to create the login_error_temp page which will called if
there is an error with the entered login data with error message in
the same way of creating the user_login_temp
odoo.exceptions.UserError: ("No inverse field None found for '_unknown'", '')
ODOO
errors
This error usually happens with relational field when they defined in wrong way for example
student_id = fields.One2many(string="Student")
here I don't defined the relational object for this field , so that will make the same error
Tuesday, July 16, 2019
thread in odoo
Let us say we have 10000 employees record and we want to increase the performance of processes on these records , in this case we can use the thread
So :
Tread is away to distribute the work into many processes which are running at the same time , and that will increase the performance of our server
Example :-
let us say that we want to display the multiplication table of number inserted by the user
we will define the object which contain the fields and the functions , then create four function each one make the multiplication table for the number with only 3 numbers , then we will call the four functions at the same time by using threads
from odoo import models, fields, api, _
import threading
class multiplication_table(models.Model):
_name = 'multiplication.table'
number = fields.Interger('Number', required=True)
def thread1(self):
for x in xrange(1,4):
print (self.number," * ",x,"=",self.number*x)
def thread2(self):
for x in xrange(4,7):
print (self.number," * ",x,"=",self.number*x)
def thread3(self):
for x in xrange(7,10):
print (self.number," * ",x,"=",self.number*x)
def thread4(self):
for x in xrange(10,13):
print (self.number," * ",x,"=",self.number*x)
t1= threading.Thread(target=self.thread1, args=())
t2= threading.Thread(target=self.thread2, args=())
t3= threading.Thread(target=self.thread3, args=())
t4= threading.Thread(target=self.thread4, args=())
t1.start()
t2.start()
t3.start()
t4.start()
Thursday, July 11, 2019
report from wizard in odoo
To show how to generate report from wizard let me give a simple definition of report in odoo
- The report is a xml template read and show data from python file
so if we want to generate report we have to pass the data form the python file to the template we designed , so we can say that we have 2 cases here
- we want to generate report for single record , so we can linked the model with the template directly and read the fields that we want to show in our template
- we want to show data from multi records and depends on some conditions , so we must get the data we want first and then pass it to the template and that can make by using wizard by following the steps below
- create the transient model "the wizard model" which will contain the function that will pass the needed data to the report template , and of course create it view "the wizard view"
- create template and design it's form
- link the model with the template to make data move form the model to the template
Now let us make an example
let us say we have model contain the student data by name student.py as below , and we want to generate report of students who age is in range defined by the user
from openerp import models, fields, api, _
class Student(models.Model):
_name = 'student.student'
"""
contain all student data
"""
name = fields.Char('Name', required=True)
age = fields.Integer('Age', required=True)
phone = fields.Integer('Phone', required=True)
email = fields.Char('Email', required=True)
so first we gonna create wizard by name student_report_wiz.py and we gonna add two integers fields to make the user define the range of age , after that we will take the two values which entered by the user and go to the student model and get the id of any student whose age is less than the max value and larger than the min value which are defined by the user , and push all ids in dictionary which passed to the template , as below
from openerp import models, api
class student_report_wiz(models.TransientModel):
"""
get students by age range
"""
_name = 'student.report.wiz'
class student_report_wiz(models.TransientModel):
"""
get students by age range
"""
_name = 'student.report.wiz'
max_age = fields.Integer('Max Age', required=True)
min_age = fields.Integer('Min Age', required=True)
@api.multi
def get_students(self):
@api.multi
def get_students(self):
student_ids = self.env['student.student'].search([])
student_list = []
for rec in student_ids :
if rec.age > self.min_age and rec.age < self.max_age"
student_list.append(rec.id)
student_dic = {stud_list: student_list}
return student_dic
return self.pool['report'].get_action(cr, uid, [], 'module_name.students_age_report_temp', data=student_dic, context=context)
Now we get all student we want in student_dic , then we will create the report py file by name students_age_report.py as below
class students_age_report(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
self.context = context
super(students_age_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'line':self._getdata,
})
def _getdata(self,data):
"""
method that return student's in age range
"""
lines = {}
lines = data['form']
return lines
class students_age_report_details(osv.AbstractModel):
_name = 'report.module_name.students_age_report_temp'
_inherit = 'report.abstract_report'
_template = 'module_name.students_age_report_temp'
_wrapped_report_class = students_age_report
def __init__(self, cr, uid, name, context):
self.context = context
super(students_age_report, self).__init__(cr, uid, name, context)
self.localcontext.update({
'line':self._getdata,
})
def _getdata(self,data):
"""
method that return student's in age range
"""
lines = {}
lines = data['form']
return lines
class students_age_report_details(osv.AbstractModel):
_name = 'report.module_name.students_age_report_temp'
_inherit = 'report.abstract_report'
_template = 'module_name.students_age_report_temp'
_wrapped_report_class = students_age_report
then we will create template by id students_age_report_temp as below
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data >
<!-- ...Define Template... -->
<template id="students_age_report_temp">
<t t-call="report.html_container">
<div class="page">
<header>
<center>
<div style="float:left; width:80%;">
<div style="float:right; width:75%;">
<b style="font-family:Georgia, serif;font-size:16px;">
student by age range
</b>
<br></br><br></br>
</div>
<openerp>
<data >
<!-- ...Define Template... -->
<template id="students_age_report_temp">
<t t-call="report.html_container">
<div class="page">
<header>
<center>
<div style="float:left; width:80%;">
<div style="float:right; width:75%;">
<b style="font-family:Georgia, serif;font-size:16px;">
student by age range
</b>
<br></br><br></br>
</div>
<div>
<table>
<th>
<td>
<b style="size:16px;">
name
</b>
name
</b>
</td>
<td>
<b style="size:16px;">
age
</b>
</td>age
</b>
<td>
<b style="size:16px;">
phone
</b>
</td>phone
</b>
<td>
<b style="size:16px;">
email
</b>
</td> </b>
</th>
<t t-foreach="line(data)" t-as="line" >
<tr>
<td>
<b style="size:16px;">
<span t-esc="line(data).name"/>
</b>
</td><span t-esc="line(data).name"/>
</b>
<td>
<b style="size:16px;">
<span t-esc="line(data).age"/>
</b>
</td><span t-esc="line(data).age"/>
</b>
<td>
<b style="size:16px;">
<span t-esc="line(data).phone"/>
</b>
</td><span t-esc="line(data).phone"/>
</b>
<td>
<b style="size:16px;">
<span t-esc="line(data).email"/>
</b>
</td> <span t-esc="line(data).email"/>
</b>
</tr>
</table
</div>
</div>
</p>
</div>
</t>
</template>
<!-- """create report """ -->
<report
id="students_age_report_id"
string="Students By Age Report"
model="student.student"
report_type="qweb-pdf"
name="maodule_name.students_age_report_temp"
menu="False"
/>
<record id="report.paperformat_euro" model="report.paperformat">
<field name="margin_top">15</field>
<field name="margin_bottom">15</field>
<field name="margin_left">15</field>
<field name="margin_right">15</field>
<field name="header_spacing">15</field>
</record>
</data>
</openerp>
</div>
</p>
</div>
</t>
</template>
<!-- """create report """ -->
<report
id="students_age_report_id"
string="Students By Age Report"
model="student.student"
report_type="qweb-pdf"
name="maodule_name.students_age_report_temp"
menu="False"
/>
<record id="report.paperformat_euro" model="report.paperformat">
<field name="margin_top">15</field>
<field name="margin_bottom">15</field>
<field name="margin_left">15</field>
<field name="margin_right">15</field>
<field name="header_spacing">15</field>
</record>
</data>
</openerp>
>>>DONE
Subscribe to:
Posts (Atom)
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...
-
ODOO In this step we will design report for clinic.booking object by wizard so first we have to create wizard in which the use...
-
ODOO configurations PyPDF2 " ImportError: No module named 'PyPDF2' " this error means that PyPDF2 package is not ...