refactor(gl): move make_discount_gl_entries onto SalesInvoiceGLComposer

It is Sales-Invoice-specific GL assembly and was the only TaxService
method called by the composer. Move it to SalesInvoiceGLComposer (verbatim),
call it as self.make_discount_gl_entries, drop the now-unused composer-level
TaxService local and the orphaned get_account_currency import in taxes.py.
This commit is contained in:
Nabin Hait
2026-06-03 13:00:50 +05:30
parent cfed16ab6c
commit e0c285e27e
2 changed files with 76 additions and 78 deletions

View File

@@ -24,7 +24,6 @@ class SalesInvoiceGLComposer(BaseGLComposer):
from erpnext.accounts.general_ledger import merge_similar_entries
doc = self.doc
tax_service = TaxService(doc)
gl_entries = []
self.make_customer_gl_entry(gl_entries)
@@ -40,7 +39,7 @@ class SalesInvoiceGLComposer(BaseGLComposer):
self.stock_delivered_but_not_billed_gl_entries(gl_entries)
self.make_precision_loss_gl_entry(gl_entries)
tax_service.make_discount_gl_entries(gl_entries)
self.make_discount_gl_entries(gl_entries)
gl_entries = make_regional_gl_entries(gl_entries, doc)
@@ -85,6 +84,81 @@ class SalesInvoiceGLComposer(BaseGLComposer):
)
)
def make_discount_gl_entries(self, gl_entries):
doc = self.doc
enable_discount_accounting = cint(
frappe.get_single_value("Selling Settings", "enable_discount_accounting")
)
if enable_discount_accounting:
for item in doc.get("items"):
if item.get("discount_amount") and item.get("discount_account"):
discount_amount = item.discount_amount * item.qty
income_account = (
item.income_account
if (not item.enable_deferred_revenue or doc.is_return)
else item.deferred_revenue_account
)
account_currency = get_account_currency(item.discount_account)
gl_entries.append(
doc.get_gl_dict(
{
"account": item.discount_account,
"against": doc.customer,
"debit": flt(
discount_amount * doc.get("conversion_rate"),
item.precision("discount_amount"),
),
"debit_in_transaction_currency": flt(
discount_amount, item.precision("discount_amount")
),
"cost_center": item.cost_center,
"project": item.project,
},
account_currency,
item=item,
)
)
account_currency = get_account_currency(income_account)
gl_entries.append(
doc.get_gl_dict(
{
"account": income_account,
"against": doc.customer,
"credit": flt(
discount_amount * doc.get("conversion_rate"),
item.precision("discount_amount"),
),
"credit_in_transaction_currency": flt(
discount_amount, item.precision("discount_amount")
),
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
account_currency,
item=item,
)
)
if (
(enable_discount_accounting or doc.get("is_cash_or_non_trade_discount"))
and doc.get("additional_discount_account")
and doc.get("discount_amount")
):
gl_entries.append(
doc.get_gl_dict(
{
"account": doc.additional_discount_account,
"against": doc.customer,
"debit": doc.base_discount_amount,
"cost_center": doc.cost_center or erpnext.get_default_cost_center(doc.company),
},
item=doc,
)
)
def stock_delivered_but_not_billed_gl_entries(self, gl_entries):
doc = self.doc
if doc.update_stock or not cint(erpnext.is_perpetual_inventory_enabled(doc.company)):

View File

@@ -10,7 +10,6 @@ from frappe import _, throw
from frappe.utils import cint, flt, parse_json
import erpnext
from erpnext.accounts.utils import get_account_currency
from erpnext.stock.get_item_details import (
NOT_APPLICABLE_TAX,
ItemDetailsCtx,
@@ -177,81 +176,6 @@ class TaxService:
return amount, base_amount
def make_discount_gl_entries(self, gl_entries: list) -> None:
doc = self.doc
enable_discount_accounting = cint(
frappe.get_single_value("Selling Settings", "enable_discount_accounting")
)
if enable_discount_accounting:
for item in doc.get("items"):
if item.get("discount_amount") and item.get("discount_account"):
discount_amount = item.discount_amount * item.qty
income_account = (
item.income_account
if (not item.enable_deferred_revenue or doc.is_return)
else item.deferred_revenue_account
)
account_currency = get_account_currency(item.discount_account)
gl_entries.append(
doc.get_gl_dict(
{
"account": item.discount_account,
"against": doc.customer,
"debit": flt(
discount_amount * doc.get("conversion_rate"),
item.precision("discount_amount"),
),
"debit_in_transaction_currency": flt(
discount_amount, item.precision("discount_amount")
),
"cost_center": item.cost_center,
"project": item.project,
},
account_currency,
item=item,
)
)
account_currency = get_account_currency(income_account)
gl_entries.append(
doc.get_gl_dict(
{
"account": income_account,
"against": doc.customer,
"credit": flt(
discount_amount * doc.get("conversion_rate"),
item.precision("discount_amount"),
),
"credit_in_transaction_currency": flt(
discount_amount, item.precision("discount_amount")
),
"cost_center": item.cost_center,
"project": item.project or doc.project,
},
account_currency,
item=item,
)
)
if (
(enable_discount_accounting or doc.get("is_cash_or_non_trade_discount"))
and doc.get("additional_discount_account")
and doc.get("discount_amount")
):
gl_entries.append(
doc.get_gl_dict(
{
"account": doc.additional_discount_account,
"against": doc.customer,
"debit": doc.base_discount_amount,
"cost_center": doc.cost_center or erpnext.get_default_cost_center(doc.company),
},
item=doc,
)
)
def get_tax_rate(account_head: str) -> dict:
return frappe.get_cached_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)