purchase receipt gl entries
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 3b6ad82..27f2064 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -316,16 +316,25 @@
stock_item_and_auto_accounting_for_stock = False
stock_items = self.get_stock_items()
for item in self.get("entries"):
- if auto_accounting_for_stock and item.item_code in stock_items:
- if flt(item.valuation_rate):
+ if flt(item.base_amount):
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": item.expense_account,
+ "against": self.credit_to,
+ "debit": item.base_amount,
+ "remarks": self.remarks,
+ "cost_center": item.cost_center
+ })
+ )
+
+ if auto_accounting_for_stock and item.item_code in stock_items and item.valuation_rate:
# if auto inventory accounting enabled and stock item,
# then do stock related gl entries
# expense will be booked in sales invoice
stock_item_and_auto_accounting_for_stock = True
- valuation_amt = flt(item.base_amount + item.item_tax_amount,
- self.precision("base_amount", item))
-
+
+
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
@@ -352,7 +361,10 @@
# this will balance out valuation amount included in cost of goods sold
expenses_included_in_valuation = \
self.get_company_default("expenses_included_in_valuation")
-
+
+ # Backward compatibility:
+ # Post expenses_included_in_valuation only if it is not booked in Purchase Receipt
+
for cost_center, amount in valuation_tax.items():
gl_entries.append(
self.get_gl_dict({
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 4eb3553..1f02f36 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -312,7 +312,7 @@
"against": warehouse_account[d.warehouse],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or "Accounting Entry for Stock",
- "credit": flt(d.base_amount + d.item_tax_amount, self.precision("base_amount", d))
+ "credit": flt(d.base_amount, self.precision("base_amount", d))
}))
# Amount added through landed-cost-voucher
@@ -338,6 +338,40 @@
elif d.warehouse not in warehouse_with_no_account or \
d.rejected_warehouse not in warehouse_with_no_account:
warehouse_with_no_account.append(d.warehouse)
+
+ # Cost center-wise amount breakup for other charges included for valuation
+ valuation_tax = {}
+ for tax in self.get("other_charges"):
+ if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
+ if not tax.cost_center:
+ frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
+ valuation_tax.setdefault(tax.cost_center, 0)
+ valuation_tax[tax.cost_center] += \
+ (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
+
+ # Backward compatibility:
+ # If expenses_included_in_valuation account has been credited in against PI
+ # and charges added via Landed Cost Voucher,
+ # post valuation related charges on "Stock Received But Not Billed"
+
+ pi_exists = frappe.db.sql("""select name from `tabPurchase Invoice Item` pi
+ where docstatus = 1 and purchase_receipt=%s
+ and exists(select name from `tabGL Entry` where voucher_type='Purchase Invoice'
+ and voucher_no=pi.parent and account=%s)""", (self.name, expenses_included_in_valuation))
+
+ if pi_exists:
+ expenses_included_in_valuation = stock_rbnb
+
+ # Expense included in valuation
+ for cost_center, amount in valuation_tax.items():
+ gl_entries.append(
+ self.get_gl_dict({
+ "account": expenses_included_in_valuation,
+ "cost_center": cost_center,
+ "credit": amount,
+ "remarks": self.remarks or "Accounting Entry for Stock"
+ })
+ )
if warehouse_with_no_account:
frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" +