Harry (OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-uom-usability into lp:openobject-addons.
Requested reviews:
OpenERP Core Team (openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-uom-usability/+merge/129387
-> UoMFactor JS Widget to display UoM factor like "1 cm = 100 m" in UOM form.
Thanks
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-uom-usability/+merge/129387
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-uom-usability.
=== modified file 'product/__openerp__.py'
--- product/__openerp__.py 2012-09-26 12:16:27 +0000
+++ product/__openerp__.py 2012-10-12 10:54:20 +0000
@@ -64,6 +64,13 @@
'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'],
=== modified file 'product/product.py'
--- product/product.py 2012-10-04 10:03:06 +0000
+++ product/product.py 2012-10-12 10:54:20 +0000
@@ -106,27 +106,27 @@
data['factor'] = self._compute_factor_inv(data['factor_inv'])
del(data['factor_inv'])
return super(product_uom, self).create(cr, uid, data, context)
-
+
_order = "name"
_columns = {
- 'name': fields.char('Name', size=64, required=True, translate=True),
- 'category_id': fields.many2one('product.uom.categ', 'Unit of Measure Category', required=True, ondelete='cascade',
+ 'name': fields.char('Unit of Measure', size=64, required=True, translate=True),
+ 'category_id': fields.many2one('product.uom.categ', 'Category', required=True, ondelete='cascade',
help="Quantity conversions may happen automatically between Units of Measure in the same category, according to their respective ratios."),
- 'factor': fields.float('Ratio', required=True,digits=(12, 12),
+ 'factor': fields.float('Computation', required=True,digits=(12, 12),
help='How many times this Unit of Measure is smaller than the reference Unit of Measure in this category:\n'\
'1 * (reference unit) = ratio * (this unit)'),
'factor_inv': fields.function(_factor_inv, digits=(12,12),
fnct_inv=_factor_inv_write,
- string='Ratio',
+ string='Computation',
help='How many times this Unit of Measure is bigger than the reference Unit of Measure in this category:\n'\
'1 * (this unit) = ratio * (reference unit)', required=True),
- 'rounding': fields.float('Rounding Precision', digits_compute=dp.get_precision('Product Unit of Measure'), required=True,
+ 'rounding': fields.float('Rounding precision', digits_compute=dp.get_precision('Product Unit of Measure'), required=True,
help="The computed quantity will be a multiple of this value. "\
"Use 1.0 for a Unit of Measure that cannot be further split, such as a piece."),
'active': fields.boolean('Active', help="By unchecking the active field you can disable a unit of measure without deleting it."),
'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')],'Unit of Measure Type', required=1),
+ ('smaller','Smaller than the reference Unit of Measure')],'Type', required=1),
}
_defaults = {
=== modified file 'product/product_view.xml'
--- product/product_view.xml 2012-10-05 07:28:25 +0000
+++ product/product_view.xml 2012-10-12 10:54:20 +0000
@@ -412,7 +412,6 @@
<tree string="Units of Measure">
<field name="name"/>
<field name="category_id"/>
- <field name="factor"/>
</tree>
</field>
</record>
@@ -430,15 +429,9 @@
</group>
<group>
<field name="uom_type" on_change="onchange_type(uom_type)"/>
- <p attrs="{'invisible':[('uom_type','!=','smaller')]}" colspan="2">
- e.g: 1 * (reference unit) = ratio * (this unit)
- </p>
- <p attrs="{'invisible':[('uom_type','!=','bigger')]}" colspan="2">
- e.g: 1 * (this unit) = ratio * (reference unit)
- </p>
+ <field name="factor" attrs="{'invisible':[('uom_type','!=','smaller')]}" widget="uom_factor" options="{'category_field': 'category_id', 'name_field': 'name'}"/>
+- <field name="factor_inv" attrs="{'invisible':[('uom_type','!=','bigger')]}" widget="uom_factor" options="{'category_field': 'category_id', 'name_field': 'name'}"/>
<field name="rounding"/>
- <field name="factor" attrs="{'invisible':[('uom_type','!=','smaller')]}"/>
- <field name="factor_inv" attrs="{'invisible':[('uom_type','!=','bigger')]}"/>
</group>
</group>
</form>
=== added directory 'product/static'
=== added directory 'product/static/src'
=== added directory 'product/static/src/js'
=== added file 'product/static/src/js/product.js'
--- product/static/src/js/product.js 1970-01-01 00:00:00 +0000
+++ product/static/src/js/product.js 2012-10-12 10:54:20 +0000
@@ -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);
+ },
+});
+}
=== added directory 'product/static/src/xml'
=== added file 'product/static/src/xml/product.xml'
--- product/static/src/xml/product.xml 1970-01-01 00:00:00 +0000
+++ product/static/src/xml/product.xml 2012-10-12 10:54:20 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<templates id="template" xml:space="preserve">
+
+<t t-name="FieldUOMFactor" t-extend="FieldChar">
+ <t t-jquery="t:first" t-operation="before">
+ <t t-if="widget.get('uom_reference')">
+ 1 <t t-esc="widget.get('uom_reference').name"/> =
+ </t>
+ </t>
+ <t t-jquery="t:last" t-operation="after">
+ <t t-esc="widget.get('name')"/>
+ </t>
+</t>
+
+</templates>
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp