I have a wizard in product template form and I want to save multiple images in wizard for a single product. In wizard, when I click on ok button, the selected images disappears. Here is my code:-
image.py code:-
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_med = fields.Many2many('ir.attachment', string="Attachments")
image = fields.Binary("Image")
@api.multi
def action_image_add(self, context=None):
rec = self._context.get('active_ids', [])
if rec:
line_values = {'image_medium':self.image_med
}
product = self.create['product.template'].write(line_values)
image.xml code:-
<?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_med" widget="many2many_binary" class="thumbimage"/>
<field name="image" invisible="1"/>
</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>
</openerp>
product.py code:-
from openerp import api, fields, models, _
from openerp import SUPERUSER_ID
from openerp.exceptions import UserError
import openerp.addons.decimal_precision as dp
class ProductImage(models.Model):
_inherit ="product.template"
product.xml code:-
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="product_image_form" model="ir.ui.view">
<field name="name">product.image.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>
</data>
</openerp>
So how to save multiple images in wizard and see the saved images in wizard as these images disappears when we click on ok button. Is there any error in my code? Can anyone suggest?