Skip to content

Commit

Permalink
Merge pull request #58 from navariltd/develop13
Browse files Browse the repository at this point in the history
Get exact batch from serial bundle on stock ledger-redirect to exact …
  • Loading branch information
maniamartial authored Jun 6, 2024
2 parents 7d3ee89 + 72c134d commit b325fb2
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions burundi_compliance/burundi_compliance/data/stock_ledger_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def get_stock_recon_movement_type(stock_ledger_entry_doc,doc, item_code):
'''
Get the movement type for stock reconciliation
'''
has_batch=check_if_item_has_batches(item_code)
warehouse=stock_ledger_entry_doc.warehouse
if doc.purpose == "Opening Stock":
for item in doc.items:
Expand All @@ -174,16 +175,25 @@ def get_stock_recon_movement_type(stock_ledger_entry_doc,doc, item_code):
else:
movement_type="SAU"

elif doc.purpose=="Stock Reconciliation":
elif doc.purpose == "Stock Reconciliation":
for item in doc.items:
if item.item_code==item_code and item.warehouse==warehouse:
quantity_difference=item.quantity_difference
if stock_ledger_entry_doc.is_cancelled==0:
item_batch = None
if has_batch:
item_batch = get_specified_batch(stock_ledger_entry_doc)

# Check if item matches the criteria
if (item.item_code == item_code and item.warehouse == warehouse and
(not has_batch or item.batch_no == item_batch)):

quantity_difference = item.quantity_difference
is_cancelled = stock_ledger_entry_doc.is_cancelled

if is_cancelled == 0:
if float(quantity_difference) > 0.0:
movement_type = "EAJ"
elif float(quantity_difference) < 0.0:
movement_type = "SAJ"
elif stock_ledger_entry_doc.is_cancelled==1:
elif is_cancelled == 1:
if float(quantity_difference) > 0.0:
movement_type = "SAJ"
elif float(quantity_difference) < 0.0:
Expand Down Expand Up @@ -291,4 +301,29 @@ def create_item_designation(specified_doc, item_code):
if item.batch_no:
return item.item_code + " - "+item.batch_no
else:
return item.item_code
return item.item_code

def get_specified_batch(specified_doc):
# Get the serial and batch bundle linked to the specified document
serial_and_batch = specified_doc.serial_and_batch_bundle

# Fetch the Serial and Batch Bundle document
serial_and_batch_doc = frappe.get_doc("Serial and Batch Bundle", serial_and_batch)

# Get the list of entries (batches) from the Serial and Batch Bundle document
batches = serial_and_batch_doc.entries

# Pick the first entry's batch number
if batches:
first_batch_no = batches[0].batch_no
return first_batch_no
else:
frappe.throw("No batches found in the specified Serial and Batch Bundle.")


def check_if_item_has_batches(item_code):
'''
Check if the item has batches
'''
item_doc=frappe.get_doc("Item", item_code)
return item_doc.has_batch_no

0 comments on commit b325fb2

Please sign in to comment.