Commit b3d2cc0d authored by Charles-Henri Decultot's avatar Charles-Henri Decultot
Browse files

Merge branch 'staging'

parents 4dd8d87c a155f538
......@@ -5,7 +5,7 @@ import frappe
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
__version__ = '1.3.13'
__version__ = '1.3.14'
def get_default_company(user=None):
'''Get default company for user'''
......
......@@ -117,9 +117,23 @@ class PaymentRequest(Document):
self.send_email(communication)
def on_cancel(self):
self.delete_linked_subscription_events(True)
self.check_if_payment_entry_exists()
self.set_as_cancelled()
def on_trash(self):
self.delete_linked_subscription_events()
def delete_linked_subscription_events(self, cancel_only=False):
events = frappe.get_all("Subscription Event", filters={"document_type": "Payment Request", "document_name": self.name}, fields=["name", "docstatus"])
for event in events:
if event.docstatus == 1:
e = frappe.get_doc("Subscription Event", event.name)
e.flags.ignore_permissions = True
e.cancel()
frappe.delete_doc("Subscription Event", event.name, force=True)
def make_invoice(self):
if self.reference_doctype == "Sales Order":
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
......
......@@ -40,6 +40,16 @@ class Subscription(Document):
self.set_subscription_status()
self.update_payment_gateway_subscription()
def on_trash(self):
events = frappe.get_all("Subscription Event", filters={"subscription": self.name}, fields=["name", "doctstatus"])
for event in events:
if event.docstatus == 1:
e = frappe.get_doc("Subscription Event", event.name)
e.flags.ignore_permissions = True
e.cancel()
frappe.delete_doc("Subscription Event", event.name, force=True)
def update_subscription_period(self, date=None):
start_date = self.current_invoice_start
end_date = self.current_invoice_end
......
......@@ -27,6 +27,7 @@
"in_list_view": 1,
"label": "Subscription",
"options": "Subscription",
"read_only": 1,
"reqd": 1
},
{
......@@ -35,6 +36,7 @@
"fieldtype": "Date",
"in_list_view": 1,
"label": "Date",
"read_only": 1,
"reqd": 1
},
{
......@@ -47,6 +49,7 @@
"in_list_view": 1,
"label": "Event Type",
"options": "New period\nSales order created\nSales invoice created\nPayment request created",
"read_only": 1,
"reqd": 1
},
{
......@@ -58,7 +61,8 @@
"fieldname": "document_type",
"fieldtype": "Link",
"label": "Created document type",
"options": "DocType"
"options": "DocType",
"read_only": 1
},
{
"fieldname": "column_break_7",
......@@ -68,7 +72,8 @@
"fieldname": "document_name",
"fieldtype": "Dynamic Link",
"label": "Created document name",
"options": "document_type"
"options": "document_type",
"read_only": 1
},
{
"fieldname": "amended_from",
......@@ -87,7 +92,8 @@
{
"fieldname": "period_start",
"fieldtype": "Date",
"label": "Period start date"
"label": "Period start date",
"read_only": 1
},
{
"fieldname": "column_break_11",
......@@ -100,13 +106,13 @@
},
{
"fieldname": "section_break_13",
"fieldtype": "Section Break"
"fieldtype": "Section Break",
"read_only": 1
}
],
"in_create": 1,
"is_submittable": 1,
"links": [],
"modified": "2020-01-21 19:14:40.213877",
"modified": "2020-03-30 14:27:11.982668",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Subscription Event",
......
......@@ -605,11 +605,11 @@ class AccountsController(TransactionBase):
unlink_ref_doc_from_payment_entries(self)
if self.doctype in ["Sales Order", "Sales Invoice", "Payment Entry"]:
self.cancel_linked_subscription_events()
self.delete_linked_subscription_events(True)
def on_trash(self):
if self.doctype in ["Sales Order", "Sales Invoice", "Payment Entry"]:
self.cancel_linked_subscription_events()
self.delete_linked_subscription_events()
def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
from erpnext.controllers.status_updater import get_allowance_for
......@@ -870,12 +870,17 @@ class AccountsController(TransactionBase):
else:
return frappe.db.get_single_value("Global Defaults", "disable_rounded_total")
def cancel_linked_subscription_events(self):
events = frappe.get_all("Subscription Event", filters={"document_type": self.doctype, "document_name": self.name})
def delete_linked_subscription_events(self, cancel_only=False):
events = frappe.get_all("Subscription Event", filters={"document_type": self.doctype, "document_name": self.name}, fields=["name", "docstatus"])
for event in events:
e = frappe.get_doc("Subscription Event", event.name)
e.flags.ignore_permissions = True
e.cancel()
# For retro-compatibility
if event.docstatus == 1:
e = frappe.get_doc("Subscription Event", event.name)
e.flags.ignore_permissions = True
e.cancel()
if not cancel_only:
frappe.delete_doc("Subscription Event", event.name)
@frappe.whitelist()
def get_tax_rate(account_head):
......
......@@ -27,9 +27,6 @@ def webhooks():
except Exception:
frappe.log_error(frappe.get_traceback(), _("GoCardless webhooks processing error"))
frappe.enqueue(method='frappe.integrations.doctype.integration_request.integration_request.retry_failed_webhooks',\
queue='long', timeout=600, service="GoCardless")
frappe.response.message = "Webhook received and event type handled"
frappe.response.http_status_code = 200
......
......@@ -38,9 +38,6 @@ def webhooks():
queue='long', timeout=600, is_async=True, **{"doctype": "Integration Request",\
"docname": doc.name})
frappe.enqueue(method='frappe.integrations.doctype.integration_request.integration_request.retry_failed_webhooks',\
queue='long', timeout=600, service="Stripe")
frappe.response.message = "Webhook received and event type handled"
frappe.response.http_status_code = 200
......
......@@ -6,13 +6,11 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import getdate, get_time, now_datetime, cint, get_datetime, format_datetime
from frappe.utils import getdate, get_time, now_datetime, cint, get_datetime
import datetime
from datetime import timedelta, date
import calendar
import json
from frappe.desk.calendar import get_rrule
from dateutil import parser
from erpnext.shopping_cart.cart import _get_cart_quotation
from erpnext.utilities.product import get_price
from erpnext.shopping_cart.product_info import get_product_info_for_website
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment