Ejemplo n.º 1
0
    def apportion_cost(self, cost):
        for assembly in self:
            if not assembly.line_in_ids:
                continue

            collects = []
            ignore_move = [line.id for line in assembly.line_in_ids]
            for parent in assembly.line_in_ids:
                collects.append((parent, parent.goods_id.get_suggested_cost_by_warehouse(
                    parent.warehouse_dest_id, parent.goods_qty, ignore_move=ignore_move)[0]))

            amount_total, collect_parent_cost = sum(collect[1] for collect in collects), 0
            for parent, amount in islice(collects, 0, len(collects) - 1):
                parent_cost = safe_division(amount, amount_total) * cost
                collect_parent_cost += parent_cost
                parent.write({
                        'cost_unit': safe_division(parent_cost, parent.goods_qty),
                        'cost': parent_cost,
                    })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_parent_cost = cost - collect_parent_cost
            collects[-1][0].write({
                    'cost_unit': safe_division(last_parent_cost, collects[-1][0].goods_qty),
                    'cost': last_parent_cost,
                })

        return True
Ejemplo n.º 2
0
    def apportion_cost(self, cr, uid, ids, subtotal, context=None):
        for assembly in self.browse(cr, uid, ids, context=context):
            if not assembly.line_in_ids:
                continue

            collects = []
            for child in assembly.line_in_ids:
                collects.append(
                    (child,
                     child.goods_id.get_suggested_cost_by_warehouse(
                         child.warehouse_dest_id.id, child.goods_qty)[0]))

            amount_total, collect_child_subtotal = sum(
                collect[1] for collect in collects), 0
            for child, amount in islice(collects, 0, len(collects) - 1):
                child_subtotal = safe_division(amount, amount_total) * subtotal
                collect_child_subtotal += child_subtotal
                child.write({
                    'price':
                    safe_division(child_subtotal, child.goods_qty),
                    'subtotal':
                    child_subtotal,
                })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_child_subtotal = subtotal - collect_child_subtotal
            collects[-1][0].write({
                'price':
                safe_division(last_child_subtotal, collects[-1][0].goods_qty),
                'subtotal':
                last_child_subtotal,
            })

        return True
Ejemplo n.º 3
0
    def apportion_cost(self, subtotal):
        for assembly in self:
            if not assembly.line_in_ids:
                continue

            collects = []
            ignore_move = [line.id for line in assembly.line_in_ids]
            for parent in assembly.line_in_ids:
                collects.append((parent, parent.goods_id.get_suggested_cost_by_warehouse(
                    parent.warehouse_dest_id, parent.goods_qty, ignore_move=ignore_move)[0]))

            amount_total, collect_parent_subtotal = sum(collect[1] for collect in collects), 0
            for parent, amount in islice(collects, 0, len(collects) - 1):
                parent_subtotal = safe_division(amount, amount_total) * subtotal
                collect_parent_subtotal += parent_subtotal
                parent.write({
                        'price': safe_division(parent_subtotal, parent.goods_qty),
                        # TODO @zzx 需要考虑一下将subtotal变成计算下字段之后的影响
                        # 'subtotal': parent_subtotal,
                    })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_parent_subtotal = subtotal - collect_parent_subtotal
            collects[-1][0].write({
                    'price': safe_division(last_parent_subtotal, collects[-1][0].goods_qty),
                    # TODO @zzx 需要考虑一下将subtotal变成计算下字段之后的影响
                    # 'subtotal': last_parent_subtotal,
                })

        return True
Ejemplo n.º 4
0
    def apportion_cost(self, cost):
        for assembly in self:
            if not assembly.line_in_ids:
                continue

            collects = []
            ignore_move = [line.id for line in assembly.line_in_ids]
            for parent in assembly.line_in_ids:
                collects.append((
                    parent, parent.goods_id.get_suggested_cost_by_warehouse(
                        parent.warehouse_dest_id, parent.goods_qty,
                        lot_id=parent.lot_id,
                        attribute=parent.attribute_id,
                        ignore_move=ignore_move)[0]))

            amount_total, collect_parent_cost = sum(
                collect[1] for collect in collects), 0
            for parent, amount in islice(collects, 0, len(collects) - 1):
                parent_cost = safe_division(amount, amount_total) * cost
                collect_parent_cost += parent_cost
                parent.write({
                        'cost_unit': safe_division(
                            parent_cost, parent.goods_qty),
                        'cost': parent_cost,
                    })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_parent_cost = cost - collect_parent_cost
            collects[-1][0].write({
                    'cost_unit': safe_division(
                        last_parent_cost, collects[-1][0].goods_qty),
                    'cost': last_parent_cost,
                })

        return True
Ejemplo n.º 5
0
    def apportion_cost(self, subtotal):
        for assembly in self:
            if not assembly.line_in_ids:
                continue

            collects = []
            for parent in assembly.line_in_ids:
                collects.append(
                    (parent,
                     parent.goods_id.get_suggested_cost_by_warehouse(
                         parent.warehouse_dest_id, parent.goods_qty)[0]))

            amount_total, collect_parent_subtotal = sum(
                collect[1] for collect in collects), 0
            for parent, amount in islice(collects, 0, len(collects) - 1):
                parent_subtotal = safe_division(amount,
                                                amount_total) * subtotal
                collect_parent_subtotal += parent_subtotal
                parent.write({
                    'price':
                    safe_division(parent_subtotal, parent.goods_qty),
                    'subtotal':
                    parent_subtotal,
                })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_parent_subtotal = subtotal - collect_parent_subtotal
            collects[-1][0].write({
                'price':
                safe_division(last_parent_subtotal, collects[-1][0].goods_qty),
                'subtotal':
                last_parent_subtotal,
            })

        return True
Ejemplo n.º 6
0
    def apportion_cost(self, cr, uid, ids, subtotal, context=None):
        for assembly in self.browse(cr, uid, ids, context=context):
            if not assembly.line_in_ids:
                continue

            collects = []
            for child in assembly.line_in_ids:
                collects.append((child, child.goods_id.get_suggested_cost_by_warehouse(
                    child.warehouse_dest_id.id, child.goods_qty)[0]))

            amount_total, collect_child_subtotal = sum(collect[1] for collect in collects), 0
            for child, amount in islice(collects, 0, len(collects) - 1):
                child_subtotal = safe_division(amount, amount_total) * subtotal
                collect_child_subtotal += child_subtotal
                child.write({
                        'price': safe_division(child_subtotal, child.goods_qty),
                        'subtotal': child_subtotal,
                    })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_child_subtotal = subtotal - collect_child_subtotal
            collects[-1][0].write({
                    'price': safe_division(last_child_subtotal, collects[-1][0].goods_qty),
                    'subtotal': last_child_subtotal,
                })

        return True
Ejemplo n.º 7
0
    def prev_action_done(self):
        for line in self:
            if line.warehouse_id.type == 'stock' and \
                    line.goods_id.is_using_matching():
                if line.goods_id.is_using_batch():
                    matching_records, cost = \
                        line.goods_id.get_matching_records_by_lot(
                            self.lot_id, self.goods_qty, self.goods_uos_qty)
                    for matching in matching_records:
                        self.create_matching_obj(line, matching)
                else:
                    matching_records, cost = line.goods_id \
                        .get_matching_records(
                            line.warehouse_id, line.goods_qty,
                            uos_qty=line.goods_uos_qty,
                            attribute=line.attribute_id)
                    for matching in matching_records:
                        self.create_matching_obj(line, matching)
                line.cost_unit = safe_division(cost, line.goods_qty)
                line.cost = cost
                # 将过保日填充到出库明细行
                line.expiration_date = matching_records and matching_records[
                    0].get('expiration_date')

        return super(wh_move_line, self).prev_action_done()
Ejemplo n.º 8
0
    def prev_action_done(self):
        """
            发货 matching
        """
        for line in self:
            if line.warehouse_id.type == 'stock' and \
                    line.goods_id.is_using_matching():
                if line.goods_id.is_using_batch() and line.lot_id:
                    matching_records, cost = \
                        line.goods_id.get_matching_records_by_lot(
                            line.lot_id, line.goods_qty, line.goods_uos_qty)
                    for matching in matching_records:
                        self.create_matching_obj(line, matching)
                else:
                    matching_records, cost = line.goods_id \
                        .get_matching_records(
                        line.warehouse_id, line.goods_qty,
                        uos_qty = line.goods_uos_qty,
                        attribute = line.attribute_id,
                        move_line = line)
                    for matching in matching_records:
                        self.create_matching_obj(line, matching)
                line.cost_unit = safe_division(cost, line.goods_qty)
                line.cost = cost
                # 将过保日填充到出库明细行
                line.expiration_date = matching_records and matching_records[0].get(
                    'expiration_date')

        return super(WhMoveLine, self).prev_action_done()
Ejemplo n.º 9
0
    def get_move_line(self, cr, uid, ids, wh_type='in', context=None):
        if isinstance(ids, (list, tuple)):
            ids = ids[0]

        line = self.browse(cr, uid, ids, context=context)

        inventory_warehouse = self.pool.get('warehouse').get_warehouse_by_type(cr, uid, 'inventory')

        res = {
            'warehouse_id': wh_type == 'out' and line.warehouse_id.id or inventory_warehouse,
            'warehouse_dest_id': wh_type == 'in' and line.warehouse_id.id or inventory_warehouse,
            'goods_id': line.goods_id.id,
            'uom_id': line.uom_id.id,
            'goods_qty': abs(line.difference_qty)
        }

        if wh_type == 'in':
            subtotal, matching_qty = line.goods_id.get_suggested_cost_by_warehouse(
                line.warehouse_id.id, abs(line.difference_qty))
            res.update({
                    'price': safe_division(subtotal, matching_qty),
                    'subtotal': subtotal,
                })

        return res
Ejemplo n.º 10
0
    def get_suggested_cost_by_warehouse(self,
                                        warehouse,
                                        qty,
                                        lot_id=None,
                                        attribute=None,
                                        ignore_move=None):
        # 存在一种情况,计算一条line的成本的时候,先done掉该line,之后在通过该函数
        # 查询成本,此时百分百搜到当前的line,所以添加ignore参数来忽略掉指定的line
        if lot_id:
            records, cost = self.get_matching_records_by_lot(lot_id,
                                                             qty,
                                                             suggested=True)
        else:
            records, cost = self.get_matching_records(warehouse,
                                                      qty,
                                                      attribute=attribute,
                                                      ignore_stock=True,
                                                      ignore=ignore_move)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            cost_unit = safe_division(cost, matching_qty)
            if matching_qty >= qty:
                return cost, cost_unit
        else:
            cost_unit = self._get_cost(warehouse, ignore=ignore_move)
        return cost_unit * qty, cost_unit
Ejemplo n.º 11
0
    def prev_action_done(self, cr, uid, ids, context=None):
        matching_obj = self.pool.get('wh.move.matching')
        for line in self.browse(cr, uid, ids, context=context):
            if line.warehouse_id.type == 'stock' and line.warehouse_dest_id.type != 'stock' and line.goods_id.is_using_matching(
            ):
                matching_records, subtotal = line.goods_id.get_matching_records(
                    line.warehouse_id.id, line.goods_qty, context=context)

                for matching in matching_records:
                    matching_obj.create_matching(cr,
                                                 uid,
                                                 matching.get('line_in_id'),
                                                 line.id,
                                                 matching.get('qty'),
                                                 context=context)

                line.write({
                    'price': safe_division(subtotal, line.goods_qty),
                    'subtotal': subtotal
                })

        return super(wh_move_line, self).prev_action_done(cr,
                                                          uid,
                                                          ids,
                                                          context=context)
Ejemplo n.º 12
0
    def prev_action_done(self):
        matching_obj = self.env['wh.move.matching']
        for line in self:
            if line.warehouse_id.type == 'stock' and line.goods_id.is_using_matching(
            ):
                if line.goods_id.is_using_batch():
                    matching_records, subtotal = line.get_matching_records_by_lot(
                    )
                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'), line.id,
                            matching.get('qty'))
                else:
                    matching_records, subtotal = line.goods_id.get_matching_records(
                        line.warehouse_id, line.goods_qty)

                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'), line.id,
                            matching.get('qty'))

                line.price = safe_division(subtotal, line.goods_qty)
                line.subtotal = subtotal

        return super(wh_move_line, self).prev_action_done()
Ejemplo n.º 13
0
    def prev_action_done(self):
        matching_obj = self.env['wh.move.matching']
        for line in self:
            if line.warehouse_id.type == 'stock' and \
                    line.goods_id.is_using_matching():
                if line.goods_id.is_using_batch():
                    matching_records, cost = \
                        line.goods_id.get_matching_records_by_lot(
                            self.lot_id, self.goods_qty, self.goods_uos_qty)
                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'), line.id,
                            matching.get('qty'), matching.get('uos_qty'))
                else:
                    matching_records, cost = line.goods_id \
                        .get_matching_records(
                            line.warehouse_id, line.goods_qty,
                            uos_qty=line.goods_uos_qty,
                            attribute=line.attribute_id)

                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'), line.id,
                            matching.get('qty'), matching.get('uos_qty'))

                line.cost_unit = safe_division(cost, line.goods_qty)
                line.cost = cost

        return super(wh_move_line, self).prev_action_done()
Ejemplo n.º 14
0
    def prev_action_done(self):
        matching_obj = self.env['wh.move.matching']
        for line in self:
            if line.warehouse_id.type == 'stock' and \
                    line.goods_id.is_using_matching():
                if line.goods_id.is_using_batch():
                    matching_records, cost = \
                        line.goods_id.get_matching_records_by_lot(
                            self.lot_id, self.goods_qty, self.goods_uos_qty)
                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'),
                            line.id, matching.get('qty'),
                            matching.get('uos_qty'))
                else:
                    matching_records, cost = line.goods_id \
                        .get_matching_records(
                            line.warehouse_id, line.goods_qty,
                            uos_qty=line.goods_uos_qty,
                            attribute=line.attribute_id)

                    for matching in matching_records:
                        matching_obj.create_matching(
                            matching.get('line_in_id'),
                            line.id, matching.get('qty'),
                            matching.get('uos_qty'))

                line.cost_unit = safe_division(cost, line.goods_qty)
                line.cost = cost

        return super(wh_move_line, self).prev_action_done()
Ejemplo n.º 15
0
    def get_move_line(self, wh_type='in', context=None):
        inventory_warehouse = self.env['warehouse'].get_warehouse_by_type(
            'inventory')
        for inventory in self:

            subtotal, matching_qty = inventory.goods_id.get_suggested_cost_by_warehouse(
                inventory.warehouse_id, abs(inventory.difference_qty))
            return {
                'warehouse_id':
                wh_type == 'out' and inventory.warehouse_id.id
                or inventory_warehouse.id,
                'warehouse_dest_id':
                wh_type == 'in' and inventory.warehouse_id.id
                or inventory_warehouse.id,
                'goods_id':
                inventory.goods_id.id,
                'uom_id':
                inventory.uom_id.id,
                'goods_qty':
                abs(inventory.difference_qty),
                'price':
                safe_division(subtotal, matching_qty),
                'subtotal':
                subtotal,
            }
Ejemplo n.º 16
0
    def get_suggested_cost_by_warehouse(self, warehouse, qty):
        records, subtotal = self.get_matching_records(warehouse, qty, ignore_stock=True)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            cost = safe_division(subtotal, matching_qty)
            if matching_qty >= qty:
                return subtotal, cost
        else:
            cost = self.get_cost()
        return cost * qty, cost
Ejemplo n.º 17
0
    def get_suggested_cost_by_warehouse(self, warehouse, qty):
        records, subtotal = self.get_matching_records(warehouse, qty, ignore_stock=True)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            cost = safe_division(subtotal, matching_qty)
            if matching_qty >= qty:
                return subtotal, cost
        else:
            cost = self.get_cost()
        return cost * qty, cost
Ejemplo n.º 18
0
    def get_suggested_cost_by_warehouse(self, cr, uid, ids, warehouse_id, qty, context=None):
        if isinstance(ids, (long, int)):
            ids = [ids]

        records, subtotal = self.get_matching_records(cr, uid,
            ids, warehouse_id, qty, ignore_stock=True, context=context)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            return subtotal, safe_division(subtotal, matching_qty)
        else:
            cost = self.get_cost(cr, uid, ids[0], context=context)
            return cost * qty, cost
Ejemplo n.º 19
0
    def prev_action_done(self, cr, uid, ids, context=None):
        matching_obj = self.pool.get('wh.move.matching')
        for line in self.browse(cr, uid, ids, context=context):
            if line.warehouse_id.type == 'stock' and line.warehouse_dest_id.type != 'stock' and line.goods_id.is_using_matching():
                matching_records, subtotal = line.goods_id.get_matching_records(
                    line.warehouse_id.id, line.goods_qty, context=context)

                for matching in matching_records:
                    matching_obj.create_matching(cr, uid,
                        matching.get('line_in_id'), line.id, matching.get('qty'), context=context)

                line.write({'price': safe_division(subtotal, line.goods_qty), 'subtotal': subtotal})

        return super(wh_move_line, self).prev_action_done(cr, uid, ids, context=context)
Ejemplo n.º 20
0
    def get_suggested_cost_by_warehouse(self, warehouse, qty, ignore_move=None):
        # 存在一种情况,计算一条line的成本的时候,先done掉该line,之后在通过该函数
        # 查询成本,此时百分百搜到当前的line,所以添加ignore参数来忽略掉指定的line
        records, cost = self.get_matching_records(warehouse, qty, ignore_stock=True,
                                                 ignore=ignore_move)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            cost_unit = safe_division(cost, matching_qty)
            if matching_qty >= qty:
                return cost, cost_unit
        else:
            cost_unit = self._get_cost(warehouse, ignore=ignore_move)
        return cost_unit * qty, cost_unit
Ejemplo n.º 21
0
    def apportion_cost(self, subtotal):
        for assembly in self:
            if not assembly.line_in_ids:
                continue

            collects = []
            ignore_move = [line.id for line in assembly.line_in_ids]
            for child in assembly.line_in_ids:
                collects.append(
                    (child,
                     child.goods_id.get_suggested_cost_by_warehouse(
                         child.warehouse_dest_id,
                         child.goods_qty,
                         ignore_move=ignore_move)[0]))

            amount_total, collect_child_subtotal = sum(
                collect[1] for collect in collects), 0
            for child, amount in islice(collects, 0, len(collects) - 1):
                child_subtotal = safe_division(amount, amount_total) * subtotal
                collect_child_subtotal += child_subtotal
                child.write({
                    'price':
                    safe_division(child_subtotal, child.goods_qty),
                    # TODO @zzx 需要考虑一下将subtotal变成计算下字段之后的影响
                    # 'subtotal': child_subtotal,
                })

            # 最后一行数据使用总金额减去已经消耗的金额来计算
            last_child_subtotal = subtotal - collect_child_subtotal
            collects[-1][0].write({
                'price':
                safe_division(last_child_subtotal, collects[-1][0].goods_qty),
                # TODO @zzx 需要考虑一下将subtotal变成计算下字段之后的影响
                # 'subtotal': last_child_subtotal,
            })

        return True
Ejemplo n.º 22
0
    def get_move_line(self, wh_type='in', context=None):
        inventory_warehouse = self.env['warehouse'].get_warehouse_by_type('inventory')
        for inventory in self:

            subtotal, matching_qty = inventory.goods_id.get_suggested_cost_by_warehouse(
                inventory.warehouse_id, abs(inventory.difference_qty))
            return {
                'warehouse_id': wh_type == 'out' and inventory.warehouse_id.id or inventory_warehouse.id,
                'warehouse_dest_id': wh_type == 'in' and inventory.warehouse_id.id or inventory_warehouse.id,
                'goods_id': inventory.goods_id.id,
                'uom_id': inventory.uom_id.id,
                'goods_qty': abs(inventory.difference_qty),
                'price': safe_division(subtotal, matching_qty),
                'subtotal': subtotal,
            }
Ejemplo n.º 23
0
    def get_suggested_cost_by_warehouse(self,
                                        warehouse,
                                        qty,
                                        ignore_move=None):
        # 存在一种情况,计算一条line的成本的时候,先done掉该line,之后在通过该函数
        # 查询成本,此时百分百搜到当前的line,所以添加ignore参数来忽略掉指定的line
        records, subtotal = self.get_matching_records(warehouse,
                                                      qty,
                                                      ignore_stock=True,
                                                      ignore=ignore_move)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            cost = safe_division(subtotal, matching_qty)
            if matching_qty >= qty:
                return subtotal, cost
        else:
            cost = self.get_cost(warehouse, ignore=ignore_move)
        return cost * qty, cost
Ejemplo n.º 24
0
    def prev_action_done(self):
        matching_obj = self.env['wh.move.matching']
        for line in self:
            if line.warehouse_id.type == 'stock' and line.goods_id.is_using_matching():
                if line.goods_id.is_using_batch():
                    matching_records, subtotal = line.get_matching_records_by_lot()
                    for matching in matching_records:
                        matching_obj.create_matching(matching.get('line_in_id'),
                            line.id, matching.get('qty'))
                else:
                    matching_records, subtotal = line.goods_id.get_matching_records(
                        line.warehouse_id, line.goods_qty)

                    for matching in matching_records:
                        matching_obj.create_matching(matching.get('line_in_id'),
                            line.id, matching.get('qty'))

                line.price = safe_division(subtotal, line.goods_qty)
                line.subtotal = subtotal

        return super(wh_move_line, self).prev_action_done()
Ejemplo n.º 25
0
    def get_suggested_cost_by_warehouse(self,
                                        cr,
                                        uid,
                                        ids,
                                        warehouse_id,
                                        qty,
                                        context=None):
        if isinstance(ids, (long, int)):
            ids = [ids]

        records, subtotal = self.get_matching_records(cr,
                                                      uid,
                                                      ids,
                                                      warehouse_id,
                                                      qty,
                                                      ignore_stock=True,
                                                      context=context)

        matching_qty = sum(record.get('qty') for record in records)
        if matching_qty:
            return subtotal, safe_division(subtotal, matching_qty)
        else:
            cost = self.get_cost(cr, uid, ids[0], context=context)
            return cost * qty, cost
Ejemplo n.º 26
0
 def get_real_cost_unit(self):
     self.ensure_one()
     return safe_division(self.cost, self.goods_qty)
Ejemplo n.º 27
0
 def _inverse_cost(self):
     self.cost_unit = safe_division(self.cost, self.goods_qty)
Ejemplo n.º 28
0
    def get_cost_by_warehouse(self, cr, uid, ids, warehouse_id, qty, context=None):
        _, subtotal = self.get_matching_records(
            cr, uid, ids, warehouse_id, qty, context=context)

        return safe_division(subtotal, qty)
 def get_real_cost_unit(self):
     self.ensure_one()
     return safe_division(self.cost, self.goods_qty)
 def _inverse_cost(self):
     self.cost_unit = safe_division(self.cost, self.goods_qty)
Ejemplo n.º 31
0
 def get_real_price(self, cr, uid, ids, context=None):
     for line in self.browse(cr, uid, ids, context=context):
         return safe_division(line.subtotal, line.goods_qty)
Ejemplo n.º 32
0
 def get_real_price(self):
     for line in self:
         return safe_division(line.subtotal, line.goods_qty)
Ejemplo n.º 33
0
 def get_real_price(self, cr, uid, ids, context=None):
     for line in self.browse(cr, uid, ids, context=context):
         return safe_division(line.subtotal, line.goods_qty)
Ejemplo n.º 34
0
 def get_real_price(self):
     for line in self:
         return safe_division(line.subtotal, line.goods_qty)