Tuesday, 23 September 2014

Show path between two Address on google map in Odoo ( formerly openerp )

To show path, distance and duration between source and destination address on google map , just use this simple function in Odoo. An new window will pop up in browser, showing path between source address and destination address .

def show_path_on_google_map(self, cr, uid, ids, context=None):
    ''’ Function to show path between Source and Destination Address on Google map '''
    url="http://maps.google.com/maps?saddr="
    # Demo Addresses
    source_address = ' Mumbai, Maharashtra '
    destination_address = 'Red Fort Delhi, India ,110006'
       
    url += source_address + '&daddr=' + destination_address
    return {
        'type': 'ir.actions.act_url',
        'url':url,
        'nodestroy': True,
        'target': 'new'
    }




Thanks

Sonu Chaudhary

Monday, 8 September 2014

How to get Latitude and Longitude of address in Odoo ( Openerp ) using Google Api in Python


You may require to get Latitude and Longitude between of an address in Odoo ( Openerp ) for many reasons . Here are steps to follow - 

1.     First install pygeocoder Python Package
          Simply you can install using –
          apt-get install python-pip
          pip install pygeocoder
          or from python packages site.
         
 2.     Now import Geocoder class from pygeocoder in your py file
       from pygeocoder import Geocoder
       import urllib
            import json
           
      Now you use get_latitude_longitude (Global )function given below , pass address as argument and you will get a list of latitude and longitude returned from Google Api – ex [19.1605798,72.8380889]

      def get_latitude_longitude(addr):
           url ='https://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
           url += urllib.quote(addr.encode('utf8'))
           res = []
           try:
                gcoder = Geocoder()
                results = gcoder.geocode(addr)
                res.append(results[0].latitude)
                res.append(results[0].longitude)
           except Exception, e:
                pass

            return res



Thanks
Sonu Chaudhary

Saturday, 14 June 2014

Show your Customers on google map in openerp ( Odoo Google Map Integration)

In this blog , I will show you ,how to show markers on google map for your Customers with their Details
I wanted to show filtered customers only . Example all customers for a particular City

Wednesday, 4 June 2014

Openerp 7 Linkedin integration ( Odoo )

This tutorial will dictate steps , how to integrate linkedin with openerp.

1. First you should have a linkedin Account .
   install Linkedin Integration Module(web_linkedin) and OAuth2 Authentication module
   now go to https://www.linkedin.com/secure/developer
 
2. create an application . I am attaching demo snapshots for that. 
   In snapshots ,I am using my local ip ie. http://192.168.1.50:8069/ instead of localhost:8069/
   Replace your ip in place of demo ip(192.168.1.50).
  



Fill the details as mentioned and give rights and then save your application . It will generate api and secret key.
   Note that api key.

3. Now in openerp , go to setting>sales>Social Network Integration
   check the "Get contacts automatically from linkedIn" checkbox
   and enter Api Key over there



4. now go to the customers -> edit view
   enter customer name and click on linkedin widget (blue icon). It will open a wizard , where related people and companies for that customer are shown.


5. If you find a usable search result , click on that results and address , email , phone , mobile , website etc are fetched from linked and filled automatically on the customer form


Thanks
Sonu Chaudhary



Tuesday, 3 June 2014

How to add new field in Delivery Orders or in shipments

I sufferd from this problem. I was trying to add new field in Delivery Order ,but it was disappearing from the view.
  So I thought to share it with you guys.
To add new field in Delivery Orders ex-'delivery_tracking' -
   inherit stock.picking.out and normal stock.picking with both having the fields.
Means you need to add your custom field in both stock.picking and stock.picking.out.

class stock_picking(osv.osv):
    _inherit = "stock.picking"
    _columns={
            'delivery_tracking': fields.char('Delivery Tracking' , size=32), # Your custom field

            }

class stock_picking_out(osv.osv):
    _inherit = "stock.picking.out"
    _columns={
            'delivery_tracking': fields.char('Delivery Tracking' , size=32), # Your custom field

            }
           

Now in xml, inherit Delivery view and add your custom field

<record id="view_stock_picking_out_extended" model="ir.ui.view">
    <field name="name">stock.picking.out.extended.form</field>
    <field name="model">stock.picking.out</field>
    <field name="inherit_id" ref="stock.view_picking_out_form"/>
    <field name="arch" type="xml">
            <field name="backorder_id" position="after">
                <field name="delivery_tracking" ><!-- Your custom field -->
            </field>
    </field>
</record>

The same applies for shipment view

Thanks
Sonu Chaudhary

Add Date range in Group by search filters in Openerp 7 ( Odoo )

Example -  You want to add this filter in tasks.
       In project.task object there are 2 fields - date_start and date_end , and we can use these fields for our date range filter

To add date from and date to filter in openerp , you can follow these steps:

1. import these packages in py file

import netsvc
from osv import fields, osv
from tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT, DATETIME_FORMATS_MAP, float_compare

2. inherit project_task class and add two fields - task_date_from and task_date_to, to be used for filter -
    class project_task(osv.osv):
        _inherit = "project.task"

        _columns = {
            'task_date_from':fields.function(lambda *a,**k:{}, method=True, type='date',string="Task date from"),
            'task_date_to':fields.function(lambda *a,**k:{}, method=True, type='date',string="Task date to"),

        }

3. Now add task_date_from and task_date_to fields in the view -
   For more interactive search view , you can use widget="calendar"

    <record id="view_task_search_form_inherit" model="ir.ui.view">
            <field name="name">project.task.search</field>
            <field name="model">project.task</field>
            <field name="inherit_id" ref="project.view_task_search_form" />
            <field name="arch" type="xml">
                <xpath expr="/search[@string='Tasks']/field[@name='project_id]" position="after">
                    <field name="task_date_from" filter_domain="[('date_start','&gt;=',self)]" widget="calendar"/>
                    <field name="task_date_to" filter_domain="[('date_end','&lt;=',self)]" widget="calendar"/>
                </xpath>
                
            </field>
        </record>



Thanks 
Sonu Chaudhary 

Thursday, 15 May 2014

How to hide create and edit from many2one dropdown in openerp v7

Sometimes case might happen , like you dont want to let create new records from many2one field.
example - There is customer field in sale order form , and you dont want to let user create a new customer from there .
You want let everyone create customer , then it is importtant post for you.

Install a openerp module named "web_m2x_options"
module url - https://www.openerp.com/apps/7.0/web_m2x_options/

Now you can use several options for many2one -

limit- Number of displayed record in drop-down panel(limit)
example - <field name="partner_id" options="{'limit': 10, }" />

create - Whether to display the "Create..." entry in dropdown panel(depends if user have create rights)).
example - <field name="partner_id" options="{'create': False, }" />

create_edit - Whether to display "Create and Edit..." entry in dropdown panel(depends if user have create rights)
example - <field name="partner_id" options="{'create_edit': False }" />

no_open - if you want to hide many2one link (used to open form view for many2one)
example - <field name="partner_id" options="{"no_open": True }" />


you can use all options at once also

options="{'limit': 10, 'create': False, 'create_edit': False ,"no_open": True }"


Thanks
Sonu Chaudhary

How to validate address of customer in openerp

It is answer to the questions like -
    a- how to verify address of partner in openerp
    b- how to correct address entered by user

We need varified and valid address in several cases like for - shipping address. 
Here I am going to tell you how to verify your address with TAX CLOUD (https://taxcloud.net/default.aspx).It is a short integration.
Follow these simple steps:-

1. for this you have to install a python package "suds" -
  can use command - pip install suds

2. then import suds into your code -
    import suds

3. then get instance of client -
    client = suds.client.Client(wsdl)

4. put this wsdl address into your code -
    wsdl = "https://api.taxcloud.net/1.0/?wsdl"

5. now create a usps id -
    go to address - https://www.usps.com/business/web-tools-apis/developers-center.htm
    register your self . You will get USPS user id. put that into variable usps_id into your code
    usps_id = "269SONUCXXXX" // example

6. now you can use "VerifyAddress" method of client class , to validate and correct address .
    Here is sample code


    vals ={}
    try:
        verifiedAddress = client.service.VerifyAddress(usps_id, 'street' ,'street2', 'city',state_code, 'zip')
        if verifiedAddress.ErrNumber!='0':
        vals.update({'address_valid_message':str(verifiedAddress.ErrDescription)})
        raise osv.except_osv(_('Address Validation Error'), _(str(verifiedAddress.ErrDescription)))
        else:
        vals.update({
                'street': verifiedAddress.Address1,
                'street2': verifiedAddress.Address2 if verifiedAddress.__contains__('Address2') else '',
                'city': verifiedAddress.City,
                'state_id': self.get_state_id(cr, uid, verifiedAddress.State, context=context),
                'zip': verifiedAddress.Zip5+'-'+verifiedAddress.Zip4,
                'address_valid_message': 'Valid Address',
                #'valid_address':True,
                 })
    except Exception, e:
        print "Exception E......",e.args
        raise osv.except_osv(_('Address Validation Error'), _("Address is not Valid"
        " %s") % str((e.args)))
        pass
    return vals

    it retuns ErrNumber non-zero on failure and zero on success
    so you can identify whether address was valid or not .

It returns corrected address ,which you can put back into your form
  To access corrected street
     corrected_street = verifiedAddress.Address1
     example - vals.update({
                'street': verifiedAddress.Address1,
                'street2': verifiedAddress.Address2 if verifiedAddress.__contains__('Address2') else '',
                'city': verifiedAddress.City,
                'state_id': self.get_state_id(cr, uid, verifiedAddress.State, context=context),
                'zip': verifiedAddress.Zip5+'-'+verifiedAddress.Zip4,
                'address_valid_message': 'Valid Address',
                #'valid_address':True,
                 })
Note - It requires a working internet connection

Thanks
Sonu Chaudhary

How to choose form view used by many2one field in OpenERP V7


When you click on the link  of many2one field in edidatble mode , your default form view gets open.
But sometimes you might want to open a minimum view (with less fields ) or your customised view. In that case , you can pass your form id in the context.







 For example, I have a many2one field partner_id from res.partner, and I want to show my own form view ,instead of default view for res.partner .

<field name="partner_id" context="{'form_view_ref':'module_name.view_partner_form_your_view'}"/>

Here we pass form_view_ref in context and value for it as xml_id of form view.

ex:- <field name="partner_id" default_focus="1" context="{'form_view_ref':'partner_extend.view_partner_form_inherit'}" />

partner_extend - It is module nameview_partner_form_inherit - view xml id to open on many2one link

Now my form gets open from many2one link.




Thanks
Sonu Chaudhary