Skip to content

Commit

Permalink
refactor(Payment Entry): translatable strings (frappe#36017)
Browse files Browse the repository at this point in the history
* refactor(Payment Entry): translatable strings

* fix: German translations
  • Loading branch information
barredterra authored Jul 9, 2023
1 parent ef7fd75 commit af28f95
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 141 deletions.
55 changes: 30 additions & 25 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import frappe
from frappe import ValidationError, _, qb, scrub, throw
from frappe.utils import cint, comma_or, flt, getdate, nowdate
from frappe.utils.data import comma_and, fmt_money

import erpnext
from erpnext.accounts.doctype.bank_account.bank_account import (
Expand Down Expand Up @@ -124,13 +125,16 @@ def set_liability_account(self):

self.set(self.party_account_field, liability_account)

msg = "Book Advance Payments as Liability option is chosen. Paid From account changed from {0} to {1}.".format(
frappe.bold(self.party_account),
frappe.bold(liability_account),
frappe.msgprint(
_(
"Book Advance Payments as Liability option is chosen. Paid From account changed from {0} to {1}."
).format(
frappe.bold(self.party_account),
frappe.bold(liability_account),
),
alert=True,
)

frappe.msgprint(_(msg), alert=True)

def on_cancel(self):
self.ignore_linked_doctypes = (
"GL Entry",
Expand Down Expand Up @@ -230,7 +234,7 @@ def validate_allocated_amount_with_latest_data(self):
# The reference has already been fully paid
if not latest:
frappe.throw(
_("{0} {1} has already been fully paid.").format(d.reference_doctype, d.reference_name)
_("{0} {1} has already been fully paid.").format(_(d.reference_doctype), d.reference_name)
)
# The reference has already been partly paid
elif (
Expand All @@ -240,7 +244,7 @@ def validate_allocated_amount_with_latest_data(self):
frappe.throw(
_(
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' or the 'Get Outstanding Orders' button to get the latest outstanding amounts."
).format(d.reference_doctype, d.reference_name)
).format(_(d.reference_doctype), d.reference_name)
)

fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
Expand Down Expand Up @@ -342,7 +346,7 @@ def validate_payment_type(self):
def validate_party_details(self):
if self.party:
if not frappe.db.exists(self.party_type, self.party):
frappe.throw(_("Invalid {0}: {1}").format(self.party_type, self.party))
frappe.throw(_("{0} {1} does not exist").format(_(self.party_type), self.party))

def set_exchange_rate(self, ref_doc=None):
self.set_source_exchange_rate(ref_doc)
Expand Down Expand Up @@ -391,7 +395,9 @@ def validate_reference_documents(self):
continue
if d.reference_doctype not in valid_reference_doctypes:
frappe.throw(
_("Reference Doctype must be one of {0}").format(comma_or(valid_reference_doctypes))
_("Reference Doctype must be one of {0}").format(
comma_or((_(d) for d in valid_reference_doctypes))
)
)

elif d.reference_name:
Expand All @@ -404,7 +410,7 @@ def validate_reference_documents(self):
if self.party != ref_doc.get(scrub(self.party_type)):
frappe.throw(
_("{0} {1} is not associated with {2} {3}").format(
d.reference_doctype, d.reference_name, self.party_type, self.party
_(d.reference_doctype), d.reference_name, _(self.party_type), self.party
)
)
else:
Expand All @@ -426,18 +432,18 @@ def validate_reference_documents(self):
):
frappe.throw(
_("{0} {1} is associated with {2}, but Party Account is {3}").format(
d.reference_doctype, d.reference_name, ref_party_account, self.party_account
_(d.reference_doctype), d.reference_name, ref_party_account, self.party_account
)
)

if ref_doc.doctype == "Purchase Invoice" and ref_doc.get("on_hold"):
frappe.throw(
_("{0} {1} is on hold").format(d.reference_doctype, d.reference_name),
title=_("Invalid Invoice"),
_("{0} {1} is on hold").format(_(d.reference_doctype), d.reference_name),
title=_("Invalid Purchase Invoice"),
)

if ref_doc.docstatus != 1:
frappe.throw(_("{0} {1} must be submitted").format(d.reference_doctype, d.reference_name))
frappe.throw(_("{0} {1} must be submitted").format(_(d.reference_doctype), d.reference_name))

def get_valid_reference_doctypes(self):
if self.party_type == "Customer":
Expand All @@ -463,14 +469,13 @@ def validate_paid_invoices(self):
if outstanding_amount <= 0 and not is_return:
no_oustanding_refs.setdefault(d.reference_doctype, []).append(d)

for k, v in no_oustanding_refs.items():
for reference_doctype, references in no_oustanding_refs.items():
frappe.msgprint(
_(
"{} - {} now has {} as it had no outstanding amount left before submitting the Payment Entry."
"References {0} of type {1} had no outstanding amount left before submitting the Payment Entry. Now they have a negative outstanding amount."
).format(
_(k),
frappe.bold(", ".join(d.reference_name for d in v)),
frappe.bold(_("negative outstanding amount")),
frappe.bold(comma_and((d.reference_name for d in references))),
_(reference_doctype),
)
+ "<br><br>"
+ _("If this is undesirable please cancel the corresponding Payment Entry."),
Expand Down Expand Up @@ -505,7 +510,7 @@ def validate_journal_entry(self):
if not valid:
frappe.throw(
_("Against Journal Entry {0} does not have any unmatched {1} entry").format(
d.reference_name, dr_or_cr
d.reference_name, _(dr_or_cr)
)
)

Expand Down Expand Up @@ -572,7 +577,7 @@ def update_payment_schedule(self, cancel=0):
if allocated_amount > outstanding:
frappe.throw(
_("Row #{0}: Cannot allocate more than {1} against payment term {2}").format(
idx, outstanding, key[0]
idx, fmt_money(outstanding), key[0]
)
)

Expand Down Expand Up @@ -876,7 +881,7 @@ def validate_payment_against_negative_invoice(self):
elif paid_amount - additional_charges > total_negative_outstanding:
frappe.throw(
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
total_negative_outstanding
fmt_money(total_negative_outstanding)
),
InvalidPaymentEntry,
)
Expand Down Expand Up @@ -1546,7 +1551,7 @@ def get_outstanding_reference_documents(args, validate=False):
_(
"No outstanding {0} found for the {1} {2} which qualify the filters you have specified."
).format(
ref_document_type, _(args.get("party_type")).lower(), frappe.bold(args.get("party"))
_(ref_document_type), _(args.get("party_type")).lower(), frappe.bold(args.get("party"))
)
)

Expand Down Expand Up @@ -1758,7 +1763,7 @@ def get_negative_outstanding_invoices(
def get_party_details(company, party_type, party, date, cost_center=None):
bank_account = ""
if not frappe.db.exists(party_type, party):
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
frappe.throw(_("{0} {1} does not exist").format(_(party_type), party))

party_account = get_party_account(party_type, party, company)
account_currency = get_account_currency(party_account)
Expand Down Expand Up @@ -1912,7 +1917,7 @@ def get_payment_entry(
if dt in ("Sales Order", "Purchase Order") and flt(doc.per_billed, 2) >= (
100.0 + over_billing_allowance
):
frappe.throw(_("Can only make payment against unbilled {0}").format(dt))
frappe.throw(_("Can only make payment against unbilled {0}").format(_(dt)))

if not party_type:
party_type = set_party_type(dt)
Expand Down
Loading

0 comments on commit af28f95

Please sign in to comment.