fix: Non Profit fixes (#30280)

This commit is contained in:
Rucha Mahabal
2022-03-17 12:52:02 +05:30
committed by GitHub
parent 0becc1e231
commit 15413cf835
14 changed files with 79 additions and 54 deletions

View File

@@ -17,7 +17,8 @@
"paid",
"amount",
"mode_of_payment",
"razorpay_payment_id",
"column_break_12",
"payment_id",
"amended_from"
],
"fields": [
@@ -73,12 +74,6 @@
"label": "Mode of Payment",
"options": "Mode of Payment"
},
{
"fieldname": "razorpay_payment_id",
"fieldtype": "Data",
"label": "Razorpay Payment ID",
"read_only": 1
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
@@ -108,12 +103,21 @@
"options": "Donation",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "payment_id",
"fieldtype": "Data",
"label": "Payment ID"
},
{
"fieldname": "column_break_12",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2021-03-11 10:53:11.269005",
"modified": "2022-03-16 17:18:45.611741",
"modified_by": "Administrator",
"module": "Non Profit",
"name": "Donation",

View File

@@ -102,7 +102,7 @@ def capture_razorpay_donations(*args, **kwargs):
if not donor:
donor = create_donor(payment)
donation = create_donation(donor, payment)
donation = create_razorpay_donation(donor, payment)
donation.run_method('create_payment_entry')
except Exception as e:
@@ -114,7 +114,7 @@ def capture_razorpay_donations(*args, **kwargs):
return { 'status': 'Success' }
def create_donation(donor, payment):
def create_razorpay_donation(donor, payment):
if not frappe.db.exists('Mode of Payment', payment.method):
create_mode_of_payment(payment.method)
@@ -128,7 +128,7 @@ def create_donation(donor, payment):
'date': getdate(),
'amount': flt(payment.amount) / 100, # Convert to rupees from paise
'mode_of_payment': payment.method,
'razorpay_payment_id': payment.id
'payment_id': payment.id
}).insert(ignore_mandatory=True)
donation.submit()

View File

@@ -5,7 +5,7 @@ import unittest
import frappe
from erpnext.non_profit.doctype.donation.donation import create_donation
from erpnext.non_profit.doctype.donation.donation import create_razorpay_donation
class TestDonation(unittest.TestCase):
@@ -30,7 +30,7 @@ class TestDonation(unittest.TestCase):
'method': 'Debit Card',
'id': 'pay_MeXAmsgeKOhq7O'
})
donation = create_donation(donor, payment)
donation = create_razorpay_donation(donor, payment)
self.assertTrue(donation.name)

View File

@@ -100,10 +100,13 @@ def create_customer(user_details, member=None):
customer = frappe.new_doc("Customer")
customer.customer_name = user_details.fullname
customer.customer_type = "Individual"
customer.customer_group = frappe.db.get_single_value("Selling Settings", "customer_group")
customer.territory = frappe.db.get_single_value("Selling Settings", "territory")
customer.flags.ignore_mandatory = True
customer.insert(ignore_permissions=True)
try:
frappe.db.savepoint("contact_creation")
contact = frappe.new_doc("Contact")
contact.first_name = user_details.fullname
if user_details.mobile:
@@ -129,6 +132,7 @@ def create_customer(user_details, member=None):
return customer.name
except Exception as e:
frappe.db.rollback(save_point="contact_creation")
frappe.log_error(frappe.get_traceback(), _("Contact Creation Failed"))
pass

View File

@@ -21,9 +21,11 @@
"paid",
"currency",
"amount",
"column_break_16",
"invoice",
"razorpay_details_section",
"subscription_id",
"column_break_19",
"payment_id"
],
"fields": [
@@ -106,20 +108,17 @@
{
"fieldname": "razorpay_details_section",
"fieldtype": "Section Break",
"hidden": 1,
"label": "Razorpay Details"
},
{
"fieldname": "subscription_id",
"fieldtype": "Data",
"label": "Subscription ID",
"read_only": 1
"label": "Subscription ID"
},
{
"fieldname": "payment_id",
"fieldtype": "Data",
"label": "Payment ID",
"read_only": 1
"label": "Payment ID"
},
{
"fieldname": "invoice",
@@ -140,11 +139,19 @@
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"fieldname": "column_break_19",
"fieldtype": "Column Break"
},
{
"fieldname": "column_break_16",
"fieldtype": "Column Break"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-19 14:33:44.925122",
"modified": "2022-03-16 17:37:28.672916",
"modified_by": "Administrator",
"module": "Non Profit",
"name": "Membership",

View File

@@ -104,7 +104,7 @@ class Membership(Document):
return invoice
def validate_membership_type_and_settings(self, plan, settings):
settings_link = get_link_to_form("Membership Type", self.membership_type)
settings_link = get_link_to_form("Non Profit Settings", "Non Profit Settings")
if not settings.membership_debit_account:
frappe.throw(_("You need to set <b>Debit Account</b> in {0}").format(settings_link))

View File

@@ -353,3 +353,4 @@ erpnext.patches.v13_0.amazon_mws_deprecation_warning
erpnext.patches.v13_0.set_work_order_qty_in_so_from_mr
erpnext.patches.v13_0.update_accounts_in_loan_docs
erpnext.patches.v13_0.remove_unknown_links_to_prod_plan_items
erpnext.patches.v13_0.rename_non_profit_fields

View File

@@ -0,0 +1,17 @@
import frappe
from frappe.model.utils.rename_field import rename_field
def execute():
if frappe.db.table_exists("Donation"):
frappe.reload_doc("non_profit", "doctype", "Donation")
rename_field("Donation", "razorpay_payment_id", "payment_id")
if frappe.db.table_exists("Tax Exemption 80G Certificate"):
frappe.reload_doc("regional", "doctype", "Tax Exemption 80G Certificate")
frappe.reload_doc("regional", "doctype", "Tax Exemption 80G Certificate Detail")
rename_field("Tax Exemption 80G Certificate", "razorpay_payment_id", "payment_id")
rename_field("Tax Exemption 80G Certificate Detail", "razorpay_payment_id", "payment_id")

View File

@@ -36,7 +36,7 @@ frappe.ui.form.on('Tax Exemption 80G Certificate', {
'date_of_donation': '',
'amount': 0,
'mode_of_payment': '',
'razorpay_payment_id': ''
'payment_id': ''
});
}
},

View File

@@ -38,7 +38,7 @@
"amount",
"column_break_27",
"mode_of_payment",
"razorpay_payment_id"
"payment_id"
],
"fields": [
{
@@ -201,13 +201,6 @@
"options": "Mode of Payment",
"read_only": 1
},
{
"fetch_from": "donation.razorpay_payment_id",
"fieldname": "razorpay_payment_id",
"fieldtype": "Data",
"label": "RazorPay Payment ID",
"read_only": 1
},
{
"fetch_from": "donation.date",
"fieldname": "date_of_donation",
@@ -266,11 +259,18 @@
"hidden": 1,
"label": "Title",
"print_hide": 1
},
{
"fetch_from": "donation.payment_id",
"fieldname": "payment_id",
"fieldtype": "Data",
"label": "Payment ID",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-02-22 00:03:34.215633",
"modified": "2022-03-16 17:21:39.831059",
"modified_by": "Administrator",
"module": "Regional",
"name": "Tax Exemption 80G Certificate",

View File

@@ -6,29 +6,19 @@ import frappe
from frappe import _
from frappe.contacts.doctype.address.address import get_company_address
from frappe.model.document import Document
from frappe.utils import flt, get_link_to_form, getdate
from frappe.utils import flt, get_link_to_form
from erpnext.accounts.utils import get_fiscal_year
class TaxExemption80GCertificate(Document):
def validate(self):
self.validate_date()
self.validate_duplicates()
self.validate_company_details()
self.set_company_address()
self.calculate_total()
self.set_title()
def validate_date(self):
if self.recipient == 'Member':
if getdate(self.date):
fiscal_year = get_fiscal_year(fiscal_year=self.fiscal_year, as_dict=True)
if not (fiscal_year.year_start_date <= getdate(self.date) \
<= fiscal_year.year_end_date):
frappe.throw(_('The Certificate Date is not in the Fiscal Year {0}').format(frappe.bold(self.fiscal_year)))
def validate_duplicates(self):
if self.recipient == 'Donor':
certificate = frappe.db.exists(self.doctype, {
@@ -96,7 +86,7 @@ class TaxExemption80GCertificate(Document):
'date': doc.from_date,
'amount': doc.amount,
'invoice_id': doc.invoice,
'razorpay_payment_id': doc.payment_id,
'payment_id': doc.payment_id,
'membership': doc.name
})
total += flt(doc.amount)

View File

@@ -7,7 +7,7 @@ import frappe
from frappe.utils import getdate
from erpnext.accounts.utils import get_fiscal_year
from erpnext.non_profit.doctype.donation.donation import create_donation
from erpnext.non_profit.doctype.donation.donation import create_razorpay_donation
from erpnext.non_profit.doctype.donation.test_donation import (
create_donor,
create_donor_type,
@@ -39,11 +39,11 @@ class TestTaxExemption80GCertificate(unittest.TestCase):
donor = create_donor()
create_mode_of_payment()
payment = frappe._dict({
'amount': 100,
'amount': 100, # rzp sends data in paise
'method': 'Debit Card',
'id': 'pay_MeXAmsgeKOhq7O'
})
donation = create_donation(donor, payment)
donation = create_razorpay_donation(donor, payment)
args = frappe._dict({
'recipient': 'Donor',

View File

@@ -9,7 +9,7 @@
"amount",
"invoice_id",
"column_break_4",
"razorpay_payment_id",
"payment_id",
"membership"
],
"fields": [
@@ -35,26 +35,28 @@
"options": "Sales Invoice",
"reqd": 1
},
{
"fieldname": "razorpay_payment_id",
"fieldtype": "Data",
"label": "Razorpay Payment ID"
},
{
"fieldname": "membership",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Membership",
"options": "Membership"
},
{
"fieldname": "column_break_4",
"fieldtype": "Column Break"
},
{
"fieldname": "payment_id",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Payment ID"
}
],
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-02-15 16:35:10.777587",
"modified": "2022-03-17 11:55:24.621708",
"modified_by": "Administrator",
"module": "Regional",
"name": "Tax Exemption 80G Certificate Detail",

View File

@@ -10,10 +10,10 @@
"docstatus": 0,
"doctype": "Print Format",
"font": "Default",
"html": "{% if letter_head and not no_letterhead -%}\n <div class=\"letter-head\">{{ letter_head }}</div>\n{%- endif %}\n\n<div>\n <h3 class=\"text-center\">{{ doc.company }} 80G Donor Certificate</h3>\n</div>\n<br><br>\n\n<div class=\"details\">\n <p> <b>{{ _(\"Certificate No. : \") }}</b> {{ doc.name }} </p>\n <p>\n \t<b>{{ _(\"Date\") }} :</b> {{ doc.get_formatted(\"date\") }}<br>\n </p>\n <br><br>\n \n <div>\n\n This is to confirm that the {{ doc.company }} received an amount of <b>{{doc.get_formatted(\"amount\")}}</b>\n from <b>{{ doc.donor_name }}</b>\n {% if doc.pan_number -%}\n bearing PAN Number {{ doc.member_pan_number }}\n {%- endif %}\n\n via the Mode of Payment {{doc.mode_of_payment}}\n\n {% if doc.razorpay_payment_id -%}\n bearing RazorPay Payment ID {{ doc.razorpay_payment_id }}\n {%- endif %}\n\n on {{ doc.get_formatted(\"date_of_donation\") }}\n <br><br>\n \n <p>\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n </p>\n\n </div>\n</div>\n\n<br><br>\n<p class=\"company-address text-left\"> {{doc.company_address_display }}</p>\n\n<div class=\"certificate-footer text-center\">\n <p><i>Computer generated receipt - Does not require signature</i></p><br>\n \n {% if doc.company_pan_number %}\n <p>\n <b>{{ doc.company }}'s PAN Account No :</b> {{ doc.company_pan_number }}\n <p><br>\n {% endif %}\n \n <p>\n <b>80G Number : </b> {{ doc.company_80g_number }}\n {% if doc.company_80g_wef %}\n ( w.e.f. {{ doc.get_formatted('company_80g_wef') }} )\n {% endif %}\n </p><br>\n</div>",
"html": "{% if letter_head and not no_letterhead -%}\n <div class=\"letter-head\">{{ letter_head }}</div>\n{%- endif %}\n\n<div>\n <h3 class=\"text-center\">{{ doc.company }} 80G Donor Certificate</h3>\n</div>\n<br><br>\n\n<div class=\"details\">\n <p> <b>{{ _(\"Certificate No. : \") }}</b> {{ doc.name }} </p>\n <p>\n \t<b>{{ _(\"Date\") }} :</b> {{ doc.get_formatted(\"date\") }}<br>\n </p>\n <br><br>\n \n <div>\n\n This is to confirm that the {{ doc.company }} received an amount of <b>{{doc.get_formatted(\"amount\")}}</b>\n from <b>{{ doc.donor_name }}</b>\n {% if doc.pan_number -%}\n bearing PAN Number {{ doc.member_pan_number }}\n {%- endif %}\n\n via the Mode of Payment {{doc.mode_of_payment}}\n\n {% if doc.payment_id -%}\n bearing Payment ID {{ doc.payment_id }}\n {%- endif %}\n\n on {{ doc.get_formatted(\"date_of_donation\") }}\n <br><br>\n \n <p>\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n </p>\n\n </div>\n</div>\n\n<br><br>\n<p class=\"company-address text-left\"> {{doc.company_address_display }}</p>\n\n<div class=\"certificate-footer text-center\">\n <p><i>Computer generated receipt - Does not require signature</i></p><br>\n \n {% if doc.company_pan_number %}\n <p>\n <b>{{ doc.company }}'s PAN Account No :</b> {{ doc.company_pan_number }}\n <p><br>\n {% endif %}\n \n <p>\n <b>80G Number : </b> {{ doc.company_80g_number }}\n {% if doc.company_80g_wef %}\n ( w.e.f. {{ doc.get_formatted('company_80g_wef') }} )\n {% endif %}\n </p><br>\n</div>",
"idx": 0,
"line_breaks": 0,
"modified": "2021-02-22 00:20:08.516600",
"modified": "2022-03-16 17:25:33.420509",
"modified_by": "Administrator",
"module": "Regional",
"name": "80G Certificate for Donation",