feat: Add Create Expense Claim button in Delivery Trip (#25526)

* feat(Delivery Trip): Add employee_code field

* feat(Expense Claim): Add Delivery Trip Number field

* feat(Delivery Trip): Add Create Expense Claim button

* feat(Delivery Trip): Make Create Expense Claim button show up after save

* fix(Delivery Trip): Fix Sider issues

* fix(Delivery Trip): Display button after submit

* fix(Delivery Trip & Expense Claim): Rename new fields

* fix(Delivery Trip): Add button in refresh

* fix(Delivery Trip): Remove redundant line

* fix(Expense Claim): Display delivery_trip only if non-empty

* fix(Delivery Trip): Add test for Create Expense Claim

* fix(Delivery Trip): Fix Sider Issue

* fix(Delivery Trip): Only display Create Expense Claim if the driver is an employee

* fix(Delivery Trip): Fix test

* fix(Delivery Trip): Fix make_expense_claim()

* fix: sider

Co-authored-by: Saqib <nextchamp.saqib@gmail.com>
This commit is contained in:
Ganga Manoj 2021-05-08 17:15:33 +05:30 committed by GitHub
parent 64bd4f27b8
commit aa9e172091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 3 deletions

View File

@ -14,6 +14,7 @@
"column_break_5",
"expense_approver",
"approval_status",
"delivery_trip",
"is_paid",
"expense_details",
"expenses",
@ -365,13 +366,20 @@
"label": "Total Taxes and Charges",
"options": "Company:company:default_currency",
"read_only": 1
},
{
"depends_on": "eval: doc.delivery_trip",
"fieldname": "delivery_trip",
"fieldtype": "Link",
"label": "Delivery Trip",
"options": "Delivery Trip"
}
],
"icon": "fa fa-money",
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2020-09-18 17:26:09.703215",
"modified": "2021-05-04 05:35:12.040199",
"modified_by": "Administrator",
"module": "HR",
"name": "Expense Claim",

View File

@ -41,6 +41,15 @@ frappe.ui.form.on('Delivery Trip', {
},
refresh: function (frm) {
if (frm.doc.docstatus == 1 && frm.doc.employee) {
frm.add_custom_button(__('Expense Claim'), function() {
frappe.model.open_mapped_doc({
method: 'erpnext.stock.doctype.delivery_trip.delivery_trip.make_expense_claim',
frm: cur_frm,
});
}, __("Create"));
}
if (frm.doc.docstatus == 1 && frm.doc.delivery_stops.length > 0) {
frm.add_custom_button(__("Notify Customers via Email"), function () {
frm.trigger('notify_customers');

View File

@ -21,6 +21,7 @@
"column_break_4",
"vehicle",
"departure_time",
"employee",
"delivery_service_stops",
"delivery_stops",
"calculate_arrival_time",
@ -176,11 +177,19 @@
"fieldtype": "Data",
"label": "Driver Email",
"read_only": 1
},
{
"fetch_from": "driver.employee",
"fieldname": "employee",
"fieldtype": "Link",
"label": "Employee",
"options": "Employee",
"read_only": 1
}
],
"is_submittable": 1,
"links": [],
"modified": "2020-01-26 22:37:14.824021",
"modified": "2021-04-30 21:21:36.610142",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Trip",

View File

@ -11,6 +11,7 @@ from frappe import _
from frappe.contacts.doctype.address.address import get_address_display
from frappe.model.document import Document
from frappe.utils import cint, get_datetime, get_link_to_form
from frappe.model.mapper import get_mapped_doc
class DeliveryTrip(Document):
@ -394,3 +395,15 @@ def get_driver_email(driver):
employee = frappe.db.get_value("Driver", driver, "employee")
email = frappe.db.get_value("Employee", employee, "prefered_email")
return {"email": email}
@frappe.whitelist()
def make_expense_claim(source_name, target_doc=None):
doc = get_mapped_doc("Delivery Trip", source_name,
{"Delivery Trip": {
"doctype": "Expense Claim",
"field_map": {
"name" : "delivery_trip"
}
}}, target_doc)
return doc

View File

@ -7,7 +7,7 @@ import unittest
import erpnext
import frappe
from erpnext.stock.doctype.delivery_trip.delivery_trip import get_contact_and_address, notify_customers
from erpnext.stock.doctype.delivery_trip.delivery_trip import get_contact_and_address, notify_customers, make_expense_claim
from erpnext.tests.utils import create_test_contact_and_address
from frappe.utils import add_days, flt, now_datetime, nowdate
@ -28,6 +28,10 @@ class TestDeliveryTrip(unittest.TestCase):
frappe.db.sql("delete from `tabEmail Template`")
frappe.db.sql("delete from `tabDelivery Trip`")
def test_expense_claim_fields_are_fetched_properly(self):
expense_claim = make_expense_claim(self.delivery_trip.name)
self.assertEqual(self.delivery_trip.name, expense_claim.delivery_trip)
def test_delivery_trip_notify_customers(self):
notify_customers(delivery_trip=self.delivery_trip.name)
self.delivery_trip.load_from_db()