Thursday, August 16, 2012

OpenERP Meeting Invitation . 

In Core OpenERP 6.1 meeting invitations are going wia mail and ICS file as attachment. But no feature for the Get back Response Or the Normal Invitation Feature which Mail Client are providing by default for accepting or rejecting invitations.


You can have this feature by providing . "METHOD : REQUEST" with valid Dates and organizer with "mailto" attributes.
"cal.add('METHOD').value = 'REQUEST' "

also you have to set the header for the mail .

"part = MIMEBase('text', "calendar") "
"part.set_param('method','REQUEST') "





Wednesday, July 13, 2011

Generate BarCode in Python

You can Generate Barcode (image, Pdf Etc...) in Python
Example is for JPG file
from reportlab.graphics.barcode import createBarcodeDrawing, \
getCodes
def get_image(self, value, width, hight, hr, code='QR'):
""" genrating image for barcode """
options = {}

if width:options['width'] = width
if hight:options['hight'] = hight
if hr:options['humanReadable'] = hr
try:
ret_val = createBarcodeDrawing(code, value=value,
**options)
except Exception, e:
raise osv.except_osv('Error', e)
return ret_val.asString('jpg')


To get Supported barcode in your system

$ print getCodes()

reference : report lab

Tuesday, February 8, 2011

Convert PDF in Text format

import popen2
from StringIO import StringIO
class InputStreamReader(object):

def __init__(self, inputStream, encoding):

super(InputStreamReader, self).__init__()
self.inputStream = inputStream
self.encoding = encoding or 'utf-8'

def _read(self, length):

return self.inputStream.read(length)

def read(self, length=-1):

text = self._read(length)
text = unicode(text, self.encoding)
return text

def close(self):

self.inputStream.close()

process = popen2.Popen4(["pdftotext", "-enc", "UTF-8", 'Full_Path', "-"])
data=InputStreamReader(process.fromchild, 'utf-8')._read(-1)
print data

Wednesday, November 17, 2010

Domain's value depending on condition

In OpenERP view depending on condition value for the right argument can be provided.

domain="[('product_tmpl_id.categ_id.name', 'ilike',
(parent.category in ('RM', 'PM') and parent.category) or
(parent.category == 'OM' and 'Other') or
'')]"

Friday, November 12, 2010

Python Magic

Serves Current Directory listing on 8000 port


$ python -m SimpleHTTPServer

Download HTML Page
$ python -m urllib http://www.python.org > python.html


Prints the year calendar, like the "cal" command.

$ python -m calendar

Works as a command line ftp client

$ python -m ftplib

Sends email using localhost smtp server as relay.

$ python -m smtplib

Wednesday, October 13, 2010

VIM : Working with files

Working with files
Vim command Action
:e filename Open a new file. You can use the Tab key for automatic file name completion, just like at the shell command prompt.
:w filename Save changes to a file. If you don't specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:q Quit Vim. If you have unsaved changes, Vim refuses to exit.
:q! Exit Vim without saving changes.
:wq Write the file and exit.
:x Almost the same as :wq, write the file and exit if you've made changes to the file. If you haven't made any changes to the file, Vim exits without writing the file.
These Vim commands and keys work both in command mode and visual mode.
Vim command Action
j or Up Arrow Move the cursor up one line.
k or Down Arrow Down one line.
h or Left Arrow Left one character.
l or Right Arrow Right one character.
e To the end of a word.
E To the end of a whitespace-delimited word.
b To the beginning of a word.
B To the beginning of a whitespace-delimited word.
0 To the beginning of a line.
^ To the first non-whitespace character of a line.
$ To the end of a line.
H To the first line of the screen.
M To the middle line of the screen.
L To the the last line of the screen.
:n Jump to line number n. For example, to jump to line 42, you'd type :42
Inserting and overwriting text
Vim command Action
i Insert before cursor.
I Insert to the start of the current line.
a Append after cursor.
A Append to the end of the current line.
o Open a new line below and insert.
O Open a new line above and insert.
C Change the rest of the current line.
r Overwrite one character. After overwriting the single character, go back to command mode.
R Enter insert mode but replace characters rather than inserting.
The ESC key Exit insert/overwrite mode and go back to command mode.
Deleting text
Vim command Action
x Delete characters under the cursor.
X Delete characters before the cursor.
dd or :d Delete the current line.
Entering visual mode
Vim command Action
v Start highlighting characters. Use the normal movement keys and commands to select text for highlighting.
V Start highlighting lines.
The ESC key Exit visual mode and return to command mode.
Editing blocks of text
Note: the Vim commands marked with (V) work in visual mode, when you've selected some text. The other commands work in the command mode, when you haven't selected any text.
Vim command Action
~ Change the case of characters. This works both in visual and command mode. In visual mode, change the case of highlighted characters. In command mode, change the case of the character uder cursor.
> (V) Shift right (indent).
< (V) Shift left (de-indent).
c (V) Change the highlighted text.
y (V) Yank the highlighted text. In Windows terms, "copy the selected text to clipboard."
d (V) Delete the highlighted text. In Windows terms, "cut the selected text to clipboard."
yy or :y or Y Yank the current line. You don't need to highlight it first.
dd or :d Delete the current line. Again, you don't need to highlight it first.
p Put the text you yanked or deleted. In Windows terms, "paste the contents of the clipboard". Put characters after the cursor. Put lines below the current line.
P Put characters before the cursor. Put lines above the current line.
Undo and redo
Vim command Action
u Undo the last action.
U Undo all the latest changes that were made to the current line.
Ctrl + r Redo.
Vim command Action
/pattern Search the file for pattern.
n Scan for next search match in the same direction.
N Scan for next search match but opposite direction.
Replace
Vim command Action
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
The range (r) can be
nothing Work on current line only.
number Work on the line whose number you give.
% The whole file.
Arguments (a) can be
g Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i Ignore case for the search pattern.
I Don't ignore case.
c Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches ("Yes to all"), and q to quit substitution.
Examples
:452s/foo/bar/ Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/g Replace every occurrence of the word foo with bar on current line.
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/foo/bar/gc Confirm every substitution.
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.

Wednesday, April 28, 2010

Remove index.php from url in magento

Solution for ubuntu

* Enable rewrite mod for apache by command "a2enmod rewrite"

* sudo vim /etc/apache2/sites-available/default

* change AllowOverride None to AllowOverride All in this file

* sudo vim /etc/apache2/sites-enabled/000-default

* change AllowOverride None to AllowOverride All in this file

* sudo vim /var/www/magento/.htaccess

* change RewriteBase / to RewriteBase /magento/

* now restart apache sudo /etc/init.d/apache2 restart