Skip to content

feat(core): actual distance travelled by the driver - #32

Merged
Alchez merged 9 commits into
Bloomstack:stagingfrom
DeeMysterio:mileage
Jul 3, 2019
Merged

feat(core): actual distance travelled by the driver#32
Alchez merged 9 commits into
Bloomstack:stagingfrom
DeeMysterio:mileage

Conversation

@DeeMysterio

@DeeMysterio DeeMysterio commented Jun 11, 2019

Copy link
Copy Markdown
Contributor

@DeeMysterio
DeeMysterio requested a review from Alchez June 11, 2019 15:32
@Alchez

Alchez commented Jun 11, 2019

Copy link
Copy Markdown
Contributor

Looks good, but a few notes:

  • The new odometer fields are missing.
    • If you used Customize Form, you also need to export them (to an app, in our case it'll be Bloomstack Core) to have them appear in code.
    • If you're editing the DocType directly, then they'll go in the main ERPNext repo, since that's where the Delivery Trip doctype lives.
  • Make sure to validate the odometer values - the end value should not be lower than the start value (there may be an edge case where the driver resets the odometer value on their car, but that shouldn't happen during the trip; might need discussion).
    • Also update the stop value in the Vehicle's last odometer value reading. You can even use this value in Vehicle to set a default value in the prompt for the "Start" button.
  • You don't need to manually reload the page everytime. Just use frm.refresh() after setting the odometer values to reload the fields.
  • Make the "Actual Distance Travelled" field read-only.
  • Fix the PR title and use Conventional Commit naming.

},
],
function (data) {
frappe.call({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't go to the server. Just take the value that the user inputs and set in the form itself.

},
],
function (data) {
frappe.call({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@vjFaLk
vjFaLk temporarily deployed to Tugboat June 13, 2019 09:18 Destroyed
@DeeMysterio DeeMysterio changed the title Actual distance travelled by driver feat(core): actual distance travelled by the driver Jun 13, 2019
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 13, 2019 09:37 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 14, 2019 00:54 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 14, 2019 14:30 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 15, 2019 01:07 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 16, 2019 01:05 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 17, 2019 01:05 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 18, 2019 00:09 Destroyed


def set_vehicle_last_odometer_value(self, event):
print("reached here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove print

def set_vehicle_last_odometer_value(self, event):
print("reached here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
if self.actual_distance_travelled:
vehicle = frappe.get_doc("Vehicle", self.vehicle)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_doc is overkill for this. Just do a simple frappe.db.set_value.

import frappe


def set_vehicle_last_odometer_value(self, event):

@Alchez Alchez Jun 18, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

@Alchez Alchez Jun 18, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the time check. The user does not input that, so it's going to be later always.

Comment thread bloomstack_core/utils.py Outdated
frappe.db.commit()

@frappe.whitelist()
def update_odometer(dn, start=None, stop=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this method anymore.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
],
function (data) {
frm.set_value('odometer_stop_value', data.odometer_stop_value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't update the stop value if it's lower than the start value. Put it inside the check.

@vjFaLk
vjFaLk temporarily deployed to Tugboat June 18, 2019 07:25 Destroyed


def set_vehicle_last_odometer_value(trip, method):
if self.actual_distance_travelled:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need an explicit commit. It'll happen automatically if the hook runs successfully.

Comment thread bloomstack_core/utils.py Outdated
from erpnext.stock.doctype.batch.batch import get_batch_qty
from python_metrc import METRC

from frappe.utils import now_datetime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all changes from this file.

@vjFaLk
vjFaLk temporarily deployed to Tugboat June 18, 2019 08:59 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 19, 2019 00:39 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 20, 2019 00:10 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 21, 2019 00:12 Destroyed
@vjFaLk

vjFaLk commented Jun 21, 2019

Copy link
Copy Markdown
Contributor

@Alchez Is this approved?

@Alchez

Alchez commented Jun 21, 2019

Copy link
Copy Markdown
Contributor

Not yet, it's still missing the fields.

@vjFaLk
vjFaLk temporarily deployed to Tugboat June 22, 2019 00:10 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 23, 2019 00:09 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 24, 2019 00:09 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 25, 2019 00:22 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 25, 2019 10:19 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 25, 2019 10:28 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 25, 2019 12:42 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 26, 2019 00:10 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 27, 2019 00:11 Destroyed
"label": "Make Payment Entry",
"modified": "2018-09-28 22:54:48.552714",
"modified_by": "Administrator",
"name": "Delivery Stop-make_payment_entry",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Comment thread bloomstack_core/utils.py Outdated
frappe.db.commit()

@frappe.whitelist()
def update_odometer(dn, start=None, stop=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vjFaLk
vjFaLk temporarily deployed to Tugboat June 29, 2019 00:09 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat June 30, 2019 00:07 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat July 1, 2019 00:08 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat July 2, 2019 00:07 Destroyed
@vjFaLk
vjFaLk temporarily deployed to Tugboat July 3, 2019 12:01 Destroyed
Rohan Bansal and others added 2 commits July 3, 2019 17:40
@vjFaLk
vjFaLk temporarily deployed to Tugboat July 3, 2019 12:11 Destroyed
@Alchez
Alchez merged commit dbe75bb into Bloomstack:staging Jul 3, 2019
@dti-deploy

Copy link
Copy Markdown

🎉 This PR is included in version 1.3.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants