Browse Source
Add module pos_default_empty_image
Add module pos_default_empty_image
Big perf improvement for loading POS if you have thousand of products without imagepull/351/head
Hparfr
9 years ago
committed by
Sylvain LE GAL
6 changed files with 181 additions and 0 deletions
-
72pos_default_empty_image/README.rst
-
1pos_default_empty_image/__init__.py
-
44pos_default_empty_image/__openerp__.py
-
20pos_default_empty_image/product.py
-
34pos_default_empty_image/static/src/js/pos_default_empty_image.js
-
10pos_default_empty_image/view/view.xml
@ -0,0 +1,72 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
=========================== |
||||
|
POS Default Empty Image |
||||
|
=========================== |
||||
|
|
||||
|
In the point of sale, trying to load known inexistant images is a waste of time. |
||||
|
|
||||
|
|
||||
|
When you have 8000 products in your Point of Sale and most of them don't have images, |
||||
|
you are happy to save thousands of useless requests : the POS load way faster. |
||||
|
|
||||
|
Technical information |
||||
|
===================== |
||||
|
|
||||
|
Each time the pos instantiate a product, it will add an |
||||
|
|
||||
|
<img src="'/web/binary/image?model=product.product&field=image_medium&id='+product.id;"> |
||||
|
|
||||
|
The browser will trigger as many requests than there is different url. |
||||
|
|
||||
|
|
||||
|
If you have many products, the browser will soon reach his limit of network connections to Odoo server and |
||||
|
will wait for free slots instead of loading other valuable contents. Then the POS is then very slow to work with. |
||||
|
|
||||
|
|
||||
|
This module adds a field _has_image_ in product.template and will change the product image url to his default placeholder directly in the POS. |
||||
|
|
||||
|
Because there is only one url for this placeholder, you will have only one request for all the products with no images. |
||||
|
|
||||
|
Indeed, if the product has an image, it will load normally. |
||||
|
|
||||
|
Known issues |
||||
|
============ |
||||
|
|
||||
|
|
||||
|
Updates |
||||
|
======= |
||||
|
* Feb 2016 : First version |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. |
||||
|
In case of trouble, please check there if your issue has already been reported. |
||||
|
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here <https://github.com/OCA/web/issues/new?body=module:%20web_switch_company_warning%0Aversion:%200.1%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. |
||||
|
|
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Hparfr <https://github.com/hparfr> (Akretion)[https://akretion.com] |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit http://odoo-community.org. |
@ -0,0 +1 @@ |
|||||
|
# -*- coding: utf-8 -*- |
@ -0,0 +1,44 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © <2015> <Akretion, OCA> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
{ |
||||
|
'name': 'POS Default empty image', |
||||
|
'version': '8.0.0.1.0', |
||||
|
'category': 'Point Of Sale', |
||||
|
'summary': 'Optimise load time for products with no image', |
||||
|
'description': """ |
||||
|
POS Default empty Image |
||||
|
======================= |
||||
|
|
||||
|
In the point of sale, trying to load known inexistant images is a waste of time. |
||||
|
|
||||
|
|
||||
|
When you have 8000 products in your Point of Sale and most of them don't have images, |
||||
|
you are happy to save thousands of useless requests : the POS load way faster. |
||||
|
|
||||
|
Technical information |
||||
|
===================== |
||||
|
|
||||
|
Each time the pos instantiate a product, it will add an |
||||
|
<img src="/web/.... + imageId"> to DOM. |
||||
|
The browser will trigger as many requests than there is different url. |
||||
|
If you have many products, the browser will soon reach his limit of network connections to Odoo server and |
||||
|
will wait for free slots instead of loading other valuable contents. |
||||
|
The POS is then very slow to work with. |
||||
|
|
||||
|
|
||||
|
This module adds a field _has_image_ in product.template and will change |
||||
|
the product image url to his default placeholder directly in the POS. |
||||
|
Because there is only one url for this placeholder, you will have only one request for all the products with |
||||
|
no images. |
||||
|
|
||||
|
Indeed, if the product has an image, it will load normally. |
||||
|
|
||||
|
""", |
||||
|
'author': "Akretion / Odoo Community Association (OCA)", |
||||
|
'website': "https://akretion.com", |
||||
|
'license': 'AGPL-3', |
||||
|
'depends': ['point_of_sale'], |
||||
|
'data': [ 'view/view.xml'], |
||||
|
'qweb': [], |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © <2015> <Akretion, OCA> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp import models, fields, api |
||||
|
|
||||
|
class ProductTemplate(models.Model): |
||||
|
_inherit = ['product.template'] |
||||
|
_name = 'product.template' |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends('field.image') |
||||
|
def _has_image(self): |
||||
|
for record in self: |
||||
|
record.has_image = bool(record.image) |
||||
|
|
||||
|
has_image = fields.Boolean( |
||||
|
compute='_has_image', |
||||
|
store=True, |
||||
|
readonly=True) |
@ -0,0 +1,34 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
openerp.pos_default_empty_image = function (instance) { |
||||
|
var module = instance.point_of_sale; |
||||
|
var _t = instance.web._t; |
||||
|
|
||||
|
//don't try to get an image if we know the product ain't one
|
||||
|
module.ProductListWidget = module.ProductListWidget.extend({ |
||||
|
get_product_image_url: function(product){ |
||||
|
if (product.has_image) |
||||
|
return this._super(product); |
||||
|
|
||||
|
return '/web/static/src/img/placeholder.png'; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
//we can't extend it because self.pos not ready yet
|
||||
|
var _initializePosModel_ = module.PosModel.prototype.initialize; |
||||
|
module.PosModel.prototype.initialize = function(session, attributes){ |
||||
|
//add has_image to the request of product product
|
||||
|
this.models.some(function (m, idx) { |
||||
|
if (m.model !== "product.product") |
||||
|
return false; |
||||
|
|
||||
|
//check if not already done by someone else
|
||||
|
if (m.fields.indexOf('has_image') === -1) { |
||||
|
m.fields.push('has_image'); |
||||
|
} |
||||
|
|
||||
|
return true; //no need to continue
|
||||
|
}); |
||||
|
return _initializePosModel_.call(this, session, attributes); |
||||
|
}; |
||||
|
}; |
@ -0,0 +1,10 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<template id="assets_backend" name="pos_default_empty_image assets" inherit_id="web.assets_backend"> |
||||
|
<xpath expr="." position="inside"> |
||||
|
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/pos_default_empty_image.js"></script> |
||||
|
</xpath> |
||||
|
</template> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue