Purchase receipt gl entries if there is warehouse without account

This commit is contained in:
nabinhait 2014-07-25 12:02:36 +05:30 committed by Nabin Hait
parent f807cda375
commit cfd1b10980
2 changed files with 39 additions and 22 deletions

View File

@ -502,7 +502,8 @@ class TestSalesInvoice(unittest.TestCase):
"warehouse": "_Test Warehouse - _TC" "warehouse": "_Test Warehouse - _TC"
}) })
pos_setting.insert() if not frappe.db.exists("POS Setting", "_Test POS Setting"):
pos_setting.insert()
def test_si_gl_entry_with_aii_and_update_stock_with_warehouse_but_no_account(self): def test_si_gl_entry_with_aii_and_update_stock_with_warehouse_but_no_account(self):
self.clear_stock_account_balance() self.clear_stock_account_balance()

View File

@ -292,11 +292,12 @@ class PurchaseReceipt(BuyingController):
gl_entries = [] gl_entries = []
warehouse_with_no_account = [] warehouse_with_no_account = []
negative_expense_to_be_booked = 0.0
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
for d in self.get("purchase_receipt_details"): for d in self.get("purchase_receipt_details"):
if d.item_code in stock_items and flt(d.valuation_rate): if d.item_code in stock_items and flt(d.valuation_rate):
if warehouse_account.get(d.warehouse) and flt(d.qty) and flt(d.valuation_rate): if warehouse_account.get(d.warehouse) and flt(d.qty) and flt(d.valuation_rate):
# warehouse account # warehouse account
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
"account": warehouse_account[d.warehouse], "account": warehouse_account[d.warehouse],
@ -315,6 +316,8 @@ class PurchaseReceipt(BuyingController):
"credit": flt(d.base_amount, self.precision("base_amount", d)) "credit": flt(d.base_amount, self.precision("base_amount", d))
})) }))
negative_expense_to_be_booked += flt(d.item_tax_amount)
# Amount added through landed-cost-voucher # Amount added through landed-cost-voucher
if flt(d.landed_cost_voucher_amount): if flt(d.landed_cost_voucher_amount):
gl_entries.append(self.get_gl_dict({ gl_entries.append(self.get_gl_dict({
@ -349,29 +352,42 @@ class PurchaseReceipt(BuyingController):
valuation_tax[tax.cost_center] += \ valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount) (tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
# Backward compatibility: if negative_expense_to_be_booked and valuation_tax:
# If expenses_included_in_valuation account has been credited in against PI # Backward compatibility:
# and charges added via Landed Cost Voucher, # If expenses_included_in_valuation account has been credited in against PI
# post valuation related charges on "Stock Received But Not Billed" # and charges added via Landed Cost Voucher,
# post valuation related charges on "Stock Received But Not Billed"
stock_rbnb_booked_in_pi = frappe.db.sql("""select name from `tabPurchase Invoice Item` pi stock_rbnb_booked_in_pi = frappe.db.sql("""select name from `tabPurchase Invoice Item` pi
where docstatus = 1 and purchase_receipt=%s where docstatus = 1 and purchase_receipt=%s
and exists(select name from `tabGL Entry` where voucher_type='Purchase Invoice' and exists(select name from `tabGL Entry` where voucher_type='Purchase Invoice'
and voucher_no=pi.parent and account=%s)""", (self.name, stock_rbnb)) and voucher_no=pi.parent and account=%s)""", (self.name, stock_rbnb))
if stock_rbnb_booked_in_pi: if stock_rbnb_booked_in_pi:
expenses_included_in_valuation = stock_rbnb expenses_included_in_valuation = stock_rbnb
# Expense included in valuation against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0])
for cost_center, amount in valuation_tax.items(): total_valuation_amount = sum(valuation_tax.values())
gl_entries.append( amount_including_divisional_loss = negative_expense_to_be_booked
self.get_gl_dict({ i = 1
"account": expenses_included_in_valuation, for cost_center, amount in valuation_tax.items():
"cost_center": cost_center, if i == len(valuation_tax):
"credit": amount, applicable_amount = amount_including_divisional_loss
"remarks": self.remarks or "Accounting Entry for Stock" else:
}) applicable_amount = negative_expense_to_be_booked * (amount / total_valuation_amount)
) amount_including_divisional_loss -= applicable_amount
gl_entries.append(
self.get_gl_dict({
"account": expenses_included_in_valuation,
"cost_center": cost_center,
"credit": applicable_amount,
"remarks": self.remarks or "Accounting Entry for Stock",
"against": against_account
})
)
i += 1
if warehouse_with_no_account: if warehouse_with_no_account:
frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" + frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" +