Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5633 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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,


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lip 22
7987
0
wrz 17
3411
0
lut 25
1029
2
gru 24
1395
0
lip 24
1139