Browse Source

[PORT] pos_default_empty_image courtesy @invitu

pull/351/head
Sylvain LE GAL 7 years ago
parent
commit
c0fd62427b
  1. 1
      pos_default_empty_image/__init__.py
  2. 2
      pos_default_empty_image/__manifest__.py
  3. 16
      pos_default_empty_image/models/product.py
  4. 20
      pos_default_empty_image/product.py
  5. 50
      pos_default_empty_image/static/src/js/pos_default_empty_image.js
  6. 10
      pos_default_empty_image/view/view.xml
  7. 8
      pos_default_empty_image/views/view.xml

1
pos_default_empty_image/__init__.py

@ -0,0 +1 @@
from . import models

2
pos_default_empty_image/__openerp__.py → 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)",

16
pos_default_empty_image/models/product.py

@ -0,0 +1,16 @@
# -*- 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')

20
pos_default_empty_image/product.py

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

50
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);
},
});
});

10
pos_default_empty_image/view/view.xml

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="pos_default_empty_image assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/pos_default_empty_image.js"></script>
</xpath>
</template>
</data>
</openerp>

8
pos_default_empty_image/views/view.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" name="pos_default_empty_image assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/pos_default_empty_image.js"></script>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save