[Fix] Asset gl entry not creating for non perpetual

This commit is contained in:
Rohit Waghchaure 2018-05-16 18:16:08 +05:30
parent 64076730a1
commit 421697250b
7 changed files with 152 additions and 88 deletions

View File

@ -352,6 +352,7 @@ class PurchaseInvoice(BuyingController):
self.make_supplier_gl_entry(gl_entries)
self.make_item_gl_entries(gl_entries)
self.get_asset_gl_entry(gl_entries)
self.make_tax_gl_entries(gl_entries)
gl_entries = merge_similar_entries(gl_entries)
@ -389,10 +390,10 @@ class PurchaseInvoice(BuyingController):
warehouse_account = get_warehouse_account_map()
for item in self.get("items"):
if flt(item.base_net_amount):
if flt(item.base_net_amount) and item.item_code in stock_items:
account_currency = get_account_currency(item.expense_account)
if self.update_stock and self.auto_accounting_for_stock and item.item_code in stock_items:
if self.update_stock and self.auto_accounting_for_stock:
val_rate_db_precision = 6 if cint(item.precision("valuation_rate")) <= 6 else 9
# warehouse account
@ -434,50 +435,6 @@ class PurchaseInvoice(BuyingController):
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(item.rm_supp_cost)
}, warehouse_account[self.supplier_warehouse]["account_currency"]))
elif item.is_fixed_asset:
asset_accounts = self.get_company_default(["asset_received_but_not_billed",
"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
if not self.update_stock:
asset_rbnb_currency = get_account_currency(asset_accounts[0])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[0],
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if asset_rbnb_currency == self.company_currency else asset_amount)
}))
else:
cwip_account = get_asset_category_account(item.asset,
'capital_work_in_progress_account') or asset_accounts[2]
cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({
"account": cwip_account,
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if cwip_account_currency == self.company_currency else asset_amount)
}))
if item.item_tax_amount:
asset_eiiav_currency = get_account_currency(asset_accounts[0])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1],
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"cost_center": item.cost_center,
"credit": item.item_tax_amount,
"credit_in_account_currency": (item.item_tax_amount
if asset_eiiav_currency == self.company_currency else
item.item_tax_amount / self.conversion_rate)
}))
else:
gl_entries.append(
self.get_gl_dict({
@ -513,6 +470,67 @@ class PurchaseInvoice(BuyingController):
self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
item.precision("item_tax_amount"))
def get_asset_gl_entry(self, gl_entries):
for item in self.get("items"):
if item.is_fixed_asset:
asset_accounts = self.get_company_default(["asset_received_but_not_billed",
"expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
if not self.update_stock:
asset_rbnb_currency = get_account_currency(asset_accounts[0])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[0],
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if asset_rbnb_currency == self.company_currency else asset_amount)
}))
if item.item_tax_amount:
asset_eiiav_currency = get_account_currency(asset_accounts[0])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1],
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"cost_center": item.cost_center,
"credit": item.item_tax_amount,
"credit_in_account_currency": (item.item_tax_amount
if asset_eiiav_currency == self.company_currency else
item.item_tax_amount / self.conversion_rate)
}))
else:
cwip_account = get_asset_category_account(item.asset,
'capital_work_in_progress_account') or asset_accounts[2]
cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({
"account": cwip_account,
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if cwip_account_currency == self.company_currency else asset_amount)
}))
if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
asset_eiiav_currency = get_account_currency(asset_accounts[0])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1],
"against": self.supplier,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"cost_center": item.cost_center,
"credit": item.item_tax_amount,
"credit_in_account_currency": (item.item_tax_amount
if asset_eiiav_currency == self.company_currency else
item.item_tax_amount / self.conversion_rate)
}))
return gl_entries
def make_tax_gl_entries(self, gl_entries):
# tax table gl entries
valuation_tax = {}

View File

@ -2027,6 +2027,39 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"depends_on": "is_fixed_asset",
"fieldname": "asset_location",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Asset Location",
"length": 0,
"no_copy": 0,
"options": "Location",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
@ -2258,7 +2291,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
"modified": "2018-04-23 14:07:33.576495",
"modified": "2018-05-16 17:50:21.957780",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",

View File

@ -28,6 +28,7 @@ class Asset(AccountsController):
self.validate_expected_value_after_useful_life()
def on_submit(self):
self.validate_in_use_date()
self.set_status()
self.update_stock_movement()
@ -48,6 +49,10 @@ class Asset(AccountsController):
elif item.is_stock_item:
frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code))
def validate_in_use_date(self):
if not self.available_for_use_date:
frappe.throw(_("Available for use data is required"))
def set_missing_values(self):
if not self.asset_category:
self.asset_category = frappe.db.get_value("Item", self.item_code, "asset_category")

View File

@ -639,10 +639,10 @@ class AccountsController(TransactionBase):
frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
elif self.doctype == "Purchase Invoice":
if asset.status != "Submitted":
frappe.throw(_("Row #{0}: Asset {1} is already {2}")
.format(d.idx, d.asset, asset.status))
elif getdate(asset.purchase_date) != getdate(self.posting_date):
# if asset.status != "Submitted":
# frappe.throw(_("Row #{0}: Asset {1} is already {2}")
# .format(d.idx, d.asset, asset.status))
if getdate(asset.purchase_date) != getdate(self.posting_date):
frappe.throw(_("Row #{0}: Posting Date must be same as purchase date {1} of asset {2}").format(d.idx, asset.purchase_date, d.asset))
elif asset.is_existing_asset:
frappe.throw(_("Row #{0}: Purchase Invoice cannot be made against an existing asset {1}").format(d.idx, d.asset))

View File

@ -33,6 +33,10 @@ class StockController(AccountsController):
items, warehouses = self.get_items_and_warehouses()
update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items,
warehouse_account)
elif self.doctype in ['Purchase Receipt', 'Purchase Invoice']:
gl_entries = []
gl_entries = self.get_asset_gl_entry(gl_entries)
make_gl_entries(gl_entries, from_repost=from_repost)
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None):

View File

@ -62,9 +62,8 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
this._super();
if(this.frm.doc.docstatus===1) {
this.show_stock_ledger();
if (erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
this.show_general_ledger();
}
//removed for temporary
this.show_general_ledger();
this.frm.add_custom_button(__('Asset'), function() {
frappe.route_options = {

View File

@ -254,40 +254,7 @@ class PurchaseReceipt(BuyingController):
d.rejected_warehouse not in warehouse_with_no_account:
warehouse_with_no_account.append(d.warehouse)
elif d.is_fixed_asset:
asset_accounts = self.get_company_default(["capital_work_in_progress_account",
"asset_received_but_not_billed"])
# CWIP entry
cwip_account = get_asset_category_account(d.asset,
'capital_work_in_progress_account') or asset_accounts[0]
asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({
"account": cwip_account,
"against": asset_accounts[1],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if cwip_account_currency == self.company_currency else asset_amount)
}))
# Asset received but not billed
asset_rbnb_currency = get_account_currency(asset_accounts[1])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1],
"against": asset_accounts[0],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"credit": base_asset_amount,
"credit_in_account_currency": (base_asset_amount
if asset_rbnb_currency == self.company_currency else asset_amount)
}))
self.get_asset_gl_entry(gl_entries)
# Cost center-wise amount breakup for other charges included for valuation
valuation_tax = {}
for tax in self.get("taxes"):
@ -340,6 +307,44 @@ class PurchaseReceipt(BuyingController):
"\n".join(warehouse_with_no_account))
return process_gl_map(gl_entries)
def get_asset_gl_entry(self, gl_entries):
for d in self.get("items"):
if d.is_fixed_asset:
asset_accounts = self.get_company_default(["capital_work_in_progress_account",
"asset_received_but_not_billed"])
# CWIP entry
cwip_account = get_asset_category_account(d.asset,
'capital_work_in_progress_account') or asset_accounts[0]
asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
cwip_account_currency = get_account_currency(cwip_account)
gl_entries.append(self.get_gl_dict({
"account": cwip_account,
"against": asset_accounts[1],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"debit": base_asset_amount,
"debit_in_account_currency": (base_asset_amount
if cwip_account_currency == self.company_currency else asset_amount)
}))
# Asset received but not billed
asset_rbnb_currency = get_account_currency(asset_accounts[1])
gl_entries.append(self.get_gl_dict({
"account": asset_accounts[1],
"against": asset_accounts[0],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"credit": base_asset_amount,
"credit_in_account_currency": (base_asset_amount
if asset_rbnb_currency == self.company_currency else asset_amount)
}))
return gl_entries
def update_status(self, status):
self.set_status(update=True, status = status)