具有产品预览的多张图像

问题描述 投票:1回答:1

如何在产品模板中使用预览创建多张图像?例如,我想为一个产品显示多个图像,并且在销售订单中也可以看到它,那么我们如何获得带有预览的多个图像呢?我可以帮忙吗?

这是我的代码:-

class product_image(models.Model):
    _name = 'product.image'
    _order = 'sequence, id DESC'

    name = fields.Char('Name')
    description = fields.Text('Description')
    sequence = fields.Integer('Sequence')
    image_alt = fields.Text('Image Label')
    image = fields.Binary('Image')
    image_small = fields.Binary('Small Image')
    product_tmpl_id = fields.Many2one('product.template', 'Product', select=True)
    from_main_image = fields.Boolean('From Main Image', default=False)


class product_product(models.Model):
    _inherit = 'product.product'

    images = fields.One2many('product.image', related='product_tmpl_id.images',
                             string='Images', store=False)


class product_template(models.Model):
    _inherit = 'product.template'

    images = fields.One2many('product.image', 'product_tmpl_id',
                             string='Images')

    @api.one
    def action_copy_image_to_images(self):
        if not self.image:
            return
        image = None
        for r in self.images:
            if r.from_main_image:
                image = r
                break

        if image:
            image.image = self.image
        else:
            vals = {'image': self.image,
                    'name': self.name,
                    'product_tmpl_id': self.id,
                    'from_main_image': True, }
            self.env['product.image'].create(vals)

xml代码:-

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="product_product_template_only_form_view" model="ir.ui.view">
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_form_view"/>
            <field name="arch" type="xml">
                   <xpath expr="//notebook[1]" position="inside">
                      <page string="Product Images" name="website_mutli_image">
                     <field name="images" context="{'default_name': name}">
                          <tree editable="bottom">
                                <field name="sequence" widget="handle"/>
                           <field name="name"/>
                           <field name="description"/>
                           <field name="image_alt"/>
                           <field name="image" widget="image" height="64"/>
                          </tree>
                     </field>
                      </page>
                   </xpath>
            </field>
    </record>
    <record id="product_product_product_only_form_view" model="ir.ui.view">
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_normal_form_view"/>
            <field name="arch" type="xml">
                <xpath expr="//notebook[1]" position="inside">
                    <page string="Product Images" name="website_mutli_image">
                   <field name="images" mode="kanban" context="{'default_name': name}">
                     <kanban>
                         <field name="name"/>
                         <field name="description"/>
                         <field name="image_alt"/>
                         <field name="image"/>
                         <templates>
                           <t t-name="kanban-box">
                               <div style="position: relative">
                              <div class="oe_module_vignette">
                                  <a type="open">
                                      <img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
                                  </a>
                                  <div class="oe_module_desc">
                                 <div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
                                     <table class="oe_kanban_table">
                                    <tr>
                                        <td class="oe_kanban_title1" align="left" valign="middle">
                                       <h4><a type="open"><field name="name"/></a></h4>
                                       <i><div t-if="record.description.raw_value">
                                           <field name="description"/></div></i>
                                        </td>
                                    </tr>
                                     </table>
                                 </div>
                                  </div>
                              </div>
                               </div>
                           </t>
                         </templates>
                     </kanban>
                   </field>
                    </page>
                </xpath>
            </field>
        </record>

    </data>
</openerp>

我可以为此解决办法吗?

python xml python-2.7 openerp odoo-10
1个回答
0
投票

什么是最终解决方案?

© www.soinside.com 2019 - 2024. All rights reserved.