From 29dccd8e4188302638f70a48fcee708dad2169ab Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 17 Apr 2017 11:09:36 +0200 Subject: [PATCH] [IMP] pos_default_empty_image courtesy @invitu --- pos_default_empty_image/README.rst | 20 +++++----- pos_default_empty_image/__manifest__.py | 13 +++++-- pos_default_empty_image/models/__init__.py | 1 + .../src/css/pos_default_empty_image.css | 38 +++++++++++++++++++ .../static/src/js/pos_default_empty_image.js | 31 +++++++++++++-- .../src/xml/pos_default_empty_image.xml | 23 +++++++++++ .../views/{view.xml => templates.xml} | 3 ++ 7 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 pos_default_empty_image/models/__init__.py create mode 100644 pos_default_empty_image/static/src/css/pos_default_empty_image.css create mode 100644 pos_default_empty_image/static/src/xml/pos_default_empty_image.xml rename pos_default_empty_image/views/{view.xml => templates.xml} (64%) diff --git a/pos_default_empty_image/README.rst b/pos_default_empty_image/README.rst index abe091b5..77c13d62 100644 --- a/pos_default_empty_image/README.rst +++ b/pos_default_empty_image/README.rst @@ -29,15 +29,17 @@ 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. -Because there is only one url for this placeholder, -you will have only one request for all the products with no images. +If product has no image, the product image url is not sent to the POS +In the product list, the display of the product is changed, + (Size of the name is increased for better visibility); Indeed, if the product has an image, it will load normally. +This module is compatible with pos_product_template + Known issues ============ @@ -47,13 +49,16 @@ Updates ======= * Feb 2016 : First version +* Feb 2017 : migration to v10 and improvements for Display - taken from + this module `pos_improve_images from GRAP + `_ for OpenERP 7. Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 @@ -65,9 +70,6 @@ Contributors * Hparfr `Akretion `_ * Sylvain LE GAL -See also this module `pos_improve_images from GRAP -`_ for OpenERP 7. - Maintainer ---------- diff --git a/pos_default_empty_image/__manifest__.py b/pos_default_empty_image/__manifest__.py index 3f2d6771..e08c1364 100644 --- a/pos_default_empty_image/__manifest__.py +++ b/pos_default_empty_image/__manifest__.py @@ -9,7 +9,14 @@ 'author': "Akretion, GRAP, Odoo Community Association (OCA)", 'website': "https://akretion.com", 'license': 'AGPL-3', - 'depends': ['point_of_sale'], - 'data': ['view/view.xml'], - 'qweb': [], + 'depends': [ + 'point_of_sale', + ], + 'data': [ + 'views/templates.xml', + ], + 'qweb': [ + 'static/src/xml/pos_default_empty_image.xml', + ], + 'installable': True, } 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/static/src/css/pos_default_empty_image.css b/pos_default_empty_image/static/src/css/pos_default_empty_image.css new file mode 100644 index 00000000..3d88ab07 --- /dev/null +++ b/pos_default_empty_image/static/src/css/pos_default_empty_image.css @@ -0,0 +1,38 @@ +/****************************************************************************** + Point Of Sale - Improve Images module for OpenERP + Copyright (C) 2014 GRAP (http://www.grap.coop) + @author Julien WESTE + @author Sylvain LE GAL (https://twitter.com/legalsylvain) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +******************************************************************************/ + +/* + New display for 'product-img' and 'product-name' where there isn't image; +*/ + +.product-img-without-image{ + height:25px !important; +} + +.product-name-without-image{ + bottom:auto !important; + top:25px !important; + padding-top:3px !important; + height:80px !important; + font-size: 24px !important; + line-height: 20px; + text-align: center; + word-wrap: break-word; +} 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 index f73442ca..15abc508 100644 --- 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 @@ -1,17 +1,42 @@ odoo.define('pos_default_empty_image', function (require) { -"use strict"; + "use strict"; var models = require('point_of_sale.models'); var screens = require('point_of_sale.screens'); + var core = require('web.core'); + + var QWeb = core.qweb; + //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'; - } + // Change product display if product has no image; + render_product: function(product){ + if (product.has_image){ + return this._super(product); + } + else { + var cached = this.product_cache.get_node(product.id); + if(!cached){ + var image_url = this.get_product_image_url(product); + var product_html = QWeb.render('ProductNoImage',{ + widget: this, + product: product, + }); + var product_node = document.createElement('div'); + product_node.innerHTML = product_html; + product_node = product_node.childNodes[1]; + this.product_cache.cache_node(product.id,product_node); + return product_node; + } + return cached; + } + }, }); var _super_posmodel = models.PosModel.prototype; diff --git a/pos_default_empty_image/static/src/xml/pos_default_empty_image.xml b/pos_default_empty_image/static/src/xml/pos_default_empty_image.xml new file mode 100644 index 00000000..46060953 --- /dev/null +++ b/pos_default_empty_image/static/src/xml/pos_default_empty_image.xml @@ -0,0 +1,23 @@ + + + + +
+ + + + + + + + + + +
+
+ +
+
+
+
+ diff --git a/pos_default_empty_image/views/view.xml b/pos_default_empty_image/views/templates.xml similarity index 64% rename from pos_default_empty_image/views/view.xml rename to pos_default_empty_image/views/templates.xml index 06c99f73..ce1ee79f 100644 --- a/pos_default_empty_image/views/view.xml +++ b/pos_default_empty_image/views/templates.xml @@ -4,5 +4,8 @@ + + +