Skip to content

Commit

Permalink
fix(inventory): remove avg_consumption column
Browse files Browse the repository at this point in the history
This commit removes the avg_consumption column in the inventory table
since it does not play a role anymore. Additionally, it unifies the
inventory databases to using the same test/data/inventories.sql file.

Closes Third-Culture-Software#5144.
  • Loading branch information
jniles committed Feb 9, 2021
1 parent f2d92ac commit ff0ba53
Show file tree
Hide file tree
Showing 8 changed files with 2,351 additions and 5,183 deletions.
2 changes: 1 addition & 1 deletion server/controllers/inventory/inventory/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function getItemsMetadataById(uid) {
it.text AS type, ig.name AS groupName, BUID(ig.uuid) AS group_uuid,
ig.unique_item, i.consumable, i.locked, i.stock_min, i.sellable,
i.stock_max, i.created_at AS timestamp, i.type_id, i.unit_id, i.unit_weight, i.unit_volume,
ig.sales_account, i.default_quantity, i.avg_consumption, i.delay, i.purchase_interval,
ig.sales_account, i.default_quantity, i.delay, i.purchase_interval,
i.last_purchase, i.num_purchase, ig.tracking_consumption, ig.tracking_expiration,
i.importance
FROM inventory AS i JOIN inventory_type AS it
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async function getLotsDepot(depotUuid, params, finalClause) {
DATEDIFF(l.expiration_date, CURRENT_DATE()) AS lifetime,
BUID(l.inventory_uuid) AS inventory_uuid, BUID(l.origin_uuid) AS origin_uuid,
i.code, i.text, BUID(m.depot_uuid) AS depot_uuid,
m.date AS entry_date, i.avg_consumption, i.purchase_interval, i.delay,
m.date AS entry_date, i.purchase_interval, i.delay,
iu.text AS unit_type,
ig.name AS group_name, ig.tracking_expiration, ig.tracking_consumption,
dm.text AS documentReference, t.name AS tag_name, t.color
Expand Down Expand Up @@ -649,7 +649,7 @@ async function getInventoryQuantityAndConsumption(params) {
DATEDIFF(l.expiration_date, CURRENT_DATE()) AS lifetime,
BUID(l.inventory_uuid) AS inventory_uuid, BUID(l.origin_uuid) AS origin_uuid,
l.entry_date, BUID(i.uuid) AS inventory_uuid, i.code, i.text, BUID(m.depot_uuid) AS depot_uuid,
i.avg_consumption, i.purchase_interval, i.delay, MAX(m.created_at) AS last_movement_date,
i.purchase_interval, i.delay, MAX(m.created_at) AS last_movement_date,
iu.text AS unit_type, ig.tracking_consumption, ig.tracking_expiration,
BUID(ig.uuid) AS group_uuid, ig.name AS group_name,
dm.text AS documentReference, d.enterprise_id
Expand Down Expand Up @@ -828,7 +828,7 @@ function getInventoryMovements(params) {
m.quantity, m.is_exit, m.date,
BUID(l.inventory_uuid) AS inventory_uuid, BUID(l.origin_uuid) AS origin_uuid,
l.entry_date, i.code, i.text, BUID(m.depot_uuid) AS depot_uuid,
i.avg_consumption, i.purchase_interval, i.delay, iu.text AS unit_type,
i.purchase_interval, i.delay, iu.text AS unit_type,
dm.text AS documentReference, flux.label as flux
FROM stock_movement m
JOIN lot l ON l.uuid = m.lot_uuid
Expand Down
10 changes: 9 additions & 1 deletion server/models/migrations/next/migrate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,12 @@ CALL add_column_if_missing('depot', 'dhis2_uid', 'VARCHAR(150) DEFAULT NULL AFTE
* @subject : Add nav entry for 'Find Duplicate Lots' page
*/
INSERT INTO unit VALUES
(293, 'Duplicate Lots','TREE.DUPLICATE_LOTS','The stock lots duplicates list',160,'/stock/lots/duplicates');
(293, 'Duplicate Lots','TREE.DUPLICATE_LOTS','The stock lots duplicates list',160,'/stock/lots/duplicates');

/*
* @author: jniles
* @date: 2021-02-04
* @subject: drop average_consumption column
* @issue:
*/
CALL drop_column_if_exists('inventory', 'avg_consumption');
5 changes: 0 additions & 5 deletions server/models/procedures/stock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@ BEGIN
/* continue only if inventoryUuid is defined */
IF (inventoryUuid IS NOT NULL) THEN

/* update the consumption (avg_consumption) */
IF (inventoryCmm IS NOT NULL OR inventoryCmm <> '' OR inventoryCmm <> 'NULL') THEN
UPDATE inventory SET avg_consumption = inventoryCmm WHERE `uuid` = inventoryUuid;
END IF;

/*
=======================================================================
check if the lot exists in the depot
Expand Down
1 change: 0 additions & 1 deletion server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,6 @@ CREATE TABLE `inventory` (
`note` text NULL,
`locked` TINYINT(1) NOT NULL DEFAULT 0,
`delay` DECIMAL(10,4) UNSIGNED NOT NULL DEFAULT 1 COMMENT 'Delivery time',
`avg_consumption` DECIMAL(10,4) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Average consumption' ,
`purchase_interval` DECIMAL(10,4) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Purchase Order Interval' ,
`last_purchase` DATE NULL COMMENT 'This element allows to store the date of the last purchase order of the product in order to allow the calculation without making much of the average ordering INTerval',
`num_purchase` INT(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'Number of purchase orders' ,
Expand Down
2,372 changes: 3 additions & 2,369 deletions test/data.sql

Large diffs are not rendered by default.

5,135 changes: 2,333 additions & 2,802 deletions test/data/inventories.sql

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion test/data/service-stock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ END $$

DELIMITER ;

INSERT INTO `lot` (`uuid`, `label`, `initial_quantity`, `quantity`, `unit_cost`, `description`, `expiration_date`, `inventory_uuid`, `origin_uuid`, `delay`, `entry_date`, `is_assigned`) VALUES (0x3CAA76C5748041F5A55600D48B770B9D,'QUININE-C-XXX',100,100,9.4000,NULL,@expiration_date,0x6D93ED88393211EBA0B954E1AD7439C7,0x9EE84A161CF5491A9B5EC06A5BBCBC5D,0,@one_year_ago,0),
INSERT INTO `lot` (`uuid`, `label`, `initial_quantity`, `quantity`, `unit_cost`, `description`, `expiration_date`, `inventory_uuid`, `origin_uuid`, `delay`, `entry_date`, `is_assigned`) VALUES
(0x3CAA76C5748041F5A55600D48B770B9D,'QUININE-C-XXX',100,100,9.4000,NULL,@expiration_date,0x6D93ED88393211EBA0B954E1AD7439C7,0x9EE84A161CF5491A9B5EC06A5BBCBC5D,0,@one_year_ago,0),
(0x6AA623AAA6EF4ECAB811E398D37C110D,'AMP-C-ZZZ',60,60,3.1800,NULL,'2021-12-30',0x6D920858393211EBA0B954E1AD7439C7,0x9EE84A161CF5491A9B5EC06A5BBCBC5D,0,@one_year_ago,0),
(0x6E8A11992E8641758727F73A3648A1B8,'AMP-A-ZZZ',120,120,3.1800,NULL,@expiration_date,0x6D920858393211EBA0B954E1AD7439C7,0x9EE84A161CF5491A9B5EC06A5BBCBC5D,0,@one_year_ago,0),
(0x8E8D1F39D57348689800EB8EA707E813,'OXY-A-YYYY',10000,10000,7.0600,NULL,@expiration_date,0x6D93A100393211EBA0B954E1AD7439C7,0x9EE84A161CF5491A9B5EC06A5BBCBC5D,0,@one_year_ago,0),
Expand Down

0 comments on commit ff0ba53

Please sign in to comment.