Reputation: 3907
I have this method:
@api.multi
def new_open_window(self, list_ids, xml_id, module):
""" Generate new window at view form or tree
"""
mod_obj = self.env['ir.model.data']
act_obj = self.env['ir.actions.act_window']
result = mod_obj._get_id(module, xml_id)
imd_id = mod_obj.browse(result)['res_id']
result = act_obj.browse(imd_id)
result['res_id']
return result
Right now, I click on a button which call this function like this return self.new_open_window([inv_id], 'action_invoice_tree1', 'account')
the complete method looks like this:
@api.multi
def create_invoice(self):
""" Create a invoice refund
"""
#context = context or {}
wizard_brw = self.browse()
inv_id = self._context.get('active_id')
for wizard in wizard_brw:
if not wizard.sure:
raise UserError(
_("Validation error!"),
_("Please confirm that you know what you're doing by"
" checking the option bellow!"))
if (wizard.invoice_id and wizard.invoice_id.company_id.jour_id and
wizard.invoice_id and wizard.invoice_id.company_id.acc_id):
inv_id = self.action_invoice_create(wizard,
wizard.invoice_id)
else:
raise UserError(
_('Validation error!'),
_("You must go to the company form and configure a journal"
" and an account for damaged invoices"))
return self.new_open_window([inv_id], 'action_invoice_tree1', 'account')
But it doesn't loads anything, before the method new_open_window
looked like this:
@api.multi
def new_open_window(self, list_ids, xml_id, module): #cr, uid, ids, list_ids, xml_id, module, context=None
""" Generate new window at view form or tree
"""
mod_obj = self.env['ir.model.data']
act_obj = self.env['ir.actions.act_window']
result = mod_obj._get_id(module, xml_id) #cr, uid was first
imd_id = mod_obj.browse(result)['res_id']#['res_id'] #cr, uid were first was read() before #(result, ['res_id'])
result = act_obj.browse(imd_id) # cr, uid were first was read() before
result['res_id'] = list_ids
return result
But list_ids
was throwing me this:
Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 866, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 681, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 672, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_invoice_nro_ctrl.py", line 139, in create_invoice
return self.new_open_window([inv_id], 'action_invoice_tree1', 'account')
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_invoice_nro_ctrl.py", line 114, in new_open_window
result['res_id'] = list_ids
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 5180, in __setitem__
return self._fields[key].__set__(self, value)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 878, in __set__
value = self.convert_to_cache(value, record)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/fields.py", line 1109, in convert_to_cache
return int(value or 0)
TypeError: int() argument must be a string or a number, not 'list'
The problem was this line result['res_id'] = list_ids
, but now it doesn't throw any error but it doesn't work, it just stay on the same window and doesn't rewrite any invoice.
The method which creates the invoice which comes first before these two functions now looks like this:
@api.multi
def action_invoice_create(self, wizard_brw, inv_brw): #cr, uid, ids, wizard_brw, inv_brw, context=None
"""
If the invoice has control number, this function is responsible for
passing the bill to damaged paper
@param wizard_brw: nothing for now
@param inv_brw: damaged paper
"""
invoice_line_obj = self.env['account.invoice.line']
invoice_obj = self.env['account.invoice']
acc_mv_obj = self.env['account.move']
acc_mv_l_obj = self.env['account.move.line']
tax_obj = self.env['account.invoice.tax']
invoice = {}
if inv_brw.nro_ctrl:
invoice.update({
'name': 'PAPELANULADO_NRO_CTRL_%s' % (
inv_brw.nro_ctrl and inv_brw.nro_ctrl or ''),
'state': 'paid',
'tax_line': [],
})
else:
raise UserError(
_('Validation error!'),
_("You can run this process just if the invoice have Control"
" Number, please verify the invoice and try again."))
inv_brw.write(invoice)
inv_brw.invoice_line_ids.write({
'quantity' : 0.0,
'invoice_line_tax_id' : [],
'price_unit' : 0.0
})
taxes = self.env['account.tax'].search([])
invoice_taxes = tax_obj.search(
[('invoice_id', '=', inv_brw and inv_brw.id)]).unlink()
move = inv_brw.move_id
if move: #if move_id:
move.button_cancel()
move.ref = 'Damanged Paper'
move.line_ids.unlink()
return inv_brw.id
Any ideas?
EDIT
This is the original new_open_window
method:
def new_open_window(self, cr, uid, ids, list_ids, xml_id, module,
context=None):
""" Generate new window at view form or tree
"""
mod_obj = self.pool.get('ir.model.data')
act_obj = self.pool.get('ir.actions.act_window')
result = mod_obj._get_id(cr, uid, module, xml_id)
imd_id = mod_obj.read(cr, uid, result, ['res_id'])['res_id']
result = act_obj.read(cr, uid, imd_id)
result['res_id'] = list_ids
return result
Upvotes: 0
Views: 572
Reputation: 14751
The problem is here :
result['res_id'] = list_ids
I think that res_id should be an integer not a list like you are giving, if you want to show it in form view only then you need to pass only one id in res_id. but if you want to pass more that record then use domain not res_id.
result['domain'] = [('id', 'in' , list_ids)]
this way only the records that muches the domain will be shown
res_id is used when you need to edit a record only one record if you want more use domain
Upvotes: 1
Reputation: 14801
I would migrate the method like:
@api.multi
def new_open_window(list_ids, xml_id, module)
""" Generate new window at view form or tree """
action = self.env.ref("{}.{}".format(module, xml_id))
result = action.read()[0]
if isinstance(list_ids, (list, tuple)):
result['domain'] = [('id', 'in', list_ids)]
else:
result['res_id'] = list_ids
return result
ref
will get the record of the action. read
is a multi record method and will return a list of dictionaries. At the end i have added @Charif's interesting hint.
Upvotes: 2