mirror of
https://github.com/erpnext/foundation.git
synced 2026-10-16 18:00:47 +02:00
feat: enabled auto invoicing for tickets
This commit is contained in:
@@ -12,49 +12,24 @@ class ConferenceParticipant(Document):
|
|||||||
self.conference = '2019'
|
self.conference = '2019'
|
||||||
|
|
||||||
def validate_payment(self):
|
def validate_payment(self):
|
||||||
self.amount = self.full_conference_tickets * (5000 if self.currency == 'INR' else 70)
|
self.amount = self.full_conference_tickets * (5000 if self.currency == 'INR' else 80)
|
||||||
|
|
||||||
def on_payment_authorized(self, status_changed_to=None):
|
def on_payment_authorized(self, status_changed_to=None):
|
||||||
self.paid = 1
|
self.paid = 1
|
||||||
self.save(ignore_permissions=True)
|
self.save(ignore_permissions=True)
|
||||||
|
self.create_and_send_invoice()
|
||||||
|
|
||||||
def on_update(self):
|
def create_and_send_invoice(self):
|
||||||
transaction = get_integration_request(self.name, self.currency)
|
transaction = get_integration_request(self.name, self.currency)
|
||||||
if self.paid and transaction:
|
if not transaction:
|
||||||
self.create_and_send_invoice(transaction)
|
return
|
||||||
|
|
||||||
def create_and_send_invoice(self, transaction):
|
|
||||||
series = 'BC-19-20-'
|
series = 'BC-19-20-'
|
||||||
rate = '5000'
|
rate = '5000'
|
||||||
currency = 'INR'
|
currency = 'INR'
|
||||||
|
customer = 'ERPNext Conference 2019 Participant'
|
||||||
item_income_account = 'Sales - Event Tickets - EF'
|
item_income_account = 'Sales - Event Tickets - EF'
|
||||||
|
account_type = 'Debtors - EF'
|
||||||
if transaction.service == 'Paypal':
|
taxes = [
|
||||||
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',
|
'charge_type': 'On Net Total',
|
||||||
'account_head': 'SGST - EF',
|
'account_head': 'SGST - EF',
|
||||||
@@ -70,9 +45,64 @@ class ConferenceParticipant(Document):
|
|||||||
'included_in_print_rate': 1,
|
'included_in_print_rate': 1,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if transaction.service == 'Paypal':
|
||||||
|
series = 'EXP-19-20-'
|
||||||
|
rate = '80'
|
||||||
|
currency = 'USD'
|
||||||
|
account_type = 'Debtors USD - EF'
|
||||||
|
customer = 'ERPNext Conference 2019 Participant International'
|
||||||
|
item_income_account = 'Sales - Event Tickets (International) - EF'
|
||||||
|
taxes = []
|
||||||
|
|
||||||
|
invoice = frappe.get_doc({
|
||||||
|
'doctype': 'Sales Invoice',
|
||||||
|
'customer': customer,
|
||||||
|
'debit_to': account_type,
|
||||||
|
'remarks': json.dumps(transaction),
|
||||||
|
'currency': currency,
|
||||||
|
'selling_price_list': currency,
|
||||||
|
'series': series,
|
||||||
|
'payment_mode': transaction.service,
|
||||||
|
'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': taxes
|
||||||
})
|
})
|
||||||
|
|
||||||
invoice.insert()
|
invoice.insert()
|
||||||
|
invoice.submit()
|
||||||
|
|
||||||
|
self.make_payment_entry(invoice, transaction, currency)
|
||||||
|
self.send_email(invoice)
|
||||||
|
|
||||||
|
def make_payment_entry(self, invoice, transaction, currency):
|
||||||
|
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||||
|
pe = get_payment_entry(dt='Sales Invoice', dn=invoice.name, bank_amount=invoice.grand_total)
|
||||||
|
pe.paid_to = frappe.get_value("Mode of Payment Account",
|
||||||
|
{'parent': transaction.service,
|
||||||
|
'parenttype': 'Mode of Payment'},
|
||||||
|
['default_account'])
|
||||||
|
|
||||||
|
pe.paid_to_account_currency = currency
|
||||||
|
|
||||||
|
pe.target_exchange_rate = invoice.conversion_rate
|
||||||
|
pe.source_exchange_rate = invoice.conversion_rate
|
||||||
|
pe.mode_of_paypment = transaction.service
|
||||||
|
|
||||||
|
pe.reference_no = transaction.transaction_id
|
||||||
|
pe.reference_date = invoice.posting_date
|
||||||
|
pe.save(ignore_permissions=True)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
def send_email(self, invoice):
|
||||||
email_args = {
|
email_args = {
|
||||||
"recipients": [self.email],
|
"recipients": [self.email],
|
||||||
"message": "Thank you for registering for the ERPNext Conference, Attached herewith is the invoice for the ticket.",
|
"message": "Thank you for registering for the ERPNext Conference, Attached herewith is the invoice for the ticket.",
|
||||||
@@ -83,8 +113,6 @@ class ConferenceParticipant(Document):
|
|||||||
}
|
}
|
||||||
frappe.sendmail(**email_args)
|
frappe.sendmail(**email_args)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_integration_request(docname, currency):
|
def get_integration_request(docname, currency):
|
||||||
service = 'Paypal'
|
service = 'Paypal'
|
||||||
transaction_field = 'correlation_id'
|
transaction_field = 'correlation_id'
|
||||||
|
|||||||
Reference in New Issue
Block a user