Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
5656 Visualizzazioni

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?

Avatar
Abbandona
Risposta migliore

Hello Gautam,

You can do with store image at your form and when you edit your form then by default get method again show image which are stored on your form.

Avatar
Abbandona
Risposta migliore

Hello Gautam,

In wizard, values are not stored. So use many2many fields in product.template for saving multiple images.

For Example :-
class ProductTemplate(models.Model):
    _inherit = 'product.template'

    product_images_line = fields.Many2many('product.image', 'image_product', 'image_id', 'product_id', string="Images")


class ProductImage(models.Model):
    _name = 'product.image'

    image = fields.Binary('Image')


Now, you can inherit the product template view and add product_images_line field with widget many2many_kanban.

Hope it will helps you.
Thanks,


Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
lug 22
8004
0
set 17
3455
0
feb 25
1111
2
dic 24
1428
0
lug 24
1185