Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to Replace Default picking_type_id on Purchase Order Without Change the Original Module purchase (by inherit) ?

By
Miftah
on 3/20/15, 6:29 AM 1,390 views

I have tried to inherit purchase module and replace default picking_type_id to False. 

This is original module :

_defaults = {
        'date_order': fields.datetime.now,
        'state': 'draft',
        'name': lambda obj, cr, uid, context: '/',
        'shipped': 0,
        'invoice_method': 'order',
        'invoiced': 0,
        'pricelist_id': lambda self, cr, uid, context: context.get('partner_id', False) and self.pool.get('res.partner').browse(cr, uid, context['partner_id']).property_product_pricelist_purchase.id,
        'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'purchase.order', context=c),
        'journal_id': _get_journal,
        'currency_id': lambda self, cr, uid, context: self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id,
        'picking_type_id': _get_picking_in,
    }

And I change to : 

_defaults = {
                 'name': '/',
                 'picking_type_id': False,
                 'salesman_id': lambda obj, cr, uid, context:uid,
                 'partner_ref': 'try'
                 }

But the default of picking_type_id (just picking_type_id) still get default from original module. How to change it?

What is the definition of the field in your module? Module starts?

zbik
on 3/20/15, 9:05 AM
1

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 3/20/15, 3:47 PM

Hi,

you can override default_get function in your class sale_order like this :


def default_get(self, cr, uid, fields, context=None):

     context = context or {}

     res = super(sale_order, self).default_get(cr, uid, fields, context=context)

     if 'name' in fields:

         res.update({'name': '/'})

     if 'salesman_id' in fields:

         res.update({'salesman_id': uid})

     if 'picking_type_id' in fields:

         res.update({'picking_type_id': False})

     if 'partner_ref' in fields:

         res.update({'partner_ref': 'try'})

    return res

bye


It works, thank you Cyril

Miftah
on 3/23/15, 2:54 AM
0
Edy Kendengis
On 3/20/15, 10:39 AM

you must rewrite the code like this in your new module

_columns = {

    'picking_type_id': fields.many2one('stock.picking.type', 'Deliver To', help="This will determine picking type of incoming       shipment", required=True,

states={'confirmed': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}),

}

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/20/15, 6:29 AM
Seen: 1390 times
Last updated: 7/10/15, 10:50 AM