mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
refactor: convert class method to standalone function
(cherry picked from commit 1ea1bfebc4)
This commit is contained in:
@@ -1845,3 +1845,74 @@ class QueryPaymentLedger(object):
|
||||
self.query_for_outstanding()
|
||||
|
||||
return self.voucher_outstandings
|
||||
|
||||
|
||||
def create_gain_loss_journal(
|
||||
company,
|
||||
party_type,
|
||||
party,
|
||||
party_account,
|
||||
gain_loss_account,
|
||||
exc_gain_loss,
|
||||
dr_or_cr,
|
||||
reverse_dr_or_cr,
|
||||
ref1_dt,
|
||||
ref1_dn,
|
||||
ref1_detail_no,
|
||||
ref2_dt,
|
||||
ref2_dn,
|
||||
ref2_detail_no,
|
||||
) -> str:
|
||||
journal_entry = frappe.new_doc("Journal Entry")
|
||||
journal_entry.voucher_type = "Exchange Gain Or Loss"
|
||||
journal_entry.company = company
|
||||
journal_entry.posting_date = nowdate()
|
||||
journal_entry.multi_currency = 1
|
||||
|
||||
party_account_currency = frappe.get_cached_value("Account", party_account, "account_currency")
|
||||
|
||||
if not gain_loss_account:
|
||||
frappe.throw(_("Please set default Exchange Gain/Loss Account in Company {}").format(company))
|
||||
gain_loss_account_currency = get_account_currency(gain_loss_account)
|
||||
company_currency = frappe.get_cached_value("Company", company, "default_currency")
|
||||
|
||||
if gain_loss_account_currency != company_currency:
|
||||
frappe.throw(_("Currency for {0} must be {1}").format(gain_loss_account, company_currency))
|
||||
|
||||
journal_account = frappe._dict(
|
||||
{
|
||||
"account": party_account,
|
||||
"party_type": party_type,
|
||||
"party": party,
|
||||
"account_currency": party_account_currency,
|
||||
"exchange_rate": 0,
|
||||
"cost_center": erpnext.get_default_cost_center(company),
|
||||
"reference_type": ref1_dt,
|
||||
"reference_name": ref1_dn,
|
||||
"reference_detail_no": ref1_detail_no,
|
||||
dr_or_cr: abs(exc_gain_loss),
|
||||
dr_or_cr + "_in_account_currency": 0,
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry.append("accounts", journal_account)
|
||||
|
||||
journal_account = frappe._dict(
|
||||
{
|
||||
"account": gain_loss_account,
|
||||
"account_currency": gain_loss_account_currency,
|
||||
"exchange_rate": 1,
|
||||
"cost_center": erpnext.get_default_cost_center(company),
|
||||
"reference_type": ref2_dt,
|
||||
"reference_name": ref2_dn,
|
||||
"reference_detail_no": ref2_detail_no,
|
||||
reverse_dr_or_cr + "_in_account_currency": 0,
|
||||
reverse_dr_or_cr: abs(exc_gain_loss),
|
||||
}
|
||||
)
|
||||
|
||||
journal_entry.append("accounts", journal_account)
|
||||
|
||||
journal_entry.save()
|
||||
journal_entry.submit()
|
||||
return journal_entry.name
|
||||
|
||||
Reference in New Issue
Block a user