Skip to content

Commit

Permalink
Merge branch 'develop' into quotation_order_item_syn
Browse files Browse the repository at this point in the history
  • Loading branch information
deepeshgarg007 authored Jun 25, 2022
2 parents 58fe220 + 9c1eb77 commit 904e69e
Show file tree
Hide file tree
Showing 49 changed files with 2,142 additions and 817 deletions.
16 changes: 0 additions & 16 deletions erpnext/accounts/doctype/journal_entry/journal_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,6 @@ frappe.ui.form.on("Journal Entry", {
}
});
}
else if(frm.doc.voucher_type=="Opening Entry") {
return frappe.call({
type:"GET",
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
args: {
"company": frm.doc.company
},
callback: function(r) {
frappe.model.clear_table(frm.doc, "accounts");
if(r.message) {
update_jv_details(frm.doc, r.message);
}
cur_frm.set_value("is_opening", "Yes");
}
});
}
}
},

Expand Down
5 changes: 3 additions & 2 deletions erpnext/accounts/doctype/journal_entry/journal_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"fieldname": "finance_book",
"fieldtype": "Link",
"label": "Finance Book",
"options": "Finance Book"
"options": "Finance Book",
"read_only": 1
},
{
"fieldname": "2_add_edit_gl_entries",
Expand Down Expand Up @@ -538,7 +539,7 @@
"idx": 176,
"is_submittable": 1,
"links": [],
"modified": "2022-04-06 17:18:46.865259",
"modified": "2022-06-23 22:01:32.348337",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry",
Expand Down
18 changes: 0 additions & 18 deletions erpnext/accounts/doctype/journal_entry/journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,24 +1204,6 @@ def get_payment_entry(ref_doc, args):
return je if args.get("journal_entry") else je.as_dict()


@frappe.whitelist()
def get_opening_accounts(company):
"""get all balance sheet accounts for opening entry"""
accounts = frappe.db.sql_list(
"""select
name from tabAccount
where
is_group=0 and report_type='Balance Sheet' and company={0} and
name not in (select distinct account from tabWarehouse where
account is not null and account != '')
order by name asc""".format(
frappe.db.escape(company)
)
)

return [{"account": a, "balance": get_balance_on(a)} for a in accounts]


@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_against_jv(doctype, txt, searchfield, start, page_len, filters):
Expand Down
48 changes: 48 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,54 @@ def test_payment(self):
jv.cancel()
self.assertEqual(frappe.db.get_value("Sales Invoice", w.name, "outstanding_amount"), 562.0)

def test_outstanding_on_cost_center_allocation(self):
# setup cost centers
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
from erpnext.accounts.doctype.cost_center_allocation.test_cost_center_allocation import (
create_cost_center_allocation,
)

cost_centers = [
"Main Cost Center 1",
"Sub Cost Center 1",
"Sub Cost Center 2",
]
for cc in cost_centers:
create_cost_center(cost_center_name=cc, company="_Test Company")

cca = create_cost_center_allocation(
"_Test Company",
"Main Cost Center 1 - _TC",
{"Sub Cost Center 1 - _TC": 60, "Sub Cost Center 2 - _TC": 40},
)

# make invoice
si = frappe.copy_doc(test_records[0])
si.is_pos = 0
si.insert()
si.submit()

from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry

# make payment - fully paid
pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC")
pe.reference_no = "1"
pe.reference_date = nowdate()
pe.paid_from_account_currency = si.currency
pe.paid_to_account_currency = si.currency
pe.source_exchange_rate = 1
pe.target_exchange_rate = 1
pe.paid_amount = si.outstanding_amount
pe.cost_center = cca.main_cost_center
pe.insert()
pe.submit()

# cancel cost center allocation
cca.cancel()

si.reload()
self.assertEqual(si.outstanding_amount, 0)

def test_sales_invoice_gl_entry_without_perpetual_inventory(self):
si = frappe.copy_doc(test_records[1])
si.insert()
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None):
for sub_cost_center, percentage in cost_center_allocation.get(cost_center, {}).items():
gle = copy.deepcopy(d)
gle.cost_center = sub_cost_center
for field in ("debit", "credit", "debit_in_account_currency", "credit_in_company_currency"):
for field in ("debit", "credit", "debit_in_account_currency", "credit_in_account_currency"):
gle[field] = flt(flt(d.get(field)) * percentage / 100, precision)
new_gl_map.append(gle)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_columns():
"options": "Account",
"width": 170,
},
{"label": _("Amount"), "fieldname": "amount", "width": 120},
{"label": _("Amount"), "fieldname": "amount", "fieldtype": "Currency", "width": 120},
]

return columns
Expand Down
2 changes: 1 addition & 1 deletion erpnext/accounts/report/general_ledger/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def update_value_in_dict(data, key, gle):
update_value_in_dict(totals, "opening", gle)
update_value_in_dict(totals, "closing", gle)

elif gle.posting_date <= to_date:
elif gle.posting_date <= to_date or (cstr(gle.is_opening) == "Yes" and show_opening_entries):
if not group_by_voucher_consolidated:
update_value_in_dict(gle_map[group_by_value].totals, "total", gle)
update_value_in_dict(gle_map[group_by_value].totals, "closing", gle)
Expand Down
20 changes: 14 additions & 6 deletions erpnext/assets/doctype/asset/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def _make_depreciation_schedule(self, finance_book, start, date_of_sale):
number_of_pending_depreciations += 1

skip_row = False
should_get_last_day = is_last_day_of_the_month(finance_book.depreciation_start_date)

for n in range(start[finance_book.idx - 1], number_of_pending_depreciations):
# If depreciation is already completed (for double declining balance)
Expand All @@ -265,6 +266,9 @@ def _make_depreciation_schedule(self, finance_book, start, date_of_sale):
finance_book.depreciation_start_date, n * cint(finance_book.frequency_of_depreciation)
)

if should_get_last_day:
schedule_date = get_last_day(schedule_date)

# schedule date will be a year later from start date
# so monthly schedule date is calculated by removing 11 months from it
monthly_schedule_date = add_months(schedule_date, -finance_book.frequency_of_depreciation + 1)
Expand Down Expand Up @@ -849,14 +853,9 @@ def get_depreciation_rate(self, args, on_validate=False):
if args.get("rate_of_depreciation") and on_validate:
return args.get("rate_of_depreciation")

no_of_years = (
flt(args.get("total_number_of_depreciations") * flt(args.get("frequency_of_depreciation")))
/ 12
)
value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount)

# square root of flt(salvage_value) / flt(asset_cost)
depreciation_rate = math.pow(value, 1.0 / flt(no_of_years, 2))
depreciation_rate = math.pow(value, 1.0 / flt(args.get("total_number_of_depreciations"), 2))

return 100 * (1 - flt(depreciation_rate, float_precision))

Expand Down Expand Up @@ -1105,9 +1104,18 @@ def is_cwip_accounting_enabled(asset_category):
def get_total_days(date, frequency):
period_start_date = add_months(date, cint(frequency) * -1)

if is_last_day_of_the_month(date):
period_start_date = get_last_day(period_start_date)

return date_diff(date, period_start_date)


def is_last_day_of_the_month(date):
last_day_of_the_month = get_last_day(date)

return getdate(last_day_of_the_month) == getdate(date)


@erpnext.allow_regional
def get_depreciation_amount(asset, depreciable_value, row):
if row.depreciation_method in ("Straight Line", "Manual"):
Expand Down
61 changes: 60 additions & 1 deletion erpnext/assets/doctype/asset/test_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,39 @@ def test_pro_rata_depreciation_entry_for_wdv(self):

self.assertEqual(schedules, expected_schedules)

def test_monthly_depreciation_by_wdv_method(self):
asset = create_asset(
calculate_depreciation=1,
available_for_use_date="2022-02-15",
purchase_date="2022-02-15",
depreciation_method="Written Down Value",
gross_purchase_amount=10000,
expected_value_after_useful_life=5000,
depreciation_start_date="2022-02-28",
total_number_of_depreciations=5,
frequency_of_depreciation=1,
)

expected_schedules = [
["2022-02-28", 645.0, 645.0],
["2022-03-31", 1206.8, 1851.8],
["2022-04-30", 1051.12, 2902.92],
["2022-05-31", 915.52, 3818.44],
["2022-06-30", 797.42, 4615.86],
["2022-07-15", 384.14, 5000.0],
]

schedules = [
[
cstr(d.schedule_date),
flt(d.depreciation_amount, 2),
flt(d.accumulated_depreciation_amount, 2),
]
for d in asset.get("schedules")
]

self.assertEqual(schedules, expected_schedules)

def test_discounted_wdv_depreciation_rate_for_indian_region(self):
# set indian company
company_flag = frappe.flags.company
Expand Down Expand Up @@ -838,7 +871,7 @@ def test_make_depreciation_schedule(self):
expected_values = [["2020-12-31", 30000.0], ["2021-12-31", 30000.0], ["2022-12-31", 30000.0]]

for i, schedule in enumerate(asset.schedules):
self.assertEqual(expected_values[i][0], schedule.schedule_date)
self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date)
self.assertEqual(expected_values[i][1], schedule.depreciation_amount)

def test_set_accumulated_depreciation(self):
Expand Down Expand Up @@ -1333,6 +1366,32 @@ def test_asset_cost_center(self):
asset.cost_center = "Main - _TC"
asset.submit()

def test_depreciation_on_final_day_of_the_month(self):
"""Tests if final day of the month is picked each time, if the depreciation start date is the last day of the month."""

asset = create_asset(
item_code="Macbook Pro",
calculate_depreciation=1,
purchase_date="2020-01-30",
available_for_use_date="2020-02-15",
depreciation_start_date="2020-02-29",
frequency_of_depreciation=1,
total_number_of_depreciations=5,
submit=1,
)

expected_dates = [
"2020-02-29",
"2020-03-31",
"2020-04-30",
"2020-05-31",
"2020-06-30",
"2020-07-15",
]

for i, schedule in enumerate(asset.schedules):
self.assertEqual(getdate(expected_dates[i]), getdate(schedule.schedule_date))


def create_asset_data():
if not frappe.db.exists("Asset Category", "Computers"):
Expand Down
Empty file.
48 changes: 48 additions & 0 deletions erpnext/crm/doctype/crm_note/crm_note.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"actions": [],
"autoname": "autoincrement",
"creation": "2022-06-04 15:49:23.416644",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"note",
"added_by",
"added_on"
],
"fields": [
{
"columns": 5,
"fieldname": "note",
"fieldtype": "Text Editor",
"in_list_view": 1,
"label": "Note"
},
{
"fieldname": "added_by",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Added By",
"options": "User"
},
{
"fieldname": "added_on",
"fieldtype": "Datetime",
"in_list_view": 1,
"label": "Added On"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2022-06-04 16:29:07.807252",
"modified_by": "Administrator",
"module": "CRM",
"name": "CRM Note",
"naming_rule": "Autoincrement",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions erpnext/crm/doctype/crm_note/crm_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class CRMNote(Document):
pass
17 changes: 2 additions & 15 deletions erpnext/crm/doctype/crm_settings/crm_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
"campaign_naming_by",
"allow_lead_duplication_based_on_emails",
"column_break_4",
"create_event_on_next_contact_date",
"auto_creation_of_contact",
"opportunity_section",
"close_opportunity_after_days",
"column_break_9",
"create_event_on_next_contact_date_opportunity",
"quotation_section",
"default_valid_till",
"section_break_13",
Expand Down Expand Up @@ -55,12 +53,6 @@
"fieldtype": "Check",
"label": "Auto Creation of Contact"
},
{
"default": "1",
"fieldname": "create_event_on_next_contact_date",
"fieldtype": "Check",
"label": "Create Event on Next Contact Date"
},
{
"fieldname": "opportunity_section",
"fieldtype": "Section Break",
Expand All @@ -73,12 +65,6 @@
"fieldtype": "Int",
"label": "Close Replied Opportunity After Days"
},
{
"default": "1",
"fieldname": "create_event_on_next_contact_date_opportunity",
"fieldtype": "Check",
"label": "Create Event on Next Contact Date"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
Expand All @@ -105,7 +91,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-12-20 12:51:38.894252",
"modified": "2022-06-06 11:22:08.464253",
"modified_by": "Administrator",
"module": "CRM",
"name": "CRM Settings",
Expand Down Expand Up @@ -143,5 +129,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
Loading

0 comments on commit 904e69e

Please sign in to comment.