From 5158884dc9660cba1353b285e1eeb930ed9a204e Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 29 Dec 2023 12:52:41 +0530 Subject: [PATCH] fix: Multiple subscription fixes (#39005) fix: Multiple subscription fixes (#39005) (cherry picked from commit 3b4b2275de7a49ba48b09f7229bee45f1e890ac9) Co-authored-by: Deepesh Garg --- .../doctype/subscription/subscription.json | 6 +++--- .../doctype/subscription/subscription.py | 19 ++++++++++++------- erpnext/controllers/accounts_controller.py | 5 +++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.json b/erpnext/accounts/doctype/subscription/subscription.json index 187b7abce1..97fd4d040f 100644 --- a/erpnext/accounts/doctype/subscription/subscription.json +++ b/erpnext/accounts/doctype/subscription/subscription.json @@ -148,13 +148,13 @@ { "fieldname": "additional_discount_percentage", "fieldtype": "Percent", - "label": "Additional DIscount Percentage" + "label": "Additional Discount Percentage" }, { "collapsible": 1, "fieldname": "additional_discount_amount", "fieldtype": "Currency", - "label": "Additional DIscount Amount" + "label": "Additional Discount Amount" }, { "collapsible": 1, @@ -267,7 +267,7 @@ "link_fieldname": "subscription" } ], - "modified": "2023-09-18 17:48:21.900252", + "modified": "2023-12-28 17:20:42.687789", "modified_by": "Administrator", "module": "Accounts", "name": "Subscription", diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 6cc2d1e9ee..94f5e29f06 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -356,18 +356,20 @@ class Subscription(Document): self, from_date: Optional[Union[str, datetime.date]] = None, to_date: Optional[Union[str, datetime.date]] = None, + posting_date: Optional[Union[str, datetime.date]] = None, ) -> Document: """ Creates a `Invoice` for the `Subscription`, updates `self.invoices` and saves the `Subscription`. Backwards compatibility """ - return self.create_invoice(from_date=from_date, to_date=to_date) + return self.create_invoice(from_date=from_date, to_date=to_date, posting_date=posting_date) def create_invoice( self, from_date: Optional[Union[str, datetime.date]] = None, to_date: Optional[Union[str, datetime.date]] = None, + posting_date: Optional[Union[str, datetime.date]] = None, ) -> Document: """ Creates a `Invoice`, submits it and returns it @@ -385,11 +387,13 @@ class Subscription(Document): invoice = frappe.new_doc(self.invoice_document_type) invoice.company = company invoice.set_posting_time = 1 - invoice.posting_date = ( - self.current_invoice_start - if self.generate_invoice_at == "Beginning of the current subscription period" - else self.current_invoice_end - ) + + if self.generate_invoice_at == "Beginning of the current subscription period": + invoice.posting_date = self.current_invoice_start + elif self.generate_invoice_at == "Days before the current subscription period": + invoice.posting_date = posting_date or self.current_invoice_start + else: + invoice.posting_date = self.current_invoice_end invoice.cost_center = self.cost_center @@ -413,6 +417,7 @@ class Subscription(Document): # Subscription is better suited for service items. I won't update `update_stock` # for that reason items_list = self.get_items_from_plans(self.plans, is_prorate()) + for item in items_list: item["cost_center"] = self.cost_center invoice.append("items", item) @@ -556,7 +561,7 @@ class Subscription(Document): if not self.is_current_invoice_generated( self.current_invoice_start, self.current_invoice_end ) and self.can_generate_new_invoice(posting_date): - self.generate_invoice() + self.generate_invoice(posting_date=posting_date) self.update_subscription_period(add_days(self.current_invoice_end, 1)) if self.cancel_at_period_end and ( diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 4447b076c7..9e4abff6b4 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -225,6 +225,11 @@ class AccountsController(TransactionBase): apply_pricing_rule_on_transaction(self) self.set_total_in_words() + self.set_default_letter_head() + + def set_default_letter_head(self): + if hasattr(self, "letter_head") and not self.letter_head: + self.letter_head = frappe.db.get_value("Company", self.company, "default_letter_head") def init_internal_values(self): # init all the internal values as 0 on sa