|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (c) 2015, Frappe and contributors |
| 3 | +# For license information, please see license.txt |
| 4 | +from __future__ import unicode_literals |
| 5 | +import frappe |
| 6 | +from frappe import msgprint, _ |
| 7 | +from frappe.model.document import Document |
| 8 | +from frappe.desk.reportview import get_match_cond, get_filters_cond |
| 9 | +from erpnext.education.doctype.program_enrollment.program_enrollment import ProgramEnrollment |
| 10 | +from frappe.utils import comma_and |
| 11 | +from frappe import utils |
| 12 | +import json |
| 13 | + |
| 14 | + |
| 15 | +@frappe.whitelist() |
| 16 | +def make_inv(customer, customer_name, due_date, courses, fees): |
| 17 | + count = 0 |
| 18 | + #courses and fees are lists that have the docnames from the front end |
| 19 | + courses = json.loads(courses) |
| 20 | + fees = json.loads(fees) |
| 21 | + udoc = frappe.new_doc("Sales Invoice") |
| 22 | + udoc.naming_series = "ACC-SINV-.YYYY.-" |
| 23 | + udoc.customer = customer |
| 24 | + udoc.customer_name = customer_name |
| 25 | + #Fees |
| 26 | + if(fees): |
| 27 | + for d in fees: |
| 28 | + #fetch fee_structure, it has the amount for the sales invoice, as well as.. |
| 29 | + fee_structure = frappe.get_doc("Fee Structure", d) |
| 30 | + for e in fee_structure.components: |
| 31 | + fee_amount = e.amount |
| 32 | + #The fee category. This is have a new field for |
| 33 | + #"Items" doctype, which will make sure each |
| 34 | + #course correlates to a proper item for identification |
| 35 | + fetched_item = frappe.get_doc("Fee Category", e.fees_category) |
| 36 | + if(fetched_item.item): |
| 37 | + udoc.append('items', { |
| 38 | + 'item_code': fetched_item.item, |
| 39 | + 'qty': '1', |
| 40 | + 'rate': fee_amount, |
| 41 | + 'amount': fee_amount, |
| 42 | + }) |
| 43 | + count = count + 1 |
| 44 | + #Only for checking if the sales invoice will turn out empty |
| 45 | + #In case none of the fee category or the Course doctypes |
| 46 | + #Have any items listed |
| 47 | + #For course |
| 48 | + if(courses): |
| 49 | + for i in range(len(courses)): |
| 50 | + fdata = frappe.get_doc('Course', courses[i]) |
| 51 | + if(fdata.item): |
| 52 | + count= count + 1 |
| 53 | + udoc.append('items', { |
| 54 | + 'item_code': fdata.item, |
| 55 | + 'qty': '1', |
| 56 | + }) |
| 57 | + udoc.posting_date = frappe.utils.nowdate() |
| 58 | + #Due date = enrollment date |
| 59 | + udoc.due_date = due_date |
| 60 | + #saves only if there is at least one potential tx |
| 61 | + if( count > 0 ): |
| 62 | + udoc.save() |
| 63 | + return frappe.get_last_doc("Sales Invoice"); |
| 64 | + else: |
| 65 | + msgprint(_("Invoice couldn't be generated : None of your courses or fee structures have an item group assigned.")) |
| 66 | + return |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +def suppress(self): |
| 71 | + self.update_student_joining_date() |
| 72 | + if not self.invoice: |
| 73 | + self.make_fee_records() |
| 74 | + |
| 75 | + |
| 76 | +def submit(doc, method): |
| 77 | + msgprint(_("Overridden!")) |
| 78 | + ProgramEnrollment.on_submit = suppress |
0 commit comments