This question has been flagged
6 Replies
34921 Views

how can I add small images in sale.order.line in OpenERP 7 web client? So that each product in orders or quotations has as small image.

Thank you very much.

Avatar
Discard
Author

What I mean is that sale.order.line shows the image of each product. I know how to add a image to product. I need the images to be shown in the sale orders.

Thank You!

@Stefan, can you take a look at my "answer"-post below? I've installed the module just as you've described, it's changed all the views, but there's no thumbnail, only a "Download link". Thanks for the time!

I have modified Stefan's original code below and have made some changes to make an installable module in Odoo 8.0 (please use 8.0 branch for stable merges, and master for trunk branch): https://github.com/OdooCommunityWidgets/product_image_list_view Currently I have a download link from the binary field with 0 bytes which means the field is not being related correctly for 8.0 as far as I can tell. I will continue to troubleshoot to try to get it working on the 8.0 branch, however if anyone is interested in submitting pull requests to fix current issues they can see, or improve the module please feel free. I'll post back here with an update once I have figured out how to get the image field showing up correctly with no download link in 8.0.

[UPDATE]: this is now working in Odoo 8.0, but the image widget only displays in live editing mode and goes back to a download link when saved.

Luke's module is working

@aci,

Thanks for letting me know. It's actually just some minor modifications to views to make it compatible with version 8.0, so it's fundamentally the same module Stefan put together.

I've started a new thread for the 8.0 version if you're interested:

https://www.odoo.com/forum/help-1/question/8-0-odoo-8-how-can-i-add-images-in-sale-oder-line-or-in-treeview-generally-82412

You'll need to install Stefan's OCA module here, as it is a dependency:

https://github.com/OCA/web/tree/8.0/web_tree_image

Author Best Answer

ok, finally i have found a way. i created a module as following:

__init__.py:

import product
import stock

__openerp__.py:

{
    "name" : "Product Image",
    "version" : "0.1",
    "author" : "Stefan Reisich, Rove.design GmbH",
    "website" : "http://www.rove.de/",
    "description": """
This Module overwrites openerp.web.list.Binary field to show the product image in the listview. A new column with product image is added.
    """,
    "depends" : [
                 "sale",
                 "sale_stock",
                 "stock"
    ],
    'js': [
           'static/src/js/view_list.js'
    ],
    "data": [
        'product_view.xml',
        'sale_view.xml',
        'stock_view.xml'
    ],
    'installable': True,
    "active": False,
}

product_view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>

        <record id="product_product_tree_view_image" model="ir.ui.view">
            <field name="name">product.product.tree</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_product_tree_view"/>
            <field name="arch" type="xml">
                <field name="default_code" position="before">
                    <field name="image_small"/>
                </field>
            </field>
        </record>

    </data>
</openerp>

sale_view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>

        <record id="view_order_image_form_change" model="ir.ui.view">
            <field name="name">sale.order.form.sale.image</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='product_id']" position="replace">
                    <field name="product_id"
                           context="{'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'shop':parent.shop_id, 'uom':product_uom}"
                           groups="base.group_user"
                           on_change="product_id_change(parent.pricelist_id, product_id, product_uom_qty, product_uom, product_uos_qty, product_uos, name, parent.partner_id, False, True, parent.date_order, False, parent.fiscal_position, False,image_small, context)"/>
                </xpath> 

            </field>
        </record>

        <record id="view_order_image_form_inherit" model="ir.ui.view">
            <field name="name">sale.order.form.sale.image</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/form[@string='Sales Order Lines']/group/group/field[@name='product_id']" position="after">
                    <field name="image_small" widget="image"/>
                </xpath> 

                <xpath expr="//page[@string='Order Lines']/field[@name='order_line']/tree[@string='Sales Order Lines']/field[@name='price_subtotal']" position="after">
                    <field name="image_small" widget="image"/>
                </xpath>


            </field>
         </record>

    </data>
</openerp>

stock_view.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>

        <record id="view_move_form2" model="ir.ui.view">
            <field name="name">stock.move.form2</field>
            <field name="model">stock.move</field>
            <field name="inherit_id" ref="stock.view_move_form"/>
            <field name="arch" type="xml">
                <xpath expr="/form/sheet/group/group/field[@name='product_id']" position="after">
                        <field name="image_small" widget="image"/>
                </xpath>
            </field>
        </record>

        <record id="view_move_tree_inherit" model="ir.ui.view">
            <field name="name">stock.move.tree2</field>
            <field name="model">stock.move</field>
            <field name="inherit_id" ref="stock.view_move_picking_tree"/>
            <field name="arch" type="xml">
                <field name="product_id" position="before">
                        <field name="image_small" widget="image" string="Image"/>
                </field>
            </field>
        </record>

    </data>
</openerp>

stock.py:

from openerp.osv import fields, osv

class stock_move(osv.Model):
    _name = 'stock.move'
    _inherit = 'stock.move'

    def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
                            loc_dest_id=False, partner_id=False):
        res_prod = super(stock_move, self).onchange_product_id(cr, uid, ids, prod_id, loc_id,loc_dest_id, partner_id)
        prod_obj = self.pool.get('product.product')
        obj = prod_obj.browse(cr, uid, prod_id)
        res_prod['value'].update({'image_small': obj.image_small})
        return res_prod


    _columns = {
        'image_small' : fields.binary('Product Image'),
    }

stock_move()

class sale_order_line(osv.Model):
    _name = 'sale.order.line'
    _inherit = 'sale.order.line'
    _columns = {
        'image_small' : fields.binary('Product Image'),
    }

    def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
                          uom=False, qty_uos=0, uos=False, name='', partner_id=False,
                          lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False,image_small=False, context=None):
        context = context or {}

        res = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
                                                             uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
                                                             lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag, context=context)

        product_obj = self.pool.get('product.product')
        product_obj = product_obj.browse(cr, uid, product, context=context)

        res['value'].update({'image_small': product_obj.image_small or False})
        return res


sale_order_line()

class sale_order(osv.Model):
    _name = 'sale.order'
    _inherit = 'sale.order'

    def _prepare_order_line_move(self, cr, uid, order, line, picking_id, date_planned, context=None):
        res = super(sale_order, self)._prepare_order_line_move(cr, uid, order=order, line=line, picking_id=picking_id, date_planned=date_planned, context=context)
        res['image_small'] = line.image_small
        return res

sale_order()

view_list.js:

openerp.nfx_product_image = function(openerp) {
    var _t = openerp.web._t;

    openerp.web.list.Binary.include({
        placeholder: "/web/static/src/img/placeholder.png",
        _format: function (row_data, options) {
            var value = row_data[this.id].value;
            var download_url;
            if (value && value.substr(0, 10).indexOf(' ') == -1) {
                download_url = "data:application/octet-stream;base64," + value;
            } else {
                download_url = this.placeholder;
            }

            return _.template("<img width='50' height='50' src='<%-href%>'/>", {
                href: download_url,
            });
        }

    });
}
Avatar
Discard
Author

as soon as I get some time I will share this on launchpad or apps.openerp.com too. At the moment I'm trying to resolve another problem: http://help.openerp.com/question/7586/modulefunction-that-showsreturns-stock-locations-in-products/

what about "product_view.xml"?

Author

updated answer (product_view.xml)... :-)

Hi Stefan, These three xml file& stock.py is new or core module files? Thanks.

I cant see any image in Quotation/order. Any other configuration is needeed?

Author

the xml files are new files. Try creating a new order/quotation, if you dont't see the images. The images won't appear in old orders, only in new...

So the above code must be updated in the existing xml file( product_view.xml,sale_view.xml,stock_view.xml)

Author

NO. Never change core files ;-) You must create a new module with this files. If you never have created a module it is better to start here: http://doc.openerp.com/trunk/developers/web/module/

But i create a new module with all these files. Then, what is the next step?

Author

go to settings and update the modules list. if you don't see the option "update modules list" you must activate technical view for your user. to active the technical features you must go to settings -> users. then edit you user and under the "acces rights" tab you can activate the technical features... after that you can update the modules list. then you must go to settings -> installed modules. in the search box you must delete the "installed" filter. then you can search for the new module and install it... hope it works :-)

Hi Stefan, I installed my custom module. But when i take Quotation/Order print out, it doesnt shows image.

Author

what you mean with print out? do you want the images in the printed order(in the pdf)?

In sale.order.line & treeview , but image doesnt appered in both. Then i tried to take print out. But it also doesnt shows.

Author

do you have created a new order? do you see a placeholder instead of the image?

I have created a new order, but cant see any placeholder.

Author

i'm sorry, then i don't know

what about "product.pyl"?

Author

don't have product.py

Hi Stefan, can we have the images in the printed order(in the pdf)?

Author

Hi Kris, sorry, not with this module. Maybe you are searching this: http://help.openerp.com/question/9336/how-can-i-add-a-products-image-in-report/

Thank you Stefan, wil try it out... Have a great day! :)

hi......Stefan I need to add a image to my report which is not in database can you please help me out

Author

This module adds images to the tree view not to a report... I don't know how to add a images to reports...

Could you please add the purchase view too? Thanks for the great module

In openerp7 this error show me: "res_id = model_obj.create(cr, uid, values, context=context) File "/opt/openerp/server/openerp/addons/base/ir/ir_ui_view.py", line 103, in create return super(view, self).create(cr, uid, values, context) File "/opt/openerp/server/openerp/osv/orm.py", line 4525, in create self._validate(cr, user, [id_new], context) File "/opt/openerp/server/openerp/osv/orm.py", line 1557, in _validate raise except_orm('ValidateError', '\n'.join(error_msgs)) except_osv: ('ValidateError', u'Ha ocurrido un error mientras se validaban los campo(s) arch: Invalid XML"

Author

please check your xml files. it must be something wrong there...

Hi show me this error in sale order line, is good installed: "ProgrammingError: operator does not exist: integer = boolean LINE 1: ...d FROM "product_product" WHERE product_product.id IN (false)... ^ HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts."

@Stefan, can you take a look at my post below? I've installed the module just as you've described, it's changed all the views, but there's no thumbnail, only a "Download link". Thanks for the time!

@Stefan Reisich, Do you have any plans to release an Odoo 8.0 version of this module? I think there are a large number of people who would benefit from this script. I would be happy to discuss organising funding for this project if this is something you are open to discussing.

Best Answer

I think putting image in the sale.order.line is not possible. But you can put image for a specific product just by configuring it in the Product configuration. :)

Avatar
Discard

Hello, Would you please commit your code on launchpad or github. Its really useful to other.

really a nice work

Author

thank you.

Good work, can you tell me what changes would have to do to make it work in version 6.1, I hope you can help me, thank you very much.

Author

sorry, i begun with openerp 7.0

Okay anyway Stefan really appreciate your response, I wanted to ask if it works 100% on version 7 and if possible the file you showed product.py not see it in your answer, good job and thanks.

Author

its working for me :-) the module don't has a product.py

Stefan Thanks anyway, as view_list.js file use, ie that part is placed in another file or embedded?

again thanks for your answers, Best regards.

Author

all files are new files. That's the way a new module is created. Please see here how to create a new module: http://doc.openerp.com/trunk/developers/web/module/

Hi Stefan,

Thank you for creating this module. It's exactly what I need. Unfortunately I am having an issue with the thumbnails displaying on sales order line and product list view. Instead of displaying a thumbnail I am only able to display a download link with file size (eg. Download (3.69 Kb)). Is there any way to display a thumbnail instead?

I would also like to know if it is possible to apply this to the print version of the sales order, quotation, etc. as it would be very useful to display a product thumbnail on the customer's document. Any advice would be very much appreciated.

Hi Stefan! I'm having the same issue, as 22719. I'm abble to see only a download link instead of the thumbnails. What should I do ? Thanks, TArpi

Author

please just follow all the steps written above. if you have done right, you will see the image instead of the download link. after that restart openerp with -u your_module_name.

Thank Stefan for your patience, but still nothing. Today I made a new module, with the above file names, and file contents, but still the Download thing. Another issue: when I want to create a Sale Order, I get the following error: File "/opt/openerp/server/openerp/sql_db.py", line 226, in execute res = self._obj.execute(query, params) ProgrammingError: operator does not exist: integer = boolean LINE 1: ...d FROM "product_product" WHERE product_product.id IN (false)... ^ ...

... HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

I restarted the server, too, but no progress. Thanks for your help.

Can you post the github or another other link where can i found your code. Please help me to find it.

Author

the code is posted above... i don't have other location where you can find it...

You can share link in github or launchpad, tnks

change none for false, is work for me.

But no show thumbnail only show "Descargar (11.12 Kb)" and when download it is bad because no extentions

Best Answer

I've been struggling with this one, I've created all the files as @Stefan showed, inserted in server's addon folder, updated modules list, it appears there as product_image, I click install and it goes very well. However, now I get a list of download links instead of the thumbnails, as you can see here:

I've already tried restarting the server, stopping and then starting with "-u product_image" modifier, upgrading the module in configuration, but I get the same results.

The only thing that worked was while creating a sales order, picking view:

 

Avatar
Discard

Stefan, would you have any tips?

@Igor, I've just begun porting this module to 8.0. I have an installable module for the 8.0 branch now, but I am still running into the same issue. Did you ever figure this one out?

@Igor, I think this has something to do with the /static/src/js/view_list.js not being called correctly in the backend. I can see no difference between including it in my module and not including it, which means I am not including it correctly in the backend. This js controls the functionality of replacing the binary download link with an image widget and therefore I think in both 7.0 and 8.0/Master it will not work unless included correctly. I'll post back here if I make any progress on this. I have a working module ported to 8.0 here: https://github.com/OdooCommunityWidgets/product_image_list_view

@Igor,

I have finally figured out a way to do this in 8.0 with Stefan's new module in github.com/OCA/web/web_tree_image.

I've modified the original 7.0 module to work with 8.0 depending on Stefan's OCA module above:

https://github.com/OdooCommunityWidgets/product_image_list_view

@Luke: that's great news! Will try it when possible, thanks!!!

@Igor,

no problem. Let me know if you have any feedback on the module and i'll try to implement some suggested changes.

Just a heads up, if you want to change the size of the image on the invoice the image uses the image_small image from the database (64px by 64px) and you can change the height of the image by modifying this line:

field name="image_small" widget="image" height="64" class="oe_avatar"

in this file:

https://github.com/OdooCommunityWidgets/product_image_list_view/blob/8.0/views/sale_view.xml

I'll add support for using image_medium as well as changing the image height through the GUI when I can find time.

@Igor,

no problem. Let me know if you have any feedback on the module and i'll try to implement some suggested changes.

Just a heads up, if you want to change the size of the image on the invoice the image uses the image_small image from the database (64px by 64px) and you can change the height of the image by modifying this line:

field name="image_small" widget="image" height="64" class="oe_avatar"

in this file:

https://github.com/OdooCommunityWidgets/product_image_list_view/blob/8.0/views/sale_view.xml

I'll add support for using image_medium as well as changing the image height through the GUI when I can find time.

@Igor,

I've changed the OdooCommunityWidgets repository URL to match the OCA dependency. Here's the new link:

https://github.com/OdooCommunityWidgets/web_tree_image_order_line

Best Answer

What is happiness measured by?

Is happiness also measured?

Happiness should be all about

Feelings, emotions, perspective of life

It should be personal for each person.

Depending on each person's point of view

https://bit.ly/2SRyNoo

Avatar
Discard
Best Answer

I installed both the apps web_tree_image and product_image_list_view and I am still getting only download links instead of images in tree view. In sale order line, I am able to see an image. But when I edit the product.template tree view (warehouse -> products) to add "<field name="image_small" widget='image'/>" I am seeing only download link instead of the images. Is this the correct way to include image in list view ?

Avatar
Discard
Best Answer

I installed the module and it works fine. But I can not either upgrade or install it. The pop-up error shows as bellow, anyone else have the same issue?

OpenERP Server Error Client Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/http.py", line 204, in dispatch response["result"] = method(self, *self.params) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1135, in call_button action = self._call_kw(req, model, method, args, {}) File "/opt/openerp/server/openerp/addons/web/controllers/main.py", line 1123, in _call_kw return getattr(req.session.model(model), method)(args, **kwargs) File "/opt/openerp/server/openerp/addons/web/session.py", line 42, in proxy result = self.proxy.execute_kw(self.session._db, self.session._uid, self.session._password, self.model, method, args, kw) File "/opt/openerp/server/openerp/addons/web/session.py", line 30, in proxy_method result = self.session.send(self.service_name, method, *args) File "/opt/openerp/server/openerp/addons/web/session.py", line 103, in send raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)

Server Traceback (most recent call last): File "/opt/openerp/server/openerp/addons/web/session.py", line 89, in send return openerp.netsvc.dispatch_rpc(service_name, method, args) File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc result = ExportService.getService(service_name).dispatch(method, params) File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch res = fn(db, uid, params) File "/opt/openerp/server/openerp/osv/osv.py", line 190, in execute_kw return self.execute(db, uid, obj, method, *args, *kw or {}) File "/opt/openerp/server/openerp/osv/osv.py", line 132, in wrapper return f(self, dbname, args, *kwargs) File "/opt/openerp/server/openerp/osv/osv.py", line 199, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/opt/openerp/server/openerp/osv/osv.py", line 187, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/opt/openerp/server/openerp/addons/base/module/module.py", line 495, in button_immediate_uninstall return self._button_immediate_function(cr, uid, ids, self.button_uninstall, context=context) File "/opt/openerp/server/openerp/addons/base/module/module.py", line 475, in _button_immediate_function _, pool = pooler.restart_pool(cr.dbname, update_module=True) File "/opt/openerp/server/openerp/pooler.py", line 39, in restart_pool registry = RegistryManager.new(db_name, force_demo, status, update_module) File "/opt/openerp/server/openerp/modules/registry.py", line 233, in new openerp.modules.load_modules(registry.db, force_demo, status, update_module) File "/opt/openerp/server/openerp/modules/loading.py", line 354, in load_modules loaded_modules, update_module) File "/opt/openerp/server/openerp/modules/loading.py", line 256, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "/opt/openerp/server/openerp/modules/loading.py", line 188, in load_module_graph load_data(module_name, idref, mode) File "/opt/openerp/server/openerp/modules/loading.py", line 76, in <lambda> load_data = lambda *args: _load_data(cr, *args, kind='data') File "/opt/openerp/server/openerp/modules/loading.py", line 124, in _load_data tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report) File "/opt/openerp/server/openerp/tools/convert.py", line 941, in convert_xml_import doc = etree.parse(xmlfile) File "lxml.etree.pyx", line 2953, in lxml.etree.parse (src/lxml/lxml.etree.c:56204) File "parser.pxi", line 1555, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:82511) File "parser.pxi", line 1585, in lxml.etree._parseFilelikeDocument (src/lxml/lxml.etree.c:82832) File "parser.pxi", line 1468, in lxml.etree._parseDocFromFilelike (src/lxml/lxml.etree.c:81688) File "parser.pxi", line 1024, in lxml.etree._BaseParser._parseDocFromFilelike (src/lxml/lxml.etree.c:78735) File "parser.pxi", line 569, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:74472) File "parser.pxi", line 650, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:75363) File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:74696) XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

Avatar
Discard