NeoVe NeoVe -3 years ago 175
Python Question

How to Open a form from a wizard button - Odoo v8

I have this view:

<record id="view_prod_order_form" model="ir.ui.view">
<field name="name">bsi.production.order.form</field>
<field name="model">bsi.production.order</field>
<field name="arch" type="xml">
<form string="Production Order">
<div class="oe_title">
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" />
</h1>
</div>
<sheet>
<h1>
<field name="name" class="oe_inline" readonly="1"/>
</h1>
<group>
<group>
<field name="product_id"/>
<field name="qty_available"/>
<field name="isbn1" attrs="{'invisible': [('type_prod', '!=', 'direct')]}" />
<field name="isbn2" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn3" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn4" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn5" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn6" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn7" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="isbn8" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
</group>
<group>
<field name="type_prod"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}" />
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
<field name="print_order" attrs="{'invisible': [('type_prod', '!=', 'direct')]}"/>
</group>
</group>
</sheet>
</form>
</field>
</record>


From this model:

class bsi_production_order(models.Model):
_name = 'bsi.production.order'
_inherit = ['mail.thread','text.paper','book.binding', 'book.block','book.edge','book.edition','book.size','cut.off','end.paper','job.rate','paper.master','printing.code', 'mrp.worksheet.contract', 'work.order.isbn.code', 'product.template'] #, 'stock.quant'

@api.model
def create(self, vals):
if vals.get('name', 'New') == 'New':
vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.order') or '/'
return super(bsi_production_order, self).create(vals)

name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
type_prod = fields.Selection([
('budgeted','Budgeted'),
('nonbudgeted','Non Budgeted'),
('direct','Direct Order'),
], string='Type of Order', index=True,
track_visibility='onchange', copy=False,
help=" ")
product_id = fields.Many2one('product.template', string="Product")
qty_available = fields.Float(string="Qty Available", related="product_id.qty_available")
isbn1 = fields.Many2one('work.order.isbn.code', string="ISBN 1")
isbn2 = fields.Many2one('work.order.isbn.code', string="ISBN 2")
isbn3 = fields.Many2one('work.order.isbn.code', string="ISBN 3")
isbn4 = fields.Many2one('work.order.isbn.code', string="ISBN 4")
isbn5 = fields.Many2one('work.order.isbn.code', string="ISBN 5")
isbn6 = fields.Many2one('work.order.isbn.code', string="ISBN 6")
isbn7 = fields.Many2one('work.order.isbn.code', string="ISBN 7")
isbn8 = fields.Many2one('work.order.isbn.code', string="ISBN 8")
print_order = fields.One2many('bsi.print.order', 'production_orders', string="Print Order", copy=True)


I want to call the view frmo a wizard button, and save it to database, as if I access it from a standard menu.

In this very same model I have this routine:

@api.multi
def action_open_prod(self):
assert len(self) == 1, 'This option should only be used for a single id at a time.'
#template = self.env.ref('account.email_template_edi_invoice', False)
id = self.id
return {
'name': self.name,
'res_model': 'bsi.production.order',
'res_id': id,
'type': 'ir.actions.act_window',
'context': {},
'view_mode': 'form',
'view_type': 'form',
'view_id': self.env.ref('view_prod_order_form'),
'target': 'current', #'target': 'current',

}


And this is the wizard view for this button (when I try to add this to transient model it says the view cannot be located although is there, so I had to put this on the same model):

<record id="action_prod_order" model="ir.actions.act_window">
<field name="name">Production Order (Wizard)</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">bsi.production.order</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_wizard_prod_order_form"/>
<field name="target">new</field>
</record>

<record id="view_wizard_prod_order_form" model="ir.ui.view">
<field name="name">bsi.production.order.form</field>
<field name="model">bsi.production.order</field>
<field name="arch" type="xml">
<form string="Production Order">
<footer>
<button name="action_open_prod" string="Open Production Order" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</footer>
</form>
</field>
</record>


Anyways , every time I click on this button it throws me:

Traceback (most recent call last):
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 399, in old_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\mrp_worksheet_contract\models\models.py", line 523, in action_open_prod
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 797, in ref
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 508, in new_api
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\base\ir\ir_model.py", line 923, in xmlid_to_object
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\base\ir\ir_model.py", line 909, in xmlid_to_res_model_res_id
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\api.py", line 268, in wrapper
File "<decorator-gen-3>", line 2, in xmlid_lookup
File "C:\Program Files\Odoo 8.0-20170809\server\.\openerp\tools\cache.py", line 74, in lookup
File "C:\Program Files\Odoo 8.0-20170809\server\openerp\addons\base\ir\ir_model.py", line 896, in xmlid_lookup
ValueError: need more than 1 value to unpack


I just want to open the original form from the button

Any ideas?

Answer Source

Your ref call must have two arguments.

Instead of:

self.env.ref('view_prod_order_form')

You actually need:

self.env.ref('module_name.view_prod_order_form')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download