diff --git a/erpnext/accounts/doctype/subscription/patches/use_the_correct_state_key_for_sales_invoices.py b/erpnext/accounts/doctype/subscription/patches/use_the_correct_state_key_for_sales_invoices.py new file mode 100644 index 0000000000000000000000000000000000000000..66ae465fffb00e471895345d9604e32df6d3788e --- /dev/null +++ b/erpnext/accounts/doctype/subscription/patches/use_the_correct_state_key_for_sales_invoices.py @@ -0,0 +1,10 @@ +import frappe + + +def execute(): + """Use the correct state key for sales invoices""" + for sub in frappe.get_all("Subscription", fields=["name", "subscription_state"]): + state = frappe.parse_json(sub.subscription_state) or {} + if state.get("invoice"): + doc = frappe.get_doc("Subscription", sub.name) + doc.set_state("sales_invoice", state["invoice"]) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index a60c49a2c837734c46881165a13bc2bfa8d0a7e5..5ad0c3bded68e88afffa65e6d02836592f42ca94 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -258,6 +258,8 @@ class Subscription(Document): def get_billing_contact(self): if self.customer and not self.contact_person: self.contact_person = get_default_contact("Customer", self.customer) + if self.contact_person: + self.contact_email = frappe.db.get_value("Contact", self.contact_person, "email_id") def get_customer_details(self, ignore_permissions=False): from erpnext.accounts.party import _get_party_details @@ -527,4 +529,4 @@ def update_subscription_state(doc, method=None): and doc.from_date == subscription.current_invoice_start and doc.to_date == subscription.current_invoice_end ): - subscription.set_state("invoice", doc.name) + subscription.set_state("sales_invoice", doc.name) diff --git a/erpnext/accounts/doctype/subscription/subscription_transaction.py b/erpnext/accounts/doctype/subscription/subscription_transaction.py index 4efe41c3eb990b9c5cdb2f05aa97721b0fca9adf..daa57a41cc69640c1a7d11ea1635abc09a8f6173 100644 --- a/erpnext/accounts/doctype/subscription/subscription_transaction.py +++ b/erpnext/accounts/doctype/subscription/subscription_transaction.py @@ -12,7 +12,10 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import ( from erpnext.accounts.doctype.subscription.subscription_plans_manager import ( SubscriptionPlansManager, ) -from erpnext.accounts.doctype.subscription.subscription_state_manager import SubscriptionPeriod +from erpnext.accounts.doctype.subscription.subscription_state_manager import ( + SubscriptionPeriod, + SubscriptionStateManager, +) from erpnext.controllers.accounts_controller import add_taxes_from_tax_template from erpnext.setup.doctype.terms_and_conditions.terms_and_conditions import ( get_terms_and_conditions, @@ -223,7 +226,7 @@ class SubscriptionInvoiceGenerator(SubscriptionTransactionBase): invoice.run_method("validate") return invoice.grand_total except erpnext.exceptions.PartyDisabled: - if not self.is_cancelled(): + if not SubscriptionStateManager(self.subscription).is_cancelled(): self.subscription.reload() self.subscription.cancel_subscription() except Exception: diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 626bae37c186f645d3583d3cae2804b3e59e8fb1..2c852e25228b9b2e6d10ae5c5717046d2ca37ad2 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -827,7 +827,7 @@ def validate_party_frozen_disabled(party_type, party_name): if party_type in ("Customer", "Supplier"): party = frappe.get_cached_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True) if party.disabled: - frappe.throw(_("{0} {1} is disabled").format(party_type, party_name), PartyDisabled) + frappe.throw(_("{0} {1} is disabled").format(_(party_type), party_name), PartyDisabled) elif party.get("is_frozen"): frozen_accounts_modifier = frappe.db.get_single_value( "Accounts Settings", "frozen_accounts_modifier" diff --git a/erpnext/patches.txt b/erpnext/patches.txt index c5d4a26ab931c79614f3b247b435ecf2cea6106e..fcf86ba32c4ebf282e7d16a3e4c3b4098b27eba9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -382,6 +382,7 @@ execute:frappe.delete_doc_if_exists("DocType", "Subscription Event") erpnext.patches.dokos.v4_0.set_mode_of_payment_in_payment_requests erpnext.patches.dokos.v4_0.add_customer_to_payment_request erpnext.accounts.doctype.mode_of_payment.patches.migrate_fees_and_cost_center_to_account_table +erpnext.accounts.doctype.subscription.patches.use_the_correct_state_key_for_sales_invoices # @dokos @@ -389,4 +390,4 @@ erpnext.accounts.doctype.mode_of_payment.patches.migrate_fees_and_cost_center_to erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20 erpnext.patches.v14_0.set_maintain_stock_for_bom_item -erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset \ No newline at end of file +erpnext.patches.v15_0.remove_cancelled_asset_capitalization_from_asset