This question has been flagged
2768 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()
Avatar
Discard
Author

this is apparently a bug with a fix waiting for the fix to be merged. https://code.launchpad.net/~openerp-dev/openobject-server/trunk-base-model-thu/+merge/159245 The existence of the bug is noted in the delivery addon module.