Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(usage-record): Add Unique constraints" #2415

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion press/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ press.press.doctype.virtual_machine_volume.patches.rename_aws_fields
press.patches.v0_7_0.convert_marketplace_description_to_html
press.press.doctype.team.patches.remove_invalid_email_addresses
press.saas.doctype.product_trial.patches.rename_saas_product_doctypes_to_product_trial
press.press.doctype.usage_record.patches.add_unique_constraint

[post_model_sync]
press.patches.v0_7_0.rename_plan_to_site_plan
Expand Down
39 changes: 1 addition & 38 deletions press/press/doctype/subscription/test_subscription.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in press/press/doctype/subscription/test_subscription.py

View workflow job for this annotation

GitHub Actions / Lint and Format

Ruff (UP009)

press/press/doctype/subscription/test_subscription.py:1:1: UP009 UTF-8 encoding declaration is unnecessary
# Copyright (c) 2020, Frappe and Contributors
# See license.txt

Expand Down Expand Up @@ -92,44 +93,6 @@
invoice = frappe.get_doc("Invoice", {"team": self.team.name, "status": "Draft"})
self.assertEqual(invoice.total, desired_value)

def test_subscription_for_duplicate_usage_record(self):
todo = frappe.get_doc(doctype="ToDo", description="Test todo").insert()
plan = frappe.get_doc(
doctype="Site Plan",
name="Plan-10",
document_type="ToDo",
interval="Daily",
price_usd=30,
price_inr=30,
).insert()

subscription = frappe.get_doc(
doctype="Subscription",
team=self.team.name,
document_type="ToDo",
document_name=todo.name,
plan_type="Site Plan",
plan=plan.name,
).insert()

# create a usage record
subscription.create_usage_record()

# since create_usage_record silently skips if a record already exists
# check by manually creating a duplicate record
duplicate_usage_record = frappe.new_doc(
doctype="Usage Record",
team=self.team.name,
document_type="ToDo",
document_name=todo.name,
plan_type="Site Plan",
plan=plan.name,
subscription=subscription.name,
interval="Daily",
)
with self.assertRaises(frappe.UniqueValidationError):
duplicate_usage_record.insert()

def test_subscription_for_non_chargeable_document(self):
todo = frappe.get_doc(doctype="ToDo", description="Test todo").insert()
plan = frappe.get_doc(
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion press/press/doctype/usage_record/usage_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ def link_unlinked_usage_records():


def on_doctype_update():
frappe.db.add_unique("Usage Record", ["subscription", "date"], constraint_name="unique_usage_record")
frappe.db.add_index("Usage Record", ["subscription", "date"])
Loading