Tuesday, 18 July 2017

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail.

Sometimes you see following message in gmail:

and you can't download attached file

Follow steps to download file:

1. Open original message as shown in image

2. Download Original

let's name it download_original.txt

3.  Save following python script in same directory. Let's name it import_file.py

import email
import sys

if __name__=='__main__':
    if len(sys.argv)<2:
        print "Please enter a file to extract attachments from"

    msg = email.message_from_file(open(sys.argv[1]))
    for pl in msg.get_payload():
        if pl.get_filename(): # if it is an attachment
            open(pl.get_filename(), 'wb').write(pl.get_payload(decode=True))

4. Go to Python console

If you are using MAC book or Linux OS - open terminal and type python


python   import_file.py    download_original.txt

It will download your blocked file in same directory.

That's it.

Thanks!!! Enjoy Programming :)



Friday, 14 July 2017

Blogger: Set subdomain for blog using Cloudflare

If you want to point you blog hosted at blogspot.com to subdomain like http://blog.xxxx.com using Cloudflare, following are the steps:

1. Go to Basic Settings of your blog

2. Click on Third-party domain settings under Publishing

3. It will ask you to add two CNAME entries under your DNS settings. You can add as follow in Cloudflare

4. Set domain in your blog settings as http://blog.xxx.com. Save.

That's it. Sometimes it reflects immediately, sometimes it takes 24 to 48 hours as well.

Thanks!!!!!!!!!! Enjoy Programming!! :)

Wednesday, 14 June 2017

Odoo 10: Close wizard and open standard form

Hi, Today we are going to learn how to open standard form after saving data in wizard.

Let's say I have created an wizard to fill basic User details and once saved open default User form. Here is the xml code for my wizrd:

<record id="view_custom_user_wizard" model="ir.ui.view">
        <field name="name">Create User</field>
        <field name="model">res.users</field>
        <field name="arch" type="xml">
            <form string="Create User">
            <field name="company_id" />
            <field name="name" required="1"/>
            <field name="login" required="1"/>
            <field name="password" required="1" password="True" />
                        <button name="create_user" string="Create User" type="object" class="btn-primary"/>

And here is the python code for "create_user" function:

def create_user(self):
    # We need to get view_id where we are going the user to redirect
    self._cr.execute("select res_id from ir_model_data where name = 'view_users_form'")
    result = self._cr.fetchone()
    form_obj_id = result[0]
    return {
        'name': _('User'),
        'view_type': 'form',
        'view_mode': 'form',
        'view_id': form_obj_id,
        'res_model': 'res.users',
        'domain': [],
        'context': dict(self._context, active_ids=self.ids),
        'type': 'ir.actions.act_window',
        'target': 'current',
        'res_id': self.id, #represents user id


That's it!!!

Thanks!!!!!!!! Enjoy Programming!! :)

Tuesday, 6 June 2017

Odoo: Download Binary File in v10

To download any binary file in Odoo10 following is the link:<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>

module_name   - the name of the model with the Binary field
field_name        - the name of the Binary field
object_id           - id of the record containing particular file.
field_filename   - name of a Char field containing file's name (optional).

So if you want to call a function on button click and download the file, code is as follow:

file_url = "<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>"
return {
    'type': 'ir.actions.act_url',
    'url': file_url,
    'target': 'new'

In Reports or web page, you can use it as:

<t t-foreach="files" t-as="f">
        <td><t t-esc="f.name"/></td>
        <td><a t-attf-href="/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>">Download</a></td>

Where files is a list of files

Thanks!!!!!!!!! Enjoy Programming!! :)

Emails not working in PHP/Ubuntu

Hi, lot of solutions are there to fix this problem but I feel somewhere, sometimes we miss the basic part...

It may be possibility that we don't have sendemail utility itself not installed. Please install by running following command.

sudo apt-get install sendmail -y

If issue is still there please check following link:


Thanks!!!! Enjoy Programming :)

Thursday, 1 June 2017

Odoo: Set/use context in email templates

Today we are going to discuss, how to use/change context in dynamic/custom templates.

Let's say we want to send some values to email template other than normal object id, here is the code for that

In controllers/main.py

local_context = request.env.context.copy()

in module.py file

local_context = self.env.context.copy()
    'name': 'Shiv',
    'place': 'Bangalore'

template = request.env.ref('module_name.email_template_id')
            template.with_context(local_context).send_mail(object.id, force_send=True, raise_exception=True)

In email template code you can access context as:


That's it.

Thanks!!! Enjoy Programming!!! :)

To know how to create custom email template, please check here: http://www.odoo.yenthevg.com/creating-mail-templates/

Monday, 29 May 2017

Odoo: Upload binary images from backend using API

If you want to upload binary image to odoo using API..here are the steps:


# -*- coding: utf-8 -*-
from odoo.tools.translate import _
from odoo import http
from odoo.http import request
from odoo.addons import web
from time import strftime
import functools
import datetime
import json
import base64
import sys
import copy
from dateutil import parser
import logging
from operator import itemgetter
logger = logging.getLogger(__name__)

def serialize_exception(f):
    def wrap(*args, **kwargs):
            return f(*args, **kwargs)
        except Exception, e:
            logger.debug("An exception occured during an http request")
            #se = _serialize_exception(e)
            error = {
                'code': 200,
                'message': "Odoo Server Error",
                'data': str(e)
            return json.dumps(error)
    return wrap

class Binary(web.controllers.main.Binary):
    @http.route('/api/upload_images', type='http', auth="public", csrf=False)
    def upload_attachment(self, uid, ufile, ufile_name):
        user_model = request.env['res.users']
        user_ids = user_model.sudo().browse([('id', '=', uid)])
        if user_ids:
            user_obj = user_ids[0]
                    'uploaded_files': base64.encodestring(ufile.read()),
                    'uploaded_files_filename': ufile_name,
            except Exception:
                args = {'status': 0, 'error': "Something horrible happened."}
                return json.dumps(args)
            return json.dumps({'status': 1, 'message': 'File uploaded successfully'})
            return json.dumps({'status': 0, 'message': 'User does not exist.'})

Where fields are:

uploaded_files = fields.Binary(string=_('Files'), attachment=True, store=True)
uploaded_files_filename = fields.Char("Filename")

and JS code is:

    // grab your file object from a file input
    // Where fileInput is
    // <input id="fileInput" type="file" />
    $('#fileInput').change(function () {

    function sendFile(file) {
        var querydata = new FormData();
        querydata.append('uid', 10);
        //querydata.append('multi', 'true');
            url: "http://xxxxx:8069/api/upload_images",
            data: querydata,
            type: "POST",
            cache: false,
            processData: false, 
            contentType: false,
            dataType: "json",
            beforeSend: function (xhr) {

            success: function (result) {
            error: function (err) {



Thanks!!!!!!!!!! Enjoy Programming!!! :) 

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...