diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index c91b6213230..88ab9e399e6 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -23,6 +23,7 @@ import time from datetime import datetime from dateutil.relativedelta import relativedelta import logging +import Image import netsvc from osv import fields, osv @@ -739,13 +740,34 @@ class pos_category(osv.osv): } pos_category() +import io, StringIO + class product_product(osv.osv): _inherit = 'product.product' + def _get_small_image(self, cr, uid, ids, prop, unknow_none, context=None): + result = {} + for obj in self.browse(cr, uid, ids, context=context): + if not obj.product_image: + result[obj.id] = False + continue + + image_stream = io.BytesIO(obj.product_image.decode('base64')) + img = Image.open(image_stream) + img.thumbnail((120, 100), Image.ANTIALIAS) + img_stream = StringIO.StringIO() + img.save(img_stream, "JPEG") + result[obj.id] = img_stream.getvalue().encode('base64') + return result + _columns = { 'income_pdt': fields.boolean('PoS Cash Input', help="This is a product you can use to put cash into a statement for the point of sale backend."), 'expense_pdt': fields.boolean('PoS Cash Output', help="This is a product you can use to take cash from a statement for the point of sale backend, exemple: money lost, transfer to bank, etc."), 'pos_categ_id': fields.many2one('pos.category','PoS Category', - help="If you want to sell this product through the point of sale, select the category it belongs to.") + help="If you want to sell this product through the point of sale, select the category it belongs to."), + 'product_image_small': fields.function(_get_small_image, string='Small Image', type="binary", + store = { + 'product.product': (lambda self, cr, uid, ids, c={}: ids, ['product_image'], 10), + }) } product_product() diff --git a/addons/point_of_sale/static/src/js/pos.js b/addons/point_of_sale/static/src/js/pos.js index 1041a2a2f5b..56ba80d82fc 100644 --- a/addons/point_of_sale/static/src/js/pos.js +++ b/addons/point_of_sale/static/src/js/pos.js @@ -86,7 +86,7 @@ openerp.point_of_sale = function(db) { }, this)); }, this)); $.when(this.fetch('pos.category', ['name', 'parent_id', 'child_id']), - this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'product_image'], [['pos_categ_id', '!=', 'false']]), + this.fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id', 'product_image_small'], [['pos_categ_id', '!=', 'false']]), this.fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'], [['state', '=', 'open'], ['user_id', '=', this.session.uid]]), this.fetch('account.journal', ['auto_cash', 'check_dtls', 'currency', 'name', 'type']), diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index cd0dc6e4b74..d24d16713d8 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -181,7 +181,7 @@
- + @@ -291,4 +291,4 @@
- \ No newline at end of file +