Browse Source

Merge pull request #47 from cellsnake/cellsnake-pos_category_button_with_image-1

[add]pos product category button with image
pull/35/merge
Sylvain LE GAL 9 years ago
parent
commit
8c95179261
  1. 19
      pos_remove_pos_category/product.py
  2. 8
      pos_remove_pos_category/static/src/js/pos_remove_pos_category.js
  3. 13
      pos_remove_pos_category/views/pos_category.xml

19
pos_remove_pos_category/product.py

@ -20,7 +20,7 @@
##############################################################################
import sys
from openerp import models, fields, api
from openerp import models, fields, api, tools
class ProductTemplate(models.Model):
@ -44,6 +44,11 @@ class ProductTemplate(models.Model):
class ProductCategory(models.Model):
_inherit = 'product.category'
image = fields.Binary(help='Show Image Category in Form View')
image_medium = fields.Binary(help='Show image category button in POS',
compute="_get_image",
inverse="_set_image",
store=True)
available_in_pos = fields.Boolean(
string="Available in the Point of Sale",
default=True,
@ -51,6 +56,17 @@ class ProductCategory(models.Model):
"If you uncheck, children categories will becomes invisible too, "
"whatever their checkbox state.")
@api.multi
def _get_image(self):
return dict(
(rec.id, tools.image_get_resized_images(rec.image)) for rec in
self)
@api.one
def _set_image(self):
return self.write(
{'image': tools.image_resize_image_big(self.image_medium)})
_auto_end_original = models.BaseModel._auto_end
@ -87,4 +103,5 @@ def _auto_end(self, cr, context=None):
self._foreign_keys = foreign_keys
return _auto_end_original(self, cr, context=context)
models.BaseModel._auto_end = _auto_end

8
pos_remove_pos_category/static/src/js/pos_remove_pos_category.js

@ -33,4 +33,12 @@ openerp.pos_remove_pos_category = function(instance, local) {
return initialize_original.call(this, session, attributes);
}
});
//override method js POS (widgets.js)
//change pos.category by product.category
module.ProductCategoriesWidget = module.ProductCategoriesWidget.extend({
get_image_url: function(category){
return window.location.origin + '/web/binary/image?model=product.category&field=image_medium&id='+category.id;
}
});
};

13
pos_remove_pos_category/views/pos_category.xml

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="pos_remove_pos_category assets" inherit_id="web.assets_backend">
<template id="assets_backend" name="pos_remove_pos_category assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_remove_pos_category/static/src/js/pos_remove_pos_category.js"></script>
</xpath>
@ -17,6 +17,14 @@
<xpath expr="//group[@name='parent']" position="inside">
<field name="available_in_pos"/>
</xpath>
<field name="name" position="after">
<div class="oe_bottom" style="margin-top: 10px;">
<field name="image_medium"
widget="image"
class="oe_left oe_avatar"
options='{"size": [100, 100]}'/>
</div>
</field>
</field>
</record>
@ -29,6 +37,5 @@
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save