本文整理汇总了Python中utils.safe_division函数的典型用法代码示例。如果您正苦于以下问题:Python safe_division函数的具体用法?Python safe_division怎么用?Python safe_division使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safe_division函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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
示例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
示例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()
示例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()
示例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
示例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
示例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
示例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)
示例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
示例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,
}
示例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()
示例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)
示例14: get_real_cost_unit
def get_real_cost_unit(self):
self.ensure_one()
return safe_division(self.cost, self.goods_qty)
示例15: _inverse_cost
def _inverse_cost(self):
self.cost_unit = safe_division(self.cost, self.goods_qty)