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

Is possible inherit class (osv. osv_memory)?

By
Luís
on 10/12/13, 8:17 PM 2,562 views

Hi,

I want inherit the class stock_return_picking(osv.osv_memory):

In this class exist the function view_init (def view_init(self, cr, uid, fields_list, context=None):).

I want overwrite all of this function, is possible?

I'm trying do this:

class stock_return_picking(osv.osv_memory):
    _name = 'stock.return.picking'
    _inherit = "stock.return.picking"
    _description = 'Return Picking'



def view_init(self, cr, uid, fields_list, context=None):
        """
         Creates view dynamically and adding fields at runtime.
         @param self: The object pointer.
         @param cr: A database cursor
         @param uid: ID of the user currently logged in
         @param context: A standard dictionary
         @return: New arch of view with new columns.
        """
        if context is None:
            context = {}
        res = super(stock_return_picking, self).view_init(cr, uid, fields_list, context=context)
        record_id = context and context.get('active_id', False)
        if record_id:
            pick_obj = self.pool.get('stock.picking')
            pick = pick_obj.browse(cr, uid, record_id, context=context)


           My code here


            if pick.state not in ['done','confirmed','assigned']:
                raise osv.except_osv(_('Warning!'), _("You may only return pickings that are Confirmed, Available, Shipped or Delivered!"))
            valid_lines = 0
            return_history = self.get_return_history(cr, uid, record_id, context)
            for m  in pick.move_lines:
                if m.state == 'done' and m.product_qty * m.product_uom.factor > return_history.get(m.id, 0):
                    valid_lines += 1
            if not valid_lines:
                raise osv.except_osv(_('Warning!'), _("No products to return (only lines in Done state and not fully returned yet can be returned)!"))
        return res

But the function doesn't do nothing because is not called.

Anyone helps me?

1

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 10/22/13, 12:34 AM

Get rid of the _name = 'stock.return.picking' line, and make sure that function is properly tabbed over to be within the class declaration (assuming that's not just a copy/paste error).

0
Jasad
On 10/22/13, 4:21 AM

yes, you can inherit osv.osv_memory. Please refer 'base_setup' module for example...

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

0 follower(s)

Stats

Asked: 10/12/13, 8:17 PM
Seen: 2562 times
Last updated: 3/16/15, 8:10 AM