Python 使用odoo 9
我正在处理Odoo 9中的序列,我需要一些关于默认函数的帮助: 我的实际模型从字段中读取值,然后在序列表中检查是否存在带有该代码的序列(与标签相同),如果不存在,我的自定义创建函数将创建序列并为序列字段分配值 现在我的问题是,当我取消一张唱片的链接时,我想再次释放序列上的一点 作为参考,我将发布我的创建函数:Python 使用odoo 9,python,openerp,odoo-9,Python,Openerp,Odoo 9,我正在处理Odoo 9中的序列,我需要一些关于默认函数的帮助: 我的实际模型从字段中读取值,然后在序列表中检查是否存在带有该代码的序列(与标签相同),如果不存在,我的自定义创建函数将创建序列并为序列字段分配值 现在我的问题是,当我取消一张唱片的链接时,我想再次释放序列上的一点 作为参考,我将发布我的创建函数: @api.model def create(self,vals): prefix = "v" code = str(vals
@api.model
def create(self,vals):
prefix = "v"
code = str(vals['label'])
name = prefix+"_"+code
implementation = "no_gap"
dict = {"prefix":prefix,
"code":code,
"name":name,
"active":True,
"implementation":implementation
}
if vals.get('sequence','New') == 'New':
#First if will return True if can find a value for the field sequence in the current entry, if not, will return 'New'
if self.env['ir.sequence'].search([('code','=',code)]).code == code:
vals['sequence'] = self.env['ir.sequence'].next_by_code(code)
result = super(t_self_sequence,self).create(vals)
return result
else:
new_seq = self.env['ir.sequence'].create(dict)
vals['sequence'] = self.env['ir.sequence'].next_by_code(code)
result = super(t_self_sequence,self).create(vals)
return result
我试图在unlink()函数中更新number_next value,但无法找到正确的方法,因为如果我只在序列模型上使用write,我将更新该值,但例如,如果我有3条记录:
版本/标签
你好
你好
你好
然后我删除V2 Hello并在序列中的2旁边写为number_,下面的记录将有V2 Hello,但接下来的number_将更新为3,因此如果我添加另一条记录,我将有另一条V3 Hello,这将使我的数据不一致如果删除一条记录,为什么要重新打开序列中的点?我能想到的唯一解决方案就是迭代整个系列,然后使用第一个未找到的。像这样的
# I'm not sure of your exact fields, so you'll want to adapt some of this
object = self.env['model.name']
i = 1
stop = False
while stop != True:
label = 'V%d Hello' % i
record = object.search([('name','=',label)])
if record:
i += 1
else:
stop = True
new_sequence = label
免责声明:我不喜欢这个解决方案