Purchase receipt to purchase invoice item
This commit is contained in:
parent
292a254bc1
commit
d341254786
@ -440,7 +440,7 @@
|
|||||||
"icon": "icon-file-text",
|
"icon": "icon-file-text",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"modified": "2014-05-01 11:24:52.313364",
|
"modified": "2014-05-01 17:07:31.129188",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Journal Voucher",
|
"name": "Journal Voucher",
|
||||||
|
@ -235,7 +235,7 @@ class StockController(AccountsController):
|
|||||||
|
|
||||||
def check_expense_account(self, item):
|
def check_expense_account(self, item):
|
||||||
if not item.get("expense_account"):
|
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"):
|
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")))
|
frappe.throw(_("""Cost Center is mandatory for Item {0}""").format(item.get("item_code")))
|
||||||
|
@ -290,12 +290,19 @@ class PurchaseReceipt(BuyingController):
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_purchase_invoice(source_name, target_doc=None):
|
def make_purchase_invoice(source_name, target_doc=None):
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
invoiced_qty_map = get_invoiced_qty_map(source_name)
|
||||||
|
|
||||||
def set_missing_values(source, target):
|
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 = frappe.get_doc(target)
|
||||||
doc.run_method("set_missing_values")
|
doc.run_method("set_missing_values")
|
||||||
doc.run_method("calculate_taxes_and_totals")
|
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, {
|
doclist = get_mapped_doc("Purchase Receipt", source_name, {
|
||||||
"Purchase Receipt": {
|
"Purchase Receipt": {
|
||||||
"doctype": "Purchase Invoice",
|
"doctype": "Purchase Invoice",
|
||||||
@ -311,6 +318,8 @@ def make_purchase_invoice(source_name, target_doc=None):
|
|||||||
"prevdoc_detail_docname": "po_detail",
|
"prevdoc_detail_docname": "po_detail",
|
||||||
"prevdoc_docname": "purchase_order",
|
"prevdoc_docname": "purchase_order",
|
||||||
},
|
},
|
||||||
|
"postprocess": update_item,
|
||||||
|
"filter": lambda d: d.qty - invoiced_qty_map.get(d.name, 0)<=0
|
||||||
},
|
},
|
||||||
"Purchase Taxes and Charges": {
|
"Purchase Taxes and Charges": {
|
||||||
"doctype": "Purchase Taxes and Charges",
|
"doctype": "Purchase Taxes and Charges",
|
||||||
@ -319,3 +328,15 @@ def make_purchase_invoice(source_name, target_doc=None):
|
|||||||
}, target_doc, set_missing_values)
|
}, target_doc, set_missing_values)
|
||||||
|
|
||||||
return doclist
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user