【发布时间】:2017-08-05 02:20:40
【问题描述】:
早安,
我一直在 odoo 9 中开发批次和序列号模块。
我更改了模块默认的顺序,并将其替换为 UUID 的生成,但是当我在收到的项目部分调用此组件时,当我单击生成 UUID 的按钮时,应用程序突然返回到我用来调用它的窗口,而不让我保存我生成的 UUID。
这是我的代码:
class stock_production_lot(osv.osv):
_name = 'stock.production.lot'
_inherit = ['mail.thread']
_description = 'Lot/Serial'
_columns = {
'name': fields.char('Serial Number', required=True, help="Unique Serial Number"),
'x_num_serie_': fields.char('No. de serie', required=False, help="No. de serie del producto"),
'ref': fields.char('Internal Reference', help="Internal reference number in case it differs from the manufacturer's serial number"),
'product_id': fields.many2one('product.product', 'Product', required=True, domain=[('type', 'in', ['product', 'consu'])]),
'quant_ids': fields.one2many('stock.quant', 'lot_id', 'Quants', readonly=True),
'create_date': fields.datetime('Creation Date'),
}
_defaults = {
'name': lambda x, y, z, c: x.pool.get('ir.sequence').next_by_code(y, z, 'stock.lot.serial'),
'x_num_serie_':None,
'product_id': lambda x, y, z, c: c.get('product_id', False),
}
_sql_constraints = [
('name_ref_uniq', 'unique (name, product_id)', 'The combination of serial number and product must be unique !'),
]
def action_traceability(self, cr, uid, ids, context=None):
""" It traces the information of lots
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@param ids: List of IDs selected
@param context: A standard dictionary
@return: A dictionary of values
"""
quant_obj = self.pool.get("stock.quant")
quants = quant_obj.search(cr, uid, [('lot_id', 'in', ids)], context=context)
moves = set()
for quant in quant_obj.browse(cr, uid, quants, context=context):
moves |= {move.id for move in quant.history_ids}
if moves:
return {
'domain': "[('id','in',[" + ','.join(map(str, list(moves))) + "])]",
'name': _('Traceability'),
'view_mode': 'tree,form',
'view_type': 'form',
'context': {'tree_view_ref': 'stock.view_move_tree'},
'res_model': 'stock.move',
'type': 'ir.actions.act_window',
}
return False
def action_generate_uuid(self, cr, uid, ids, context=None):
print "< action_generate_uuid >"
_uuid = (uuid.uuid1()).hex
obj = self.browse(cr, uid, ids,context=context)
print "< obj.name >",obj.name
for item in self.browse(cr, uid, ids,context=context):
if item.name:
item.name = _uuid
item.x_num_serie_ = _uuid
print "< name >",item.name
print "< x_num_serie_>",item.x_num_serie_
else:
print "< falta un elemento >"
return None
我真的很感激任何关于正在发生的事情以及如何避免它的想法。
最好的问候,
阿兰
【问题讨论】: