From 5586957347adac85655b7528e2a07393adcbcd8a Mon Sep 17 00:00:00 2001 From: Andro0o0o0w-Romany Date: Wed, 24 Jul 2024 07:37:32 +0000 Subject: [PATCH] Calculating the fields in the child table CostType in Costing Note doctype --- .../business_clause/business_clause.json | 10 +------- .../doctype/clearance/clearance.json | 14 +++++++---- .../doctype/costing_note/costing_note.js | 14 +++++++---- .../doctype/costing_note/costing_note.json | 11 +++++++-- .../doctype/costing_note/costing_note.py | 6 ++++- .../contracta/doctype/costtype/costtype.py | 5 +--- contracta/hooks.py | 5 +++- contracta/public/js/costtype.js | 0 contracta/public/js/quotation.js | 23 +++++++++++++++++++ 9 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 contracta/public/js/costtype.js create mode 100644 contracta/public/js/quotation.js diff --git a/contracta/contracta/doctype/business_clause/business_clause.json b/contracta/contracta/doctype/business_clause/business_clause.json index a201411..39a8214 100644 --- a/contracta/contracta/doctype/business_clause/business_clause.json +++ b/contracta/contracta/doctype/business_clause/business_clause.json @@ -1,7 +1,6 @@ { "actions": [], "allow_rename": 1, - "autoname": "naming_series:", "creation": "2024-07-17 17:24:17.584874", "doctype": "DocType", "editable_grid": 1, @@ -12,7 +11,6 @@ "project_classification", "clause", "uom", - "naming_series", "column_break_cawa", "qty", "costing_note", @@ -83,18 +81,12 @@ "fieldname": "total", "fieldtype": "Int", "label": "Total" - }, - { - "fieldname": "naming_series", - "fieldtype": "Select", - "label": "series", - "options": "BUSINESS-CLS-.YYYY.-" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2024-07-21 13:03:47.429120", + "modified": "2024-07-23 17:09:30.507334", "modified_by": "Administrator", "module": "Contracta", "name": "Business Clause", diff --git a/contracta/contracta/doctype/clearance/clearance.json b/contracta/contracta/doctype/clearance/clearance.json index d222c79..8380497 100644 --- a/contracta/contracta/doctype/clearance/clearance.json +++ b/contracta/contracta/doctype/clearance/clearance.json @@ -9,14 +9,15 @@ "section_break_gfmf", "amended_from", "naming_series", - "company", "clearance_date", - "sales_invoice", "status", "column_break_cjfp", "clearance_number", - "description", "clearance_type", + "company", + "sales_invoice", + "description_section", + "description", "section_break_iywj", "down_payment_discount_rate", "column_break_hltc", @@ -103,12 +104,17 @@ "fieldtype": "Select", "label": "Series", "options": "CLEARANCE-.YYYY.-" + }, + { + "fieldname": "description_section", + "fieldtype": "Section Break", + "label": "description" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2024-07-21 14:53:42.557905", + "modified": "2024-07-23 17:16:13.068922", "modified_by": "Administrator", "module": "Contracta", "name": "Clearance", diff --git a/contracta/contracta/doctype/costing_note/costing_note.js b/contracta/contracta/doctype/costing_note/costing_note.js index e61487b..45a5945 100644 --- a/contracta/contracta/doctype/costing_note/costing_note.js +++ b/contracta/contracta/doctype/costing_note/costing_note.js @@ -1,8 +1,12 @@ // Copyright (c) 2024, Andrew Romany and contributors // For license information, please see license.txt -// frappe.ui.form.on("Costing Note", { -// refresh(frm) { - -// }, -// }); +frappe.ui.form.on("Costing Note", { + validate: function(frm) { + frm.doc.costtype.forEach(function(row){ + row.total_cost = row.qty * row.unit_cost; + row.tax_value = row.tax * row.total_cost; + row.grand_total_with_tax = row.total_cost + row.tax_value; + }); + }, +}); diff --git a/contracta/contracta/doctype/costing_note/costing_note.json b/contracta/contracta/doctype/costing_note/costing_note.json index 67f2851..5e72e7e 100644 --- a/contracta/contracta/doctype/costing_note/costing_note.json +++ b/contracta/contracta/doctype/costing_note/costing_note.json @@ -25,7 +25,8 @@ "equipment_costs", "contractors_costs", "expense_schedule", - "totals" + "totals", + "costtype" ], "fields": [ { @@ -140,12 +141,18 @@ "fieldtype": "Select", "label": "Series", "options": "COST-NOTE-.YYYY.-" + }, + { + "fieldname": "costtype", + "fieldtype": "Table", + "label": "CostType", + "options": "CostType" } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2024-07-21 12:51:23.651208", + "modified": "2024-07-23 13:43:04.997310", "modified_by": "Administrator", "module": "Contracta", "name": "Costing Note", diff --git a/contracta/contracta/doctype/costing_note/costing_note.py b/contracta/contracta/doctype/costing_note/costing_note.py index 673be35..e8f7ece 100644 --- a/contracta/contracta/doctype/costing_note/costing_note.py +++ b/contracta/contracta/doctype/costing_note/costing_note.py @@ -6,4 +6,8 @@ class CostingNote(Document): - pass + def validate(self): + for calucate in self.costtype: + calucate.total_cost = calucate.qty * calucate.unit_cost + calucate.tax_value = calucate.tax * calucate.total_cost + calucate.grand_total_with_tax = calucate.total_cost + calucate.tax_value diff --git a/contracta/contracta/doctype/costtype/costtype.py b/contracta/contracta/doctype/costtype/costtype.py index 511b2b8..98b9343 100644 --- a/contracta/contracta/doctype/costtype/costtype.py +++ b/contracta/contracta/doctype/costtype/costtype.py @@ -6,7 +6,4 @@ class CostType(Document): - def validate(self): - self.total_cost = self.qty * self.unit_cost - self.tax_value = self.tax * self.total_cost - self.grand_total_with_tax = self.total_cost + self.tax_value + pass diff --git a/contracta/hooks.py b/contracta/hooks.py index db9d986..5e740ec 100644 --- a/contracta/hooks.py +++ b/contracta/hooks.py @@ -28,7 +28,10 @@ # page_js = {"page" : "public/js/file.js"} # include js in doctype views -# doctype_js = {"doctype" : "public/js/doctype.js"} +doctype_js = { + "Quotation": "public/js/quotation.js", + "CostType": "public/js/costtype.js", + } # doctype_list_js = {"doctype" : "public/js/doctype_list.js"} # doctype_tree_js = {"doctype" : "public/js/doctype_tree.js"} # doctype_calendar_js = {"doctype" : "public/js/doctype_calendar.js"} diff --git a/contracta/public/js/costtype.js b/contracta/public/js/costtype.js new file mode 100644 index 0000000..e69de29 diff --git a/contracta/public/js/quotation.js b/contracta/public/js/quotation.js new file mode 100644 index 0000000..62def49 --- /dev/null +++ b/contracta/public/js/quotation.js @@ -0,0 +1,23 @@ +frappe.ui.form.on('Quotation', { + refresh(frm) { + frm.add_custom_button('Contract', function() { + frappe.call({ + method: 'frappe.client.insert', + args: { + doc: { + doctype: "Contract", + party_name: frm.doc.customer_name, + contract_terms: frm.doc.terms, + quotation: frm.doc.name + } + }, + callback: function(response) { + let contract = response.message; + if (contract && contract.name) { + frappe.set_route("Form", "Contract", contract.name); + } + } + }); + }, __("Create")); + } +}); \ No newline at end of file