Skip to content

Commit

Permalink
fix: set project in GL from the SLE (#44879)
Browse files Browse the repository at this point in the history
(cherry picked from commit 021d077)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Dec 24, 2024
1 parent b48f46e commit eed8784
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def get_gl_entries(self, warehouse_account=None, default_expense_account=None, d
"account": warehouse_account[sle.warehouse]["account"],
"against": expense_account,
"cost_center": item_row.cost_center,
"project": item_row.project or self.get("project"),
"project": sle.get("project") or item_row.project or self.get("project"),
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": flt(sle.stock_value_difference, precision),
"is_opening": item_row.get("is_opening")
Expand All @@ -550,7 +550,9 @@ def get_gl_entries(self, warehouse_account=None, default_expense_account=None, d
"cost_center": item_row.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": -1 * flt(sle.stock_value_difference, precision),
"project": item_row.get("project") or self.get("project"),
"project": sle.get("project")
or item_row.get("project")
or self.get("project"),
"is_opening": item_row.get("is_opening")
or self.get("is_opening")
or "No",
Expand Down Expand Up @@ -678,23 +680,34 @@ def get_items_and_warehouses(self) -> tuple[list[str], list[str]]:

def get_stock_ledger_details(self):
stock_ledger = {}
stock_ledger_entries = frappe.db.sql(
"""
select
name, warehouse, stock_value_difference, valuation_rate,
voucher_detail_no, item_code, posting_date, posting_time,
actual_qty, qty_after_transaction
from
`tabStock Ledger Entry`
where
voucher_type=%s and voucher_no=%s and is_cancelled = 0
""",
(self.doctype, self.name),
as_dict=True,
)

table = frappe.qb.DocType("Stock Ledger Entry")

stock_ledger_entries = (
frappe.qb.from_(table)
.select(
table.name,
table.warehouse,
table.stock_value_difference,
table.valuation_rate,
table.voucher_detail_no,
table.item_code,
table.posting_date,
table.posting_time,
table.actual_qty,
table.qty_after_transaction,
table.project,
)
.where(
(table.voucher_type == self.doctype)
& (table.voucher_no == self.name)
& (table.is_cancelled == 0)
)
).run(as_dict=True)

for sle in stock_ledger_entries:
stock_ledger.setdefault(sle.voucher_detail_no, []).append(sle)

return stock_ledger

def check_expense_account(self, item):
Expand Down

0 comments on commit eed8784

Please sign in to comment.