[IMP] product: images modified accordign to new spec. Propagated changes to stock/product and point of sale, and also to demo data.

bzr revid: tde@openerp.com-20120628090133-zmdbmjeiajhtmo3m
This commit is contained in:
Thibault Delavallée
2012-06-28 11:01:33 +02:00
parent b89442e0de
commit 3650c035f5
7 changed files with 161 additions and 133 deletions
-18
View File
@@ -756,30 +756,12 @@ 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."),
'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()
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -106,7 +106,7 @@ openerp.point_of_sale = function(db) {
return self.set({'categories': result});
});
var prod_def = fetch('product.product', ['name', 'list_price', 'pos_categ_id', 'taxes_id',
'product_image_small'], [['pos_categ_id', '!=', 'false']]).then(function(result) {
'image_small'], [['pos_categ_id', '!=', 'false']]).then(function(result) {
return self.set({'product_list': result});
});
var bank_def = fetch('account.bank.statement', ['account_id', 'currency', 'journal_id', 'state', 'name'],
+1 -1
View File
@@ -181,7 +181,7 @@
<t t-name="pos-product-template">
<a href="#">
<div class="product-img">
<img t-att-src="'data:image/gif;base64,'+ product_image_small" />
<img t-att-src="'data:image/gif;base64,'+ image_small" />
<span class="price-tag">
<t t-esc="format_amount(list_price)"/>
</span>
+47 -1
View File
@@ -492,6 +492,33 @@ class product_product(osv.osv):
(data['name'] or '') + (data['variants'] and (' - '+data['variants']) or '')
return res
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = {'image_medium': False, 'image_small': False}
if obj.image:
result[obj.id]['image_medium'] = tools.resize_image_medium(obj.image)
result[obj.id]['image_small'] = tools.resize_image_small(obj.image)
return result
def _set_image(self, cr, uid, id, name, value, args, context=None):
if value:
value = tools.resize_image_big(value)
return self.write(cr, uid, [id], {'image': value}, context=context)
def onchange_image(self, cr, uid, ids, value, context=None):
if not value:
return {'value': {
'image': value,
'image_medium': value,
'image_small': value,
}}
return {'value': {
'image': tools.resize_image_big(value),
'image_medium': tools.resize_image_medium(value),
'image_small': tools.resize_image_small(value),
}}
_defaults = {
'active': lambda *a: 1,
'price_extra': lambda *a: 0.0,
@@ -525,7 +552,26 @@ class product_product(osv.osv):
'pricelist_id': fields.dummy(string='Pricelist', relation='product.pricelist', type='many2one'),
'name_template': fields.related('product_tmpl_id', 'name', string="Name", type='char', size=128, store=True, select=True),
'color': fields.integer('Color Index'),
'product_image': fields.binary('Image'),
'image': fields.binary("Image",
help="This field holds the image used for the "\
"product. The image is base64 encoded, and PIL-supported. "\
"It is limited to a 12024x1024 px image."),
'image_medium': fields.function(_get_image, fnct_inv=_set_image,
string="Medium-sized image", type="binary", multi="_get_image",
store = {
'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Medium-sized image of the product. It is automatically "\
"resized as a 180x180px image, with aspect ratio kept. "\
"Use this field in form views or some kanban views."),
'image_small': fields.function(_get_image, fnct_inv=_set_image,
string="Smal-sized image", type="binary", multi="_get_image",
store = {
'product.product': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Small-sized image of the product. It is automatically "\
"resized as a 50x50px image, with aspect ratio keps. "\
"Use this field anywhere a small image is required."),
}
def create(self, cr, uid, vals, context=None):
+3 -3
View File
@@ -68,7 +68,7 @@
<field name="arch" type="xml">
<form string="Product" layout="auto" version="7.0">
<sheet>
<field name="product_image" widget="image" class="oe_avatar oe_right" />
<field name="image_small" widget="image" class="oe_avatar oe_right" onchange="onchange_image(image_small"/>
<div class="oe_title">
<div class="oe_edit_only">
@@ -198,7 +198,7 @@
<kanban>
<field name="color"/>
<field name="type"/>
<field name="product_image"/>
<field name="image"/>
<field name="list_price"/>
<templates>
<t t-name="kanban-box">
@@ -209,7 +209,7 @@
<field name="name"/>
</div>
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_box_show_onclick_trigger">
<img t-att-src="kanban_image('product.product', 'product_image', record.id.value)" width="48" style="float: left; padding: 0 4px 4px 0"/>
<img t-att-src="kanban_image('product.product', 'image_medium', record.id.value)" width="48" style="float: left; padding: 0 4px 4px 0"/>
Code: <field name="code"/>
<div t-if="record.type.raw_value == 'service'">No Stock</div>
<t t-if="record.type.raw_value != 'service'">
+2 -2
View File
@@ -158,7 +158,7 @@
<kanban>
<field name="color"/>
<field name="type"/>
<field name="product_image"/>
<field name="image"/>
<field name="list_price"/>
<field name="reception_count"/>
<field name="delivery_count"/>
@@ -166,7 +166,7 @@
<t t-name="kanban-box">
<div class="oe_product_vignette">
<div class="oe_product_img">
<a type="edit"><img t-att-src="kanban_image('product.product', 'product_image', record.id.value)" class="oe_product_photo"/></a>
<a type="edit"><img t-att-src="kanban_image('product.product', 'image_medium', record.id.value)" class="oe_product_photo"/></a>
</div>
<div class="oe_product_desc">
<h4><a type="edit"><field name="name"></field></a></h4>