From 55cf73dd463a4dcb44a74f48b65b188166c722c3 Mon Sep 17 00:00:00 2001 From: Invitu Date: Thu, 2 Mar 2017 21:37:09 -1000 Subject: [PATCH] [MIG] pos_default_empty_image: Migrate to 10.0 --- pos_default_empty_image/README.rst | 85 +++++++++++++++++++ pos_default_empty_image/__init__.py | 1 + pos_default_empty_image/__manifest__.py | 15 ++++ pos_default_empty_image/models/__init__.py | 1 + pos_default_empty_image/models/product.py | 16 ++++ .../static/src/js/pos_default_empty_image.js | 26 ++++++ pos_default_empty_image/view/view.xml | 8 ++ 7 files changed, 152 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/__manifest__.py create mode 100644 pos_default_empty_image/models/__init__.py create mode 100644 pos_default_empty_image/models/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..abe091b5 --- /dev/null +++ b/pos_default_empty_image/README.rst @@ -0,0 +1,85 @@ +.. 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 `_ +* Sylvain LE GAL + +See also this module `pos_improve_images from GRAP +`_ for OpenERP 7. + + +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..0650744f --- /dev/null +++ b/pos_default_empty_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_default_empty_image/__manifest__.py b/pos_default_empty_image/__manifest__.py new file mode 100644 index 00000000..3f2d6771 --- /dev/null +++ b/pos_default_empty_image/__manifest__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © <2015> +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + 'name': 'POS Default empty image', + 'version': '10.0.0.1.0', + 'category': 'Point Of Sale', + 'summary': 'Optimise load time for products with no image', + 'author': "Akretion, GRAP, 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/models/__init__.py b/pos_default_empty_image/models/__init__.py new file mode 100644 index 00000000..9649db77 --- /dev/null +++ b/pos_default_empty_image/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/pos_default_empty_image/models/product.py b/pos_default_empty_image/models/product.py new file mode 100644 index 00000000..0a9344db --- /dev/null +++ b/pos_default_empty_image/models/product.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © <2015> +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields, api + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + @api.multi + def _get_has_image(self): + self.ensure_one() + self.has_image = self.image is not False + + has_image = fields.Boolean(compute='_get_has_image', string='Has Image') 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..f73442ca --- /dev/null +++ b/pos_default_empty_image/static/src/js/pos_default_empty_image.js @@ -0,0 +1,26 @@ +odoo.define('pos_default_empty_image', function (require) { +"use strict"; + + var models = require('point_of_sale.models'); + var screens = require('point_of_sale.screens'); + + //don't try to get an image if we know the product ain't one + var ProductListImageWidget = screens.ProductListWidget.include({ + get_product_image_url: function(product){ + if (product.has_image) + return this._super(product); + + return '/web/static/src/img/placeholder.png'; + } + }); + + var _super_posmodel = models.PosModel.prototype; + models.PosModel = models.PosModel.extend({ + initialize: function (session, attributes) { + var product_model = _.find(this.models, function(model){ return model.model === 'product.product'; }); + product_model.fields.push('has_image'); + + return _super_posmodel.initialize.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..06c99f73 --- /dev/null +++ b/pos_default_empty_image/view/view.xml @@ -0,0 +1,8 @@ + + + +