• odoo创建编号


    def create(self,cr,uid,vals,context=None):
    if context is None:
    context ={}
    print 111111
    print vals
    []
    if vals.get('lx_origin', '/') == '/' :
    vals['lx_origin'] = self.pool.get('ir.sequence').get(cr, uid, 'demo.contract.lx', context=context) or '/'
    if vals['lx_origin'] and vals['lx_type']=='3':
    vals['lx_origin']=vals['lx_origin']+'S'

    elif vals['lx_origin'] and vals['lx_type']=='4' :
    vals['lx_origin']=vals['lx_origin']+'S(LX)'

    elif vals['lx_origin'] and vals['lx_type']=='5' :
    vals['lx_origin']=vals['lx_origin']+'C'


    elif vals['lx_origin'] and vals['lx_type']=='6' :
    vals['lx_origin']=vals['lx_origin']+'C(LX)'
    else:
    vals['lx_origin']=vals['lx_origin']

    if vals['lx_origin'] and vals['display_name']==14:
    vals['lx_origin']='HL'+vals['lx_origin']

    elif vals['lx_origin'] and vals['display_name']==19:
    vals['lx_origin']='TZRL'+vals['lx_origin']

    elif vals['lx_origin'] and vals['display_name']==18:
    vals['lx_origin']='JT'+vals['lx_origin']

    elif vals['lx_origin'] and vals['display_name']==17:
    vals['lx_origin']='YC'+vals['lx_origin']

    elif vals['lx_origin'] and vals['display_name']==22:
    vals['lx_origin']='XN'+vals['lx_origin']

    elif vals['lx_origin'] and vals['display_name']==3 or vals['display_name']==13 or vals['display_name']==11:
    vals['lx_origin']='WQ'+vals['lx_origin']

    else:
    vals['lx_origin']=vals['lx_origin']



    new_id=super(demo_contract_lx,self).create(cr,uid,vals,context=context)
    return new_id



      WQLX2017-070S(LX)



    def create(self, cr, uid, vals, context=None):
    if context is None:
    context = {}
    if vals.get('name', '/') == '/':
    vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'mrp.production.report') or '/'
    ctx = dict(context or {}, mail_create_nolog=True)
    new_id = super(mrp_production_report, self).create(cr, uid, vals, context=ctx)
    bgdate=vals.get('date')
    name=vals.get('name')
    sql="update mrp_production_report_line set ldate='%s',lrname='%s' where line_id=%d"%(bgdate,name,new_id)
    cr.execute(sql)
    return new_id
      第三种: TZRL2017-001SL 
    # 新加的地方
    def create(self, cr, uid, vals, context=None):
    context = context or {}

    partner_id = vals.get('display_name')
    print partner_id


    # 根据公司来生成不同的编号
    if partner_id:
    vals['lx_origin'] = self.get_lx_sequence(cr,uid,partner_id)
    else:
    raise osv.except_osv(u'请先选择公司!')

    new_id=super(demo_contract_lx, self).create(cr, uid, vals, context)
    return new_id


    def create_new_sequence(self,cr,uid,code,partner_id):
    #创建编码原则
    ir_sequence_type_obj=self.pool.get('ir.sequence.type')
    ir_sequence_type_obj.create(cr,uid,{'name':code,'code':code})
    values={}
    values['name']=code
    values['code']=code
    values['implementation']='no_gap'
    values['active']=True
    values['prefix']="%(year)s-"
    values['number_next']=1
    values['number_next_actual']=1
    values['number_increment']=1
    values['padding']=3
    ir_sequence_obj=self.pool.get('ir.sequence')
    ir_sequence_obj.create(cr,uid,values)

    def get_lx_sequence(self,cr,uid,partner_id,context=None):


    code="demo_contract_lx_no_%d" %(partner_id)

    no=self.pool.get('ir.sequence').get(cr, uid, code, context=context)

    if no==False:
    self.create_new_sequence(cr,uid,code,partner_id)
    no=self.pool.get('ir.sequence').get(cr, uid, code, context=context)
    partner_ids=self.pool.get('res.partner').search(cr,uid,[('id','=',partner_id)])
    partner_obj=self.pool.get('res.partner').browse(cr,uid,partner_ids)
    no = "%s%s" %(partner_obj.code,no)
    return no
    
    

    所用方法:
    def get(self, cr, uid, code, context=None):
    company_ids = self.pool.get('res.company').search(cr, uid, [], context=context) + [False]

    ids = self.search(cr, uid, ['&', ('code', '=', code), ('company_id', 'in', company_ids),('active','=',True)])

    # assert len(ids)==1
    ir_seq_obj=self.browse(cr,uid,ids,context)
    implementation=ir_seq_obj.implementation

    if implementation=='yyrnum': #表示编号用年月日+流水号 那么只输入前缀和后缀即可
    oldnyr=ir_seq_obj.nyr #现在模块在使用的年月日
    nowyyr=datetime.datetime.now().strftime("%Y%m%d") #当前年月日
    prefix=ir_seq_obj.prefix if ir_seq_obj.prefix else ''
    suffix=ir_seq_obj.suffix if ir_seq_obj.suffix else ''
    padding=ir_seq_obj.padding

    if oldnyr==nowyyr: #如果序列规则保存的日期和当前的是一样,那么说明是同一天,反之不是同一天,那么就修改保存的日期以及序列从1开始
    yyrnext_num=ir_seq_obj.yyrnext_num #序列号
    #修改下一个号码
    self.write(cr,uid,ids,{'yyrnext_num':yyrnext_num+1})
    else:
    yyrnext_num=1
    self.write(cr,uid,ids,{'nyr':nowyyr,'yyrnext_num':2})

    return prefix+nowyyr+'%%0%sd' % padding % yyrnext_num+suffix
    else:
    return self.get_id(cr, uid, code, 'code', context)



  • 相关阅读:
    JS连接数据库“实例”
    sql数据字典
    硬件防火墙的配置
    xxx
    rhs属性文件删除法
    思科pix防火墙配置实例大全
    SilverLight中的画刷小结
    数据库表间的连接总结
    导入Excel到Sql Server 2005 (转)
    关于Silverlight页面跳转的总结
  • 原文地址:https://www.cnblogs.com/1314520xh/p/6970817.html
Copyright © 2020-2023  润新知