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