博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
odoo创建编号
阅读量:6206 次
发布时间:2019-06-21

本文共 4360 字,大约阅读时间需要 14 分钟。

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)
 

转载于:https://www.cnblogs.com/1314520xh/p/6970817.html

你可能感兴趣的文章
[Node.js]事件循环
查看>>
元素重叠及position定位的z-index顺序
查看>>
【转载】MYSQL模式匹配:REGEXP和like用法
查看>>
POJ 2492 A Bug's Life (并查集)
查看>>
2018Java年底总结
查看>>
[转载] 七龙珠第一部——第096话 克林大作战
查看>>
html 刷新更新背景图
查看>>
杭电_ACM_汉诺塔VII
查看>>
Dev控件系列之ASPXGridview控件自主绑定数据
查看>>
【总结整理】原创概念原创idea---摘自《结网》
查看>>
JAVA中的枚举
查看>>
php $_SERVER["REQUEST_TIME"] 笔记
查看>>
617. Merge Two Binary Trees
查看>>
Java课程设计——扫雷(winmine)
查看>>
Android 模拟器现已支持 AMD 处理器和 Hyper-V
查看>>
线程传值
查看>>
该进程或线程自上一个步骤以来已更改
查看>>
ctrl+alt+F1~6进入不了字符界面,黑屏的解决办法
查看>>
系统级性能分析工具 — Perf【转】
查看>>
VectorCAST软件自动化测试方案
查看>>