Beispiel #1
0
    def bom_split(self, cr, uid, bom, factor, addthis=False, level=0):
        """
        split the bom into components.
        factor is the quantity to produce  expressed in bom product_uom
        """
        factor = factor / (bom.product_efficiency or 1.0)
        factor = _common.ceiling(factor, bom.product_rounding)
        if factor < bom.product_rounding:
            factor = bom.product_rounding
        result = []
        phantom = False
        if bom.type == 'phantom' and not bom.bom_lines:
            newbom = self._bom_find(
                cr, uid, bom.product_id.id, bom.product_uom.id)

            if newbom:
                result += self.bom_split(
                    cr, uid, self.browse(cr, uid, [newbom])[0],
                    factor * bom.product_qty,
                    addthis=True,
                    level=level+10)
                phantom = True
            else:
                phantom = False

        if bom.type == 'normal' and bom.bom_lines:
            result.append(self._bom_split_vals(cr, uid, bom, factor))

        elif not phantom:
            if addthis and not bom.bom_lines:
                result.append(self._bom_split_vals(cr, uid, bom, factor))

            for bom2 in bom.bom_lines:
                result += self.bom_split(
                    cr, uid, bom2, factor, addthis=True, level=level + 10)
        return result
Beispiel #2
0
 def _factor(factor, product_efficiency, product_rounding):
     factor = factor / (product_efficiency or 1.0)
     factor = _common.ceiling(factor, product_rounding)
     if factor < product_rounding:
         factor = product_rounding
     return factor
 def _factor(factor, product_efficiency, product_rounding):
     factor = factor / (product_efficiency or 1.0)
     factor = _common.ceiling(factor, product_rounding)
     if factor < product_rounding:
         factor = product_rounding
     return factor
Beispiel #4
0
 def _factor(self, factor, product_efficiency, product_rounding):
     factor = factor / (product_efficiency or 1.0)
     factor = _common.ceiling(factor, product_rounding)
     return factor
    def _bom_explode(self, cr, uid, bom, factor, properties=None, addthis=False, level=0, routing_id=False):
        """ Finds Products and Work Centers for related BoM for manufacturing order.
        @param bom: BoM of particular product.
        @param factor: Factor of product UoM.
        @param properties: A List of properties Ids.
        @param addthis: If BoM found then True else False.
        @param level: Depth level to find BoM lines starts from 10.
        @return: result: List of dictionaries containing product details.
                 result2: List of dictionaries containing Work Center details.
        """
        routing_obj = self.pool.get('mrp.routing')
        factor = factor / (bom.product_efficiency or 1.0)
        factor = _common.ceiling(factor, bom.product_rounding)
        if factor < bom.product_rounding:
            factor = bom.product_rounding
        result = []
        result2 = []
        phantom = False
        if bom.type == 'phantom' and not bom.bom_lines:
            newbom = self._bom_find(cr, uid, bom.product_id.id, bom.product_uom.id, properties)

            if newbom:
                res = self._bom_explode(cr, uid, self.browse(cr, uid, [newbom])[0], factor*bom.product_qty, properties, addthis=True, level=level+10)
                result = result + res[0]
                result2 = result2 + res[1]
                phantom = True
            else:
                phantom = False
        if not phantom:
            if addthis and not bom.bom_lines:
                result.append(
                {
                    'name': bom.product_id.name,
                    'product_id': bom.product_id.id,
                    'product_qty': bom.product_qty * factor,
                    'product_uom': bom.product_uom.id,
                    'product_uos_qty': bom.product_uos and bom.product_uos_qty * factor or False,
                    'product_uos': bom.product_uos and bom.product_uos.id or False,
                })
            routing = (routing_id and routing_obj.browse(cr, uid, routing_id)) or bom.routing_id or False
            if routing:
                for wc_use in routing.workcenter_lines:
                    wc = wc_use.workcenter_id
                    d, m = divmod(factor, wc_use.workcenter_id.capacity_per_cycle)
                    mult = (d + (m and 1.0 or 0.0))
                    hour = 0.0
                    if wc_use.cycle_type=='fix':
                        cycle = wc_use.cycle_nbr
                        hour = float(wc_use.hour_nbr + ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0))
                    elif wc_use.cycle_type=='bom-based':
                        cycle = len(bom.bom_lines)
                        hour = float(wc_use.hour_nbr + ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0)) 
                    else: 
                        cycle = mult * wc_use.cycle_nbr
                        hour = float(wc_use.hour_nbr*mult + ((wc.time_start or 0.0)+(wc.time_stop or 0.0)+cycle*(wc.time_cycle or 0.0)) * (wc.time_efficiency or 1.0))
                    result2.append({
                        'name': tools.ustr(wc_use.name) + ' - '  + tools.ustr(bom.product_id.name),
                        'workcenter_id': wc.id,
                        'sequence': level+(wc_use.sequence or 0),
                        'cycle': cycle,
                        'hour': hour,
                    })
            for bom2 in bom.bom_lines:
                res = self._bom_explode(cr, uid, bom2, factor, properties, addthis=True, level=level+10)
                result = result + res[0]
                result2 = result2 + res[1]
        return result, result2
Beispiel #6
0
    def _bom_explode(self,
                     cr,
                     uid,
                     bom,
                     factor,
                     properties=None,
                     addthis=False,
                     level=0,
                     routing_id=False):
        """ Finds Products and Work Centers for related BoM for manufacturing order.
        @param bom: BoM of particular product.
        @param factor: Factor of product UoM.
        @param properties: A List of properties Ids.
        @param addthis: If BoM found then True else False.
        @param level: Depth level to find BoM lines starts from 10.
        @return: result: List of dictionaries containing product details.
                 result2: List of dictionaries containing Work Center details.
        """
        routing_obj = self.pool.get('mrp.routing')
        factor = factor / (bom.product_efficiency or 1.0)
        factor = _common.ceiling(factor, bom.product_rounding)
        if factor < bom.product_rounding:
            factor = bom.product_rounding
        result = []
        result2 = []
        phantom = False
        if bom.type == 'phantom' and not bom.bom_lines:
            newbom = self._bom_find(cr, uid, bom.product_id.id,
                                    bom.product_uom.id, properties)

            if newbom:
                res = self._bom_explode(cr,
                                        uid,
                                        self.browse(cr, uid, [newbom])[0],
                                        factor * bom.product_qty,
                                        properties,
                                        addthis=True,
                                        level=level + 10)
                result = result + res[0]
                result2 = result2 + res[1]
                phantom = True
            else:
                phantom = False
        if not phantom:
            if addthis and not bom.bom_lines:
                result.append({
                    'name':
                    bom.product_id.name,
                    'product_id':
                    bom.product_id.id,
                    'product_qty':
                    bom.product_qty * factor,
                    'product_uom':
                    bom.product_uom.id,
                    'product_uos_qty':
                    bom.product_uos and bom.product_uos_qty * factor or False,
                    'product_uos':
                    bom.product_uos and bom.product_uos.id or False,
                })
            routing = (routing_id and routing_obj.browse(
                cr, uid, routing_id)) or bom.routing_id or False
            if routing:
                for wc_use in routing.workcenter_lines:
                    wc = wc_use.workcenter_id
                    d, m = divmod(factor,
                                  wc_use.workcenter_id.capacity_per_cycle)
                    mult = (d + (m and 1.0 or 0.0))
                    hour = 0.0
                    if wc_use.cycle_type == 'fix':
                        cycle = wc_use.cycle_nbr
                        hour = float(wc_use.hour_nbr +
                                     ((wc.time_start or 0.0) +
                                      (wc.time_stop or 0.0) + cycle *
                                      (wc.time_cycle or 0.0)) *
                                     (wc.time_efficiency or 1.0))
                    elif wc_use.cycle_type == 'bom-based':
                        cycle = len(bom.bom_lines)
                        hour = float(wc_use.hour_nbr +
                                     ((wc.time_start or 0.0) +
                                      (wc.time_stop or 0.0) + cycle *
                                      (wc.time_cycle or 0.0)) *
                                     (wc.time_efficiency or 1.0))
                    else:
                        cycle = mult * wc_use.cycle_nbr
                        hour = float(wc_use.hour_nbr * mult +
                                     ((wc.time_start or 0.0) +
                                      (wc.time_stop or 0.0) + cycle *
                                      (wc.time_cycle or 0.0)) *
                                     (wc.time_efficiency or 1.0))
                    result2.append({
                        'name':
                        tools.ustr(wc_use.name) + ' - ' +
                        tools.ustr(bom.product_id.name),
                        'workcenter_id':
                        wc.id,
                        'sequence':
                        level + (wc_use.sequence or 0),
                        'cycle':
                        cycle,
                        'hour':
                        hour,
                    })
            for bom2 in bom.bom_lines:
                res = self._bom_explode(cr,
                                        uid,
                                        bom2,
                                        factor,
                                        properties,
                                        addthis=True,
                                        level=level + 10)
                result = result + res[0]
                result2 = result2 + res[1]
        return result, result2
Beispiel #7
0
 def _factor(self, factor, product_efficiency, product_rounding):
     factor = factor / (product_efficiency or 1.0)
     factor = _common.ceiling(factor, product_rounding)
     return factor