您好我有以下三种方法:
@api.multi
def action_invoice_create(self, wizard_brw, inv_brw):
"""
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."))
invoice_obj.write([inv_brw.id], invoice)
for line in inv_brw.invoice_line:
invoice_line_obj.write(
[line.id],
{'quantity': 0.0, 'invoice_line_tax_id': [],
'price_unit': 0.0})
tax_ids = self.env['account.tax'].search([])
tax = tax_obj.search([('invoice_id', '=', inv_brw and inv_brw.id)])
if tax:
tax_obj.write(tax[0], {'invoice_id': []})
tax_obj.create({
'name': 'SDCF',
'tax_id': tax_ids and tax_ids[0],
'amount': 0.00,
'tax_amount': 0.00,
'base': 0.00,
'account_id': inv_brw.company_id.acc_id.id,
'invoice_id': inv_brw and inv_brw.id}, {})
if move_id:
acc_mv_obj.button_cancel([inv_brw.move_id.id])
acc_mv_obj.write([inv_brw.move_id.id],{'ref': 'Damanged Paper'})
acc_mv_l_obj.unlink([i.id for i in inv_brw.move_id.line_id])
return inv_brw.id
@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.read(result, ['res_id'])
result = act_obj.read(imd_id)
result['res_id'] = list_ids
return result
@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')
这是一个在发票上声明损坏的纸张的向导,并根据该声明创建一个新纸张。
当我点击create_invoice
方法时,它会让我知道:
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 133, in create_invoice
'action_invoice_tree1', 'account')
File "/home/kristian/odoov10/gilda/l10n_ve_fiscal_requirements/wizard/wizard_invoice_nro_ctrl.py", line 105, in new_open_window
imd_id = mod_obj.read(result, ['res_id'])
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/models.py", line 2970, in read
for name in fields:
TypeError: 'int' object is not iterable
这是我的观点:
<?xml version='1.0' encoding='UTF-8'?>
<odoo>
<data>
<record model="ir.ui.view" id="wizard_nro_ctrl_form">
<field name="name">wizard.nro.ctrl.form</field>
<field name="model">wiz.nroctrl</field>
<field name="arch" type="xml">
<form string="Changing the Control Number" version="7.0">
<field name="name"/>
<separator string="Are you sure you want to do this?" colspan="4"/>
<field name="sure"/>
<button special="cancel" string="Cancel" icon="fa-book"/>
<button name="set_noctrl" string="Confirm" type="object" icon="fa-pencil-square-o"/>
</form>
</field>
</record>
<record id="action_wiz_nroctrl" model="ir.actions.act_window">
<field name="name">Change control number</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wiz.nroctrl</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</odoo>
有什么想法吗?
如果您需要旧的API原始代码,请告知我们。
答案 0 :(得分:1)
使用
imd_id = mod_obj.read(result, ['res_id']) #returns an integer not a browsable record
而不是
imd_id = mod_obj.read(result, ['res_id'])['res_id']