refactor: prevent '{debit/credit}_to' account mismatch
(cherry picked from commit 6f2fae1b6133286ab882e421e69f6a87ecb97d4a)
This commit is contained in:
parent
e4230cf6d9
commit
10fcf5af5f
@ -202,6 +202,7 @@ class AccountsController(TransactionBase):
|
|||||||
self.validate_party()
|
self.validate_party()
|
||||||
self.validate_currency()
|
self.validate_currency()
|
||||||
self.validate_party_account_currency()
|
self.validate_party_account_currency()
|
||||||
|
self.validate_return_against_account()
|
||||||
|
|
||||||
if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
|
if self.doctype in ["Purchase Invoice", "Sales Invoice"]:
|
||||||
if invalid_advances := [
|
if invalid_advances := [
|
||||||
@ -350,6 +351,20 @@ class AccountsController(TransactionBase):
|
|||||||
for bundle in bundles:
|
for bundle in bundles:
|
||||||
frappe.delete_doc("Serial and Batch Bundle", bundle.name)
|
frappe.delete_doc("Serial and Batch Bundle", bundle.name)
|
||||||
|
|
||||||
|
def validate_return_against_account(self):
|
||||||
|
if (
|
||||||
|
self.doctype in ["Sales Invoice", "Purchase Invoice"] and self.is_return and self.return_against
|
||||||
|
):
|
||||||
|
cr_dr_account_field = "debit_to" if self.doctype == "Sales Invoice" else "credit_to"
|
||||||
|
cr_dr_account_label = "Debit To" if self.doctype == "Sales Invoice" else "Credit To"
|
||||||
|
cr_dr_account = self.get(cr_dr_account_field)
|
||||||
|
if frappe.get_value(self.doctype, self.return_against, cr_dr_account_field) != cr_dr_account:
|
||||||
|
frappe.throw(
|
||||||
|
_("'{0}' account: '{1}' should match the Return Against Invoice").format(
|
||||||
|
frappe.bold(cr_dr_account_label), frappe.bold(cr_dr_account)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def validate_deferred_income_expense_account(self):
|
def validate_deferred_income_expense_account(self):
|
||||||
field_map = {
|
field_map = {
|
||||||
"Sales Invoice": "deferred_revenue_account",
|
"Sales Invoice": "deferred_revenue_account",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user