From 3899606cc6308b05aeaa6115a6aac319a995e91a Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Fri, 20 Oct 2023 11:20:26 +0530 Subject: [PATCH] fix: payment details in Case --- .../doctype/case/case.json | 23 ++++++++++++- .../frappe_changemakers/doctype/case/case.py | 33 ++++++++----------- frontend/types/FrappeChangemakers/Case.ts | 23 +++++++++---- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/changemakers/frappe_changemakers/doctype/case/case.json b/changemakers/frappe_changemakers/doctype/case/case.json index f488252..adda450 100644 --- a/changemakers/frappe_changemakers/doctype/case/case.json +++ b/changemakers/frappe_changemakers/doctype/case/case.json @@ -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", @@ -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", diff --git a/changemakers/frappe_changemakers/doctype/case/case.py b/changemakers/frappe_changemakers/doctype/case/case.py index e0a083f..b372779 100644 --- a/changemakers/frappe_changemakers/doctype/case/case.py +++ b/changemakers/frappe_changemakers/doctype/case/case.py @@ -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 diff --git a/frontend/types/FrappeChangemakers/Case.ts b/frontend/types/FrappeChangemakers/Case.ts index 3e89610..4916749 100644 --- a/frontend/types/FrappeChangemakers/Case.ts +++ b/frontend/types/FrappeChangemakers/Case.ts @@ -1,3 +1,4 @@ +import { PaymentDetails } from './PaymentDetails' import { CaseFollowup } from './CaseFollowup' export interface Case{ @@ -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 */ @@ -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 */ @@ -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 } \ No newline at end of file