diff --git a/addons/product/__openerp__.py b/addons/product/__openerp__.py
index fdadda2e4d4..ae0a737c8a6 100644
--- a/addons/product/__openerp__.py
+++ b/addons/product/__openerp__.py
@@ -64,6 +64,13 @@ Print product labels with barcode.
'test/product_uom.yml',
'test/product_pricelist.yml',
],
+ 'js': [
+ 'static/src/js/product.js',
+ ],
+ 'qweb' : [
+ "static/src/xml/product.xml",
+ ],
+
'installable': True,
'auto_install': False,
'images': ['images/product_uom.jpeg','images/product_pricelists.jpeg','images/products_categories.jpeg', 'images/products_form.jpeg'],
diff --git a/addons/product/product.py b/addons/product/product.py
index 418acf67af7..d7c95f84104 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -107,16 +107,6 @@ class product_uom(osv.osv):
del(data['factor_inv'])
return super(product_uom, self).create(cr, uid, data, context)
- def _reference_uom(self, cr, uid, ids, field, arg, context=None):
- res = {}
- for uom in self.browse(cr, uid, ids, context):
- uom_ids = []
- if uom.category_id and uom.category_id.id:
- uom_ids = self.search(cr, uid, [('category_id', '=', uom.category_id.id), ('uom_type', '=', 'reference')], context=context)
- if uom_ids:
- res[uom.id] = uom_ids[0]
- return res
-
_order = "name"
_columns = {
'name': fields.char('Unit of Measure', size=64, required=True, translate=True),
@@ -137,7 +127,6 @@ class product_uom(osv.osv):
'uom_type': fields.selection([('bigger','Bigger than the reference Unit of Measure'),
('reference','Reference Unit of Measure for this category'),
('smaller','Smaller than the reference Unit of Measure')],'Type', required=1),
- 'reference_uom_id': fields.function(_reference_uom, type='many2one', relation="product.uom"),
}
_defaults = {
@@ -150,14 +139,6 @@ class product_uom(osv.osv):
('factor_gt_zero', 'CHECK (factor!=0)', 'The conversion ratio for a unit of measure cannot be 0!')
]
- def onchange_category_id(self, cr, uid, ids, category_id):
- reference_uom = False
- if category_id:
- uom_ids = self.search(cr, uid, [('category_id', '=',category_id),('uom_type', '=', 'reference')])
- if uom_ids:
- reference_uom = uom_ids[0]
- return {'value':{'reference_uom_id': reference_uom}}
-
def _compute_qty(self, cr, uid, from_uom_id, qty, to_uom_id=False):
if not from_uom_id or not qty or not to_uom_id:
return qty
diff --git a/addons/product/product_view.xml b/addons/product/product_view.xml
index f3b5602114c..41a6360020d 100644
--- a/addons/product/product_view.xml
+++ b/addons/product/product_view.xml
@@ -424,22 +424,13 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+-
diff --git a/addons/product/static/src/js/product.js b/addons/product/static/src/js/product.js
new file mode 100644
index 00000000000..6cf2efe8da4
--- /dev/null
+++ b/addons/product/static/src/js/product.js
@@ -0,0 +1,46 @@
+openerp.product = function (instance) {
+instance.web.form.widgets.add('uom_factor', 'instance.web.form.FieldUOMFactor');
+instance.web.form.FieldUOMFactor = instance.web.form.FieldFloat.extend({
+ template: "FieldUOMFactor",
+ init: function() {
+ this._super.apply(this, arguments);
+ this.set({"category": false, 'name': false});
+ if (this.options.category_field) {
+ this.field_manager.on("field_changed:" + this.options.category_field, this, function() {
+ this.set({"category": this.field_manager.get_field_value(this.options.category_field)});
+ });
+ }
+ if (this.options.name_field) {
+ this.field_manager.on("field_changed:" + this.options.name_field, this, function() {
+ this.set({"name": this.field_manager.get_field_value(this.options.name_field)});
+ });
+ }
+ this.on("change:category", this, this.get_uom_reference);
+ this.get_uom_reference();
+ this.ci_dm = new instance.web.DropMisordered();
+ },
+ start: function() {
+ var tmp = this._super();
+ this.on("change:uom_reference", this, this.reinitialize);
+ this.on("change:name", this, this.reinitialize);
+ return tmp;
+ },
+ get_uom_reference: function() {
+ var self = this;
+ if (this.get("category") === false) {
+ this.set({"uom_reference": null});
+ return;
+ }
+ return this.ci_dm.add(new instance.web.Model("product.uom").query(["name"])
+ .filter([["category_id", "=", self.get("category")],["uom_type", "=", "reference"]]).first()).pipe(function(res) {
+ self.set({"uom_reference": res});
+ });
+ },
+ parse_value: function(val, def) {
+ return instance.web.parse_value(val, {type: "float"}, def);
+ },
+ format_value: function(val, def) {
+ return instance.web.format_value(val, {type: "float"}, def);
+ },
+});
+}
diff --git a/addons/product/static/src/xml/product.xml b/addons/product/static/src/xml/product.xml
new file mode 100644
index 00000000000..6eab4d9c899
--- /dev/null
+++ b/addons/product/static/src/xml/product.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+ 1 =
+
+
+
+
+
+
+
+