mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-20 09:56:31 +00:00
fix: incorrect pending qty when creating PI from PO and PI rates differ from PO (backport #48173) (#48340)
* fix: incorrect pending qty when creating PI from PO and PI rates differ from PO Co-authored-by: Mihir Kandoi <kandoimihir@gmail.com>
This commit is contained in:
@@ -807,11 +807,19 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
|||||||
target.credit_to = get_party_account("Supplier", source.supplier, source.company)
|
target.credit_to = get_party_account("Supplier", source.supplier, source.company)
|
||||||
|
|
||||||
def update_item(obj, target, source_parent):
|
def update_item(obj, target, source_parent):
|
||||||
target.amount = flt(obj.amount) - flt(obj.billed_amt)
|
def get_billed_qty(po_item_name):
|
||||||
target.base_amount = target.amount * flt(source_parent.conversion_rate)
|
from frappe.query_builder.functions import Sum
|
||||||
target.qty = (
|
|
||||||
target.amount / flt(obj.rate) if (flt(obj.rate) and flt(obj.billed_amt)) else flt(obj.qty)
|
table = frappe.qb.DocType("Purchase Invoice Item")
|
||||||
)
|
query = (
|
||||||
|
frappe.qb.from_(table)
|
||||||
|
.select(Sum(table.qty).as_("qty"))
|
||||||
|
.where((table.docstatus == 1) & (table.po_detail == po_item_name))
|
||||||
|
)
|
||||||
|
return query.run(pluck="qty")[0] or 0
|
||||||
|
|
||||||
|
billed_qty = flt(get_billed_qty(obj.name))
|
||||||
|
target.qty = flt(obj.qty) - billed_qty
|
||||||
|
|
||||||
item = get_item_defaults(target.item_code, source_parent.company)
|
item = get_item_defaults(target.item_code, source_parent.company)
|
||||||
item_group = get_item_group_defaults(target.item_code, source_parent.company)
|
item_group = get_item_group_defaults(target.item_code, source_parent.company)
|
||||||
|
|||||||
@@ -1286,6 +1286,25 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
self.assertFalse(po.per_billed)
|
self.assertFalse(po.per_billed)
|
||||||
self.assertEqual(po.status, "To Receive and Bill")
|
self.assertEqual(po.status, "To Receive and Bill")
|
||||||
|
|
||||||
|
@change_settings("Buying Settings", {"maintain_same_rate": 0})
|
||||||
|
def test_purchase_invoice_creation_with_partial_qty(self):
|
||||||
|
po = create_purchase_order(qty=100, rate=10)
|
||||||
|
|
||||||
|
pi = make_pi_from_po(po.name)
|
||||||
|
pi.items[0].qty = 42
|
||||||
|
pi.items[0].rate = 7.5
|
||||||
|
pi.submit()
|
||||||
|
|
||||||
|
pi = make_pi_from_po(po.name)
|
||||||
|
self.assertEqual(pi.items[0].qty, 58)
|
||||||
|
self.assertEqual(pi.items[0].rate, 10)
|
||||||
|
pi.items[0].qty = 8
|
||||||
|
pi.items[0].rate = 5
|
||||||
|
pi.submit()
|
||||||
|
|
||||||
|
pi = make_pi_from_po(po.name)
|
||||||
|
self.assertEqual(pi.items[0].qty, 50)
|
||||||
|
|
||||||
|
|
||||||
def create_po_for_sc_testing():
|
def create_po_for_sc_testing():
|
||||||
from erpnext.controllers.tests.test_subcontracting_controller import (
|
from erpnext.controllers.tests.test_subcontracting_controller import (
|
||||||
|
|||||||
Reference in New Issue
Block a user