Conversion Logic and Discount on Inventory for Seed Distribution (grams vs ct)
Good morning, @mobreza
To implement an improvement in the discount system using the fields inventoty.quantity_on_hand, inventoty.hundred_sees_weight, inventoty.distribution_default_quantity and inventoty.distribution_unit_code. This allows for explicitly managing the quantity to be deducted from inventory at the time of a distribution order, especially when the inventory is stored in different units (grams vs ct).
Direct Discount:
If inventory.quantity_on_hand_unit_code is equal to inventory.distribution_unit_code, the discount is applied directly, just as the system has always handled it. In this case, no unit conversion is required, since both the inventory and distribution share the same unit of measure.
Converted discount:
1. Calculate the weight per unit (ct):
We use the same principle: hundred_seed_weight is the weight in grams of 100 units.
- Weight per unit (grams/ct) =
hundred_seed_weight/ 100
2. Calculate the total weight to be deducted:
Multiply the number of units in the order by the weight of each unit.
-
weight_to_be_deducted (grams) =
inventoty.distribution_default_quantity* (hundred_seed_weight/ 100)
3. Update inventory:
Subtract the total weight of the stock in grams.
-
inventory.quantity_on_hand=inventory.quantity_on_hand- weight_to_be_deducted
Practical Example with Seeds
| id | inventoty_number | quantity_on_hand | quantity_on_hand_unit | hundred_weight | distribution_default_quantity | distribution_unit_code |
|---|---|---|---|---|---|---|
| 123 | COLOO3GRP2IDT2025 1 SD | 10000 | grams | 150.0 | 80 | ct |
This means:
- You have 10,000 grams of seeds.
- 100 seeds (ct) weigh 150 grams.
- You distribute 80 per unit (ct).
Step-by-step calculation:
- Inventory: “Forages Seeds” (ID 123). Stock is in grams.
- Quantity distribute: 80 ct.
- Calculate weight per seed:
-
weight_per_unit =
inventory.hundred_seed_weight/ 100 = 150.0 / 100 = 1.5 grams per seed.
- Calculate total weight to be deducted:
-
weight_to_deduct =
inventory.distribution_default_quantity* weight_per_unit = 200 * 1.5 = 300 grams.
- Update the inventory:
-
inventoty.quantity_on_hand=inventoty.quantity_on_hand- weight_to_discount = 9700 grams.
Result: The inventory table will now show inventoty.quantity_on_hand = 9700 for inventory 123.
Note: The idea is that this operation will be executed once the inventory has been shipped, and that for now it will only apply to inventories that use grams and ct as units of measurement, as these are the most common in germplasm banks.
This approach allows for controlled implementation focused on the most frequent use cases. Later, as its operation is validated, the logic can be extended to include other units of measurement used in banks, thus ensuring greater coverage of the system without compromising its initial stability.
Best Regards: JamesArias