← Back to team overview

openerp-expert-framework team mailing list archive

Re: produce more/less than expected

 

On 2013-07-30 00:42, Davide Corio wrote:
>
> are you aware of an addon that allow the user to produce a different 
> quantity of product rather than the qty specified before confirming the MO?

I too faced this issue (I deal with oranges). You can override
mrp_production.action_compute() to fix this. A version is attached. Pass
the raw_product_id and raw_qty in the context.

However, in the end I decided that Manufacturing Orders add far more
complexity than benefits, so now I just create Production Lots directly
with a custom wizard for each type.

Martin
# -*- coding: utf-8 -*-

from osv import osv, fields

class mrp_production(osv.osv):
    """Production Order"""
    _inherit = 'mrp.production'

    def action_compute(self, cr, uid, ids, properties=[], context={}):
        """ Does not modify raw_qty according to product_qty, unlike original
        @param properties: List containing dictionaries of properties.
        @return: No. of products.
        """
        bom_obj = self.pool.get('mrp.bom')
        uom_obj = self.pool.get('product.uom')
        prod_line_obj = self.pool.get('mrp.production.product.line')
        workcenter_line_obj = self.pool.get('mrp.production.workcenter.line')
        products = []

        for production in self.browse(cr, uid, ids):
            cr.execute('delete from mrp_production_product_line where production_id=%s', (production.id,))
            cr.execute('delete from mrp_production_workcenter_line where production_id=%s', (production.id,))
            bom_point = production.bom_id
            bom_id = production.bom_id.id
            if not bom_point:
                bom_id = bom_obj._bom_find(cr, uid, production.product_id.id, production.product_uom.id, properties)
                if bom_id:
                    bom_point = bom_obj.browse(cr, uid, bom_id)
                    routing_id = bom_point.routing_id.id or False
                    self.write(cr, uid, [production.id], {'bom_id': bom_id, 'routing_id': routing_id})

            if not bom_id:
                raise osv.except_osv('Error', "Couldn't find a bill of material for this product.")

            if context.get('raw_product_id'):
                factor = 1.0
            else:
                factor = uom_obj._compute_qty(cr, uid, production.product_uom.id, production.product_qty, bom_point.product_uom.id)

            products, work_centers = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, properties, routing_id=production.routing_id.id)

            for line in products:
                line['production_id'] = production.id
                if line['product_id'] == context.get('raw_product_id'):    # should only be one
                    line['product_qty'] = context.get('raw_qty')
                prod_line_obj.create(cr, uid, line)
            for line in work_centers:
                line['production_id'] = production.id
                workcenter_line_obj.create(cr, uid, line)
        return len(products)

mrp_production()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Follow ups

References