From d4b33d3c146b184e87d03a83e2d8d1c296b1056e Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Wed, 15 Apr 2015 16:41:39 +0530 Subject: [PATCH] Costing added in Time log Batch, Sales Order added to Project + more fixes --- .../hr/doctype/expense_claim/expense_claim.py | 8 +++--- erpnext/projects/doctype/project/project.js | 21 ++++++++++++++ .../doctype/time_log_batch/time_log_batch.js | 2 +- .../time_log_batch/time_log_batch.json | 28 +++++++++++++++++-- .../doctype/time_log_batch/time_log_batch.py | 15 ++++++---- .../time_log_batch_detail.json | 28 ++++++++++++------- 6 files changed, 79 insertions(+), 23 deletions(-) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index fb720b025e..b5fe880bd2 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import get_fullname +from frappe.utils import get_fullname, flt from frappe.model.document import Document from erpnext.hr.utils import set_employee_name from erpnext.accounts.utils import validate_fiscal_year @@ -39,8 +39,8 @@ class ExpenseClaim(Document): self.total_claimed_amount = 0 self.total_sanctioned_amount = 0 for d in self.expenses: - self.total_claimed_amount += d.claim_amount - self.total_sanctioned_amount += d.sanctioned_amount + self.total_claimed_amount += flt(d.claim_amount) + self.total_sanctioned_amount += flt(d.sanctioned_amount) def validate_exp_details(self): if not self.get('expenses'): @@ -62,5 +62,5 @@ class ExpenseClaim(Document): def validate_sanctioned_amount(self): for d in self.expenses: - if d.sanctioned_amount > d.claim_amount: + if flt(d.sanctioned_amount) > flt(d.claim_amount): frappe.throw(_("Sanctioned Amount cannot be greater than Claim Amount in Row {0}.").format(d.idx)) \ No newline at end of file diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 56cc09dbee..1148efeadc 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -1,6 +1,19 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt +frappe.ui.form.on("Project", { + onload: function(frm) { + var so = frappe.meta.get_docfield("Project", "sales_order"); + so.get_route_options_for_new_doc = function(field) { + if(frm.is_new()) return; + return { + "customer": frm.doc.customer, + "project_name": frm.doc.name + } + } + } +}); + frappe.ui.form.on("Project Task", "edit_task", function(frm, doctype, name) { var doc = frappe.get_doc(doctype, name); if(doc.task_id) { @@ -37,3 +50,11 @@ cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) { query: "erpnext.controllers.queries.customer_query" } } + +cur_frm.fields_dict['sales_order'].get_query = function(doc) { + return { + filters:{ + 'project_name': doc.name + } + } +} diff --git a/erpnext/projects/doctype/time_log_batch/time_log_batch.js b/erpnext/projects/doctype/time_log_batch/time_log_batch.js index 0635db09b9..39141ed968 100644 --- a/erpnext/projects/doctype/time_log_batch/time_log_batch.js +++ b/erpnext/projects/doctype/time_log_batch/time_log_batch.js @@ -2,7 +2,7 @@ // License: GNU General Public License v3. See license.txt cur_frm.add_fetch("time_log", "activity_type", "activity_type"); -cur_frm.add_fetch("time_log", "owner", "created_by"); +cur_frm.add_fetch("time_log", "billing_amount", "billing_amount"); cur_frm.add_fetch("time_log", "hours", "hours"); cur_frm.set_query("time_log", "time_logs", function(doc) { diff --git a/erpnext/projects/doctype/time_log_batch/time_log_batch.json b/erpnext/projects/doctype/time_log_batch/time_log_batch.json index a42c4ea437..c53b1e9622 100644 --- a/erpnext/projects/doctype/time_log_batch/time_log_batch.json +++ b/erpnext/projects/doctype/time_log_batch/time_log_batch.json @@ -32,6 +32,7 @@ "fieldtype": "Select", "in_list_view": 0, "label": "Status", + "no_copy": 1, "options": "Draft\nSubmitted\nBilled\nCancelled", "permlevel": 0, "read_only": 1 @@ -60,7 +61,14 @@ "reqd": 1 }, { - "description": "In Hours", + "fieldname": "section_break_8", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, + { + "default": "0", + "description": "updated via Time Logs", "fieldname": "total_hours", "fieldtype": "Float", "in_list_view": 1, @@ -68,6 +76,22 @@ "permlevel": 0, "read_only": 1 }, + { + "fieldname": "column_break_10", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, + { + "default": "0", + "description": "updated via Time Logs", + "fieldname": "total_billing_amount", + "fieldtype": "Float", + "label": "Total Billing Amount", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, { "fieldname": "amended_from", "fieldtype": "Link", @@ -83,7 +107,7 @@ "icon": "icon-time", "idx": 1, "is_submittable": 1, - "modified": "2015-02-05 05:11:48.360822", + "modified": "2015-04-15 06:07:41.771962", "modified_by": "Administrator", "module": "Projects", "name": "Time Log Batch", diff --git a/erpnext/projects/doctype/time_log_batch/time_log_batch.py b/erpnext/projects/doctype/time_log_batch/time_log_batch.py index 95655363c6..9ea3256bcf 100644 --- a/erpnext/projects/doctype/time_log_batch/time_log_batch.py +++ b/erpnext/projects/doctype/time_log_batch/time_log_batch.py @@ -7,6 +7,7 @@ from __future__ import unicode_literals import frappe from frappe import _ +from frappe.utils import flt from frappe.model.document import Document from frappe.model.mapper import get_mapped_doc @@ -14,12 +15,12 @@ class TimeLogBatch(Document): def validate(self): self.set_status() - self.total_hours = 0.0 for d in self.get("time_logs"): tl = frappe.get_doc("Time Log", d.time_log) self.update_time_log_values(d, tl) self.validate_time_log_is_submitted(tl) - self.total_hours += float(tl.hours or 0.0) + self.total_hours += flt(tl.hours) + self.total_billing_amount += flt(tl.billing_amount) def update_time_log_values(self, d, tl): d.update({ @@ -29,7 +30,9 @@ class TimeLogBatch(Document): }) def validate_time_log_is_submitted(self, tl): - if tl.status != "Submitted" and self.docstatus == 0: + if tl.status == "Batched for Billing": + frappe.throw(_("Time Log {0} already billed").format(tl.name)) + elif tl.status != "Submitted": frappe.throw(_("Time Log {0} must be 'Submitted'").format(tl.name)) def set_status(self): @@ -65,15 +68,15 @@ def make_sales_invoice(source_name, target=None): def update_item(source_doc, target_doc, source_parent): target_doc.stock_uom = "Hour" target_doc.description = "via Time Logs" + target_doc.qty = 1 target = frappe.new_doc("Sales Invoice") target.append("items", get_mapped_doc("Time Log Batch", source_name, { "Time Log Batch": { "doctype": "Sales Invoice Item", "field_map": { - "rate": "base_rate", - "name": "time_log_batch", - "total_hours": "qty", + "total_billing_amount": "rate", + "name": "time_log_batch" }, "postprocess": update_item } diff --git a/erpnext/projects/doctype/time_log_batch_detail/time_log_batch_detail.json b/erpnext/projects/doctype/time_log_batch_detail/time_log_batch_detail.json index 15e7e8e29b..da8ff4cd4a 100644 --- a/erpnext/projects/doctype/time_log_batch_detail/time_log_batch_detail.json +++ b/erpnext/projects/doctype/time_log_batch_detail/time_log_batch_detail.json @@ -1,5 +1,5 @@ { - "creation": "2013-03-05 09:11:06.000000", + "creation": "2013-03-05 09:11:06", "docstatus": 0, "doctype": "DocType", "fields": [ @@ -15,14 +15,19 @@ "width": "200px" }, { - "fieldname": "created_by", - "fieldtype": "Link", + "fieldname": "hours", + "fieldtype": "Float", "in_list_view": 1, - "label": "Created By", - "options": "User", + "label": "Hours", "permlevel": 0, "read_only": 1 }, + { + "fieldname": "section_break_3", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "activity_type", "fieldtype": "Data", @@ -32,18 +37,21 @@ "read_only": 1 }, { - "fieldname": "hours", + "fieldname": "billing_amount", "fieldtype": "Float", "in_list_view": 1, - "label": "Hours", - "permlevel": 0 + "label": "Billing Amount", + "permlevel": 0, + "precision": "", + "read_only": 1 } ], "idx": 1, "istable": 1, - "modified": "2013-12-20 19:21:54.000000", + "modified": "2015-04-15 05:35:08.805589", "modified_by": "Administrator", "module": "Projects", "name": "Time Log Batch Detail", - "owner": "Administrator" + "owner": "Administrator", + "permissions": [] } \ No newline at end of file