Create asset adjustment doctype, post gl entry for the asset

This commit is contained in:
Rohit Waghchaure
2018-05-11 01:56:05 +05:30
parent 0ea6fe4397
commit aa7b434270
22 changed files with 1695 additions and 805 deletions

View File

@@ -273,15 +273,16 @@ class AccountsController(TransactionBase):
def get_gl_dict(self, args, account_currency=None):
"""this method populates the common properties of a gl entry record"""
fiscal_years = get_fiscal_years(self.posting_date, company=self.company)
posting_date = args.get('posting_date') or self.get('posting_date')
fiscal_years = get_fiscal_years(posting_date, company=self.company)
if len(fiscal_years) > 1:
frappe.throw(_("Multiple fiscal years exist for the date {0}. Please set company in Fiscal Year").format(formatdate(self.posting_date)))
frappe.throw(_("Multiple fiscal years exist for the date {0}. Please set company in Fiscal Year").format(formatdate(posting_date)))
else:
fiscal_year = fiscal_years[0][0]
gl_dict = frappe._dict({
'company': self.company,
'posting_date': self.posting_date,
'posting_date': posting_date,
'fiscal_year': fiscal_year,
'voucher_type': self.doctype,
'voucher_no': self.name,

View File

@@ -11,7 +11,7 @@ from erpnext.stock.get_item_details import get_conversion_factor
from erpnext.buying.utils import validate_for_items, update_last_purchase_rate
from erpnext.stock.stock_ledger import get_valuation_rate
from erpnext.stock.doctype.stock_entry.stock_entry import get_used_alternative_items
from erpnext.stock.doctype.serial_no.serial_no import get_auto_serial_nos, auto_make_serial_nos
from erpnext.stock.doctype.serial_no.serial_no import get_auto_serial_nos, auto_make_serial_nos, get_serial_nos
from erpnext.controllers.stock_controller import StockController
@@ -505,6 +505,9 @@ class BuyingController(StockController):
self.make_asset_movement(d)
def make_asset(self, row):
if not row.asset_location:
frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code))
item_data = frappe.db.get_value('Item',
row.item_code, ['asset_naming_series', 'asset_category'], as_dict=1)
@@ -512,18 +515,21 @@ class BuyingController(StockController):
'doctype': 'Asset',
'item_code': row.item_code,
'asset_name': row.item_name,
'status': 'Receipt',
'naming_series': item_data.get('asset_naming_series') or 'AST',
'asset_category': item_data.get('asset_category'),
'warehouse': row.warehouse,
'location': row.asset_location,
'company': self.company,
'purchase_date': self.posting_date,
'calculate_depreciation': 1,
'gross_purchase_amount': flt(row.base_net_amount + row.item_tax_amount),
'purchase_receipt': self.name if self.doctype == 'Purchase Receipt' else None,
'purchase_invoice': self.name if self.doctype == 'Purchase Invoice' else None
})
asset.flags.ignore_validate = True
asset.flags.ignore_mandatory = True
asset.set_missing_values()
asset.insert()
frappe.msgprint(_("Asset {0} created").format(asset.name))
@@ -533,10 +539,10 @@ class BuyingController(StockController):
asset_movement = frappe.get_doc({
'doctype': 'Asset Movement',
'asset': row.asset,
'source_warehouse': '',
'target_warehouse': row.warehouse,
'target_location': row.asset_location,
'purpose': 'Receipt',
'serial_no': row.serial_no,
'quantity': len(get_serial_nos(row.serial_no)),
'company': self.company,
'transaction_date': self.posting_date,
'reference_doctype': self.doctype,
@@ -559,7 +565,7 @@ class BuyingController(StockController):
asset.set(field, self.name)
asset.purchase_date = self.posting_date
asset.supplier = self.supplier
else:
elif self.docstatus == 2:
asset.set(field, None)
asset.supplier = None