2017-10-13 79 views
1

如何在向导中显示产品图像?我试图在向导中显示产品的所有图像,但遇到错误。在向导中显示产品图像

这里是我的代码: -

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> 

但它显示一个错误“System ID not found in the system:product_pack.action_view_image_wizard”。

我的代码中是否有错误?谁能帮助解决这个问题?

+0

你有所有这些代码单独的文件夹中?或不。 –

+0

我有一个文件夹中的所有代码。 –

+0

你的文件夹的名称是什么? –

回答

1

,你可以调用你的XML编辑folder_name.xml_id

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

如何点击确定按钮时在向导中保存这些图像,因为当我点击确定按钮时,选定的图像消失? –

+0

向导记录并不意味着持久;它们会在一段时间后自动从数据库中删除。这就是为什么他们被称为短暂的。链接Doc odoo:https://www.odoo.com/documentation/10.0/howtos/backend.html#wizards –

相关问题