• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.safe_division函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.safe_division函数的典型用法代码示例。如果您正苦于以下问题:Python safe_division函数的具体用法?Python safe_division怎么用?Python safe_division使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了safe_division函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: apportion_cost

    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
开发者ID:gitter-badger,项目名称:gooderp,代码行数:27,代码来源:production.py


示例2: apportion_cost

    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
开发者ID:kvc0769,项目名称:gooderp_addons,代码行数:28,代码来源:production.py


示例3: apportion_cost

    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
开发者ID:FightingMy,项目名称:gooderp_addons,代码行数:30,代码来源:production.py


示例4: prev_action_done

    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()
开发者ID:jaronemo,项目名称:gooderp_addons,代码行数:31,代码来源:move_matching.py


示例5: prev_action_done

    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()
开发者ID:Judystudy,项目名称:gooderp_addons,代码行数:29,代码来源:move_matching.py


示例6: get_move_line

    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
开发者ID:gitter-badger,项目名称:gooderp,代码行数:25,代码来源:inventory.py


示例7: get_suggested_cost_by_warehouse

    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
开发者ID:Judystudy,项目名称:gooderp,代码行数:11,代码来源:goods.py


示例8: get_suggested_cost_by_warehouse

    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
开发者ID:gitter-badger,项目名称:gooderp,代码行数:13,代码来源:goods.py


示例9: prev_action_done

    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)
开发者ID:OpenERPjacky,项目名称:gooderp,代码行数:14,代码来源:move_matching.py


示例10: get_suggested_cost_by_warehouse

    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
开发者ID:kvc0769,项目名称:gooderp_addons,代码行数:14,代码来源:goods.py


示例11: get_move_line

    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,
            }
开发者ID:Judystudy,项目名称:gooderp,代码行数:15,代码来源:inventory.py


示例12: prev_action_done

    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()
开发者ID:Judystudy,项目名称:gooderp,代码行数:21,代码来源:move_matching.py


示例13: get_real_price

 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)
开发者ID:gitter-badger,项目名称:gooderp,代码行数:3,代码来源:warehouse_move_line.py


示例14: get_real_cost_unit

 def get_real_cost_unit(self):
     self.ensure_one()
     return safe_division(self.cost, self.goods_qty)
开发者ID:rainsongsky,项目名称:gooderp_addons,代码行数:3,代码来源:warehouse_move_line.py


示例15: _inverse_cost

 def _inverse_cost(self):
     self.cost_unit = safe_division(self.cost, self.goods_qty)
开发者ID:rainsongsky,项目名称:gooderp_addons,代码行数:2,代码来源:warehouse_move_line.py


示例16: get_real_price

 def get_real_price(self):
     for line in self:
         return safe_division(line.subtotal, line.goods_qty)
开发者ID:Judystudy,项目名称:gooderp,代码行数:3,代码来源:warehouse_move_line.py


示例17: get_cost_by_warehouse

    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)
开发者ID:OpenERPjacky,项目名称:gooderp,代码行数:5,代码来源:goods.py



注:本文中的utils.safe_division函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.safe_domain_name函数代码示例发布时间:2022-05-26
下一篇:
Python utils.run_vtworker_bg函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap