Skip to content

Commit

Permalink
fix: payment details in Case
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Oct 20, 2023
1 parent d3da251 commit 3899606
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
23 changes: 22 additions & 1 deletion changemakers/frappe_changemakers/doctype/case/case.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"shelter_update",
"admitted_to_shelter",
"other_update",
"payment_details_section",
"payment_details",
"total_amount",
"follow_up_details_section",
"family_meeting_outcome",
"followups",
Expand Down Expand Up @@ -318,11 +321,29 @@
"fieldname": "full_name",
"fieldtype": "Data",
"label": "Name"
},
{
"fieldname": "payment_details_section",
"fieldtype": "Section Break",
"label": "Payment Details"
},
{
"fieldname": "payment_details",
"fieldtype": "Table",
"label": "Payment Details",
"options": "Payment Details"
},
{
"fieldname": "total_amount",
"fieldtype": "Currency",
"label": "Total Amount",
"non_negative": 1,
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-09-06 21:55:35.529923",
"modified": "2023-10-20 11:20:19.046520",
"modified_by": "Administrator",
"module": "Frappe Changemakers",
"name": "Case",
Expand Down
33 changes: 13 additions & 20 deletions changemakers/frappe_changemakers/doctype/case/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
import frappe
from frappe.model.document import Document

class Case(Document):
def before_save(self):
self.set_created_by()
self.calculate_total_amount()

def validate(self):
self.validate_total_amount()

def set_created_by(self):
if not self.created_by:
owner = frappe.db.get_value("User", self.owner, "full_name")
self.created_by = owner
class Case(Document):
def before_save(self):
self.set_created_by()
self.set_total_amount()

def calculate_total_amount(self):
total_amount = 0
for row in self.get("payment_details"):
total_amount += row.amount
self.total_amount = total_amount
def set_created_by(self):
if not self.created_by:
owner = frappe.db.get_value("User", self.owner, "full_name")
self.created_by = owner

def validate_total_amount(self):
if self.total_amount:
if self.total_amount < 0:
frappe.throw("Total amount must not be less than zero.")
def set_total_amount(self):
total_amount = 0
for row in self.payment_details:
total_amount += row.amount
self.total_amount = total_amount
23 changes: 16 additions & 7 deletions frontend/types/FrappeChangemakers/Case.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PaymentDetails } from './PaymentDetails'
import { CaseFollowup } from './CaseFollowup'

export interface Case{
Expand All @@ -15,8 +16,8 @@ export interface Case{
title: string
/** Description : Small Text */
description?: string
/** Type : Select */
type: "Shelter" | "Medical" | "Food" | "Entitlement" | "Identified a Family" | "Legal" | "Other"
/** Type : Link - Case Type */
type: string
/** Status : Select */
status: "New" | "In Follow Up" | "Spam" | "Untraced" | "Closed"
/** Priority : Select */
Expand All @@ -27,20 +28,22 @@ export interface Case{
is_beneficiary_in_shelter_home?: 0 | 1
/** State : Link - State */
state: string
/** Zone/Block : Link - Zone */
zone: string
/** Shelter Home : Link - Shelter Home */
shelter_home?: string
/** City/District : Link - District */
district: string
/** Zone/Block : Link - Zone */
zone: string
/** Ward/GP : Link - Ward */
ward: string
/** Hotspot Name/Habitation : Link - Habitation */
habitation: string
habitation?: string
/** Shelter Home : Link - Shelter Home */
shelter_home?: string
/** Is Beneficiary Traced? : Check */
is_beneficiary_traced?: 0 | 1
/** Beneficiary : Link - Beneficiary */
beneficiary?: string
/** Name : Data */
full_name?: string
/** Gender : Link - Gender */
gender?: string
/** Age : Int */
Expand All @@ -61,8 +64,14 @@ export interface Case{
admitted_to_shelter?: string
/** Other Update : Small Text */
other_update?: string
/** Payment Details : Table - Payment Details */
payment_details?: PaymentDetails[]
/** Total Amount : Currency */
total_amount?: number
/** Family Meeting Outcome : Select */
family_meeting_outcome?: "Meeting went well and the Beneficiary returned to home" | "Meeting went well but the Beneficiary didn’t go home" | "Family members did not come" | "Beneficiary didn’t go for the meeting" | "Mismatch"
/** Followups : Table - Case Followup */
followups?: CaseFollowup[]
/** Created By : Data */
created_by?: string
}

0 comments on commit 3899606

Please sign in to comment.