Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: toggle updation of billed amount in previous purchase docs #40102

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"is_paid",
"is_return",
"return_against",
"update_billed_amount_in_purchase_order",
"update_billed_amount_in_purchase_receipt",
"apply_tds",
"tax_withholding_category",
"amended_from",
Expand Down Expand Up @@ -412,6 +414,20 @@
"read_only": 1,
"search_index": 1
},
{
"default": "0",
"depends_on": "eval: doc.is_return",
"fieldname": "update_billed_amount_in_purchase_order",
"fieldtype": "Check",
"label": "Update Billed Amount in Purchase Order"
},
{
"default": "1",
"depends_on": "eval: doc.is_return",
"fieldname": "update_billed_amount_in_purchase_receipt",
"fieldtype": "Check",
"label": "Update Billed Amount in Purchase Receipt"
},
{
"fieldname": "section_addresses",
"fieldtype": "Section Break",
Expand Down Expand Up @@ -1613,7 +1629,7 @@
"idx": 204,
"is_submittable": 1,
"links": [],
"modified": "2024-01-26 10:46:00.469053",
"modified": "2024-02-25 11:20:28.366808",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",
Expand Down
15 changes: 15 additions & 0 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class PurchaseInvoice(BuyingController):
supplied_items: DF.Table[PurchaseReceiptItemSupplied]
supplier: DF.Link
supplier_address: DF.Link | None
supplier_group: DF.Link | None
supplier_name: DF.Data | None
supplier_warehouse: DF.Link | None
tax_category: DF.Link | None
Expand All @@ -214,6 +215,8 @@ class PurchaseInvoice(BuyingController):
total_qty: DF.Float
total_taxes_and_charges: DF.Currency
unrealized_profit_loss_account: DF.Link | None
update_billed_amount_in_purchase_order: DF.Check
update_billed_amount_in_purchase_receipt: DF.Check
update_stock: DF.Check
use_company_roundoff_cost_center: DF.Check
use_transaction_date_exchange_rate: DF.Check
Expand Down Expand Up @@ -679,6 +682,11 @@ def on_submit(self):
super(PurchaseInvoice, self).on_submit()

self.check_prev_docstatus()

if self.is_return and not self.update_billed_amount_in_purchase_order:
# NOTE status updating bypassed for is_return
self.status_updater = []

self.update_status_updater_args()
self.update_prevdoc_status()

Expand Down Expand Up @@ -1426,6 +1434,10 @@ def on_cancel(self):

self.check_on_hold_or_closed_status()

if self.is_return and not self.update_billed_amount_in_purchase_order:
# NOTE status updating bypassed for is_return
self.status_updater = []

self.update_status_updater_args()
self.update_prevdoc_status()

Expand Down Expand Up @@ -1520,6 +1532,9 @@ def validate_supplier_invoice(self):
frappe.throw(_("Supplier Invoice No exists in Purchase Invoice {0}").format(pi))

def update_billing_status_in_pr(self, update_modified=True):
if self.is_return and not self.update_billed_amount_in_purchase_receipt:
return

updated_pr = []
po_details = []

Expand Down
32 changes: 32 additions & 0 deletions erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,38 @@ def test_purchase_order_advance_payment_status(self):
frappe.db.get_value(po.doctype, po.name, "advance_payment_status"), "Not Initiated"
)

def test_po_billed_amount_against_return_entry(self):
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_debit_note

# Create a Purchase Order and Fully Bill it
po = create_purchase_order()
pi = make_pi_from_po(po.name)
pi.insert()
pi.submit()

# Debit Note - 50% Qty & enable updating PO billed amount
pi_return = make_debit_note(pi.name)
pi_return.items[0].qty = -5
pi_return.update_billed_amount_in_purchase_order = 1
pi_return.submit()

# Check if the billed amount reduced
po.reload()
self.assertEqual(po.per_billed, 50)

pi_return.reload()
pi_return.cancel()

# Debit Note - 50% Qty & disable updating PO billed amount
pi_return = make_debit_note(pi.name)
pi_return.items[0].qty = -5
pi_return.update_billed_amount_in_purchase_order = 0
pi_return.submit()

# Check if the billed amount stayed the same
po.reload()
self.assertEqual(po.per_billed, 100)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down
35 changes: 35 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2430,6 +2430,41 @@ def test_auto_set_batch_based_on_bundle(self):

frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 0)

def test_pr_billed_amount_against_return_entry(self):
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_debit_note
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
make_purchase_invoice as make_pi_from_pr,
)

# Create a Purchase Receipt and Fully Bill it
pr = make_purchase_receipt(qty=10)
pi = make_pi_from_pr(pr.name)
pi.insert()
pi.submit()

# Debit Note - 50% Qty & enable updating PR billed amount
pi_return = make_debit_note(pi.name)
pi_return.items[0].qty = -5
pi_return.update_billed_amount_in_purchase_receipt = 1
pi_return.submit()

# Check if the billed amount reduced
pr.reload()
self.assertEqual(pr.per_billed, 50)

pi_return.reload()
pi_return.cancel()

# Debit Note - 50% Qty & disable updating PR billed amount
pi_return = make_debit_note(pi.name)
pi_return.items[0].qty = -5
pi_return.update_billed_amount_in_purchase_receipt = 0
pi_return.submit()

# Check if the billed amount stayed the same
pr.reload()
self.assertEqual(pr.per_billed, 100)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down
Loading