Merge pull request #40627 from deepeshgarg007/da_code_cleanup
chore: Discount accounting code cleanup
This commit is contained in:
@@ -1649,52 +1649,30 @@ class AccountsController(TransactionBase):
|
|||||||
return amount, base_amount
|
return amount, base_amount
|
||||||
|
|
||||||
def make_discount_gl_entries(self, gl_entries):
|
def make_discount_gl_entries(self, gl_entries):
|
||||||
if self.doctype == "Purchase Invoice":
|
enable_discount_accounting = cint(
|
||||||
enable_discount_accounting = cint(
|
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
|
||||||
frappe.db.get_single_value("Buying Settings", "enable_discount_accounting")
|
)
|
||||||
)
|
|
||||||
elif self.doctype == "Sales Invoice":
|
|
||||||
enable_discount_accounting = cint(
|
|
||||||
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.doctype == "Purchase Invoice":
|
|
||||||
dr_or_cr = "credit"
|
|
||||||
rev_dr_cr = "debit"
|
|
||||||
supplier_or_customer = self.supplier
|
|
||||||
|
|
||||||
else:
|
|
||||||
dr_or_cr = "debit"
|
|
||||||
rev_dr_cr = "credit"
|
|
||||||
supplier_or_customer = self.customer
|
|
||||||
|
|
||||||
if enable_discount_accounting:
|
if enable_discount_accounting:
|
||||||
for item in self.get("items"):
|
for item in self.get("items"):
|
||||||
if item.get("discount_amount") and item.get("discount_account"):
|
if item.get("discount_amount") and item.get("discount_account"):
|
||||||
discount_amount = item.discount_amount * item.qty
|
discount_amount = item.discount_amount * item.qty
|
||||||
if self.doctype == "Purchase Invoice":
|
income_account = (
|
||||||
income_or_expense_account = (
|
item.income_account
|
||||||
item.expense_account
|
if (not item.enable_deferred_revenue or self.is_return)
|
||||||
if (not item.enable_deferred_expense or self.is_return)
|
else item.deferred_revenue_account
|
||||||
else item.deferred_expense_account
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
income_or_expense_account = (
|
|
||||||
item.income_account
|
|
||||||
if (not item.enable_deferred_revenue or self.is_return)
|
|
||||||
else item.deferred_revenue_account
|
|
||||||
)
|
|
||||||
|
|
||||||
account_currency = get_account_currency(item.discount_account)
|
account_currency = get_account_currency(item.discount_account)
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict(
|
self.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": item.discount_account,
|
"account": item.discount_account,
|
||||||
"against": supplier_or_customer,
|
"against": self.customer,
|
||||||
dr_or_cr: flt(
|
"debit": flt(
|
||||||
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
|
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
|
||||||
),
|
),
|
||||||
dr_or_cr + "_in_account_currency": flt(discount_amount, item.precision("discount_amount")),
|
"debit_in_account_currency": flt(discount_amount, item.precision("discount_amount")),
|
||||||
"cost_center": item.cost_center,
|
"cost_center": item.cost_center,
|
||||||
"project": item.project,
|
"project": item.project,
|
||||||
},
|
},
|
||||||
@@ -1703,17 +1681,16 @@ class AccountsController(TransactionBase):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
account_currency = get_account_currency(income_or_expense_account)
|
account_currency = get_account_currency(income_account)
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict(
|
self.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": income_or_expense_account,
|
"account": income_account,
|
||||||
"against": supplier_or_customer,
|
"against": self.customer,
|
||||||
rev_dr_cr: flt(
|
"credit": flt(
|
||||||
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
|
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
|
||||||
),
|
),
|
||||||
rev_dr_cr
|
"credit_in_account_currency": flt(discount_amount, item.precision("discount_amount")),
|
||||||
+ "_in_account_currency": flt(discount_amount, item.precision("discount_amount")),
|
|
||||||
"cost_center": item.cost_center,
|
"cost_center": item.cost_center,
|
||||||
"project": item.project or self.project,
|
"project": item.project or self.project,
|
||||||
},
|
},
|
||||||
@@ -1731,8 +1708,8 @@ class AccountsController(TransactionBase):
|
|||||||
self.get_gl_dict(
|
self.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": self.additional_discount_account,
|
"account": self.additional_discount_account,
|
||||||
"against": supplier_or_customer,
|
"against": self.customer,
|
||||||
dr_or_cr: self.base_discount_amount,
|
"debit": self.base_discount_amount,
|
||||||
"cost_center": self.cost_center or erpnext.get_default_cost_center(self.company),
|
"cost_center": self.cost_center or erpnext.get_default_cost_center(self.company),
|
||||||
},
|
},
|
||||||
item=self,
|
item=self,
|
||||||
|
|||||||
Reference in New Issue
Block a user