Bug 411

Summary: SellInventory: did not handle the case when storage didn't have enough units for sell
Product: Group 3 Reporter: Hsu To-Liang <tlhsu2-c>
Component: Corporation Accounting SystemAssignee: Hsu To-Liang <tlhsu2-c>
Status: RESOLVED FIXED    
Severity: major CC: hsiangtai2-c
Priority: ---    
Version: unspecified   
Hardware: PC   
OS: Windows   
Attachments: Company: sellInventory()

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.