Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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.
  • Loading branch information...
commit 9e340a2196c0495ea923807c3e03dcc05b3c49cd 1 parent 1a374d7
@felicitus felicitus authored
View
38 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
View
9 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")
});
View
4 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")
});
Please sign in to comment.
Something went wrong with that request. Please try again.