美好的一天,
我一直在处理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
我真的很感激任何有关正在发生的事情的想法以及如何避免它。
致以最诚挚的问候,
阿兰
答案 0 :(得分:2)
默认行为是在按下任何按钮并执行与按钮相关的功能时关闭。解决方法是让按钮执行一个函数,然后返回一个动作,显示完全相同的向导。
您可以设置上下文以再次打开向导,并填充所有表单值。
以下是一个例子:
class MyWizard(models.TransientModel):
_name = 'myaddon.mywizard'
def _get_default_char(self):
return self._context.get('mychar',"")
mychar = fields.Char(string="My Char", default=_get_default_char)
@api.multi
def my_button(self):
# Execute Function Here
# reload wizard with context
return {
'view_type': 'form',
'view_mode': 'form',
'res_model': 'myaddon.mywizard',
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': self.id,
'context': '{"default_mychar":'HELLO WORLD'}',
}