From 9969de9d9b7d4620cdc8e1b95b56a580c6da32fd Mon Sep 17 00:00:00 2001 From: Hparfr Date: Wed, 24 Feb 2016 15:05:53 +0100 Subject: [PATCH 1/6] Add module pos_default_empty_image Big perf improvement for loading POS if you have thousand of products without image --- pos_default_empty_image/README.rst | 72 +++++++++++++++++++ pos_default_empty_image/__init__.py | 1 + pos_default_empty_image/__openerp__.py | 44 ++++++++++++ pos_default_empty_image/product.py | 20 ++++++ .../static/src/js/pos_default_empty_image.js | 34 +++++++++ pos_default_empty_image/view/view.xml | 10 +++ 6 files changed, 181 insertions(+) create mode 100644 pos_default_empty_image/README.rst create mode 100644 pos_default_empty_image/__init__.py create mode 100644 pos_default_empty_image/__openerp__.py create mode 100644 pos_default_empty_image/product.py create mode 100644 pos_default_empty_image/static/src/js/pos_default_empty_image.js create mode 100644 pos_default_empty_image/view/view.xml diff --git a/pos_default_empty_image/README.rst b/pos_default_empty_image/README.rst new file mode 100644 index 00000000..9f49d1a9 --- /dev/null +++ b/pos_default_empty_image/README.rst @@ -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 + + + +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 `_. +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 `_. + + +Credits +======= + +Contributors +------------ + +* 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. diff --git a/pos_default_empty_image/__init__.py b/pos_default_empty_image/__init__.py new file mode 100644 index 00000000..7c68785e --- /dev/null +++ b/pos_default_empty_image/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/pos_default_empty_image/__openerp__.py b/pos_default_empty_image/__openerp__.py new file mode 100644 index 00000000..29526f77 --- /dev/null +++ b/pos_default_empty_image/__openerp__.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# © <2015> +# 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 + 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': [], +} diff --git a/pos_default_empty_image/product.py b/pos_default_empty_image/product.py new file mode 100644 index 00000000..03384a3b --- /dev/null +++ b/pos_default_empty_image/product.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# © <2015> +# 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) diff --git a/pos_default_empty_image/static/src/js/pos_default_empty_image.js b/pos_default_empty_image/static/src/js/pos_default_empty_image.js new file mode 100644 index 00000000..10d65a9f --- /dev/null +++ b/pos_default_empty_image/static/src/js/pos_default_empty_image.js @@ -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); + }; +}; diff --git a/pos_default_empty_image/view/view.xml b/pos_default_empty_image/view/view.xml new file mode 100644 index 00000000..b3de3a4b --- /dev/null +++ b/pos_default_empty_image/view/view.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file From 62853e1fed8faa7c4570395050b339b02ec53c6c Mon Sep 17 00:00:00 2001 From: raph Date: Fri, 26 Feb 2016 10:20:00 +0100 Subject: [PATCH 2/6] Limit lines to < 80 chars --- pos_default_empty_image/__openerp__.py | 23 ++++++++++++++--------- pos_default_empty_image/product.py | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/pos_default_empty_image/__openerp__.py b/pos_default_empty_image/__openerp__.py index 29526f77..72641663 100644 --- a/pos_default_empty_image/__openerp__.py +++ b/pos_default_empty_image/__openerp__.py @@ -10,11 +10,14 @@ POS Default empty Image ======================= -In the point of sale, trying to load known inexistant images is a waste of time. +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. +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 ===================== @@ -22,15 +25,17 @@ Technical information Each time the pos instantiate a product, it will add an 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. +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 +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. +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. @@ -39,6 +44,6 @@ Indeed, if the product has an image, it will load normally. 'website': "https://akretion.com", 'license': 'AGPL-3', 'depends': ['point_of_sale'], - 'data': [ 'view/view.xml'], + 'data': ['view/view.xml'], 'qweb': [], } diff --git a/pos_default_empty_image/product.py b/pos_default_empty_image/product.py index 03384a3b..7f30664c 100644 --- a/pos_default_empty_image/product.py +++ b/pos_default_empty_image/product.py @@ -4,6 +4,7 @@ from openerp import models, fields, api + class ProductTemplate(models.Model): _inherit = ['product.template'] _name = 'product.template' From f4589bdc2055e0c23d39343548f9e3c63b85a89b Mon Sep 17 00:00:00 2001 From: raph Date: Fri, 26 Feb 2016 10:26:44 +0100 Subject: [PATCH 3/6] No new line at end of file --- pos_default_empty_image/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pos_default_empty_image/__init__.py b/pos_default_empty_image/__init__.py index 7c68785e..40a96afc 100644 --- a/pos_default_empty_image/__init__.py +++ b/pos_default_empty_image/__init__.py @@ -1 +1 @@ -# -*- coding: utf-8 -*- \ No newline at end of file +# -*- coding: utf-8 -*- From c0da598d43702f42a3e5cad046a506794f8369d2 Mon Sep 17 00:00:00 2001 From: raph Date: Fri, 26 Feb 2016 12:27:34 +0100 Subject: [PATCH 4/6] Add missing credits --- pos_default_empty_image/README.rst | 6 ++++++ pos_default_empty_image/__openerp__.py | 14 ++++++++++++-- pos_default_empty_image/product.py | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/pos_default_empty_image/README.rst b/pos_default_empty_image/README.rst index 9f49d1a9..49f24983 100644 --- a/pos_default_empty_image/README.rst +++ b/pos_default_empty_image/README.rst @@ -55,6 +55,12 @@ Contributors ------------ * Hparfr (Akretion)[https://akretion.com] +* Sylvain LE GAL + +See also this module: [pos_improve_images from GRAP] +(https://github.com/grap/odoo-addons-grap/tree/7.0/pos_improve_images) + for OpenERP 7. + Maintainer ---------- diff --git a/pos_default_empty_image/__openerp__.py b/pos_default_empty_image/__openerp__.py index 72641663..654e940b 100644 --- a/pos_default_empty_image/__openerp__.py +++ b/pos_default_empty_image/__openerp__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © <2015> +# © <2015> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'POS Default empty image', @@ -39,8 +39,18 @@ only one request for all the products with no images. Indeed, if the product has an image, it will load normally. + +Other +===== + +See also this module: [pos_improve_images from GRAP] +(https://github.com/grap/odoo-addons-grap/tree/7.0/pos_improve_images) + for OpenERP 7 which emphasis the name of the product +instead of displaying the placeholder. + + """, - 'author': "Akretion / Odoo Community Association (OCA)", + 'author': "Akretion, GRAP, Odoo Community Association (OCA)", 'website': "https://akretion.com", 'license': 'AGPL-3', 'depends': ['point_of_sale'], diff --git a/pos_default_empty_image/product.py b/pos_default_empty_image/product.py index 7f30664c..09c7999d 100644 --- a/pos_default_empty_image/product.py +++ b/pos_default_empty_image/product.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# © <2015> +# © <2015> # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api From 517a9c33635716ed167411104bb45754ebf1abb5 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Fri, 26 Feb 2016 13:54:35 +0100 Subject: [PATCH 5/6] [FIX] description file; --- pos_default_empty_image/README.rst | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pos_default_empty_image/README.rst b/pos_default_empty_image/README.rst index 49f24983..714be00f 100644 --- a/pos_default_empty_image/README.rst +++ b/pos_default_empty_image/README.rst @@ -2,9 +2,9 @@ :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. @@ -17,7 +17,7 @@ Technical information Each time the pos instantiate a product, it will add an - + The browser will trigger as many requests than there is different url. @@ -38,14 +38,15 @@ Known issues Updates ======= - * Feb 2016 : First version + +* Feb 2016 : First version Bug Tracker =========== Bugs are tracked on `GitHub 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 `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. Credits @@ -54,12 +55,10 @@ Credits Contributors ------------ -* Hparfr (Akretion)[https://akretion.com] +* Hparfr `Akretion `_ * Sylvain LE GAL -See also this module: [pos_improve_images from GRAP] -(https://github.com/grap/odoo-addons-grap/tree/7.0/pos_improve_images) - for OpenERP 7. +See also this module `pos_improve_images from GRAP `_ for OpenERP 7. Maintainer From c170ef1c49166cbefb0cfe9b0cf07f42eef7b775 Mon Sep 17 00:00:00 2001 From: raph Date: Fri, 26 Feb 2016 14:35:09 +0100 Subject: [PATCH 6/6] Fix line length in readme Remove __openerp.py_.description Remove _name Remove unneeded contents in init --- pos_default_empty_image/README.rst | 24 +++++++++----- pos_default_empty_image/__init__.py | 1 - pos_default_empty_image/__openerp__.py | 44 -------------------------- pos_default_empty_image/product.py | 1 - 4 files changed, 16 insertions(+), 54 deletions(-) diff --git a/pos_default_empty_image/README.rst b/pos_default_empty_image/README.rst index 714be00f..abe091b5 100644 --- a/pos_default_empty_image/README.rst +++ b/pos_default_empty_image/README.rst @@ -6,11 +6,13 @@ POS Default Empty Image ======================= -In the point of sale, trying to load known inexistant images is a waste of time. +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. +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 ===================== @@ -22,16 +24,21 @@ Each time the pos instantiate a product, it will add an 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. +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. +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. -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 ============ @@ -58,7 +65,8 @@ Contributors * Hparfr `Akretion `_ * Sylvain LE GAL -See also this module `pos_improve_images from GRAP `_ for OpenERP 7. +See also this module `pos_improve_images from GRAP +`_ for OpenERP 7. Maintainer diff --git a/pos_default_empty_image/__init__.py b/pos_default_empty_image/__init__.py index 40a96afc..e69de29b 100644 --- a/pos_default_empty_image/__init__.py +++ b/pos_default_empty_image/__init__.py @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/pos_default_empty_image/__openerp__.py b/pos_default_empty_image/__openerp__.py index 654e940b..b0fa5408 100644 --- a/pos_default_empty_image/__openerp__.py +++ b/pos_default_empty_image/__openerp__.py @@ -6,50 +6,6 @@ '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 - 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. - - -Other -===== - -See also this module: [pos_improve_images from GRAP] -(https://github.com/grap/odoo-addons-grap/tree/7.0/pos_improve_images) - for OpenERP 7 which emphasis the name of the product -instead of displaying the placeholder. - - - """, 'author': "Akretion, GRAP, Odoo Community Association (OCA)", 'website': "https://akretion.com", 'license': 'AGPL-3', diff --git a/pos_default_empty_image/product.py b/pos_default_empty_image/product.py index 09c7999d..44c1d09c 100644 --- a/pos_default_empty_image/product.py +++ b/pos_default_empty_image/product.py @@ -7,7 +7,6 @@ from openerp import models, fields, api class ProductTemplate(models.Model): _inherit = ['product.template'] - _name = 'product.template' @api.multi @api.depends('field.image')