Sunday, 18 May 2014
Tuesday, 25 March 2014
Work with web-controller OpenERP
How to override web controller in openerp 8.0.
Here, i try to define one example that may be useful to you to understand how to work with web controller in openerp 8.0.
Existing controller (addons/web/controllers/main.py) :
- class name Home, and method index
class Home(http.Controller):
@http.route('/', type='http', auth="none")
def index(self, s_action=None, db=None, **kw):
return http.local_redirect('/web', query=request.params, keep_hash=True)
Now, here i define how to override existing controller...
- Here, my class name Website, and in parameter i pass path of controller which i want to inherit, so here "Home" class which is in addons/web/controllers/main.py so in path i pass : openerp.addons.web.controllers.main.Home.
- @http.route : in openerp 8.0 the route system changed.
'/' : '/' route will match the new index() method in Website.
'type' : There are different type like http,json...
(http : normal http requests by passing, Json : Methods that received JSON can be defined by passing 'json')
class Website(openerp.addons.web.controllers.main.Home):
@http.route('/', type='http', auth="public", website=True, multilang=True)
def index(self, **kw):
try:
main_menu = request.registry['ir.model.data'].get_object(request.cr, request.uid, 'website', 'main_menu')
first_menu = main_menu.child_id and main_menu.child_id[0]
# Dont 302 loop on /
if first_menu and not ((first_menu.url == '/') or first_menu.url.startswith('/#') or first_menu.url.startswith('/?')):
return request.redirect(first_menu.url)
except:
pass
return self.page("website.homepage")
Here, i try to define one example that may be useful to you to understand how to work with web controller in openerp 8.0.
Existing controller (addons/web/controllers/main.py) :
- class name Home, and method index
class Home(http.Controller):
@http.route('/', type='http', auth="none")
def index(self, s_action=None, db=None, **kw):
return http.local_redirect('/web', query=request.params, keep_hash=True)
Now, here i define how to override existing controller...
- Here, my class name Website, and in parameter i pass path of controller which i want to inherit, so here "Home" class which is in addons/web/controllers/main.py so in path i pass : openerp.addons.web.controllers.main.Home.
- @http.route : in openerp 8.0 the route system changed.
'/' : '/' route will match the new index() method in Website.
'type' : There are different type like http,json...
(http : normal http requests by passing, Json : Methods that received JSON can be defined by passing 'json')
class Website(openerp.addons.web.controllers.main.Home):
@http.route('/', type='http', auth="public", website=True, multilang=True)
def index(self, **kw):
try:
main_menu = request.registry['ir.model.data'].get_object(request.cr, request.uid, 'website', 'main_menu')
first_menu = main_menu.child_id and main_menu.child_id[0]
# Dont 302 loop on /
if first_menu and not ((first_menu.url == '/') or first_menu.url.startswith('/#') or first_menu.url.startswith('/?')):
return request.redirect(first_menu.url)
except:
pass
return self.page("website.homepage")
Wednesday, 5 March 2014
Change report fonts in Odoo
Change reports fonts in Odoo/OpenERP
Let's change font in Odoo/openerp reports. I mean some time we need to change the report font in our company font. Simple answer go to every report(.rml) and change manually every where.
I have simple way to just replace the font.
Steps to do in simplest way
- Download Community module from : l10n_cn_fonts- Just replace your fonts don't forget to put fonts in l10n_cn_fonts/fonts folder.
- Replace the font name in the file __init__.py accordingly.
- Install module
So, now at the time of rendering it will always consider your fonts.
..Enjoy..
Friday, 21 February 2014
Odoo Example Flow
Complete Example:
Steps :
1. Create a new customer
2. Create a new product category and product
3. Add Minimum Stock Rules
4. Create a Bill of Material
5. Warehouse and locations
6. Create a sales quotation
7. Confirm the sales order
8. Run the scheduler
9. Change the purchase request and confirm it
10.Receive the products
11.Create the draft purchase invoice
12.Run the scheduler again
13.Start manufacturing
14.Deliver the goods to the customer and create draft sales invoice
15.Create the sales invoice
16.Confirm the purchase invoice
Steps :
1. Create a new customer
2. Create a new product category and product
3. Add Minimum Stock Rules
4. Create a Bill of Material
5. Warehouse and locations
6. Create a sales quotation
7. Confirm the sales order
8. Run the scheduler
9. Change the purchase request and confirm it
10.Receive the products
11.Create the draft purchase invoice
12.Run the scheduler again
13.Start manufacturing
14.Deliver the goods to the customer and create draft sales invoice
15.Create the sales invoice
16.Confirm the purchase invoice
..Enjoy..
Thursday, 20 February 2014
Know object/table size in Odoo database
Table Size in Odoo
Every time after backup we check how much space needed. Its necessary, but its normal if we have lots of space, but when database size continuously increase then we need to check which table/object increase your database size so fast.
So, in PostgreSQL if we want to see which table/object increase your database size then by following sql query, you can easily know which object consume how much.
[Query ]:
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 100;
..Enjoy..
Wednesday, 18 December 2013
Hide field in tree view based on condition
Hide Field in Tree view
In tree view we know how to put domain or attrs to visible or invisible any field,But, if we want to hide particular field in tree view based on type or state means based on any condition , then its hard to hide as we cannot use attrs to hide as attrs hide only value not a field.
So, its need to put some condition like below as its get value from context and check.
invisible="context.get('picking_type', False) in ['in']"
Version : V8
..Enjoy..
Monday, 16 December 2013
Call xmlrpc when want to access functional field
Hello All,
In openerp sometimes we need to update database value on basis of some field value, we can direct do it but if we want to apply in old data then we use sql query and we update but if there is functional field which is not stored in database but you need to update data base on it. At that time we can do it by xmlrpc.
Here, i defined xmlrpc script in which if there is Purchase order which is 'received' and 'invoiced' but still not in 'done' state by this script purchase order gone in 'done' state.
In openerp sometimes we need to update database value on basis of some field value, we can direct do it but if we want to apply in old data then we use sql query and we update but if there is functional field which is not stored in database but you need to update data base on it. At that time we can do it by xmlrpc.
Here, i defined xmlrpc script in which if there is Purchase order which is 'received' and 'invoiced' but still not in 'done' state by this script purchase order gone in 'done' state.
Purchase Order Done :
import xmlrpclib
import time
username = 'admin' #the user
pwd = 'a' #the password of the user
dbname = 'test' #the database
model = 'purchase.order' # model name
# Get the uid
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)
#replace localhost with the address of the server
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
# argument passed to search
args = [('shipped', '=', True), ('state', 'not in', ['done']), ('invoice_method', 'in', ['manual','picking'])]
# search ids
ids = sock.execute(dbname, uid, pwd, model, 'search', args)
# READ functional field
ids_f = []
fields = ['invoiced']
po_ord = sock.execute(dbname, uid, pwd, model, 'read', ids, fields)
for re in po_ord :
if re['invoiced'] :
ids_f.append(re['id'])
# write state done
values = {'state':'done'}
results = sock.execute(dbname, uid, pwd, model, 'write', ids_f, values)
if ids_f :
print "Successfully applied records ",ids_f
else:
print "No records found to update"
>
Subscribe to:
Posts (Atom)