diff --git a/pos_default_empty_image/__init__.py b/pos_default_empty_image/__init__.py index e69de29b..0650744f 100644 --- a/pos_default_empty_image/__init__.py +++ b/pos_default_empty_image/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_default_empty_image/__openerp__.py b/pos_default_empty_image/__manifest__.py similarity index 94% rename from pos_default_empty_image/__openerp__.py rename to pos_default_empty_image/__manifest__.py index b0fa5408..3f2d6771 100644 --- a/pos_default_empty_image/__openerp__.py +++ b/pos_default_empty_image/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'POS Default empty image', - 'version': '8.0.0.1.0', + '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)", 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/product.py b/pos_default_empty_image/product.py deleted file mode 100644 index 44c1d09c..00000000 --- a/pos_default_empty_image/product.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- 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'] - - @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 index 10d65a9f..f73442ca 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,34 +1,26 @@ -'use strict'; +odoo.define('pos_default_empty_image', function (require) { +"use strict"; -openerp.pos_default_empty_image = function (instance) { - var module = instance.point_of_sale; - var _t = instance.web._t; + 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 - module.ProductListWidget = module.ProductListWidget.extend({ - get_product_image_url: function(product){ - if (product.has_image) - return this._super(product); + //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'; - } - }); + 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; + 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'); - //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); - }; -}; + 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 deleted file mode 100644 index b3de3a4b..00000000 --- a/pos_default_empty_image/view/view.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/pos_default_empty_image/views/view.xml b/pos_default_empty_image/views/view.xml new file mode 100644 index 00000000..06c99f73 --- /dev/null +++ b/pos_default_empty_image/views/view.xml @@ -0,0 +1,8 @@ + + + +