mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-14 12:25:09 +00:00
fix(stock): validate company for receipt documents and expense accounts
(cherry picked from commit 15dfc08a31)
This commit is contained in:
@@ -75,6 +75,7 @@ class LandedCostVoucher(Document):
|
|||||||
self.check_mandatory()
|
self.check_mandatory()
|
||||||
self.validate_receipt_documents()
|
self.validate_receipt_documents()
|
||||||
self.validate_line_items()
|
self.validate_line_items()
|
||||||
|
self.validate_expense_accounts()
|
||||||
init_landed_taxes_and_totals(self)
|
init_landed_taxes_and_totals(self)
|
||||||
self.set_total_taxes_and_charges()
|
self.set_total_taxes_and_charges()
|
||||||
if not self.get("items"):
|
if not self.get("items"):
|
||||||
@@ -116,11 +117,27 @@ class LandedCostVoucher(Document):
|
|||||||
receipt_documents = []
|
receipt_documents = []
|
||||||
|
|
||||||
for d in self.get("purchase_receipts"):
|
for d in self.get("purchase_receipts"):
|
||||||
docstatus = frappe.db.get_value(d.receipt_document_type, d.receipt_document, "docstatus")
|
docstatus, company = frappe.get_cached_value(
|
||||||
|
d.receipt_document_type, d.receipt_document, ["docstatus", "company"]
|
||||||
|
)
|
||||||
if docstatus != 1:
|
if docstatus != 1:
|
||||||
msg = f"Row {d.idx}: {d.receipt_document_type} {frappe.bold(d.receipt_document)} must be submitted"
|
msg = f"Row {d.idx}: {d.receipt_document_type} {frappe.bold(d.receipt_document)} must be submitted"
|
||||||
frappe.throw(_(msg), title=_("Invalid Document"))
|
frappe.throw(_(msg), title=_("Invalid Document"))
|
||||||
|
|
||||||
|
if company != self.company:
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Row {0}: {1} {2} is linked to company {3}. Please select a document belonging to company {4}."
|
||||||
|
).format(
|
||||||
|
d.idx,
|
||||||
|
d.receipt_document_type,
|
||||||
|
frappe.bold(d.receipt_document),
|
||||||
|
frappe.bold(company),
|
||||||
|
frappe.bold(self.company),
|
||||||
|
),
|
||||||
|
title=_("Incorrect Company"),
|
||||||
|
)
|
||||||
|
|
||||||
if d.receipt_document_type == "Purchase Invoice":
|
if d.receipt_document_type == "Purchase Invoice":
|
||||||
update_stock = frappe.db.get_value(
|
update_stock = frappe.db.get_value(
|
||||||
d.receipt_document_type, d.receipt_document, "update_stock"
|
d.receipt_document_type, d.receipt_document, "update_stock"
|
||||||
@@ -152,6 +169,23 @@ class LandedCostVoucher(Document):
|
|||||||
_("Row {0}: Cost center is required for an item {1}").format(item.idx, item.item_code)
|
_("Row {0}: Cost center is required for an item {1}").format(item.idx, item.item_code)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def validate_expense_accounts(self):
|
||||||
|
for t in self.taxes:
|
||||||
|
company = frappe.get_cached_value("Account", t.expense_account, "company")
|
||||||
|
|
||||||
|
if company != self.company:
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Row {0}: Expense Account {1} is linked to company {2}. Please select an account belonging to company {3}."
|
||||||
|
).format(
|
||||||
|
t.idx,
|
||||||
|
frappe.bold(t.expense_account),
|
||||||
|
frappe.bold(company),
|
||||||
|
frappe.bold(self.company),
|
||||||
|
),
|
||||||
|
title=_("Incorrect Account"),
|
||||||
|
)
|
||||||
|
|
||||||
def set_total_taxes_and_charges(self):
|
def set_total_taxes_and_charges(self):
|
||||||
self.total_taxes_and_charges = sum(flt(d.base_amount) for d in self.get("taxes"))
|
self.total_taxes_and_charges = sum(flt(d.base_amount) for d in self.get("taxes"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user