mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
Avoid status updation for purchase invoice from paid to unpaid by issuing a paid debit note against it (#54382)
This commit is contained in:
@@ -591,6 +591,25 @@ frappe.ui.form.on("Purchase Invoice", {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.set_query("write_off_account", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
report_type: "Profit and Loss",
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
frm.set_query("write_off_cost_center", function (doc) {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
is_group: 0,
|
||||||
|
company: doc.company,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
frm.fields_dict["items"].grid.get_field("deferred_expense_account").get_query = function (doc) {
|
frm.fields_dict["items"].grid.get_field("deferred_expense_account").get_query = function (doc) {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
self.validate_expense_account()
|
self.validate_expense_account()
|
||||||
self.set_against_expense_account()
|
self.set_against_expense_account()
|
||||||
self.validate_write_off_account()
|
self.validate_write_off_account()
|
||||||
|
self.validate_write_off_cost_center()
|
||||||
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount")
|
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount")
|
||||||
self.set_status()
|
self.set_status()
|
||||||
self.validate_purchase_receipt_if_update_stock()
|
self.validate_purchase_receipt_if_update_stock()
|
||||||
@@ -652,6 +653,27 @@ class PurchaseInvoice(BuyingController):
|
|||||||
if self.write_off_amount and not self.write_off_account:
|
if self.write_off_amount and not self.write_off_account:
|
||||||
throw(_("Please enter Write Off Account"))
|
throw(_("Please enter Write Off Account"))
|
||||||
|
|
||||||
|
if not self.write_off_account:
|
||||||
|
return
|
||||||
|
|
||||||
|
doc = frappe.db.get_value(
|
||||||
|
"Account", self.write_off_account, ["report_type", "is_group", "company"], as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
if not doc or doc.report_type != "Profit and Loss" or doc.is_group or doc.company != self.company:
|
||||||
|
throw(_("Please enter a valid Write Off Account"))
|
||||||
|
|
||||||
|
def validate_write_off_cost_center(self):
|
||||||
|
if not self.write_off_cost_center:
|
||||||
|
return
|
||||||
|
|
||||||
|
doc = frappe.db.get_value(
|
||||||
|
"Cost Center", self.write_off_cost_center, ["is_group", "company"], as_dict=True
|
||||||
|
)
|
||||||
|
|
||||||
|
if not doc or doc.is_group or doc.company != self.company:
|
||||||
|
throw(_("Please enter a valid Write Off Cost Center"))
|
||||||
|
|
||||||
def check_prev_docstatus(self):
|
def check_prev_docstatus(self):
|
||||||
for d in self.get("items"):
|
for d in self.get("items"):
|
||||||
if d.purchase_order:
|
if d.purchase_order:
|
||||||
@@ -732,6 +754,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
|
|
||||||
def validate_for_repost(self):
|
def validate_for_repost(self):
|
||||||
self.validate_write_off_account()
|
self.validate_write_off_account()
|
||||||
|
self.validate_write_off_cost_center()
|
||||||
self.validate_expense_account()
|
self.validate_expense_account()
|
||||||
validate_docs_for_voucher_types(["Purchase Invoice"])
|
validate_docs_for_voucher_types(["Purchase Invoice"])
|
||||||
validate_docs_for_deferred_accounting([], [self.name])
|
validate_docs_for_deferred_accounting([], [self.name])
|
||||||
@@ -842,7 +865,9 @@ class PurchaseInvoice(BuyingController):
|
|||||||
if update_outstanding == "No":
|
if update_outstanding == "No":
|
||||||
update_voucher_outstanding(
|
update_voucher_outstanding(
|
||||||
voucher_type=self.doctype,
|
voucher_type=self.doctype,
|
||||||
voucher_no=self.return_against if cint(self.is_return) and self.return_against else self.name,
|
voucher_no=self.return_against
|
||||||
|
if (cint(self.is_return) and self.return_against)
|
||||||
|
else self.name,
|
||||||
account=self.credit_to,
|
account=self.credit_to,
|
||||||
party_type="Supplier",
|
party_type="Supplier",
|
||||||
party=self.supplier,
|
party=self.supplier,
|
||||||
@@ -1536,6 +1561,9 @@ class PurchaseInvoice(BuyingController):
|
|||||||
def make_payment_gl_entries(self, gl_entries):
|
def make_payment_gl_entries(self, gl_entries):
|
||||||
# Make Cash GL Entries
|
# Make Cash GL Entries
|
||||||
if cint(self.is_paid) and self.cash_bank_account and self.paid_amount:
|
if cint(self.is_paid) and self.cash_bank_account and self.paid_amount:
|
||||||
|
against_voucher = self.name
|
||||||
|
if self.is_return and self.return_against and not self.update_outstanding_for_self:
|
||||||
|
against_voucher = self.return_against
|
||||||
bank_account_currency = get_account_currency(self.cash_bank_account)
|
bank_account_currency = get_account_currency(self.cash_bank_account)
|
||||||
# CASH, make payment entries
|
# CASH, make payment entries
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
@@ -1550,9 +1578,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
if self.party_account_currency == self.company_currency
|
if self.party_account_currency == self.company_currency
|
||||||
else self.paid_amount,
|
else self.paid_amount,
|
||||||
"debit_in_transaction_currency": self.paid_amount,
|
"debit_in_transaction_currency": self.paid_amount,
|
||||||
"against_voucher": self.return_against
|
"against_voucher": against_voucher,
|
||||||
if cint(self.is_return) and self.return_against
|
|
||||||
else self.name,
|
|
||||||
"against_voucher_type": self.doctype,
|
"against_voucher_type": self.doctype,
|
||||||
"cost_center": self.cost_center,
|
"cost_center": self.cost_center,
|
||||||
"project": self.project,
|
"project": self.project,
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class AccountsController(TransactionBase):
|
|||||||
if not get_meta(self.doctype).has_field("outstanding_amount"):
|
if not get_meta(self.doctype).has_field("outstanding_amount"):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.get("is_return") and self.return_against and not self.get("is_pos"):
|
if self.get("is_return") and self.return_against and not (self.get("is_pos") or self.get("is_paid")):
|
||||||
against_voucher_outstanding = frappe.get_value(
|
against_voucher_outstanding = frappe.get_value(
|
||||||
self.doctype, self.return_against, "outstanding_amount"
|
self.doctype, self.return_against, "outstanding_amount"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user