This question has been flagged

Hello all,

Can I produce a Manufacturing Order (assign + force production + produce) from Python? I want to do the same, via python code, as I do clicking on the buttons above the Manufacturing Order.

My attempt so far is this, but it is not working:

class mrp_production(osv.osv):

    """ Production Orders / Manufacturing Orders """ _inherit = 'mrp.production'

    def create(self, cr, uid, values, context=None):

        res = super(mrp_production, self).create(cr, uid, values, context=context)

        prod_obj = self.pool.get('mrp.production')

        production = prod_obj.browse(cr, uid, res, context=context)

        prod_obj.action_assign(cr, uid, production.id, context=context) production = prod_obj.browse(cr, uid, res, context=context) if production.state == 'draft':

            prod_obj.force_production(cr, uid, production.id) prod_obj.action_produce(cr, uid, production.id, production.product_qty, 'consume_produce', context=context)

        prod_obj.signal_workflow(cr, uid, [production.id,], 'button_produce', context=context)

        return res


Going step-by-step the problem seems to be because no stock moves are generated using this script.


What could I be missing?


Thanks in advance

Avatar
Discard