[fix] set default depreciation accounts and test fix

This commit is contained in:
Rushabh Mehta 2016-03-31 15:02:11 +05:30
parent cb144bfcd4
commit acf28af19c
7 changed files with 100 additions and 77 deletions

View File

@ -17,6 +17,7 @@
"fieldtype": "Section Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "",
@ -41,6 +42,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -64,6 +66,7 @@
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_list_view": 1,
"label": "Account Name",
@ -90,6 +93,7 @@
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Group",
@ -114,6 +118,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_list_view": 0,
"label": "Company",
@ -140,6 +145,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Root Type",
@ -164,6 +170,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Report Type",
@ -189,6 +196,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Currency",
@ -214,6 +222,7 @@
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
@ -237,6 +246,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Parent Account",
@ -264,6 +274,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 1,
"in_list_view": 0,
"label": "Account Type",
@ -271,7 +282,7 @@
"no_copy": 0,
"oldfieldname": "account_type",
"oldfieldtype": "Select",
"options": "\nBank\nCash\nDepreciation\nTax\nChargeable\nWarehouse\nReceivable\nPayable\nEquity\nFixed Asset\nCost of Goods Sold\nExpense Account\nRound Off\nIncome Account\nStock Received But Not Billed\nExpenses Included In Valuation\nStock Adjustment\nStock\nTemporary",
"options": "\nAccumulated Depreciation\nBank\nCash\nChargeable\nCost of Goods Sold\nDepreciation\nEquity\nExpense Account\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nTax\nTemporary\nWarehouse",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
@ -291,6 +302,7 @@
"fieldtype": "Float",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rate",
@ -317,6 +329,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Frozen",
@ -343,6 +356,7 @@
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Warehouse",
@ -367,6 +381,7 @@
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Balance must be",
@ -391,6 +406,7 @@
"fieldtype": "Int",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Lft",
@ -414,6 +430,7 @@
"fieldtype": "Int",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Rgt",
@ -437,6 +454,7 @@
"fieldtype": "Data",
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Old Parent",
@ -463,7 +481,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-12-12 10:19:54.365839",
"modified": "2016-03-31 05:15:51.062604",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Account",
@ -572,5 +590,7 @@
],
"read_only": 0,
"read_only_onload": 0,
"search_fields": ""
"search_fields": "",
"sort_order": "ASC",
"track_seen": 0
}

View File

@ -53,7 +53,9 @@ def get():
_("Plant and Machinery"): {
"account_type": "Fixed Asset"
},
_("Accumulated Depreciations"): {}
_("Accumulated Depreciation"): {
"account_type": "Accumulated Depreciation"
}
},
_("Investments"): {
"is_group": 1
@ -89,7 +91,7 @@ def get():
"account_type": "Expense Account"
},
_("Depreciation"): {
"account_type": "Expense Account"
"account_type": "Depreciation"
},
_("Entertainment Expenses"): {
"account_type": "Expense Account"

View File

@ -108,7 +108,7 @@
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 1,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
@ -576,14 +576,14 @@
],
"hide_heading": 0,
"hide_toolbar": 0,
"idx": 0,
"idx": 72,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2016-03-30 05:25:56.710106",
"modified": "2016-03-31 05:02:49.890116",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Asset",
@ -609,26 +609,6 @@
"share": 1,
"submit": 1,
"write": 1
},
{
"amend": 1,
"apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"if_owner": 0,
"import": 1,
"permlevel": 0,
"print": 1,
"read": 1,
"report": 1,
"role": "Accounts Manager",
"set_user_permissions": 0,
"share": 1,
"submit": 1,
"write": 1
}
],
"read_only": 0,

View File

@ -10,7 +10,7 @@ from frappe.model.document import Document
class Asset(Document):
def validate(self):
self.set_status()
self.status = self.get_status()
self.validate_fixed_asset_item()
self.validate_asset_values()
self.set_depreciation_settings()
@ -112,7 +112,13 @@ class Asset(Document):
.format(company.meta.get_label(field), self.company))
def set_status(self, status=None):
'''Set asset and update status'''
if not status:
status = self.get_status()
self.db_set("status", status)
def get_status(self):
'''Returns status based on whether it is draft, submitted, scrapped or depreciated'''
if self.docstatus == 0:
status = "Draft"
elif self.docstatus == 1:
@ -126,4 +132,4 @@ class Asset(Document):
elif self.docstatus == 2:
status = "Cancelled"
self.db_set("status", status)
return status

View File

@ -1,5 +1,6 @@
from __future__ import unicode_literals
import frappe
import calendar
import frappe.utils
import frappe.defaults
@ -172,7 +173,17 @@ def validate_recurring_next_date(doc):
if getdate(posting_date) > getdate(doc.next_date):
frappe.throw(_("Next Date must be greater than Posting Date"))
if getdate(doc.next_date).day != doc.repeat_on_day_of_month:
next_date = getdate(doc.next_date)
if next_date.day != doc.repeat_on_day_of_month:
# if the repeat day is the last day of the month (31)
# and the current month does not have as many days,
# then the last day of the current month is a valid date
lastday = calendar.monthrange(next_date.year, next_date.month)[1]
if doc.repeat_on_day_of_month < lastday:
# the specified day of the month is not same as the day specified
# or the last day of the month
frappe.throw(_("Next Date's day and Repeat on Day of Month must be equal"))
def convert_to_recurring(doc, posting_date):

View File

@ -111,6 +111,8 @@ class Company(Document):
self._set_default_account("default_cash_account", "Cash")
self._set_default_account("default_bank_account", "Bank")
self._set_default_account("round_off_account", "Round Off")
self._set_default_account("accumulated_depreciation_account", "Accumulated Depreciation")
self._set_default_account("depreciation_expense_account", "Depreciation")
if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")):
self._set_default_account("stock_received_but_not_billed", "Stock Received But Not Billed")
@ -159,6 +161,7 @@ class Company(Document):
frappe.db.set(self, "cost_center", _("Main") + " - " + self.abbr)
frappe.db.set(self, "round_off_cost_center", _("Main") + " - " + self.abbr)
frappe.db.set(self, "depreciation_cost_center", _("Main") + " - " + self.abbr)
def before_rename(self, olddn, newdn, merge=False):
if merge:

View File

@ -191,7 +191,8 @@ class TestShoppingCart(unittest.TestCase):
frappe.set_user("test_cart_user@example.com")
def login_as_customer(self):
self.create_user_if_not_exists("test_contact_customer@example.com")
self.create_user_if_not_exists("test_contact_customer@example.com",
"_Test Contact For _Test Customer")
frappe.set_user("test_contact_customer@example.com")
def remove_all_items_from_cart(self):
@ -199,7 +200,7 @@ class TestShoppingCart(unittest.TestCase):
quotation.set("items", [])
quotation.save(ignore_permissions=True)
def create_user_if_not_exists(self, email):
def create_user_if_not_exists(self, email, first_name = None):
if frappe.db.exists("User", email):
return
@ -208,7 +209,7 @@ class TestShoppingCart(unittest.TestCase):
"user_type": "Website User",
"email": email,
"send_welcome_email": 0,
"first_name": email.split("@")[0]
"first_name": first_name or email.split("@")[0]
}).insert(ignore_permissions=True)
test_dependencies = ["Sales Taxes and Charges Template", "Price List", "Item Price", "Shipping Rule", "Currency Exchange",