refactor: use payment's CC for gain/loss if company default is unset

(cherry picked from commit d6a3b9a5c7)

# Conflicts:
#	erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
This commit is contained in:
ruthra kumar
2023-09-03 07:21:09 +05:30
committed by Mergify
parent 7fd96d0116
commit d24c8b1bbc
5 changed files with 40 additions and 7 deletions

View File

@@ -100,7 +100,7 @@ class PaymentReconciliation(Document):
"Journal Entry" as reference_type, t1.name as reference_name,
t1.posting_date, t1.remark as remarks, t2.name as reference_row,
{dr_or_cr} as amount, t2.is_advance, t2.exchange_rate,
t2.account_currency as currency
t2.account_currency as currency, t2.cost_center as cost_center
from
`tabJournal Entry` t1, `tabJournal Entry Account` t2
where
@@ -196,6 +196,7 @@ class PaymentReconciliation(Document):
"amount": -(inv.outstanding_in_account_currency),
"posting_date": inv.posting_date,
"currency": inv.currency,
"cost_center": inv.cost_center,
}
)
)
@@ -344,6 +345,7 @@ class PaymentReconciliation(Document):
"allocated_amount": allocated_amount,
"difference_amount": pay.get("difference_amount"),
"currency": inv.get("currency"),
"cost_center": pay.get("cost_center"),
}
)
@@ -418,6 +420,7 @@ class PaymentReconciliation(Document):
"allocated_amount": flt(row.get("allocated_amount")),
"difference_amount": flt(row.get("difference_amount")),
"difference_account": row.get("difference_account"),
"cost_center": row.get("cost_center"),
}
)
@@ -590,7 +593,12 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
inv.dr_or_cr: abs(inv.allocated_amount),
"reference_type": inv.against_voucher_type,
"reference_name": inv.against_voucher,
<<<<<<< HEAD
"cost_center": erpnext.get_default_cost_center(company),
=======
"cost_center": inv.cost_center or erpnext.get_default_cost_center(company),
"exchange_rate": inv.exchange_rate,
>>>>>>> d6a3b9a5c7 (refactor: use payment's CC for gain/loss if company default is unset)
"user_remark": f"{fmt_money(flt(inv.allocated_amount), currency=company_currency)} against {inv.against_voucher}",
"exchange_rate": inv.exchange_rate,
},
@@ -605,7 +613,12 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
),
"reference_type": inv.voucher_type,
"reference_name": inv.voucher_no,
<<<<<<< HEAD
"cost_center": erpnext.get_default_cost_center(company),
=======
"cost_center": inv.cost_center or erpnext.get_default_cost_center(company),
"exchange_rate": inv.exchange_rate,
>>>>>>> d6a3b9a5c7 (refactor: use payment's CC for gain/loss if company default is unset)
"user_remark": f"{fmt_money(flt(inv.allocated_amount), currency=company_currency)} from {inv.voucher_no}",
"exchange_rate": inv.exchange_rate,
},
@@ -644,4 +657,5 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
inv.against_voucher_type,
inv.against_voucher,
None,
inv.cost_center,
)

View File

@@ -22,7 +22,8 @@
"column_break_7",
"difference_account",
"exchange_rate",
"currency"
"currency",
"cost_center"
],
"fields": [
{
@@ -144,11 +145,17 @@
"fieldtype": "Float",
"label": "Exchange Rate",
"read_only": 1
},
{
"fieldname": "cost_center",
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
}
],
"istable": 1,
"links": [],
"modified": "2022-12-24 21:01:14.882747",
"modified": "2023-09-03 07:52:33.684217",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation Allocation",

View File

@@ -16,7 +16,8 @@
"sec_break1",
"remark",
"currency",
"exchange_rate"
"exchange_rate",
"cost_center"
],
"fields": [
{
@@ -98,11 +99,17 @@
"fieldtype": "Float",
"hidden": 1,
"label": "Exchange Rate"
},
{
"fieldname": "cost_center",
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
}
],
"istable": 1,
"links": [],
"modified": "2022-11-08 18:18:36.268760",
"modified": "2023-09-03 07:43:29.965353",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Reconciliation Payment",

View File

@@ -1724,6 +1724,7 @@ class QueryPaymentLedger(object):
ple.posting_date,
ple.due_date,
ple.account_currency.as_("currency"),
ple.cost_center.as_("cost_center"),
Sum(ple.amount).as_("amount"),
Sum(ple.amount_in_account_currency).as_("amount_in_account_currency"),
)
@@ -1786,6 +1787,7 @@ class QueryPaymentLedger(object):
).as_("paid_amount_in_account_currency"),
Table("vouchers").due_date,
Table("vouchers").currency,
Table("vouchers").cost_center.as_("cost_center"),
)
.where(Criterion.all(filter_on_outstanding_amount))
)
@@ -1869,6 +1871,7 @@ def create_gain_loss_journal(
ref2_dt,
ref2_dn,
ref2_detail_no,
cost_center,
) -> str:
journal_entry = frappe.new_doc("Journal Entry")
journal_entry.voucher_type = "Exchange Gain Or Loss"
@@ -1894,7 +1897,7 @@ def create_gain_loss_journal(
"party": party,
"account_currency": party_account_currency,
"exchange_rate": 0,
"cost_center": erpnext.get_default_cost_center(company),
"cost_center": cost_center or erpnext.get_default_cost_center(company),
"reference_type": ref1_dt,
"reference_name": ref1_dn,
"reference_detail_no": ref1_detail_no,
@@ -1910,7 +1913,7 @@ def create_gain_loss_journal(
"account": gain_loss_account,
"account_currency": gain_loss_account_currency,
"exchange_rate": 1,
"cost_center": erpnext.get_default_cost_center(company),
"cost_center": cost_center or erpnext.get_default_cost_center(company),
"reference_type": ref2_dt,
"reference_name": ref2_dn,
"reference_detail_no": ref2_detail_no,

View File

@@ -1087,6 +1087,7 @@ class AccountsController(TransactionBase):
self.doctype,
self.name,
arg.get("referenced_row"),
arg.get("cost_center"),
)
frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format(
@@ -1165,6 +1166,7 @@ class AccountsController(TransactionBase):
self.doctype,
self.name,
d.idx,
self.cost_center,
)
frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format(