Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct rates inserted when creating sales order from leaflink #1287

Merged
merged 5 commits into from
May 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import frappe
import json
import pprint
from frappe.utils import add_days, cint, cstr
from frappe.utils import add_days, cint, cstr, flt
import datetime
import requests
from frappe.model.document import Document
Expand Down Expand Up @@ -163,11 +163,15 @@ def sales_order_from_leaflink(**args):
batch_details = requests.get(leaflink_settings.get("base_url")+"/batches/", headers=legacy_header,params={"id": item_details.get("batch")}).json()
batch_name = batch_details.get("results")[0].get("production_batch_number")

#adjust rate or quantity when item is sold by case vs item is sold by gram
quantity = flt(item.get("quantity"))/flt(item.get("unit_multiplier")) if item_details.get("sold_by_case") else flt(item.get("quantity"))
rate = flt(item.get("sale_price")) if item_details.get("sold_by_case") else flt(item.get("sale_price"))/flt(item.get("unit_multiplier"))

#appending items to sales order document, might fail if item or batch_no is missing from bloomstack
sales_order_doc.append("items",{
"item_code": item.get("product").get("sku"),
"rate": item.get("sale_price"),
"qty": item.get("quantity"),
"rate": rate,
"qty": quantity,
"batch_no": batch_name,
"actual_qty": item.get("quantity"),
"delivery_date": add_days(datetime.datetime.now(), expected_delivery_days)
Expand Down