fix: call validate before setting repost flag
This commit is contained in:
parent
1856050ef9
commit
8ef0d88708
@ -11,6 +11,9 @@ from frappe.utils import cint, cstr, flt, formatdate, get_link_to_form, getdate,
|
|||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.accounts.deferred_revenue import validate_service_stop_date
|
from erpnext.accounts.deferred_revenue import validate_service_stop_date
|
||||||
from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
|
from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt
|
||||||
|
from erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger import (
|
||||||
|
validate_docs_for_deferred_accounting,
|
||||||
|
)
|
||||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
||||||
check_if_return_invoice_linked_with_payment_entry,
|
check_if_return_invoice_linked_with_payment_entry,
|
||||||
get_total_in_party_account_currency,
|
get_total_in_party_account_currency,
|
||||||
@ -484,6 +487,11 @@ class PurchaseInvoice(BuyingController):
|
|||||||
_("Stock cannot be updated against Purchase Receipt {0}").format(item.purchase_receipt)
|
_("Stock cannot be updated against Purchase Receipt {0}").format(item.purchase_receipt)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_for_repost(self):
|
||||||
|
self.validate_write_off_account()
|
||||||
|
self.validate_expense_account()
|
||||||
|
validate_docs_for_deferred_accounting([], [self.name])
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
super(PurchaseInvoice, self).on_submit()
|
super(PurchaseInvoice, self).on_submit()
|
||||||
|
|
||||||
@ -531,8 +539,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
]
|
]
|
||||||
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
|
child_tables = {"items": ("expense_account",), "taxes": ("account_head",)}
|
||||||
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
|
self.needs_repost = self.check_if_fields_updated(fields_to_check, child_tables)
|
||||||
self.validate_write_off_account()
|
self.validate_for_repost()
|
||||||
self.validate_expense_account()
|
|
||||||
self.db_set("repost_required", self.needs_repost)
|
self.db_set("repost_required", self.needs_repost)
|
||||||
|
|
||||||
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
||||||
|
@ -21,29 +21,8 @@ class RepostAccountingLedger(Document):
|
|||||||
|
|
||||||
def validate_for_deferred_accounting(self):
|
def validate_for_deferred_accounting(self):
|
||||||
sales_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Sales Invoice"]
|
sales_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Sales Invoice"]
|
||||||
docs_with_deferred_revenue = frappe.db.get_all(
|
|
||||||
"Sales Invoice Item",
|
|
||||||
filters={"parent": ["in", sales_docs], "docstatus": 1, "enable_deferred_revenue": True},
|
|
||||||
fields=["parent"],
|
|
||||||
as_list=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
purchase_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Purchase Invoice"]
|
purchase_docs = [x.voucher_no for x in self.vouchers if x.voucher_type == "Purchase Invoice"]
|
||||||
docs_with_deferred_expense = frappe.db.get_all(
|
validate_docs_for_deferred_accounting(sales_docs, purchase_docs)
|
||||||
"Purchase Invoice Item",
|
|
||||||
filters={"parent": ["in", purchase_docs], "docstatus": 1, "enable_deferred_expense": 1},
|
|
||||||
fields=["parent"],
|
|
||||||
as_list=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
if docs_with_deferred_revenue or docs_with_deferred_expense:
|
|
||||||
frappe.throw(
|
|
||||||
_("Documents: {0} have deferred revenue/expense enabled for them. Cannot repost.").format(
|
|
||||||
frappe.bold(
|
|
||||||
comma_and([x[0] for x in docs_with_deferred_expense + docs_with_deferred_revenue])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def validate_for_closed_fiscal_year(self):
|
def validate_for_closed_fiscal_year(self):
|
||||||
if self.vouchers:
|
if self.vouchers:
|
||||||
@ -184,3 +163,26 @@ def start_repost(account_repost_doc=str) -> None:
|
|||||||
doc.make_gl_entries()
|
doc.make_gl_entries()
|
||||||
|
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def validate_docs_for_deferred_accounting(sales_docs, purchase_docs):
|
||||||
|
docs_with_deferred_revenue = frappe.db.get_all(
|
||||||
|
"Sales Invoice Item",
|
||||||
|
filters={"parent": ["in", sales_docs], "docstatus": 1, "enable_deferred_revenue": True},
|
||||||
|
fields=["parent"],
|
||||||
|
as_list=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
docs_with_deferred_expense = frappe.db.get_all(
|
||||||
|
"Purchase Invoice Item",
|
||||||
|
filters={"parent": ["in", purchase_docs], "docstatus": 1, "enable_deferred_expense": 1},
|
||||||
|
fields=["parent"],
|
||||||
|
as_list=1,
|
||||||
|
)
|
||||||
|
|
||||||
|
if docs_with_deferred_revenue or docs_with_deferred_expense:
|
||||||
|
frappe.throw(
|
||||||
|
_("Documents: {0} have deferred revenue/expense enabled for them. Cannot repost.").format(
|
||||||
|
frappe.bold(comma_and([x[0] for x in docs_with_deferred_expense + docs_with_deferred_revenue]))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user