Purchase receipt to purchase invoice item
diff --git a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
index 6a70c69..15611a3 100644
--- a/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
+++ b/erpnext/accounts/doctype/journal_voucher/journal_voucher.json
@@ -440,7 +440,7 @@
"icon": "icon-file-text",
"idx": 1,
"is_submittable": 1,
- "modified": "2014-05-01 11:24:52.313364",
+ "modified": "2014-05-01 17:07:31.129188",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Voucher",
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index ad645e7..86f1dd9 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -235,7 +235,7 @@
def check_expense_account(self, item):
if not item.get("expense_account"):
- frappe.throw(_("Expense or Difference account is mandatory for Item {0} as there is difference in value").format(item.item_code))
+ frappe.throw(_("Expense or Difference account is mandatory for Item {0} as it impacts overall stock value").format(item.item_code))
if item.get("expense_account") and not item.get("cost_center"):
frappe.throw(_("""Cost Center is mandatory for Item {0}""").format(item.get("item_code")))
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 8b134bd..2535860 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -290,12 +290,19 @@
@frappe.whitelist()
def make_purchase_invoice(source_name, target_doc=None):
from frappe.model.mapper import get_mapped_doc
+ invoiced_qty_map = get_invoiced_qty_map(source_name)
def set_missing_values(source, target):
+ if len(target.get("entries")) == 0:
+ frappe.throw(_("All items have already been invoiced"))
+
doc = frappe.get_doc(target)
doc.run_method("set_missing_values")
doc.run_method("calculate_taxes_and_totals")
+ def update_item(source_doc, target_doc, source_parent):
+ target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0)
+
doclist = get_mapped_doc("Purchase Receipt", source_name, {
"Purchase Receipt": {
"doctype": "Purchase Invoice",
@@ -311,6 +318,8 @@
"prevdoc_detail_docname": "po_detail",
"prevdoc_docname": "purchase_order",
},
+ "postprocess": update_item,
+ "filter": lambda d: d.qty - invoiced_qty_map.get(d.name, 0)<=0
},
"Purchase Taxes and Charges": {
"doctype": "Purchase Taxes and Charges",
@@ -319,3 +328,15 @@
}, target_doc, set_missing_values)
return doclist
+
+def get_invoiced_qty_map(purchase_receipt):
+ """returns a map: {pr_detail: invoiced_qty}"""
+ invoiced_qty_map = {}
+
+ for pr_detail, qty in frappe.db.sql("""select pr_detail, qty from `tabPurchase Invoice Item`
+ where purchase_receipt=%s and docstatus=1""", purchase_receipt):
+ if not invoiced_qty_map.get(pr_detail):
+ invoiced_qty_map[pr_detail] = 0
+ invoiced_qty_map[pr_detail] += qty
+
+ return invoiced_qty_map