Skip to content

Commit

Permalink
chore: release v15 (#42308)
Browse files Browse the repository at this point in the history
* fix(Warehouse): add buttons only if the user can use them

(cherry picked from commit 10ae5aa)

* fix: missing discount on POS Credit Notes

(cherry picked from commit 1049550)

* chore: rename test suite for payable report

(cherry picked from commit 9474f72)

* refactor: test suite for item-wise sales register

(cherry picked from commit 3aaa22e)

* refactor(test): use each instance UOM for assertion

(cherry picked from commit cf4fbfb)

* fix: slowness in reposting dependent vouchers. (backport #42282) (#42292)

fix: slowness in reposting dependent vouchers. (#42282)

(cherry picked from commit b17696a)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>

* refactor(test): clear old records

* fix: keep status as In Progress for RIV for Timeout Error (backport #42274) (#42296)

fix: keep status as In Progress for RIV for Timeout Error (#42274)

(cherry picked from commit 10280d6)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>

* fix: cost center filter by company (backport #42297) (#42299)

fix: cost center filter by company (#42297)

(cherry picked from commit 9838f7e)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>

* feat: configurable depreciation calculation via accounts settings (#42276)

* feat: configurable depreciation calculation via accounts settings

* refactor: code optimization

* style: changes in description and label

(cherry picked from commit b04da63)

* fix: not able to submit LCV entry (backport #42303) (#42304)

fix: not able to submit LCV entry (#42303)

(cherry picked from commit 9cf92ea)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>

* fix: While submitting PCV ensure previous FY is closed (backport #42284) (#42300)

fix: While submitting PCV ensure previous FY is closed (#42284)

(cherry picked from commit d0bbc8c)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>

---------

Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
Co-authored-by: ruthra kumar <ruthra@erpnext.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
  • Loading branch information
6 people committed Jul 12, 2024
1 parent f975333 commit ce8b423
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 37 deletions.
17 changes: 15 additions & 2 deletions erpnext/accounts/doctype/accounts_settings/accounts_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"post_change_gl_entries",
"assets_tab",
"asset_settings_section",
"calculate_depr_using_total_days",
"column_break_gjcc",
"book_asset_depreciation_entry_automatically",
"closing_settings_tab",
"period_closing_settings_section",
Expand Down Expand Up @@ -462,14 +464,25 @@
"fieldname": "enable_immutable_ledger",
"fieldtype": "Check",
"label": "Enable Immutable Ledger"
},
{
"fieldname": "column_break_gjcc",
"fieldtype": "Column Break"
},
{
"default": "0",
"description": "Enable this option to calculate daily depreciation by considering the total number of days in the entire depreciation period, (including leap years) while using daily pro-rata based depreciation",
"fieldname": "calculate_depr_using_total_days",
"fieldtype": "Check",
"label": "Calculate daily depreciation using total days in depreciation period"
}
],
"icon": "icon-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-05-11 23:19:44.673975",
"modified": "2024-07-12 00:24:20.957726",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounts Settings",
Expand Down Expand Up @@ -498,4 +511,4 @@
"sort_order": "ASC",
"states": [],
"track_changes": 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AccountsSettings(Document):
book_deferred_entries_based_on: DF.Literal["Days", "Months"]
book_deferred_entries_via_journal_entry: DF.Check
book_tax_discount_loss: DF.Check
calculate_depr_using_total_days: DF.Check
check_supplier_invoice_uniqueness: DF.Check
credit_controller: DF.Link | None
delete_linked_ledger_entries: DF.Check
Expand Down
37 changes: 37 additions & 0 deletions erpnext/accounts/doctype/journal_entry/test_journal_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,43 @@ def check_gl_entries(self):
for field in self.fields:
self.assertEqual(self.expected_gle[i][field], gl_entries[i][field])

def test_negative_debit_and_credit_with_same_account_head(self):
from erpnext.accounts.general_ledger import process_gl_map

# Create JV with defaut cost center - _Test Cost Center
frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 0)

jv = make_journal_entry("_Test Bank - _TC", "_Test Bank - _TC", 100 * -1, save=True)
jv.append(
"accounts",
{
"account": "_Test Cash - _TC",
"debit": 100 * -1,
"credit": 100 * -1,
"debit_in_account_currency": 100 * -1,
"credit_in_account_currency": 100 * -1,
"exchange_rate": 1,
},
)
jv.flags.ignore_validate = True
jv.save()

self.assertEqual(len(jv.accounts), 3)

gl_map = jv.build_gl_map()

for row in gl_map:
if row.account == "_Test Cash - _TC":
self.assertEqual(row.debit_in_account_currency, 100 * -1)
self.assertEqual(row.credit_in_account_currency, 100 * -1)

gl_map = process_gl_map(gl_map, False)

for row in gl_map:
if row.account == "_Test Cash - _TC":
self.assertEqual(row.debit_in_account_currency, 100)
self.assertEqual(row.credit_in_account_currency, 100)


def make_journal_entry(
account1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,28 @@ def validate_posting_date(self):

def check_if_previous_year_closed(self):
last_year_closing = add_days(self.year_start_date, -1)

previous_fiscal_year = get_fiscal_year(last_year_closing, company=self.company, boolean=True)
if not previous_fiscal_year:
return

if previous_fiscal_year and not frappe.db.exists(
previous_fiscal_year_start_date = previous_fiscal_year[0][1]
if not frappe.db.exists(
"GL Entry",
{"posting_date": ("<=", last_year_closing), "company": self.company, "is_cancelled": 0},
{
"posting_date": ("between", [previous_fiscal_year_start_date, last_year_closing]),
"company": self.company,
"is_cancelled": 0,
},
):
return

if previous_fiscal_year and not frappe.db.exists(
if not frappe.db.exists(
"Period Closing Voucher",
{"posting_date": ("<=", last_year_closing), "docstatus": 1, "company": self.company},
{
"posting_date": ("between", [previous_fiscal_year_start_date, last_year_closing]),
"docstatus": 1,
"company": self.company,
},
):
frappe.throw(_("Previous Year is not closed, please close it first"))

Expand Down
3 changes: 3 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends (
return this.frm.call({
doc: me.frm.doc,
method: "set_missing_values",
args: {
for_validate: true,
},
callback: function (r) {
if (!r.exc) {
if (r.message && r.message.print_format) {
Expand Down
12 changes: 12 additions & 0 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,18 @@ def check_if_in_list(gle, gl_map):
def toggle_debit_credit_if_negative(gl_map):
for entry in gl_map:
# toggle debit, credit if negative entry
if flt(entry.debit) < 0 and flt(entry.credit) < 0 and flt(entry.debit) == flt(entry.credit):
entry.credit *= -1
entry.debit *= -1

if (
flt(entry.debit_in_account_currency) < 0
and flt(entry.credit_in_account_currency) < 0
and flt(entry.debit_in_account_currency) == flt(entry.credit_in_account_currency)
):
entry.credit_in_account_currency *= -1
entry.debit_in_account_currency *= -1

if flt(entry.debit) < 0:
entry.credit = flt(entry.credit) - flt(entry.debit)
entry.debit = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin


class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
class TestAccountsPayable(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.create_company()
self.create_customer()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import getdate, today

from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.report.item_wise_sales_register.item_wise_sales_register import execute
from erpnext.accounts.test.accounts_mixin import AccountsTestMixin


class TestItemWiseSalesRegister(AccountsTestMixin, FrappeTestCase):
def setUp(self):
self.create_company()
self.create_customer()
self.create_item()
self.clear_old_entries()

def tearDown(self):
frappe.db.rollback()

def create_sales_invoice(self, do_not_submit=False):
si = create_sales_invoice(
item=self.item,
company=self.company,
customer=self.customer,
debit_to=self.debit_to,
posting_date=today(),
parent_cost_center=self.cost_center,
cost_center=self.cost_center,
rate=100,
price_list_rate=100,
do_not_save=1,
)
si = si.save()
if not do_not_submit:
si = si.submit()
return si

def test_basic_report_output(self):
si = self.create_sales_invoice()

filters = frappe._dict({"from_date": today(), "to_date": today(), "company": self.company})
report = execute(filters)

self.assertEqual(len(report[1]), 1)

expected_result = {
"item_code": si.items[0].item_code,
"invoice": si.name,
"posting_date": getdate(),
"customer": si.customer,
"debit_to": si.debit_to,
"company": self.company,
"income_account": si.items[0].income_account,
"stock_qty": 1.0,
"stock_uom": si.items[0].stock_uom,
"rate": 100.0,
"amount": 100.0,
"total_tax": 0,
"total_other_charges": 0,
"total": 100.0,
"currency": "INR",
}

report_output = {k: v for k, v in report[1][0].items() if k in expected_result}
self.assertDictEqual(report_output, expected_result)
Original file line number Diff line number Diff line change
Expand Up @@ -701,20 +701,57 @@ def get_straight_line_or_manual_depr_amount(
def get_daily_prorata_based_straight_line_depr(
asset, row, schedule_idx, number_of_pending_depreciations, amount
):
total_years = flt(number_of_pending_depreciations * row.frequency_of_depreciation) / 12
every_year_depr = amount / total_years
daily_depr_amount = get_daily_depr_amount(asset, row, schedule_idx, amount)

year_start_date = add_years(
row.depreciation_start_date, (row.frequency_of_depreciation * schedule_idx) // 12
)
year_end_date = add_days(add_years(year_start_date, 1), -1)
daily_depr_amount = every_year_depr / (date_diff(year_end_date, year_start_date) + 1)
from_date, total_depreciable_days = _get_total_days(
row.depreciation_start_date, schedule_idx, row.frequency_of_depreciation
)
return daily_depr_amount * total_depreciable_days


def get_daily_depr_amount(asset, row, schedule_idx, amount):
if cint(frappe.db.get_single_value("Accounts Settings", "calculate_depr_using_total_days")):
total_days = (
date_diff(
get_last_day(
add_months(
row.depreciation_start_date,
flt(
row.total_number_of_depreciations
- asset.opening_number_of_booked_depreciations
- 1
)
* row.frequency_of_depreciation,
)
),
add_days(
get_last_day(add_months(row.depreciation_start_date, -1 * row.frequency_of_depreciation)),
1,
),
)
+ 1
)

return amount / total_days
else:
total_years = (
flt(
(row.total_number_of_depreciations - row.total_number_of_booked_depreciations)
* row.frequency_of_depreciation
)
/ 12
)

every_year_depr = amount / total_years

year_start_date = add_years(
row.depreciation_start_date, (row.frequency_of_depreciation * schedule_idx) // 12
)
year_end_date = add_days(add_years(year_start_date, 1), -1)

return every_year_depr / (date_diff(year_end_date, year_start_date) + 1)


def get_shift_depr_amount(asset_depr_schedule, asset, row, schedule_idx):
if asset_depr_schedule.get("__islocal") and not asset.flags.shift_allocation:
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,68 @@ def test_daily_prorata_based_depr_on_sl_method(self):
]
self.assertEqual(schedules, expected_schedules)

# Enable Checkbox to Calculate depreciation using total days in depreciation period
def test_daily_prorata_based_depr_after_enabling_configuration(self):
frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 1)

asset = create_asset(
calculate_depreciation=1,
depreciation_method="Straight Line",
daily_prorata_based=1,
gross_purchase_amount=1096,
available_for_use_date="2020-01-15",
depreciation_start_date="2020-01-31",
frequency_of_depreciation=1,
total_number_of_depreciations=36,
)

expected_schedule = [
["2020-01-31", 17.0, 17.0],
["2020-02-29", 29.0, 46.0],
["2020-03-31", 31.0, 77.0],
["2020-04-30", 30.0, 107.0],
["2020-05-31", 31.0, 138.0],
["2020-06-30", 30.0, 168.0],
["2020-07-31", 31.0, 199.0],
["2020-08-31", 31.0, 230.0],
["2020-09-30", 30.0, 260.0],
["2020-10-31", 31.0, 291.0],
["2020-11-30", 30.0, 321.0],
["2020-12-31", 31.0, 352.0],
["2021-01-31", 31.0, 383.0],
["2021-02-28", 28.0, 411.0],
["2021-03-31", 31.0, 442.0],
["2021-04-30", 30.0, 472.0],
["2021-05-31", 31.0, 503.0],
["2021-06-30", 30.0, 533.0],
["2021-07-31", 31.0, 564.0],
["2021-08-31", 31.0, 595.0],
["2021-09-30", 30.0, 625.0],
["2021-10-31", 31.0, 656.0],
["2021-11-30", 30.0, 686.0],
["2021-12-31", 31.0, 717.0],
["2022-01-31", 31.0, 748.0],
["2022-02-28", 28.0, 776.0],
["2022-03-31", 31.0, 807.0],
["2022-04-30", 30.0, 837.0],
["2022-05-31", 31.0, 868.0],
["2022-06-30", 30.0, 898.0],
["2022-07-31", 31.0, 929.0],
["2022-08-31", 31.0, 960.0],
["2022-09-30", 30.0, 990.0],
["2022-10-31", 31.0, 1021.0],
["2022-11-30", 30.0, 1051.0],
["2022-12-31", 31.0, 1082.0],
["2023-01-15", 14.0, 1096.0],
]

schedules = [
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
for d in get_depr_schedule(asset.name, "Draft")
]
self.assertEqual(schedules, expected_schedule)
frappe.db.set_single_value("Accounts Settings", "calculate_depr_using_total_days", 0)

# Test for Written Down Value Method
# Frequency of deprciation = 3
def test_for_daily_prorata_based_depreciation_wdv_method_frequency_3_months(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def repost(doc):
if isinstance(message, dict):
message = message.get("message")

status = "Failed"
# If failed because of timeout, set status to In Progress
if traceback and "timeout" in traceback.lower():
status = "In Progress"

if traceback:
message += "<br><br>" + "<b>Traceback:</b> <br>" + traceback

Expand All @@ -297,7 +302,7 @@ def repost(doc):
doc.name,
{
"error_log": message,
"status": "Failed",
"status": status,
},
)

Expand Down
Loading

0 comments on commit ce8b423

Please sign in to comment.