如何从向导按钮打开表单 - Odoo v8

时间:2017-08-16 03:47:57

标签: python openerp odoo-8

我有这个观点:

   <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>

从这个模型:

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)

我想将视图frmo称为向导按钮,并将其保存到数据库,就像我从标准菜单中访问它一样。

在这个相同的模型中,我有这个例程:

@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',

    }

这是此按钮的向导视图(当我尝试将其添加到瞬态模型时,它表示视图无法定位,尽管存在,所以我不得不将它放在同一模型上):

    <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>

无论如何,每次我点击这个按钮都会引发我的注意:

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

我只是想从按钮

打开原始表单

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您的ref来电必须有两个参数。

而不是:

self.env.ref('view_prod_order_form')

你真的需要:

self.env.ref('module_name.view_prod_order_form')