mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 11:39:18 +00:00
fix: incorrect pending qty when creating PI from PO and PI rates differ from PO
This commit is contained in:
@@ -831,11 +831,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user