Merge pull request #39391 from ruthra-kumar/multiple_typeerror_fixes
fix: possible typerror in utils.js
diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py
index 72e574c..ce56a7b 100644
--- a/erpnext/accounts/doctype/subscription/subscription.py
+++ b/erpnext/accounts/doctype/subscription/subscription.py
@@ -16,6 +16,7 @@
date_diff,
flt,
get_last_day,
+ get_link_to_form,
getdate,
nowdate,
)
@@ -317,6 +318,37 @@
if self.is_new():
self.set_subscription_status()
+ self.validate_party_billing_currency()
+
+ def validate_party_billing_currency(self):
+ """
+ Subscription should be of the same currency as the Party's default billing currency or company default.
+ """
+ if self.party:
+ party_billing_currency = frappe.get_cached_value(
+ self.party_type, self.party, "default_currency"
+ ) or frappe.get_cached_value("Company", self.company, "default_currency")
+
+ plans = [x.plan for x in self.plans]
+ subscription_plan_currencies = frappe.db.get_all(
+ "Subscription Plan", filters={"name": ("in", plans)}, fields=["name", "currency"]
+ )
+ unsupported_plans = []
+ for x in subscription_plan_currencies:
+ if x.currency != party_billing_currency:
+ unsupported_plans.append("{0}".format(get_link_to_form("Subscription Plan", x.name)))
+
+ if unsupported_plans:
+ unsupported_plans = [
+ _(
+ "Below Subscription Plans are of different currency to the party default billing currency/Company currency: {0}"
+ ).format(frappe.bold(party_billing_currency))
+ ] + unsupported_plans
+
+ frappe.throw(
+ unsupported_plans, frappe.ValidationError, "Unsupported Subscription Plans", as_list=True
+ )
+
def validate_trial_period(self) -> None:
"""
Runs sanity checks on trial period dates for the `Subscription`
diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py
index 785fd04..37326fd 100644
--- a/erpnext/accounts/doctype/subscription/test_subscription.py
+++ b/erpnext/accounts/doctype/subscription/test_subscription.py
@@ -463,7 +463,7 @@
subscription = create_subscription(
start_date="2018-01-01",
generate_invoice_at="Beginning of the current subscription period",
- plans=[{"plan": "_Test Plan Multicurrency", "qty": 1}],
+ plans=[{"plan": "_Test Plan Multicurrency", "qty": 1, "currency": "USD"}],
party="_Test Subscription Customer",
)
@@ -528,13 +528,21 @@
def make_plans():
- create_plan(plan_name="_Test Plan Name", cost=900)
- create_plan(plan_name="_Test Plan Name 2", cost=1999)
+ create_plan(plan_name="_Test Plan Name", cost=900, currency="INR")
+ create_plan(plan_name="_Test Plan Name 2", cost=1999, currency="INR")
create_plan(
- plan_name="_Test Plan Name 3", cost=1999, billing_interval="Day", billing_interval_count=14
+ plan_name="_Test Plan Name 3",
+ cost=1999,
+ billing_interval="Day",
+ billing_interval_count=14,
+ currency="INR",
)
create_plan(
- plan_name="_Test Plan Name 4", cost=20000, billing_interval="Month", billing_interval_count=3
+ plan_name="_Test Plan Name 4",
+ cost=20000,
+ billing_interval="Month",
+ billing_interval_count=3,
+ currency="INR",
)
create_plan(
plan_name="_Test Plan Multicurrency", cost=50, billing_interval="Month", currency="USD"
diff --git a/erpnext/accounts/doctype/subscription_plan/subscription_plan.json b/erpnext/accounts/doctype/subscription_plan/subscription_plan.json
index 563df79..bc1f579 100644
--- a/erpnext/accounts/doctype/subscription_plan/subscription_plan.json
+++ b/erpnext/accounts/doctype/subscription_plan/subscription_plan.json
@@ -41,7 +41,8 @@
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
- "options": "Currency"
+ "options": "Currency",
+ "reqd": 1
},
{
"fieldname": "column_break_3",
@@ -148,10 +149,11 @@
}
],
"links": [],
- "modified": "2021-12-10 15:24:15.794477",
+ "modified": "2024-01-14 17:59:34.687977",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Subscription Plan",
+ "naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
@@ -193,5 +195,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
+ "states": [],
"track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/subscription_plan/subscription_plan.py b/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
index 118d254..cdfa3e5 100644
--- a/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
+++ b/erpnext/accounts/doctype/subscription_plan/subscription_plan.py
@@ -24,7 +24,7 @@
billing_interval_count: DF.Int
cost: DF.Currency
cost_center: DF.Link | None
- currency: DF.Link | None
+ currency: DF.Link
item: DF.Link
payment_gateway: DF.Link | None
plan_name: DF.Data
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js
index 39fb3ca..06f426b 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.js
@@ -59,7 +59,21 @@
"fieldname": "group_by",
"fieldtype": "Select",
"options": ["Customer Group", "Customer", "Item Group", "Item", "Territory", "Invoice"]
- }
+ },
+ {
+ "fieldname": "income_account",
+ "label": __("Income Account"),
+ "fieldtype": "Link",
+ "options": "Account",
+ get_query: () => {
+ let company = frappe.query_report.get_filter_value('company');
+ return {
+ filters: {
+ 'company': company,
+ }
+ };
+ }
+ },
],
"formatter": function(value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index ce22d75..56ae41a 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -83,9 +83,7 @@
"company": d.company,
"sales_order": d.sales_order,
"delivery_note": d.delivery_note,
- "income_account": d.unrealized_profit_loss_account
- if d.is_internal_customer == 1
- else d.income_account,
+ "income_account": get_income_account(d),
"cost_center": d.cost_center,
"stock_qty": d.stock_qty,
"stock_uom": d.stock_uom,
@@ -150,6 +148,15 @@
return columns, data, None, None, None, skip_total_row
+def get_income_account(row):
+ if row.enable_deferred_revenue:
+ return row.deferred_revenue_account
+ elif row.is_internal_customer == 1:
+ return row.unrealized_profit_loss_account
+ else:
+ return row.income_account
+
+
def get_columns(additional_table_columns, filters):
columns = []
@@ -358,6 +365,13 @@
if filters.get("item_group"):
conditions += """and ifnull(`tabSales Invoice Item`.item_group, '') = %(item_group)s"""
+ if filters.get("income_account"):
+ conditions += """
+ and (ifnull(`tabSales Invoice Item`.income_account, '') = %(income_account)s
+ or ifnull(`tabSales Invoice Item`.deferred_revenue_account, '') = %(income_account)s
+ or ifnull(`tabSales Invoice`.unrealized_profit_loss_account, '') = %(income_account)s)
+ """
+
if not filters.get("group_by"):
conditions += (
"ORDER BY `tabSales Invoice`.posting_date desc, `tabSales Invoice Item`.item_group desc"
@@ -399,6 +413,7 @@
`tabItem`.`item_name` as i_item_name, `tabItem`.`item_group` as i_item_group,
`tabSales Invoice Item`.sales_order, `tabSales Invoice Item`.delivery_note,
`tabSales Invoice Item`.income_account, `tabSales Invoice Item`.cost_center,
+ `tabSales Invoice Item`.enable_deferred_revenue, `tabSales Invoice Item`.deferred_revenue_account,
`tabSales Invoice Item`.stock_qty, `tabSales Invoice Item`.stock_uom,
`tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount,
`tabSales Invoice`.customer_name, `tabSales Invoice`.customer_group, `tabSales Invoice Item`.so_detail,