Skip to content

Commit

Permalink
feat: decrement inventory operation added
Browse files Browse the repository at this point in the history
Support for this operation in Omni will make it easier to control double buying.
  • Loading branch information
joamag committed Apr 21, 2023
1 parent 6fcdd8f commit 899e8de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

*
* Support for auto-decrement of stock on payment of `Order` using the `inventory_decremented` flag

### Changed

Expand Down
23 changes: 23 additions & 0 deletions src/budy/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ class Order(bundle.Bundle):
redeeming of the vouchers associated with the current order"""
)

inventory_decremented = appier.field(
type = bool,
observations = """Controls if the inventory stock levels
have been decrement according to current order's lines"""
)

lines = appier.field(
type = appier.references(
"OrderLine",
Expand Down Expand Up @@ -962,6 +968,7 @@ def mark_paid_s(self):
self.paid = True
self.date = time.time()
self.set_reference_f_s()
self.decrement_inventory_s()
self.save()

@appier.operation(name = "Unmark Paid")
Expand Down Expand Up @@ -1061,6 +1068,22 @@ def fix_closed_s(self):
if not self.is_closed(): return
self.close_lines_s()

@appier.operation(
name = "Decrement Inventory",
description = """Decrements the inventory stock levels
according to order lines""",
parameters = (("Force", "force", bool, False),),
level = 2
)
def decrement_inventory_s(self, force = False):
if self.inventory_decremented and not force: return
for line in self.lines:
line.merchandise.quantity_hand =\
max(line.merchandise.quantity_hand - line.quantity, 0)
line.merchandise.save()
self.inventory_decremented = True
self.save()

@appier.operation(
name = "Import Omni",
parameters = (
Expand Down

0 comments on commit 899e8de

Please sign in to comment.