fix: multiple issues

This commit is contained in:
Mihir Kandoi
2026-01-02 20:53:44 +05:30
parent 7308021aa8
commit 247cc1d53e

View File

@@ -135,11 +135,8 @@ class ReportData:
if value: if value:
key = (row.item_code, row.reference_name, value) key = (row.item_code, row.reference_name, value)
if self.doctype_name == "Batch": sabb_details = self.get_data_from_sabb(row)
sabb_details = self.get_qty_from_sabb(row) row.update(sabb_details)
row.update(sabb_details)
else:
row.qty = 1
if key not in source_data: if key not in source_data:
row["raw_materials"] = frappe._dict({}) row["raw_materials"] = frappe._dict({})
@@ -147,7 +144,7 @@ class ReportData:
return source_data return source_data
def get_qty_from_sabb(self, row): def get_data_from_sabb(self, row):
sabb = frappe.qb.DocType("Serial and Batch Bundle") sabb = frappe.qb.DocType("Serial and Batch Bundle")
sabb_entry = frappe.qb.DocType("Serial and Batch Entry") sabb_entry = frappe.qb.DocType("Serial and Batch Entry")
@@ -158,18 +155,22 @@ class ReportData:
.select( .select(
sabb_entry.qty, sabb_entry.qty,
sabb_entry.warehouse, sabb_entry.warehouse,
sabb_entry.posting_datetime,
) )
.where( .where(
(sabb_entry.batch_no == row.batch_no) (sabb.voucher_type == row.reference_doctype)
& (sabb.voucher_type == row.reference_doctype)
& (sabb.voucher_no == row.reference_name) & (sabb.voucher_no == row.reference_name)
& (sabb.is_cancelled == 0) & (sabb.is_cancelled == 0)
& (sabb_entry.docstatus == 1) & (sabb_entry.docstatus == 1)
) )
) )
results = query.run(as_dict=True) if row.batch_no:
query = query.where(sabb_entry.batch_no == row.batch_no)
else:
query = query.where(sabb_entry.serial_no == row.serial_no)
results = query.run(as_dict=True)
return results[0] if results else {} return results[0] if results else {}
def set_backward_data(self, sabb_data, qty=None): def set_backward_data(self, sabb_data, qty=None):
@@ -194,7 +195,7 @@ class ReportData:
details = inward_data[-1] details = inward_data[-1]
if details: if details:
details.update(self.get_qty_from_sabb(details)) details.update(self.get_data_from_sabb(details))
sabb_data.raw_materials[key] = details sabb_data.raw_materials[key] = details
if sabb_data.raw_materials.get(key): if sabb_data.raw_materials.get(key):
@@ -228,14 +229,12 @@ class ReportData:
query = query.select( query = query.select(
doctype.item.as_("item_code"), doctype.item.as_("item_code"),
doctype.name.as_("batch_no"), doctype.name.as_("batch_no"),
doctype.manufacturing_date.as_("posting_date"),
doctype.expiry_date.as_("batch_expiry_date"), doctype.expiry_date.as_("batch_expiry_date"),
) )
else: else:
query = query.select( query = query.select(
doctype.item_code, doctype.item_code,
doctype.name.as_("serial_no"), doctype.name.as_("serial_no"),
doctype.posting_date,
doctype.warranty_expiry_date, doctype.warranty_expiry_date,
doctype.amc_expiry_date, doctype.amc_expiry_date,
) )
@@ -331,7 +330,7 @@ class ReportData:
self.add_direct_outward_entry(row, sabb_data) self.add_direct_outward_entry(row, sabb_data)
def add_direct_outward_entry(self, row, batch_details): def add_direct_outward_entry(self, row, batch_details):
key = (row.item_code, row.reference_name) key = (row.item_code, row.reference_name, row.serial_no, row.batch_no)
if key not in batch_details: if key not in batch_details:
row["indent"] = 0 row["indent"] = 0
batch_details[key] = row batch_details[key] = row
@@ -390,10 +389,16 @@ class ReportData:
"batch_no": batch_no, "batch_no": batch_no,
"indent": 0, "indent": 0,
"warehouse": fg_item.warehouse, "warehouse": fg_item.warehouse,
"raw_materials": frappe._dict({(row.item_code, row.reference_name): row}), "raw_materials": frappe._dict(
{(row.item_code, row.reference_name, row.serial_no, row.batch_no): row}
),
} }
) )
batch_details[key] = fg_item batch_details[key] = fg_item
else:
batch_details[key].raw_materials[
(row.item_code, row.reference_name, row.serial_no, row.batch_no)
] = row
def get_finished_item_from_stock_entry(self, reference_name): def get_finished_item_from_stock_entry(self, reference_name):
return frappe.db.get_value( return frappe.db.get_value(
@@ -497,9 +502,9 @@ class ReportData:
"width": 120, "width": 120,
}, },
{ {
"fieldname": "posting_date", "fieldname": "posting_datetime",
"label": _("Posting Date"), "label": _("Posting Datetime"),
"fieldtype": "Date", "fieldtype": "Datetime",
"width": 120, "width": 120,
}, },
{ {