Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: toggle for negative item rates in Selling Settings #36642

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3376,6 +3376,7 @@ def test_advance_entries_as_liability(self):

set_advance_flag(company="_Test Company", flag=0, default_account="")

@change_settings("Selling Settings", {"allow_negative_rates_for_items": 0})
def test_sales_return_negative_rate(self):
si = create_sales_invoice(is_return=1, qty=-2, rate=-10, do_not_save=True)
self.assertRaises(frappe.ValidationError, si.save)
Expand Down
15 changes: 12 additions & 3 deletions erpnext/controllers/status_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import comma_or, flt, getdate, now, nowdate
from frappe.utils import comma_or, flt, get_link_to_form, getdate, now, nowdate


class OverAllowanceError(frappe.ValidationError):
Expand Down Expand Up @@ -233,8 +233,17 @@ def validate_qty(self):
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"):
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))

if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
frappe.throw(_("For an item {0}, rate must be a positive number").format(d.item_code))
if not frappe.db.get_single_value("Selling Settings", "allow_negative_rates_for_items"):
if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
frappe.throw(
_(
"For item {0}, rate must be a positive number. To Allow negative rates, enable {1} in {2}"
).format(
frappe.bold(d.item_code),
frappe.bold(_("`Allow Negative rates for Items`")),
get_link_to_form("Selling Settings", "Selling Settings"),
),
)

if d.doctype == args["source_dt"] and d.get(args["join_field"]):
args["name"] = d.get(args["join_field"])
Expand Down
5 changes: 3 additions & 2 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ erpnext.patches.v14_0.update_closing_balances #14-07-2023
execute:frappe.db.set_single_value("Accounts Settings", "merge_similar_account_heads", 0)
erpnext.patches.v14_0.update_reference_type_in_journal_entry_accounts
erpnext.patches.v14_0.update_subscription_details
# below migration patches should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
execute:frappe.delete_doc_if_exists("Report", "Tax Detail")
erpnext.patches.v15_0.enable_all_leads
erpnext.patches.v14_0.update_company_in_ldc
Expand All @@ -340,3 +338,6 @@ erpnext.buying.doctype.supplier.patches.migrate_supplier_portal_users
execute:frappe.defaults.clear_default("fiscal_year")
erpnext.patches.v15_0.remove_exotel_integration
erpnext.patches.v14_0.single_to_multi_dunning
execute:frappe.db.set_single_value('Selling Settings', 'allow_negative_rates_for_items', 0)
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"editable_price_list_rate",
"validate_selling_price",
"editable_bundle_item_rates",
"allow_negative_rates_for_items",
"sales_transactions_settings_section",
"so_required",
"dn_required",
Expand Down Expand Up @@ -193,14 +194,20 @@
"fieldname": "dont_reserve_sales_order_qty_on_sales_return",
"fieldtype": "Check",
"label": "Don't Reserve Sales Order Qty on Sales Return"
},
{
"default": "0",
"fieldname": "allow_negative_rates_for_items",
"fieldtype": "Check",
"label": "Allow Negative rates for Items"
}
],
"icon": "fa fa-cog",
"idx": 1,
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2023-08-09 15:35:42.914354",
"modified": "2023-08-14 20:33:05.693667",
"modified_by": "Administrator",
"module": "Selling",
"name": "Selling Settings",
Expand Down
Loading