From 1101b7bfdfebe01ddcca5ccd48b455e389e2048d Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Tue, 4 Apr 2023 17:49:16 +0530 Subject: [PATCH 1/7] fix: don't include cancelled JVs in assdeprledger report (cherry picked from commit 3896d41e95a2054b4ec76c5f5b2819b3f28ef98e) --- .../asset_depreciation_ledger/asset_depreciation_ledger.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py index 57d80492ae..f21c94b494 100644 --- a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py +++ b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py @@ -25,6 +25,7 @@ def get_data(filters): ["posting_date", "<=", filters.get("to_date")], ["against_voucher_type", "=", "Asset"], ["account", "in", depreciation_accounts], + ["is_cancelled", "=", 0], ] if filters.get("asset"): From 5cc3c080590845fe8199641912961f548b151970 Mon Sep 17 00:00:00 2001 From: Anand Baburajan Date: Wed, 5 Apr 2023 11:46:31 +0530 Subject: [PATCH 2/7] fix: asset monthly WDV and DD schedule and refactor [develop] (#34646) * fix: monthly wdv and dd schedule * chore: minor rename * chore: fix tests --- erpnext/assets/doctype/asset/asset.py | 86 ++----- erpnext/assets/doctype/asset/test_asset.py | 25 ++- .../asset_depreciation_schedule.py | 209 ++++++++++++++++-- 3 files changed, 221 insertions(+), 99 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index b5b7ba88f5..6001254762 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -8,16 +8,12 @@ import math import frappe from frappe import _ from frappe.utils import ( - add_months, cint, - date_diff, flt, get_datetime, get_last_day, get_link_to_form, getdate, - is_last_day_of_the_month, - month_diff, nowdate, today, ) @@ -239,30 +235,6 @@ class Asset(AccountsController): self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation") ) - # if it returns True, depreciation_amount will not be equal for the first and last rows - def check_is_pro_rata(self, row): - has_pro_rata = False - - # if not existing asset, from_date = available_for_use_date - # otherwise, if number_of_depreciations_booked = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12 - # from_date = 01/01/2022 - from_date = self.get_modified_available_for_use_date(row) - days = date_diff(row.depreciation_start_date, from_date) + 1 - - # if frequency_of_depreciation is 12 months, total_days = 365 - total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation) - - if days < total_days: - has_pro_rata = True - - return has_pro_rata - - def get_modified_available_for_use_date(self, row): - return add_months( - self.available_for_use_date, - (self.number_of_depreciations_booked * row.frequency_of_depreciation), - ) - def validate_asset_finance_books(self, row): if flt(row.expected_value_after_useful_life) >= flt(self.gross_purchase_amount): frappe.throw( @@ -471,29 +443,6 @@ class Asset(AccountsController): return records - @erpnext.allow_regional - def get_depreciation_amount(self, depreciable_value, fb_row): - if fb_row.depreciation_method in ("Straight Line", "Manual"): - # if the Depreciation Schedule is being modified after Asset Repair due to increase in asset life and value - if self.flags.increase_in_asset_life: - depreciation_amount = ( - flt(fb_row.value_after_depreciation) - flt(fb_row.expected_value_after_useful_life) - ) / (date_diff(self.to_date, self.available_for_use_date) / 365) - # if the Depreciation Schedule is being modified after Asset Repair due to increase in asset value - elif self.flags.increase_in_asset_value_due_to_repair: - depreciation_amount = ( - flt(fb_row.value_after_depreciation) - flt(fb_row.expected_value_after_useful_life) - ) / flt(fb_row.total_number_of_depreciations) - # if the Depreciation Schedule is being prepared for the first time - else: - depreciation_amount = ( - flt(self.gross_purchase_amount) - flt(fb_row.expected_value_after_useful_life) - ) / flt(fb_row.total_number_of_depreciations) - else: - depreciation_amount = flt(depreciable_value * (flt(fb_row.rate_of_depreciation) / 100)) - - return depreciation_amount - def validate_make_gl_entry(self): purchase_document = self.get_purchase_document() if not purchase_document: @@ -618,7 +567,12 @@ class Asset(AccountsController): float_precision = cint(frappe.db.get_default("float_precision")) or 2 if args.get("depreciation_method") == "Double Declining Balance": - return 200.0 / args.get("total_number_of_depreciations") + return 200.0 / ( + ( + flt(args.get("total_number_of_depreciations"), 2) * flt(args.get("frequency_of_depreciation")) + ) + / 12 + ) if args.get("depreciation_method") == "Written Down Value": if ( @@ -635,17 +589,20 @@ class Asset(AccountsController): else: value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount) - depreciation_rate = math.pow(value, 1.0 / flt(args.get("total_number_of_depreciations"), 2)) + depreciation_rate = math.pow( + value, + 1.0 + / ( + ( + flt(args.get("total_number_of_depreciations"), 2) + * flt(args.get("frequency_of_depreciation")) + ) + / 12 + ), + ) return flt((100 * (1 - depreciation_rate)), float_precision) - def get_pro_rata_amt(self, row, depreciation_amount, from_date, to_date): - days = date_diff(to_date, from_date) - months = month_diff(to_date, from_date) - total_days = get_total_days(to_date, row.frequency_of_depreciation) - - return (depreciation_amount * flt(days)) / flt(total_days), days, months - def update_maintenance_status(): assets = frappe.get_all( @@ -889,15 +846,6 @@ def get_asset_value_after_depreciation(asset_name, finance_book=None): return asset.get_value_after_depreciation(finance_book) -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) - - @frappe.whitelist() def split_asset(asset_name, split_qty): asset = frappe.get_doc("Asset", asset_name) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 2c9772d12a..cde02809f1 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -29,8 +29,11 @@ from erpnext.assets.doctype.asset.depreciation import ( scrap_asset, ) from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( + _check_is_pro_rata, + _get_pro_rata_amt, get_asset_depr_schedule_doc, get_depr_schedule, + get_depreciation_amount, ) from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( make_purchase_invoice as make_invoice, @@ -234,7 +237,7 @@ class TestAsset(AssetSetup): asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation, asset.precision("gross_purchase_amount"), ) - pro_rata_amount, _, _ = asset.get_pro_rata_amt( + pro_rata_amount, _, _ = _get_pro_rata_amt( asset.finance_books[0], 9000, get_last_day(add_months(purchase_date, 1)), date ) pro_rata_amount = flt(pro_rata_amount, asset.precision("gross_purchase_amount")) @@ -321,7 +324,7 @@ class TestAsset(AssetSetup): self.assertEquals(second_asset_depr_schedule.status, "Active") self.assertEquals(first_asset_depr_schedule.status, "Cancelled") - pro_rata_amount, _, _ = asset.get_pro_rata_amt( + pro_rata_amount, _, _ = _get_pro_rata_amt( asset.finance_books[0], 9000, get_last_day(add_months(purchase_date, 1)), date ) pro_rata_amount = flt(pro_rata_amount, asset.precision("gross_purchase_amount")) @@ -857,12 +860,12 @@ class TestDepreciationMethods(AssetSetup): ) expected_schedules = [ - ["2022-02-28", 647.25, 647.25], - ["2022-03-31", 1210.71, 1857.96], - ["2022-04-30", 1053.99, 2911.95], - ["2022-05-31", 917.55, 3829.5], - ["2022-06-30", 798.77, 4628.27], - ["2022-07-15", 371.73, 5000.0], + ["2022-02-28", 310.89, 310.89], + ["2022-03-31", 654.45, 965.34], + ["2022-04-30", 654.45, 1619.79], + ["2022-05-31", 654.45, 2274.24], + ["2022-06-30", 654.45, 2928.69], + ["2022-07-15", 2071.31, 5000.0], ] schedules = [ @@ -938,7 +941,7 @@ class TestDepreciationBasics(AssetSetup): }, ) - depreciation_amount = asset.get_depreciation_amount(100000, asset.finance_books[0]) + depreciation_amount = get_depreciation_amount(asset, 100000, asset.finance_books[0]) self.assertEqual(depreciation_amount, 30000) def test_make_depr_schedule(self): @@ -997,7 +1000,7 @@ class TestDepreciationBasics(AssetSetup): }, ) - has_pro_rata = asset.check_is_pro_rata(asset.finance_books[0]) + has_pro_rata = _check_is_pro_rata(asset, asset.finance_books[0]) self.assertFalse(has_pro_rata) asset.finance_books = [] @@ -1012,7 +1015,7 @@ class TestDepreciationBasics(AssetSetup): }, ) - has_pro_rata = asset.check_is_pro_rata(asset.finance_books[0]) + has_pro_rata = _check_is_pro_rata(asset, asset.finance_books[0]) self.assertTrue(has_pro_rata) def test_expected_value_after_useful_life_greater_than_purchase_amount(self): diff --git a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py index d23edfa4a1..116593ad9e 100644 --- a/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py +++ b/erpnext/assets/doctype/asset_depreciation_schedule/asset_depreciation_schedule.py @@ -8,12 +8,16 @@ from frappe.utils import ( add_days, add_months, cint, + date_diff, flt, get_last_day, getdate, is_last_day_of_the_month, + month_diff, ) +import erpnext + class AssetDepreciationSchedule(Document): def before_save(self): @@ -185,7 +189,7 @@ class AssetDepreciationSchedule(Document): ): asset_doc.validate_asset_finance_books(row) - value_after_depreciation = self._get_value_after_depreciation_for_making_schedule(asset_doc, row) + value_after_depreciation = _get_value_after_depreciation_for_making_schedule(asset_doc, row) row.value_after_depreciation = value_after_depreciation if update_asset_finance_book_row: @@ -195,21 +199,46 @@ class AssetDepreciationSchedule(Document): self.number_of_depreciations_booked ) - has_pro_rata = asset_doc.check_is_pro_rata(row) + has_pro_rata = _check_is_pro_rata(asset_doc, row) if has_pro_rata: number_of_pending_depreciations += 1 + has_wdv_or_dd_non_yearly_pro_rata = False + if ( + row.depreciation_method in ("Written Down Value", "Double Declining Balance") + and cint(row.frequency_of_depreciation) != 12 + ): + has_wdv_or_dd_non_yearly_pro_rata = _check_is_pro_rata( + asset_doc, row, wdv_or_dd_non_yearly=True + ) + skip_row = False should_get_last_day = is_last_day_of_the_month(row.depreciation_start_date) + depreciation_amount = 0 + for n in range(start, number_of_pending_depreciations): # If depreciation is already completed (for double declining balance) if skip_row: continue - depreciation_amount = asset_doc.get_depreciation_amount(value_after_depreciation, row) + if n > 0 and len(self.get("depreciation_schedule")) > n - 1: + prev_depreciation_amount = self.get("depreciation_schedule")[n - 1].depreciation_amount + else: + prev_depreciation_amount = 0 - if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1: + depreciation_amount = get_depreciation_amount( + asset_doc, + value_after_depreciation, + row, + n, + prev_depreciation_amount, + has_wdv_or_dd_non_yearly_pro_rata, + ) + + if not has_pro_rata or ( + n < (cint(number_of_pending_depreciations) - 1) or number_of_pending_depreciations == 2 + ): schedule_date = add_months( row.depreciation_start_date, n * cint(row.frequency_of_depreciation) ) @@ -227,8 +256,11 @@ class AssetDepreciationSchedule(Document): if self.depreciation_schedule: from_date = self.depreciation_schedule[-1].schedule_date - depreciation_amount, days, months = asset_doc.get_pro_rata_amt( - row, depreciation_amount, from_date, date_of_disposal + depreciation_amount, days, months = _get_pro_rata_amt( + row, + depreciation_amount, + from_date, + date_of_disposal, ) if depreciation_amount > 0: @@ -240,12 +272,20 @@ class AssetDepreciationSchedule(Document): break # For first row - if has_pro_rata and not self.opening_accumulated_depreciation and n == 0: + if ( + (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata) + and not self.opening_accumulated_depreciation + and n == 0 + ): from_date = add_days( asset_doc.available_for_use_date, -1 ) # needed to calc depr amount for available_for_use_date too - depreciation_amount, days, months = asset_doc.get_pro_rata_amt( - row, depreciation_amount, from_date, row.depreciation_start_date + depreciation_amount, days, months = _get_pro_rata_amt( + row, + depreciation_amount, + from_date, + row.depreciation_start_date, + has_wdv_or_dd_non_yearly_pro_rata, ) # For first depr schedule date will be the start date @@ -264,8 +304,12 @@ class AssetDepreciationSchedule(Document): depreciation_amount_without_pro_rata = depreciation_amount - depreciation_amount, days, months = asset_doc.get_pro_rata_amt( - row, depreciation_amount, schedule_date, asset_doc.to_date + depreciation_amount, days, months = _get_pro_rata_amt( + row, + depreciation_amount, + schedule_date, + asset_doc.to_date, + has_wdv_or_dd_non_yearly_pro_rata, ) depreciation_amount = self.get_adjusted_depreciation_amount( @@ -373,15 +417,142 @@ class AssetDepreciationSchedule(Document): accumulated_depreciation, d.precision("accumulated_depreciation_amount") ) - def _get_value_after_depreciation_for_making_schedule(self, asset_doc, fb_row): - if asset_doc.docstatus == 1 and fb_row.value_after_depreciation: - value_after_depreciation = flt(fb_row.value_after_depreciation) - else: - value_after_depreciation = flt(self.gross_purchase_amount) - flt( - self.opening_accumulated_depreciation - ) - return value_after_depreciation +def _get_value_after_depreciation_for_making_schedule(asset_doc, fb_row): + if asset_doc.docstatus == 1 and fb_row.value_after_depreciation: + value_after_depreciation = flt(fb_row.value_after_depreciation) + else: + value_after_depreciation = flt(asset_doc.gross_purchase_amount) - flt( + asset_doc.opening_accumulated_depreciation + ) + + return value_after_depreciation + + +# if it returns True, depreciation_amount will not be equal for the first and last rows +def _check_is_pro_rata(asset_doc, row, wdv_or_dd_non_yearly=False): + has_pro_rata = False + + # if not existing asset, from_date = available_for_use_date + # otherwise, if number_of_depreciations_booked = 2, available_for_use_date = 01/01/2020 and frequency_of_depreciation = 12 + # from_date = 01/01/2022 + from_date = _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly) + days = date_diff(row.depreciation_start_date, from_date) + 1 + + if wdv_or_dd_non_yearly: + total_days = get_total_days(row.depreciation_start_date, 12) + else: + # if frequency_of_depreciation is 12 months, total_days = 365 + total_days = get_total_days(row.depreciation_start_date, row.frequency_of_depreciation) + + if days < total_days: + has_pro_rata = True + + return has_pro_rata + + +def _get_modified_available_for_use_date(asset_doc, row, wdv_or_dd_non_yearly=False): + if wdv_or_dd_non_yearly: + return add_months( + asset_doc.available_for_use_date, + (asset_doc.number_of_depreciations_booked * 12), + ) + else: + return add_months( + asset_doc.available_for_use_date, + (asset_doc.number_of_depreciations_booked * row.frequency_of_depreciation), + ) + + +def _get_pro_rata_amt( + row, depreciation_amount, from_date, to_date, has_wdv_or_dd_non_yearly_pro_rata=False +): + days = date_diff(to_date, from_date) + months = month_diff(to_date, from_date) + if has_wdv_or_dd_non_yearly_pro_rata: + total_days = get_total_days(to_date, 12) + else: + total_days = get_total_days(to_date, row.frequency_of_depreciation) + + return (depreciation_amount * flt(days)) / flt(total_days), days, months + + +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) + + +@erpnext.allow_regional +def get_depreciation_amount( + asset, + depreciable_value, + row, + schedule_idx=0, + prev_depreciation_amount=0, + has_wdv_or_dd_non_yearly_pro_rata=False, +): + if row.depreciation_method in ("Straight Line", "Manual"): + return get_straight_line_or_manual_depr_amount(asset, row) + else: + return get_wdv_or_dd_depr_amount( + depreciable_value, + row.rate_of_depreciation, + row.frequency_of_depreciation, + schedule_idx, + prev_depreciation_amount, + has_wdv_or_dd_non_yearly_pro_rata, + ) + + +def get_straight_line_or_manual_depr_amount(asset, row): + # if the Depreciation Schedule is being modified after Asset Repair due to increase in asset life and value + if asset.flags.increase_in_asset_life: + return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / ( + date_diff(asset.to_date, asset.available_for_use_date) / 365 + ) + # if the Depreciation Schedule is being modified after Asset Repair due to increase in asset value + elif asset.flags.increase_in_asset_value_due_to_repair: + return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / flt( + row.total_number_of_depreciations + ) + # if the Depreciation Schedule is being prepared for the first time + else: + return (flt(asset.gross_purchase_amount) - flt(row.expected_value_after_useful_life)) / flt( + row.total_number_of_depreciations + ) + + +def get_wdv_or_dd_depr_amount( + depreciable_value, + rate_of_depreciation, + frequency_of_depreciation, + schedule_idx, + prev_depreciation_amount, + has_wdv_or_dd_non_yearly_pro_rata, +): + if cint(frequency_of_depreciation) == 12: + return flt(depreciable_value) * (flt(rate_of_depreciation) / 100) + else: + if has_wdv_or_dd_non_yearly_pro_rata: + if schedule_idx == 0: + return flt(depreciable_value) * (flt(rate_of_depreciation) / 100) + elif schedule_idx % (12 / cint(frequency_of_depreciation)) == 1: + return ( + flt(depreciable_value) * flt(frequency_of_depreciation) * (flt(rate_of_depreciation) / 1200) + ) + else: + return prev_depreciation_amount + else: + if schedule_idx % (12 / cint(frequency_of_depreciation)) == 0: + return ( + flt(depreciable_value) * flt(frequency_of_depreciation) * (flt(rate_of_depreciation) / 1200) + ) + else: + return prev_depreciation_amount def make_draft_asset_depr_schedules_if_not_present(asset_doc): From e6a9b6ee9555ac4814a2526199bd646f6701502f Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Wed, 5 Apr 2023 08:26:15 +0200 Subject: [PATCH 3/7] feat: remove deprecated get_customer_list (#34624) feat: remove deprecated method get_customer_list --- erpnext/selling/doctype/customer/customer.py | 45 -------------------- 1 file changed, 45 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index ebafddb061..18336d2c9f 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -11,7 +11,6 @@ from frappe.contacts.address_and_contact import ( delete_contact_and_address, load_address_and_contact, ) -from frappe.desk.reportview import build_match_conditions, get_filters_cond from frappe.model.mapper import get_mapped_doc from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options from frappe.model.utils.rename_doc import update_linked_doctypes @@ -445,50 +444,6 @@ def get_nested_links(link_doctype, link_name, ignore_permissions=False): return links -@frappe.whitelist() -@frappe.validate_and_sanitize_search_inputs -def get_customer_list(doctype, txt, searchfield, start, page_len, filters=None): - from frappe.utils.deprecations import deprecation_warning - - from erpnext.controllers.queries import get_fields - - deprecation_warning( - "`get_customer_list` is deprecated and will be removed in version 15. Use `erpnext.controllers.queries.customer_query` instead." - ) - - fields = ["name", "customer_name", "customer_group", "territory"] - - if frappe.db.get_default("cust_master_name") == "Customer Name": - fields = ["name", "customer_group", "territory"] - - fields = get_fields("Customer", fields) - - match_conditions = build_match_conditions("Customer") - match_conditions = "and {}".format(match_conditions) if match_conditions else "" - - if filters: - filter_conditions = get_filters_cond(doctype, filters, []) - match_conditions += "{}".format(filter_conditions) - - return frappe.db.sql( - """ - select %s - from `tabCustomer` - where docstatus < 2 - and (%s like %s or customer_name like %s) - {match_conditions} - order by - case when name like %s then 0 else 1 end, - case when customer_name like %s then 0 else 1 end, - name, customer_name limit %s, %s - """.format( - match_conditions=match_conditions - ) - % (", ".join(fields), searchfield, "%s", "%s", "%s", "%s", "%s", "%s"), - ("%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, "%%%s%%" % txt, start, page_len), - ) - - def check_credit_limit(customer, company, ignore_outstanding_sales_order=False, extra_amount=0): credit_limit = get_credit_limit(customer, company) if not credit_limit: From fd3fb64aa344b8a220f217ac6d2ffd09dbcdf0dc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 5 Apr 2023 12:02:44 +0530 Subject: [PATCH 4/7] feat: Auto allocate advance payments only against orders (#34727) feat: Auto allocate advance payments only againt orders --- .../doctype/purchase_invoice/purchase_invoice.json | 12 ++++++++++-- .../doctype/sales_invoice/sales_invoice.json | 11 ++++++++++- erpnext/controllers/accounts_controller.py | 4 +++- erpnext/public/js/controllers/accounts.js | 8 ++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 54caf6f8b0..b4d369e6c6 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -118,6 +118,7 @@ "paid_amount", "advances_section", "allocate_advances_automatically", + "only_include_allocated_payments", "get_advances", "advances", "advance_tax", @@ -1550,17 +1551,24 @@ "fieldname": "named_place", "fieldtype": "Data", "label": "Named Place" + }, + { + "default": "0", + "depends_on": "allocate_advances_automatically", + "description": "Advance payments allocated against orders will only be fetched", + "fieldname": "only_include_allocated_payments", + "fieldtype": "Check", + "label": "Only Include Allocated Payments" } ], "icon": "fa fa-file-text", "idx": 204, "is_submittable": 1, "links": [], - "modified": "2023-01-28 19:18:56.586321", + "modified": "2023-04-03 22:57:14.074982", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", - "name_case": "Title Case", "naming_rule": "By \"Naming Series\" field", "owner": "Administrator", "permissions": [ diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 2a8ff40413..a41e13c8ea 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -120,6 +120,7 @@ "account_for_change_amount", "advances_section", "allocate_advances_automatically", + "only_include_allocated_payments", "get_advances", "advances", "write_off_section", @@ -2126,6 +2127,14 @@ "fieldname": "named_place", "fieldtype": "Data", "label": "Named Place" + }, + { + "default": "0", + "depends_on": "allocate_advances_automatically", + "description": "Advance payments allocated against orders will only be fetched", + "fieldname": "only_include_allocated_payments", + "fieldtype": "Check", + "label": "Only Include Allocated Payments" } ], "icon": "fa fa-file-text", @@ -2138,7 +2147,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2023-03-13 11:43:15.883055", + "modified": "2023-04-03 22:55:14.206473", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 390af0deb2..a347323e35 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -845,7 +845,9 @@ class AccountsController(TransactionBase): def set_advances(self): """Returns list of advances against Account, Party, Reference""" - res = self.get_advance_entries() + res = self.get_advance_entries( + include_unallocated=not cint(self.get("only_include_allocated_payments")) + ) self.set("advances", []) advance_allocated = 0 diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js index a07f75d1c5..d943126018 100644 --- a/erpnext/public/js/controllers/accounts.js +++ b/erpnext/public/js/controllers/accounts.js @@ -55,6 +55,14 @@ frappe.ui.form.on(cur_frm.doctype, { }, allocate_advances_automatically: function(frm) { + frm.trigger('fetch_advances'); + }, + + only_include_allocated_payments: function(frm) { + frm.trigger('fetch_advances'); + }, + + fetch_advances: function(frm) { if(frm.doc.allocate_advances_automatically) { frappe.call({ doc: frm.doc, From f193393f5713fd274ac419ecc786057415266d38 Mon Sep 17 00:00:00 2001 From: Ritwik Puri Date: Wed, 5 Apr 2023 12:04:36 +0530 Subject: [PATCH 5/7] fix!: require sender and message for contact us page (#34707) * fix: require sender and message for contact us page * refactor: dont override frappe.send_message from client side used override_whitelisted_method hook for the same --- erpnext/hooks.py | 4 ++++ erpnext/public/js/website_utils.js | 15 --------------- erpnext/templates/utils.py | 9 +++------ 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 0cb35c1de8..862a546a76 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -28,6 +28,10 @@ doctype_js = { override_doctype_class = {"Address": "erpnext.accounts.custom.address.ERPNextAddress"} +override_whitelisted_methods = { + "frappe.www.contact.send_message": "erpnext.templates.utils.send_message" +} + welcome_email = "erpnext.setup.utils.welcome_email" # setup wizard diff --git a/erpnext/public/js/website_utils.js b/erpnext/public/js/website_utils.js index b5416065d7..2bb5255eeb 100644 --- a/erpnext/public/js/website_utils.js +++ b/erpnext/public/js/website_utils.js @@ -3,18 +3,6 @@ if(!window.erpnext) window.erpnext = {}; -// Add / update a new Lead / Communication -// subject, sender, description -frappe.send_message = function(opts, btn) { - return frappe.call({ - type: "POST", - method: "erpnext.templates.utils.send_message", - btn: btn, - args: opts, - callback: opts.callback - }); -}; - erpnext.subscribe_to_newsletter = function(opts, btn) { return frappe.call({ type: "POST", @@ -24,6 +12,3 @@ erpnext.subscribe_to_newsletter = function(opts, btn) { callback: opts.callback }); } - -// for backward compatibility -erpnext.send_message = frappe.send_message; diff --git a/erpnext/templates/utils.py b/erpnext/templates/utils.py index 48b44802a8..57750a56f6 100644 --- a/erpnext/templates/utils.py +++ b/erpnext/templates/utils.py @@ -6,13 +6,12 @@ import frappe @frappe.whitelist(allow_guest=True) -def send_message(subject="Website Query", message="", sender="", status="Open"): +def send_message(sender, message, subject="Website Query"): from frappe.www.contact import send_message as website_send_message + website_send_message(sender, message, subject) + lead = customer = None - - website_send_message(subject, message, sender) - customer = frappe.db.sql( """select distinct dl.link_name from `tabDynamic Link` dl left join `tabContact` c on dl.parent=c.name where dl.link_doctype='Customer' @@ -58,5 +57,3 @@ def send_message(subject="Website Query", message="", sender="", status="Open"): } ) comm.insert(ignore_permissions=True) - - return "okay" From 56f50783576c23dff9fcf7aab5c8627abc23eaf8 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 5 Apr 2023 12:43:32 +0530 Subject: [PATCH 6/7] fix: Shop by category fixes (#34688) * fix: Shop by category fixes * chore: Update tests --- .../doctype/website_item/test_website_item.py | 8 +++++++- erpnext/setup/doctype/item_group/item_group.py | 9 +++++++-- erpnext/www/shop-by-category/index.py | 12 +++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/test_website_item.py b/erpnext/e_commerce/doctype/website_item/test_website_item.py index e41c9da594..43b2f67571 100644 --- a/erpnext/e_commerce/doctype/website_item/test_website_item.py +++ b/erpnext/e_commerce/doctype/website_item/test_website_item.py @@ -199,8 +199,14 @@ class TestWebsiteItem(unittest.TestCase): breadcrumbs = get_parent_item_groups(item.item_group) + settings = frappe.get_cached_doc("E Commerce Settings") + if settings.enable_field_filters: + base_breadcrumb = "Shop by Category" + else: + base_breadcrumb = "All Products" + self.assertEqual(breadcrumbs[0]["name"], "Home") - self.assertEqual(breadcrumbs[1]["name"], "All Products") + self.assertEqual(breadcrumbs[1]["name"], base_breadcrumb) self.assertEqual(breadcrumbs[2]["name"], "_Test Item Group B") # parent item group self.assertEqual(breadcrumbs[3]["name"], "_Test Item Group B - 1") diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index 2fdfcf647d..2eca5cad8e 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -148,12 +148,17 @@ def get_item_for_list_in_html(context): def get_parent_item_groups(item_group_name, from_item=False): - base_nav_page = {"name": _("All Products"), "route": "/all-products"} + settings = frappe.get_cached_doc("E Commerce Settings") + + if settings.enable_field_filters: + base_nav_page = {"name": _("Shop by Category"), "route": "/shop-by-category"} + else: + base_nav_page = {"name": _("All Products"), "route": "/all-products"} if from_item and frappe.request.environ.get("HTTP_REFERER"): # base page after 'Home' will vary on Item page last_page = frappe.request.environ["HTTP_REFERER"].split("/")[-1].split("?")[0] - if last_page and last_page == "shop-by-category": + if last_page and last_page in ("shop-by-category", "all-products"): base_nav_page_title = " ".join(last_page.split("-")).title() base_nav_page = {"name": _(base_nav_page_title), "route": "/" + last_page} diff --git a/erpnext/www/shop-by-category/index.py b/erpnext/www/shop-by-category/index.py index 219747c9f8..913c1836ac 100644 --- a/erpnext/www/shop-by-category/index.py +++ b/erpnext/www/shop-by-category/index.py @@ -53,6 +53,7 @@ def get_tabs(categories): def get_category_records(categories: list): categorical_data = {} + website_item_meta = frappe.get_meta("Website Item", cached=True) for c in categories: if c == "item_group": @@ -64,7 +65,16 @@ def get_category_records(categories: list): continue - doctype = frappe.unscrub(c) + field_type = website_item_meta.get_field(c).fieldtype + + if field_type == "Table MultiSelect": + child_doc = website_item_meta.get_field(c).options + for field in frappe.get_meta(child_doc, cached=True).fields: + if field.fieldtype == "Link" and field.reqd: + doctype = field.options + else: + doctype = website_item_meta.get_field(c).options + fields = ["name"] try: From 9bf87d708e2fe585a66a565deb6a334c18fb301f Mon Sep 17 00:00:00 2001 From: Lucky-Tsuma <55623011+Lucky-Tsuma@users.noreply.github.com> Date: Wed, 5 Apr 2023 01:22:00 -0700 Subject: [PATCH 7/7] fix: `payment entry is already created` on posawesome. (#34712) --- .../doctype/payment_request/payment_request.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 7005c17362..5f5647c7ec 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -497,10 +497,16 @@ def get_amount(ref_doc, payment_account=None): if dt in ["Sales Order", "Purchase Order"]: grand_total = flt(ref_doc.rounded_total) or flt(ref_doc.grand_total) elif dt in ["Sales Invoice", "Purchase Invoice"]: - if ref_doc.party_account_currency == ref_doc.currency: - grand_total = flt(ref_doc.outstanding_amount) - else: - grand_total = flt(ref_doc.outstanding_amount) / ref_doc.conversion_rate + if not ref_doc.is_pos: + if ref_doc.party_account_currency == ref_doc.currency: + grand_total = flt(ref_doc.outstanding_amount) + else: + grand_total = flt(ref_doc.outstanding_amount) / ref_doc.conversion_rate + elif dt == "Sales Invoice": + for pay in ref_doc.payments: + if pay.type == "Phone" and pay.account == payment_account: + grand_total = pay.amount + break elif dt == "POS Invoice": for pay in ref_doc.payments: if pay.type == "Phone" and pay.account == payment_account: