Browse Source

[FIX] set has_image on 'product.product' model

[IMP] make has_image stored
[REF] improve description and add screenshots
[REF] OCA convention
pull/263/merge
Sylvain LE GAL 8 years ago
parent
commit
69d1c847c1
  1. 58
      pos_default_empty_image/README.rst
  2. 2
      pos_default_empty_image/models/__init__.py
  3. 16
      pos_default_empty_image/models/product.py
  4. 18
      pos_default_empty_image/models/product_product.py
  5. BIN
      pos_default_empty_image/static/description/pos_display_default.png
  6. BIN
      pos_default_empty_image/static/description/pos_display_improved.png
  7. 25
      pos_default_empty_image/static/src/css/pos_default_empty_image.css
  8. 17
      pos_default_empty_image/static/src/js/db.js
  9. 13
      pos_default_empty_image/static/src/js/widgets.js
  10. 3
      pos_default_empty_image/views/templates.xml

58
pos_default_empty_image/README.rst

@ -6,59 +6,66 @@
POS Default Empty Image POS Default Empty Image
======================= =======================
In the point of sale, trying to load known inexistant images
is a waste of time.
This module extends the functionality of point of sale to make PoS load faster
and to improve products display.
Point Of Sale Load faster
-------------------------
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 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: don't have images, you are happy to save thousands of useless requests:
the POS load way faster. 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;" />
Improve products display
------------------------
The browser will trigger as many requests than there is different url.
By default, Odoo PoS display a useless generic image for products that doesn't
have images.
.. figure:: /pos_default_empty_image/static/description/pos_display_default.png
:width: 800 px
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.
With this module, the display of the product is changed, (Size of the name
is increased for better visibility);
.. figure:: /pos_default_empty_image/static/description/pos_display_improved.png
:width: 800 px
This module adds a field _has_image in product.template.
Technical information
=====================
If product has no image, the product image url is not sent to the POS
Each time the pos instantiate a product, it will add this code for each product
In the product list, the display of the product is changed,
(Size of the name is increased for better visibility);
.. code:: html
Indeed, if the product has an image, it will load normally.
<img src="'/web/binary/image?model=product.product&field=image_medium&id='+product.id;" />
This module is compatible with pos_product_template
The browser will trigger as many requests than there are different urls.
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.
Known issues
============
This module adds a field has_image in product.product model.
If product has no image, the product image url is not sent to the POS
Updates Updates
======= =======
* Feb 2016 : First version * Feb 2016 : First version
* Feb 2017 : migration to v10 and improvements for Display - taken from
this module `pos_improve_images from GRAP
<https://github.com/grap/odoo-addons-grap/tree/7.0/pos_improve_images>`_ for OpenERP 7.
* Feb 2017 : migration to v10 and improvements for Display
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pos/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/pos/issues/new?body=module:%20pos_default_empty_image%0Aversion:%200.1%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/pos/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits Credits
@ -69,6 +76,7 @@ Contributors
* Hparfr <https://github.com/hparfr> `Akretion <https://akretion.com>`_ * Hparfr <https://github.com/hparfr> `Akretion <https://akretion.com>`_
* Sylvain LE GAL <https://twitter.com/legalsylvain> * Sylvain LE GAL <https://twitter.com/legalsylvain>
* Invitu <https://github.com/invitu>
Maintainer Maintainer

2
pos_default_empty_image/models/__init__.py

@ -1 +1 @@
from . import product
from . import product_product

16
pos_default_empty_image/models/product.py

@ -1,16 +0,0 @@
# -*- coding: utf-8 -*-
# © <2015> <Akretion, GRAP, OCA>
# 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')

18
pos_default_empty_image/models/product_product.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © <2015> <Akretion, GRAP, OCA>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields, api
class ProductProduct(models.Model):
_inherit = 'product.product'
@api.multi
@api.depends('image')
def _compute_has_image(self):
for product in self:
product.has_image = product.image is not False
has_image = fields.Boolean(
compute='_compute_has_image', string='Has Image', store=True)

BIN
pos_default_empty_image/static/description/pos_display_default.png

After

Width: 845  |  Height: 138  |  Size: 51 KiB

BIN
pos_default_empty_image/static/description/pos_display_improved.png

After

Width: 844  |  Height: 138  |  Size: 54 KiB

25
pos_default_empty_image/static/src/css/pos_default_empty_image.css

@ -1,25 +1,8 @@
/******************************************************************************
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 <http://www.gnu.org/licenses/>.
******************************************************************************/
/* /*
New display for 'product-img' and 'product-name' where there isn't image;
Copyright (C) 2014 - Today: GRAP (http://www.grap.coop)
@author Julien WESTE
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/ */
.product-img-without-image{ .product-img-without-image{

17
pos_default_empty_image/static/src/js/db.js

@ -0,0 +1,17 @@
odoo.define('pos_default_empty_image.db', function (require) {
"use strict";
var models = require('point_of_sale.models');
var _super_posmodel = models.PosModel.prototype;
// load new field 'has_image' for 'product.product' model
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);
},
});
});

13
pos_default_empty_image/static/src/js/pos_default_empty_image.js → pos_default_empty_image/static/src/js/widgets.js

@ -1,7 +1,6 @@
odoo.define('pos_default_empty_image', function (require) {
odoo.define('pos_default_empty_image.widgets', function (require) {
"use strict"; "use strict";
var models = require('point_of_sale.models');
var screens = require('point_of_sale.screens'); var screens = require('point_of_sale.screens');
var core = require('web.core'); var core = require('web.core');
@ -38,14 +37,4 @@ odoo.define('pos_default_empty_image', function (require) {
} }
}, },
}); });
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);
},
});
}); });

3
pos_default_empty_image/views/templates.xml

@ -2,7 +2,8 @@
<odoo> <odoo>
<template id="assets_backend" name="pos_default_empty_image assets" inherit_id="point_of_sale.assets"> <template id="assets_backend" name="pos_default_empty_image assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/pos_default_empty_image.js"></script>
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/db.js"></script>
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/widgets.js"></script>
</xpath> </xpath>
<xpath expr="//link[@id='pos-stylesheet']" position="after"> <xpath expr="//link[@id='pos-stylesheet']" position="after">
<link rel="stylesheet" href="/pos_default_empty_image/static/src/css/pos_default_empty_image.css"/> <link rel="stylesheet" href="/pos_default_empty_image/static/src/css/pos_default_empty_image.css"/>

Loading…
Cancel
Save