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.

0

Question about multi inheritance in modules

By
AJ Schrafel Paper Corp
on 10/4/13, 5:45 PM 706 views

I have a customer module that is going to inherit stock.picking - stock.picking.in and stock.picking.out

When I put some new code in draft_force_assign() in my inherited stock.picking customer module, the function is not being picked up by inherited stock.picking.in, so i have to add draft_force_assign() to both.

How can I make my inherited stock.picking.in get the

  1. stock.picking - original version of draft_force_assign()

    a. stock.picking.in - calls original version of draft_force_assign() in stock.picking.in

  2. custom model that inherits stock.picking - my modified version of draft_force_assign()

    a. custom model that inherits stock.picking.in - calls original version of draft_force_assign() - INSTEAD OF my modified version of draft_force_assign() if i add the modified version to this model, everything works fine.

How can I get 2.a to call the modified version without repeating the code?

Same thing with the columns, i have to add the column to the modified model and all models that inherit that model.

Is there a way around this?

Here is my code:

    _PRODUCT_TYPES = [('itemized','Itemized Product'),('product','Stockable Product'),('consu', 'Consumable'),('service','Service')]

class stock_picking(osv.osv):
    _inherit = "stock.picking"
    _columns = {
        'prod_type': fields.selection(_PRODUCT_TYPES, 'Product Type', required=True, select=True, store=True, help=""),
    }

    def draft_force_assign(self, cr, uid, ids, *args):
        """ Confirms picking directly from draft state.
        @return: True
        """
        wf_service = netsvc.LocalService("workflow")
        for pick in self.browse(cr, uid, ids):
            if not pick.move_lines and not pick.stock_item_lines:
                raise osv.except_osv(_('Error!'),_('You cannot process picking without any stock moves.'))
            if pick.move_lines and pick.stock_item_lines:
                raise osv.except_osv(_('Error!'),_('You cannot process\nStockable Products and Itemized Products\non the same picking please delete one.'))
            wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_confirm', cr)
        return True

stock_picking()

class stock_picking_in(osv.osv):
    _inherit = "stock.picking.in"
    _columns = {
        'prod_type': fields.selection(_PRODUCT_TYPES, 'Product Type', required=True, select=True, store=True, help=""),
    }
    _defaults = {
        #defaults added
    }

    def draft_force_assign(self, cr, uid, ids, *args):
        """ Confirms picking directly from draft state.
        @return: True
        """
        wf_service = netsvc.LocalService("workflow")
        for pick in self.browse(cr, uid, ids):
            if not pick.move_lines and not pick.stock_item_lines:
                raise osv.except_osv(_('Error!'),_('You cannot process picking without any stock moves.'))
            if pick.move_lines and pick.stock_item_lines:
                raise osv.except_osv(_('Error!'),_('You cannot process\nStockable Products and Itemized Products\non the same picking please delete one.'))
            wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_confirm', cr)
        return True

stock_picking_in()

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/4/13, 5:45 PM
Seen: 706 times
Last updated: 3/16/15, 8:10 AM