refactor(Sales Invoice Item): validate cost center

This commit is contained in:
barredterra
2024-02-14 01:14:42 +01:00
parent f1f8f59bdb
commit 76023f1fdc
3 changed files with 13 additions and 10 deletions

View File

@@ -3,10 +3,10 @@
# import frappe
from frappe.model.document import Document
from erpnext.accounts.doctype.sales_invoice_item.sales_invoice_item import SalesInvoiceItem
class POSInvoiceItem(Document):
class POSInvoiceItem(SalesInvoiceItem):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

View File

@@ -379,13 +379,7 @@ class SalesInvoice(SellingController):
def validate_item_cost_centers(self):
for item in self.items:
cost_center_company = frappe.get_cached_value("Cost Center", item.cost_center, "company")
if cost_center_company != self.company:
frappe.throw(
_("Row #{0}: Cost Center {1} does not belong to company {2}").format(
frappe.bold(item.idx), frappe.bold(item.cost_center), frappe.bold(self.company)
)
)
item.validate_cost_center(self.company)
def validate_income_account(self):
for item in self.get("items"):

View File

@@ -2,6 +2,8 @@
# License: GNU General Public License v3. See license.txt
import frappe
from frappe import _
from frappe.model.document import Document
@@ -92,4 +94,11 @@ class SalesInvoiceItem(Document):
weight_uom: DF.Link | None
# end: auto-generated types
pass
def validate_cost_center(self, company: str):
cost_center_company = frappe.get_cached_value("Cost Center", self.cost_center, "company")
if cost_center_company != company:
frappe.throw(
_("Row #{0}: Cost Center {1} does not belong to company {2}").format(
frappe.bold(self.idx), frappe.bold(self.cost_center), frappe.bold(company)
)
)