在向导中显示产品图像

时间:2017-10-13 11:43:37

标签: xml python-2.7 wizard odoo-10

如何在向导中显示产品图片?我试图在向导中显示产品的所有图像,但是发现错误。

这是我的代码: -

py代码: -

from openerp import api, fields, models, _
from openerp import SUPERUSER_ID
from openerp.exceptions import UserError
import openerp.addons.decimal_precision as dp

class image_wizard(models.TransientModel):
     _name = "image.wizard"

      image_medium = fields.Many2many("Images")





       @api.multi
       def action_image_add(self):
          rec = self._context.get('active_ids', [])
          print "REC", rec, self.product_id.categ_id #product_uom
          if rec:
              line_values = {'image_medium': self.image_medium
                       }
              sale_order_line = self.env['product.template'].create(line_values)

xml代码: -

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
    <record id="view_image_wizard" model="ir.ui.view">
        <field name="name">Image wizard</field>
        <field name="model">image.wizard</field>
        <field name="arch" type="xml">
            <form string="Sales Pack">
                <group colspan="4" col="4">
                    <group colspan="4" col="4">
                        <field name="image"/>

                    </group>
                </group>
                <footer>
                    <button name="action_image_add" string="Ok" type="object"
                            class="btn-primary"/>
                    <button string="Cancel" class="btn-default" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="action_view_image_wizard" model="ir.actions.act_window">
        <field name="name">Image wizard</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">image.wizard</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_image_wizard"/>
        <field name="target">new</field>
    </record>

</data>

xml代码: -

    <record id="product_template_pack_form" model="ir.ui.view">
        <field name="name">product.productpack.form</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">

            <xpath expr="//field[@name='image_medium']" position="before">
                <button name="%(action_view_image_wizard)d" string="see all images" type="action"/>
            </xpath> 
        </field>
     </record>

但它显示错误“系统中找不到外部ID:product_pack.action_view_image_wizard”。

我的代码中有错误吗?任何人都可以帮助解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您可以通过 folder_name.xml_id

调用XML编辑
<record id="product_template_pack_form" model="ir.ui.view">
    <field name="name">product.productpack.form</field>
    <field name="model">product.template</field>
    <field name="inherit_id" ref="product.product_template_form_view"/>
    <field name="arch" type="xml">

        <xpath expr="//field[@name='image_medium']" position="before">
            <button name="%(image_wizard.action_view_image_wizard)d" string="see all images" type="action"/>
        </xpath> 
    </field>
 </record>