refactor: prevent foreign currency subscription for a party
(cherry picked from commit 6b5fa2c673accab13a174a2945b333bd1b991cdb)
This commit is contained in:
parent
e282ba78c1
commit
61f073f8b1
@ -16,6 +16,7 @@ from frappe.utils.data import (
|
|||||||
date_diff,
|
date_diff,
|
||||||
flt,
|
flt,
|
||||||
get_last_day,
|
get_last_day,
|
||||||
|
get_link_to_form,
|
||||||
getdate,
|
getdate,
|
||||||
nowdate,
|
nowdate,
|
||||||
)
|
)
|
||||||
@ -317,6 +318,37 @@ class Subscription(Document):
|
|||||||
if self.is_new():
|
if self.is_new():
|
||||||
self.set_subscription_status()
|
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:
|
def validate_trial_period(self) -> None:
|
||||||
"""
|
"""
|
||||||
Runs sanity checks on trial period dates for the `Subscription`
|
Runs sanity checks on trial period dates for the `Subscription`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user