Browse Source

[MIG] pos_default_empty_image: Migration to 12.0

pull/351/head
Cyril VINH-TUNG 6 years ago
committed by Sylvain LE GAL
parent
commit
49f7054385
  1. 5
      pos_default_empty_image/__manifest__.py
  2. 3
      pos_default_empty_image/models/product_product.py
  3. 17
      pos_default_empty_image/static/src/js/db.js
  4. 8
      pos_default_empty_image/static/src/js/models.js
  5. 7
      pos_default_empty_image/static/src/js/widgets.js
  6. 11
      pos_default_empty_image/static/src/xml/pos_default_empty_image.xml
  7. 2
      pos_default_empty_image/views/templates.xml

5
pos_default_empty_image/__manifest__.py

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

3
pos_default_empty_image/models/product_product.py

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

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

@ -1,17 +0,0 @@
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);
},
});
});

8
pos_default_empty_image/static/src/js/models.js

@ -0,0 +1,8 @@
odoo.define('pos_default_empty_image.db', function (require) {
"use strict";
var models = require('point_of_sale.models');
// load new field 'has_image' for 'product.product' model
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); return this._super(product);
} }
else { 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){ if(!cached){
var product_html = QWeb.render('ProductNoImage',{ var product_html = QWeb.render('ProductNoImage',{
widget: this, widget: this,
product: product, product: product,
pricelist: current_pricelist,
}); });
var product_node = document.createElement('div'); var product_node = document.createElement('div');
product_node.innerHTML = product_html; product_node.innerHTML = product_html;
product_node = product_node.childNodes[1]; 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 product_node;
} }
return cached; return cached;

11
pos_default_empty_image/static/src/xml/pos_default_empty_image.xml

@ -1,23 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve"> <templates id="template" xml:space="preserve">
<t t-name="ProductNoImage"> <t t-name="ProductNoImage">
<span class='product' t-att-data-product-id="product.id">
<article class='product' t-att-data-product-id="product.id" tabindex="0" t-attf-aria-labelledby="article_product_#{product.id}">
<div class="product-img-without-image"> <div class="product-img-without-image">
<t t-if="!product.to_weight"> <t t-if="!product.to_weight">
<span class="price-tag"> <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> </span>
</t> </t>
<t t-if="product.to_weight"> <t t-if="product.to_weight">
<span class="price-tag"> <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> </span>
</t> </t>
</div> </div>
<div class="product-name-without-image">
<div class="product-name-without-image" t-attf-id="article_product_#{product.id}">
<t t-esc="product.display_name"/> <t t-esc="product.display_name"/>
</div> </div>
</span>
</article>
</t> </t>
</templates> </templates>

2
pos_default_empty_image/views/templates.xml

@ -2,7 +2,7 @@
<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/db.js"></script>
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/models.js"></script>
<script type="text/javascript" src="/pos_default_empty_image/static/src/js/widgets.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">

Loading…
Cancel
Save