mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 17:04:47 +00:00
Merge pull request #49908 from frappe/mergify/bp/version-15-hotfix/pr-49635
fix(subscription): include days before (backport #49635)
This commit is contained in:
@@ -483,18 +483,23 @@ class Subscription(Document):
|
|||||||
|
|
||||||
return invoice
|
return invoice
|
||||||
|
|
||||||
def get_items_from_plans(self, plans: list[dict[str, str]], prorate: bool | None = None) -> list[dict]:
|
def get_items_from_plans(self, plans: list[dict[str, str]], prorate: int = 0) -> list[dict]:
|
||||||
"""
|
"""
|
||||||
Returns the `Item`s linked to `Subscription Plan`
|
Returns the `Item`s linked to `Subscription Plan`
|
||||||
"""
|
"""
|
||||||
if prorate is None:
|
|
||||||
prorate = False
|
|
||||||
|
|
||||||
|
prorate_factor = 1
|
||||||
if prorate:
|
if prorate:
|
||||||
prorate_factor = get_prorata_factor(
|
prorate_factor = get_prorata_factor(
|
||||||
self.current_invoice_end,
|
self.current_invoice_end,
|
||||||
self.current_invoice_start,
|
self.current_invoice_start,
|
||||||
cint(self.generate_invoice_at == "Beginning of the current subscription period"),
|
cint(
|
||||||
|
self.generate_invoice_at
|
||||||
|
in [
|
||||||
|
"Beginning of the current subscription period",
|
||||||
|
"Days before the current subscription period",
|
||||||
|
]
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
@@ -511,33 +516,19 @@ class Subscription(Document):
|
|||||||
|
|
||||||
deferred = frappe.db.get_value("Item", item_code, deferred_field)
|
deferred = frappe.db.get_value("Item", item_code, deferred_field)
|
||||||
|
|
||||||
if not prorate:
|
item = {
|
||||||
item = {
|
"item_code": item_code,
|
||||||
"item_code": item_code,
|
"qty": plan.qty,
|
||||||
"qty": plan.qty,
|
"rate": get_plan_rate(
|
||||||
"rate": get_plan_rate(
|
plan.plan,
|
||||||
plan.plan,
|
plan.qty,
|
||||||
plan.qty,
|
party,
|
||||||
party,
|
self.current_invoice_start,
|
||||||
self.current_invoice_start,
|
self.current_invoice_end,
|
||||||
self.current_invoice_end,
|
prorate_factor,
|
||||||
),
|
),
|
||||||
"cost_center": plan_doc.cost_center,
|
"cost_center": plan_doc.cost_center,
|
||||||
}
|
}
|
||||||
else:
|
|
||||||
item = {
|
|
||||||
"item_code": item_code,
|
|
||||||
"qty": plan.qty,
|
|
||||||
"rate": get_plan_rate(
|
|
||||||
plan.plan,
|
|
||||||
plan.qty,
|
|
||||||
party,
|
|
||||||
self.current_invoice_start,
|
|
||||||
self.current_invoice_end,
|
|
||||||
prorate_factor,
|
|
||||||
),
|
|
||||||
"cost_center": plan_doc.cost_center,
|
|
||||||
}
|
|
||||||
|
|
||||||
if deferred:
|
if deferred:
|
||||||
item.update(
|
item.update(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from frappe.utils.data import (
|
|||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
add_to_date,
|
add_to_date,
|
||||||
|
add_years,
|
||||||
cint,
|
cint,
|
||||||
date_diff,
|
date_diff,
|
||||||
flt,
|
flt,
|
||||||
@@ -555,6 +556,33 @@ class TestSubscription(FrappeTestCase):
|
|||||||
subscription.reload()
|
subscription.reload()
|
||||||
self.assertEqual(len(subscription.invoices), 0)
|
self.assertEqual(len(subscription.invoices), 0)
|
||||||
|
|
||||||
|
def test_invoice_generation_days_before_subscription_period_with_prorate(self):
|
||||||
|
settings = frappe.get_single("Subscription Settings")
|
||||||
|
settings.prorate = 1
|
||||||
|
settings.save()
|
||||||
|
|
||||||
|
create_plan(
|
||||||
|
plan_name="_Test Plan Name 5",
|
||||||
|
cost=1000,
|
||||||
|
billing_interval="Year",
|
||||||
|
billing_interval_count=1,
|
||||||
|
currency="INR",
|
||||||
|
)
|
||||||
|
|
||||||
|
start_date = add_days(nowdate(), 2)
|
||||||
|
|
||||||
|
subscription = create_subscription(
|
||||||
|
start_date=start_date,
|
||||||
|
party_type="Supplier",
|
||||||
|
party="_Test Supplier",
|
||||||
|
generate_invoice_at="Days before the current subscription period",
|
||||||
|
generate_new_invoices_past_due_date=1,
|
||||||
|
number_of_days=2,
|
||||||
|
plans=[{"plan": "_Test Plan Name 5", "qty": 1}],
|
||||||
|
)
|
||||||
|
subscription.process(nowdate())
|
||||||
|
self.assertEqual(len(subscription.invoices), 1)
|
||||||
|
|
||||||
|
|
||||||
def make_plans():
|
def make_plans():
|
||||||
create_plan(plan_name="_Test Plan Name", cost=900, currency="INR")
|
create_plan(plan_name="_Test Plan Name", cost=900, currency="INR")
|
||||||
|
|||||||
Reference in New Issue
Block a user