Browse Source

[MIG] pos_default_empty_image: Migration to 11.0

pull/352/head
Cyril Vinh-Tung 5 years ago
parent
commit
5101dbeed9
  1. 5
      pos_default_empty_image/__manifest__.py
  2. 3
      pos_default_empty_image/models/product_product.py
  3. 11
      pos_default_empty_image/static/src/js/db.js
  4. 7
      pos_default_empty_image/static/src/js/widgets.js
  5. 5
      pos_default_empty_image/static/src/xml/pos_default_empty_image.xml

5
pos_default_empty_image/__manifest__.py

@ -1,13 +1,12 @@
# -*- coding: utf-8 -*-
# © 2015 Akretion, GRAP, OCA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'POS Default empty image',
'version': '10.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Point Of Sale',
'summary': 'Optimize loading time for products without image',
'author': "Akretion, GRAP, Odoo Community Association (OCA)",
'website': "https://akretion.com",
'website': "https://www.github.com/OCA/pos",
'license': 'AGPL-3',
'depends': [
'point_of_sale',

3
pos_default_empty_image/models/product_product.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2017 - Today:
# GRAP (http://www.grap.coop)
# Akretion (http://www.akretion.com)
@ -15,7 +14,7 @@ class ProductProduct(models.Model):
@api.depends('image')
def _compute_has_image(self):
for product in self:
product.has_image = product.image is not False
product.has_image = product.image
has_image = fields.Boolean(
compute='_compute_has_image', string='Has Image', store=True)

11
pos_default_empty_image/static/src/js/db.js

@ -3,15 +3,6 @@ odoo.define('pos_default_empty_image.db', function (require) {
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);
},
});
models.load_fields("product.product", ['has_image']);
});

7
pos_default_empty_image/static/src/js/widgets.js

@ -20,16 +20,19 @@ odoo.define('pos_default_empty_image.widgets', function (require) {
return this._super(product);
}
else {
var cached = this.product_cache.get_node(product.id);
var current_pricelist = this._get_active_pricelist();
var cache_key = this.calculate_cache_key(product, current_pricelist);
var cached = this.product_cache.get_node(cache_key);
if(!cached){
var product_html = QWeb.render('ProductNoImage',{
widget: this,
product: product,
pricelist: current_pricelist,
});
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);
this.product_cache.cache_node(cache_key,product_node);
return product_node;
}
return cached;

5
pos_default_empty_image/static/src/xml/pos_default_empty_image.xml

@ -5,12 +5,12 @@
<div class="product-img-without-image">
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.price,'Product Price')"/>
<t t-esc="widget.format_currency(product.get_price(pricelist, 1),'Product Price')"/>
</span>
</t>
<t t-if="product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.price,'Product Price')+'/'+widget.pos.units_by_id[product.uom_id[0]].name"/>
<t t-esc="widget.format_currency(product.get_price(pricelist, 1),'Product Price')+'/'+widget.pos.units_by_id[product.uom_id[0]].name"/>
</span>
</t>
</div>
@ -20,4 +20,3 @@
</span>
</t>
</templates>
Loading…
Cancel
Save