##判断删除情况,不允许删除
def unlink(self,cr,uid,ids,context=None):
raise osv.except_osv(u'警告!',u'单据不允许删除');
def write(self,cr,uid,ids,context=None):
raise osv.except_osv(u'警告!',u'单据不允许修改');
 
 
 # 重写删除方法
def unlink(self,cr,uid,ids,context=None):
# 首先获取这张单子的状态,read
sale_origins=self.read(cr,uid,ids,['state'],context=context)
unlink_ids=[]
for s in sale_origins:
# 如果这张单子状态为草稿和取消d 单子是可以删除的确定的单子是 不可以删除的
if s['state'] in ['draft','cancel']:
# 将要删除的单子的id放入放到删除容器里面取
unlink_ids.append(s['id'])
else:
# 如果是确定的单子就可以弹出一个不可以删除对话提示框
raise osv.except_osv((u'警告'),(u'以缺然订单不可以删除'))
# 返回这个结果的值到前台
return osv.osv.unlink(self,cr,uid,unlink_ids,context=context)

# 重写删除方法,删除合同单,连结算单一起删除,可用sql语句,ids表示这个单子的id
def unlink(self, cr, uid, ids, context=None): # sigining_contract查出状态信息
sigining_contract = self.read(cr, uid, ids, ['state'], context=context)
sigining_contract_obj=self.browse(cr,uid,ids,context)
name=sigining_contract_obj.contract_origin
# 根据合同号删除结算单号
sql="DELETE from settle_account where contract_origin='%s'"%(str(name))
cr.execute(sql)
unlink_ids = []
for s in sigining_contract:
if s['state'] in ['draft','cancel']:
unlink_ids.append(s['id'])
else:
raise osv.except_osv((u'警告!'), (u'已确认订单不可删除')) return osv.osv.unlink(self, cr, uid, unlink_ids, context=context) 创建方法:
 # 新加的地方
def create(self, cr, uid, vals, context=None):
context = context or {} partner_id = vals.get('display_name')
ht_type = vals.get('contract_type') # 根据公司来生成不同的编号,不同类别从1开始
if partner_id and ht_type:
vals['contract_origin'] = self.get_ht_sequence(cr,uid,partner_id,ht_type) else:
raise osv.except_osv(u'请先选择公司或类别!') new_id=super(sigining_contract, self).create(cr, uid, vals, context)
return new_id
保存后是编辑是write方法:
def write(self, cr, uid, ids, vals, context=None):
ddate=vals.get('date_planned')
if ddate:
obj=self.pool('sale.order.line')
sale_order_line_id=obj.search(cr,uid,[('sale_origin_line_id','=',ids[0])])
obj.write(cr,uid,sale_order_line_id,{'finish_date':ddate})
return super(sale_origin_line, self).write(cr, uid,ids, vals, context=context)
 

函数 求几个数的和#改动地方 小计增加金额 求和:
def _get_sumzaccount(self, cr, uid, ids, field_name, arg, context=None): res={}
for order in self.browse(cr, uid, ids, context=context):
Q=0.0
qq=order.zadd_money
qq1=order.zadd_money2
qq2=order.zadd_money3
qq3=order.zadd_money4
Q=qq+qq1+qq2+qq3 res[order.id]=Q return res
###整张外部订单取消,对应取消未发货的内部销售订单
# def action_cancel_sale_order(self,cr,uid,ids,context=None):
# assert len(ids)==1
# sale_origin_obj=self.browse(cr,uid,ids,context)
# sale_origin_obj.state='cancel'
# #单据明细也需要取消
# for line in sale_origin_obj.line_id:
# line.state='cancel'
# #查询出销售订单的源单据是本外部订单的所有单据
# origin_obj=self.pool.get('sale.order')
# sale_orders=origin_obj.search(cr,uid,[('sale_origin_id','=',ids[0])])
# #####取消
# origin_obj.action_cancel(cr, uid, sale_orders)
# self.message_post(cr, uid, ids, body=u"已取消订单", context=context)
# return True
05-11 18:06