Bug 411 - SellInventory: did not handle the case when storage didn't have enough units for sell
Summary: SellInventory: did not handle the case when storage didn't have enough units ...
Status: RESOLVED FIXED
Alias: None
Product: Group 3
Classification: Unclassified
Component: Corporation Accounting System (show other bugs)
Version: unspecified
Hardware: PC Windows
: --- major
Assignee: Hsu To-Liang
URL:
Depends on:
Blocks:
 
Reported: 2020-11-15 20:01 HKT by Hsu To-Liang
Modified: 2020-11-23 20:48 HKT (History)
1 user (show)

See Also:


Attachments
Company: sellInventory() (11.53 KB, text/plain)
2020-11-15 20:01 HKT, Hsu To-Liang
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hsu To-Liang 2020-11-15 20:01:29 HKT
Created attachment 45 [details]
Company: sellInventory()

Consider the following case:
1. has 150 units in storage but tried to record a transaction that sold 180 units

Code:
Date tday=new Date();
Company lukecompany = new Company();
lukecompany.recordTransaction(new CompanyTransaction("id12334", tday, "Cash", "Accounts Payable", 1000.0, "Borrow from bank"));
lukecompany.purchaseInventory("12345", 3, 50, tday, "Cash");
lukecompany.purchaseInventory("12346", 5, 100, tday, "Cash");
lukecompany.sellInventory("12347-a","12347-b", 7, 180, tday, "Cash","FIFO");

Actual output:
(from printjournal())
----------------------------------------------------------------------------------------
ID         | DATE            | ACCOUNT NAME & DESCRIPTION     |      DEBIT |     CREDIT
----------------------------------------------------------------------------------------
id12334    | 2020-11-15      | Cash                           |     1000.0 |           
           |                 | Accounts Payable               |            |     1000.0
           |                 | (Borrow from bank)             |            |           
----------------------------------------------------------------------------------------
12345      | 2020-11-15      | Inventory                      |      150.0 |           
           |                 | Cash                           |            |      150.0
           |                 | (Purchase Inventory)           |            |           
----------------------------------------------------------------------------------------
12346      | 2020-11-15      | Inventory                      |      500.0 |           
           |                 | Cash                           |            |      500.0
           |                 | (Purchase Inventory)           |            |           
----------------------------------------------------------------------------------------
12347-a    | 2020-11-15      | Cash                           |     1260.0 |           
           |                 | Sales Revenue                  |            |     1260.0
           |                 | (Revenue from Goods sold)      |            |           
----------------------------------------------------------------------------------------
12347-b    | 2020-11-15      | Cost of Goods Sold             |      650.0 |           
           |                 | Inventory                      |            |      650.0
           |                 | (Cost of Goods sold)           |            |           
----------------------------------------------------------------------------------------

Expected output:
Should print error message when executing lukecompany.sellInventory("12347-a","12347-b", 7, 180, tday, "Cash","FIFO");
Comment 1 hsiangtai2-c 2020-11-23 20:48:49 HKT
Good catch, To-Liang! It was due to our program's previous lack of a storage checking mechanism. I have solved the bug by enabling the system to check if there are enough goods in storage to sell whenever the "Sell Inventory" method is triggered. Now, if the desired amount to sell exceeds the current available amount, the system will not allow any alteration to the inventory storage and will instead show an error message notifying the user of the shortage of goods to sell.