mirror of
https://github.com/erpnext/foundation.git
synced 2026-10-16 18:00:47 +02:00
feat: auto invoicing for tickets
This commit is contained in:
@@ -43,7 +43,8 @@
|
||||
"fieldname": "email",
|
||||
"fieldtype": "Data",
|
||||
"label": "Email",
|
||||
"options": "Email"
|
||||
"options": "Email",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "conference_details_section",
|
||||
@@ -59,7 +60,8 @@
|
||||
{
|
||||
"fieldname": "full_conference_tickets",
|
||||
"fieldtype": "Int",
|
||||
"label": "Full Conference Tickets"
|
||||
"label": "Full Conference Tickets",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "user_conference_tickets",
|
||||
@@ -116,7 +118,7 @@
|
||||
"options": "\nCxO\nAnalyst\nConsultant\nDeveloper\nSystem Administrator\nOther"
|
||||
}
|
||||
],
|
||||
"modified": "2019-08-02 19:07:44.339770",
|
||||
"modified": "2019-08-05 16:31:57.901437",
|
||||
"modified_by": "Administrator",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "Conference Participant",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.model.document import Document
|
||||
import json
|
||||
|
||||
class ConferenceParticipant(Document):
|
||||
def validate(self):
|
||||
@@ -16,3 +17,98 @@ class ConferenceParticipant(Document):
|
||||
def on_payment_authorized(self, status_changed_to=None):
|
||||
self.paid = 1
|
||||
self.save(ignore_permissions=True)
|
||||
|
||||
def on_update(self):
|
||||
transaction = get_integration_request(self.name, self.currency)
|
||||
if self.paid and transaction:
|
||||
self.create_and_send_invoice(transaction)
|
||||
|
||||
def create_and_send_invoice(self, transaction):
|
||||
series = 'BC-19-20-'
|
||||
rate = '5000'
|
||||
currency = 'INR'
|
||||
item_income_account = 'Sales - Event Tickets - EF'
|
||||
|
||||
if transaction.service == 'Paypal':
|
||||
series = 'EXP-19-20-'
|
||||
rate = '70'
|
||||
currency = 'USD'
|
||||
item_income_account = 'Sales - Event Tickets (International) - EF'
|
||||
|
||||
|
||||
invoice = frappe.get_doc({
|
||||
'doctype': 'Sales Invoice',
|
||||
'customer': 'ERPNext Conference 2019 Participant',
|
||||
'taxes_and_charges': 'In State GST',
|
||||
'debit_to': 'Debtors - EF',
|
||||
'remarks': json.dumps(transaction),
|
||||
'currency': currency,
|
||||
'series': series,
|
||||
'items': [
|
||||
{
|
||||
'item_code': 'ERPNext Conference',
|
||||
'rate': rate,
|
||||
'qty': self.full_conference_tickets,
|
||||
'cost_center': 'Conference - EF',
|
||||
'income_account': item_income_account,
|
||||
'description': self.name
|
||||
}
|
||||
],
|
||||
'taxes': [
|
||||
{
|
||||
'charge_type': 'On Net Total',
|
||||
'account_head': 'SGST - EF',
|
||||
'description': 'SGST',
|
||||
'rate': 9,
|
||||
'included_in_print_rate': 1,
|
||||
},
|
||||
{
|
||||
'charge_type': 'On Net Total',
|
||||
'account_head': 'CGST - EF',
|
||||
'description': 'CGST',
|
||||
'rate': 9,
|
||||
'included_in_print_rate': 1,
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
invoice.insert()
|
||||
email_args = {
|
||||
"recipients": [self.email],
|
||||
"message": "Thank you for registering for the ERPNext Conference, Attached herewith is the invoice for the ticket.",
|
||||
"subject": 'Invoice for ERPNext Conference',
|
||||
"attachments": [frappe.attach_print('Sales Invoice', invoice.name, file_name=invoice.name)],
|
||||
"reference_doctype": 'Sales Invoice',
|
||||
"reference_name": invoice.name
|
||||
}
|
||||
frappe.sendmail(**email_args)
|
||||
|
||||
|
||||
|
||||
def get_integration_request(docname, currency):
|
||||
service = 'Paypal'
|
||||
transaction_field = 'correlation_id'
|
||||
if currency == 'INR':
|
||||
service = 'Razorpay'
|
||||
transaction_field = 'razorpay_payment_id'
|
||||
|
||||
filters = {
|
||||
'reference_doctype': 'Conference Participant',
|
||||
'reference_docname': docname,
|
||||
'integration_request_service': service,
|
||||
'status': ['in', ['Authorized', 'Completed']]
|
||||
}
|
||||
|
||||
try:
|
||||
transaction = frappe.get_list('Integration Request', filters=filters, fields=['name', 'data'])[0]
|
||||
except IndexError:
|
||||
return None
|
||||
else:
|
||||
transaction.data = json.loads(transaction.data)
|
||||
return frappe._dict({
|
||||
'transaction_id': transaction.data[transaction_field],
|
||||
'amount': transaction.data['amount'],
|
||||
'name': transaction.name,
|
||||
'service': service,
|
||||
'ref_ticket': docname,
|
||||
})
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
"docstatus": 0,
|
||||
"doctype": "Notification",
|
||||
"document_type": "Conference Participant",
|
||||
"enabled": 1,
|
||||
"enabled": 0,
|
||||
"event": "Save",
|
||||
"idx": 0,
|
||||
"is_standard": 1,
|
||||
"message": "<p>Dear {{ doc.participant_name }},</p>\n\n<p>Thank you for registering for the 2019 ERPNext Conference!</p>\n\n<p>Here are your ticket details:</p>\n\n<h4>Ticket Number {{ doc.name}}</h4>\n\n<table class=\"table table-bordered\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"padding: 30px 0px\">\n\t<tr>\n\t\t<th style='width: 50%'>Ticket Type</th>\n\t\t<th style='width: 25%'>Qty</th>\n\t\t<th style='width: 25%'>Rate</th>\n\t</tr>\n\t<tr>\n\t\t<td>Conference Tickets + Lunch + Dinner</td>\n\t\t<td>{{ doc.full_conference_tickets or 0 }}</td>\n\t\t<td>{% if doc.currency==\"INR\" %}5000{% else %}70{% endif %}</td>\n\t</tr>\n</table>\n\n<h5>Total Amount: {{ doc.currency }} {{ doc.get_formatted('amount') }}</h5>\n\n\n<p>If you need any help, please email us at foundation@erpnext.com</p>",
|
||||
"modified": "2019-08-05 13:09:17.385839",
|
||||
"modified": "2019-08-05 17:21:30.465249",
|
||||
"modified_by": "Administrator",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "Conference Ticket Confirmation",
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
"is_standard": 1,
|
||||
"login_required": 0,
|
||||
"max_attachment_size": 0,
|
||||
"modified": "2019-08-02 20:42:18.541094",
|
||||
"modified": "2019-08-05 16:32:20.478032",
|
||||
"modified_by": "Administrator",
|
||||
"module": "ERPNext Foundation",
|
||||
"name": "buy-tickets-inr",
|
||||
@@ -73,7 +73,7 @@
|
||||
"max_value": 0,
|
||||
"options": "Email",
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"reqd": 1,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
@@ -86,7 +86,7 @@
|
||||
"max_length": 0,
|
||||
"max_value": 0,
|
||||
"read_only": 0,
|
||||
"reqd": 0,
|
||||
"reqd": 1,
|
||||
"show_in_filter": 0
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user