Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions beam/beam/doctype/beam_settings/beam_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"field_order": [
"company",
"enable_handling_units",
"always_generate_for_transfer",
"barcode_font_size"
],
"fields": [
Expand All @@ -33,11 +34,18 @@
"fieldname": "barcode_font_size",
"fieldtype": "Int",
"label": "Barcode Font Size"
},
{
"default": "1",
"description": "Stock movements of complete Handling Units will keep the same number when unchecked.",
"fieldname": "always_generate_for_transfer",
"fieldtype": "Check",
"label": "Always Generate for Transfer"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-05-29 01:43:57.177980",
"modified": "2024-07-15 18:53:08.101936",
"modified_by": "Administrator",
"module": "BEAM",
"name": "BEAM Settings",
Expand Down Expand Up @@ -73,4 +81,4 @@
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
}
9 changes: 6 additions & 3 deletions beam/beam/handling_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ def generate_handling_units(doc, method=None):
in ("Material Transfer", "Send to Subcontractor", "Material Transfer for Manufacture")
and row.handling_unit
):
handling_unit = frappe.new_doc("Handling Unit")
handling_unit.save()
row.to_handling_unit = handling_unit.name
if not settings.always_generate_for_transfer and row.qty == get_handling_unit(row.handling_unit).qty:
row.to_handling_unit = row.handling_unit
else:
handling_unit = frappe.new_doc("Handling Unit")
handling_unit.save()
row.to_handling_unit = handling_unit.name
continue

if doc.doctype == "Subcontracting Receipt" and not row.handling_unit:
Expand Down
45 changes: 27 additions & 18 deletions beam/beam/scan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,34 @@ def get_barcode_context(barcode: str) -> Union[frappe._dict, None]:


def get_handling_unit(handling_unit: str, parent_doctype: Optional[str] = None) -> frappe._dict:
sl_entries = frappe.get_all(
"Stock Ledger Entry",
filters={"handling_unit": handling_unit, "is_cancelled": 0},
fields=[
"item_code",
"SUM(actual_qty) AS stock_qty",
"handling_unit",
"voucher_no",
"posting_date",
"posting_time",
"stock_uom",
"voucher_type",
"voucher_detail_no",
"warehouse",
],
group_by="handling_unit",
order_by="posting_date DESC",
limit=1,
from frappe.query_builder import DocType
from frappe.query_builder.functions import Sum

SLE = DocType("Stock Ledger Entry")

query = (
frappe.qb.from_(SLE)
.select(
SLE.item_code,
Sum(SLE.actual_qty).as_("stock_qty"),
SLE.handling_unit,
SLE.voucher_no,
SLE.posting_date,
SLE.posting_time,
SLE.stock_uom,
SLE.voucher_type,
SLE.voucher_detail_no,
SLE.warehouse
)
.where(
(SLE.handling_unit == handling_unit) &
(SLE.is_cancelled == 0)
)
.groupby(SLE.warehouse)
.orderby(SLE.creation, order=frappe.qb.desc)
.limit(1)
)
sl_entries = query.run(as_dict=True)
if len(sl_entries) == 1:
sle = sl_entries[0]
else:
Expand Down
Loading