partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit 9e340a2196c0495ea923807c3e03dcc05b3c49cd
parent 1a374d786109fba727ff72c37248923bdeb88751
Author: Felicitus <felicitus@felicitus.org>
Date:   Fri, 13 Jul 2012 05:08:55 +0200

Allow users to enter the package price; automatically calculates the price per item (or vice versa). Fixes #186. Please note that this is a calculated value which never makes it into the database; instead, values are calculated based on item price and packaging unit. This might lead to rounding errors.

Diffstat:
Msrc/frontend/js/Components/Part/Editor/PartDistributorGrid.js | 38+++++++++++++++++++++++++++++++-------
Msrc/frontend/js/Models/PartDistributor.js | 9++++++---
Msrc/frontend/js/Models/PartManufacturer.js | 4++--
3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/src/frontend/js/Components/Part/Editor/PartDistributorGrid.js b/src/frontend/js/Components/Part/Editor/PartDistributorGrid.js @@ -14,8 +14,21 @@ Ext.define('PartKeepr.PartDistributorGrid', { }); - this.editing = Ext.create('Ext.grid.plugin.RowEditing', { - clicksToEdit : 1 + this.editing = Ext.create('Ext.grid.plugin.CellEditing', { + clicksToEdit : 1, + listeners: { + beforeedit: function (editor, e, eOpts) { + if (e.field == "packagePrice") { + e.record.set("packagePrice", e.record.get("price") * e.record.get("packagingUnit")); + } + }, + edit: function (editor, e, eOpts) { + if (e.field == "packagePrice" && e.record.get("packagingUnit")) { + e.record.set("price", e.value / e.record.get("packagingUnit")); + } + }, + scope: this + } }); this.plugins = [ this.editing ]; @@ -44,7 +57,7 @@ Ext.define('PartKeepr.PartDistributorGrid', { dataIndex : 'distributor_id', xtype : 'templatecolumn', tpl : '{distributor_name}', - flex : 0.3, + flex : 1, editor : { xtype : 'DistributorComboBox', allowBlank : true @@ -52,7 +65,7 @@ Ext.define('PartKeepr.PartDistributorGrid', { }, { header : i18n("Order Number"), dataIndex : 'orderNumber', - flex : 0.2, + flex : 1, editor : { xtype : 'textfield', allowBlank : true @@ -60,7 +73,7 @@ Ext.define('PartKeepr.PartDistributorGrid', { }, { header : i18n("Packaging Unit"), dataIndex : 'packagingUnit', - flex : 0.2, + flex : 1, editor : { xtype : 'numberfield', allowDecimals : false, @@ -70,7 +83,7 @@ Ext.define('PartKeepr.PartDistributorGrid', { }, { header : i18n("Price per Item"), dataIndex : 'price', - flex : 0.2, + flex : 1, renderer : function(val, p, rec) { return PartKeepr.getApplication().formatCurrency(val); }, @@ -79,9 +92,20 @@ Ext.define('PartKeepr.PartDistributorGrid', { allowBlank : false } }, { + header: i18n("Package Price"), + flex: 1, + dataIndex: 'packagePrice', + renderer : function(val, p, rec) { + return PartKeepr.getApplication().formatCurrency(rec.get("price") * rec.get("packagingUnit")); + }, + editor : { + xtype : 'CurrencyField', + allowBlank : true + } + },{ header : i18n("SKU"), dataIndex : 'sku', - flex : 0.1, + flex : 1, editor : { xtype : 'textfield', allowBlank : true diff --git a/src/frontend/js/Models/PartDistributor.js b/src/frontend/js/Models/PartDistributor.js @@ -9,9 +9,12 @@ Ext.define("PartKeepr.PartDistributor", { { name: 'price', type: 'float' }, { name: 'orderNumber', type: 'string' }, { name: 'packagingUnit', type: 'int'}, - { name: 'sku', type: 'string' } + { name: 'sku', type: 'string' }, + + // Virtual field for the packagePrice. + { name: 'packagePrice', type: 'float' } ], - belongsTo: { type: 'belongsTo', model: 'PartKeepr.Part', primaryKey: 'id', foreignKey: 'part_id'}, - belongsTo: { type: 'belongsTo', model: 'PartKeepr.Distributor', primaryKey: 'id', foreignKey: 'distributor_id'}, + belongsTo: [{ type: 'belongsTo', model: 'PartKeepr.Part', primaryKey: 'id', foreignKey: 'part_id'}, + { type: 'belongsTo', model: 'PartKeepr.Distributor', primaryKey: 'id', foreignKey: 'distributor_id'}], proxy: PartKeepr.getRESTProxy("PartDistributor") }); diff --git a/src/frontend/js/Models/PartManufacturer.js b/src/frontend/js/Models/PartManufacturer.js @@ -8,7 +8,7 @@ Ext.define("PartKeepr.PartManufacturer", { { name: 'manufacturer_name', type: 'string' }, { name: 'partNumber', type: 'string' } ], - belongsTo: { type: 'belongsTo', model: 'PartKeepr.Part', primaryKey: 'id', foreignKey: 'part_id'}, - belongsTo: { type: 'belongsTo', model: 'PartKeepr.Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'}, + belongsTo: [{ type: 'belongsTo', model: 'PartKeepr.Part', primaryKey: 'id', foreignKey: 'part_id'}, + { type: 'belongsTo', model: 'PartKeepr.Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'}], proxy: PartKeepr.getRESTProxy("PartManufacturer") });