feat(core): actual distance travelled by the driver - #32
Conversation
|
Looks good, but a few notes:
|
| }, | ||
| ], | ||
| function (data) { | ||
| frappe.call({ |
There was a problem hiding this comment.
Don't go to the server. Just take the value that the user inputs and set in the form itself.
| }, | ||
| ], | ||
| function (data) { | ||
| frappe.call({ |
|
|
||
|
|
||
| def set_vehicle_last_odometer_value(self, event): | ||
| print("reached here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") |
| def set_vehicle_last_odometer_value(self, event): | ||
| print("reached here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") | ||
| if self.actual_distance_travelled: | ||
| vehicle = frappe.get_doc("Vehicle", self.vehicle) |
There was a problem hiding this comment.
get_doc is overkill for this. Just do a simple frappe.db.set_value.
| import frappe | ||
|
|
||
|
|
||
| def set_vehicle_last_odometer_value(self, event): |
There was a problem hiding this comment.
The self argument is convention for classes. Change the arguments to (trip, method) to keep it consistent with other hook methods.
| @@ -0,0 +1,50 @@ | |||
| frappe.ui.form.on('Delivery Trip', { | |||
| refresh: (frm) => { | |||
| if (frm.doc.docstatus == 1 && frm.doc.status != "Completed" && frm.doc.odometer_start_value == 0) { | |||
There was a problem hiding this comment.
The conditions in the if and else if have some common expressions. Maybe combine them and nest the ifs.
| frm.dirty(); | ||
| frm.save_or_update(); | ||
| } else{ | ||
| frappe.throw("Invalid Odometer Stop Value!"); |
There was a problem hiding this comment.
Let the user know what exactly went wrong - the stop value is smaller than the start value.
| function (data) { | ||
| frm.set_value('odometer_stop_value', data.odometer_stop_value); | ||
| frm.set_value('odometer_stop_time', frappe.datetime.now_datetime()); | ||
| if (data.odometer_stop_value > frm.doc.odometer_start_value && frm.doc.odometer_stop_time > frm.doc.odometer_start_time) { |
There was a problem hiding this comment.
You don't need the time check. The user does not input that, so it's going to be later always.
| frappe.db.commit() | ||
|
|
||
| @frappe.whitelist() | ||
| def update_odometer(dn, start=None, stop=None): |
There was a problem hiding this comment.
You don't need this method anymore.
| }, | ||
| ], | ||
| function (data) { | ||
| frm.set_value('odometer_stop_value', data.odometer_stop_value); |
There was a problem hiding this comment.
Don't update the stop value if it's lower than the start value. Put it inside the check.
|
|
||
|
|
||
| def set_vehicle_last_odometer_value(trip, method): | ||
| if self.actual_distance_travelled: |
There was a problem hiding this comment.
Please test your changes, lol. self is no longer available.
| def set_vehicle_last_odometer_value(trip, method): | ||
| if self.actual_distance_travelled: | ||
| frappe.db.set_value('Vehicle', trip.vehicle, 'last_odometer', trip.odometer_stop_value) | ||
| frappe.db.commit() |
There was a problem hiding this comment.
You don't need an explicit commit. It'll happen automatically if the hook runs successfully.
| from erpnext.stock.doctype.batch.batch import get_batch_qty | ||
| from python_metrc import METRC | ||
|
|
||
| from frappe.utils import now_datetime |
There was a problem hiding this comment.
Remove all changes from this file.
|
@Alchez Is this approved? |
|
Not yet, it's still missing the fields. |
| "label": "Make Payment Entry", | ||
| "modified": "2018-09-28 22:54:48.552714", | ||
| "modified_by": "Administrator", | ||
| "name": "Delivery Stop-make_payment_entry", |
There was a problem hiding this comment.
@DeeMysterio, only add the fields related to this PR (don't manually remove it from this file). The fields you've added are linked to other features, which will also need to be moved.
@neilLasrado, should we move this feature to core now?
| frappe.db.commit() | ||
|
|
||
| @frappe.whitelist() | ||
| def update_odometer(dn, start=None, stop=None): |
…dated with the odometer stop value in delivery trip
fix: Remove child table changes + minor fixes
|
🎉 This PR is included in version 1.3.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Ref: TASK-2019-00141