sale.order
Posted zcy1103
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sale.order相关的知识,希望对你有一定的参考价值。
# 初始化一个变量用来记录产品类型
line_type = ‘‘
# 循环明细行
for product in self.options:
# 拿到该明细行的产品类型
product_type = product.product_id.type
# 如果产品类型为 服务或者可库存的时候
if product_type in [‘service‘, ‘product‘]:
# 判断初始化的变量有没有值
if line_type:
# 如果有值,就判断是不是和第一种状态一致。
if product_type != line_type:
# 如果存在两种状态,就报错
raise Warning("销售订单不能既有‘服务商品‘,又存在‘可库存产品‘")
else:
# 如果没有值就把第一种状态给这个变量
line_type = product_type
@api.multi
def write(self, vals):
sales_person = self.user_id.id
res = super(BelstarSaleOrderExtend, self).write(vals)
if vals.has_key(‘user_id‘):
sales_person = vals[‘user_id‘]
section_ids = self.env[‘crm.case.section‘].search(
[‘|‘, ‘|‘, ‘|‘, (‘user_id‘, ‘=‘, self.create_uid.id), (‘user_id‘, ‘=‘, sales_person),
(‘member_ids‘, ‘in‘, [self.create_uid.id]), (‘member_ids‘, ‘in‘, [sales_person])])
values = self._calc_section(section_ids)
if len(values[‘section_leader_ids‘]) > 0:
vals[‘section_leader_ids‘] = [(4, values[‘section_leader_ids‘])]
else:
raise Warning(‘Can not find your sales team, please check with your sales team leader.‘)
if len(values[‘section_member_ids‘]) > 0:
vals[‘section_member_ids‘] = [(4, values[‘section_member_ids‘])]
else:
raise Warning(‘Can not find your sales team, please check with your sales team leader.‘)
line_type = ‘‘
for product in self.options:
product_type = product.product_id.type
# if product_type in [‘service‘, ‘product‘]:
if product_type in [‘service‘]:
if line_type:
if product_type != line_type and vals[‘order_policy‘] == ‘picking‘:
raise Warning("当‘其他信息‘中的‘创建发票‘选择‘基于交货单时‘,"
"‘推荐的产品‘中的产品不能存在产品类型为‘服务‘的产品")
else:
line_type = product_type
return res
# return super(BelstarSaleOrderExtend, self).write(vals)
@api.model
def create(self, vals):
res = super(BelstarSaleOrderExtend, self).create(vals)
section_ids = self.env[‘crm.case.section‘].search(
[‘|‘, (‘user_id‘, ‘=‘, self._uid), (‘member_ids‘, ‘in‘, [self._uid])])
values = self._calc_section(section_ids)
if len(values[‘section_leader_ids‘]) > 0:
vals[‘section_leader_ids‘] = [(4, values[‘section_leader_ids‘])]
else:
raise Warning(‘Can not find your sales team, please check with your sales team leader.‘)
if len(values[‘section_member_ids‘]) > 0:
vals[‘section_member_ids‘] = [(4, values[‘section_member_ids‘])]
else:
raise Warning(‘Can not find your sales team, please check with your sales team leader.‘)
line_type = ‘‘
for product in res.options:
product_type = product.product_id.type
# if product_type in [‘service‘, ‘product‘]:
if product_type == ‘service‘ and vals[‘order_policy‘] == ‘picking‘:
raise Warning("当‘其他信息‘中的‘创建发票‘选择‘基于交货单时‘,"
"‘推荐的产品‘中的产品不能存在产品类型为‘服务‘的产品")
# if line_type:
# if product_type != line_type and vals[‘order_policy‘] == ‘picking‘:
# raise Warning("当‘其他信息‘中的‘创建发票‘选择‘基于交货单时‘,"
# "‘推荐的产品‘中的产品不能既有‘服务商品‘,又存在‘可库存产品‘两种产品类型")
# else:
# line_type = product_type
return res
# return super(BelstarSaleOrderExtend, self).create(vals)
以上是关于sale.order的主要内容,如果未能解决你的问题,请参考以下文章