如何在向导中显示产品图片?我试图在向导中显示所有产品图像,但出现错误。
这是我的代码:-
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”。
我的代码有什么错误吗?任何人都可以帮助解决这个问题吗?
您可以通过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>
我认为您可能会遇到“系统中未找到外部 ID:”的错误 因为在 xml 文件中您输入了错误的 ID 名称。您的记录 ID 应该是 py 文件中函数的名称。 所以不是这个:“record id="action_view_image_wizard" model="ir.actions.act_window" 它应该是这样的:record id="action_image_add" model="ir.actions.act_window"