forked from frappe/erpnext
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bs-apr-sprint-1' into delivery_note_batch_no
- Loading branch information
Showing
22 changed files
with
342 additions
and
20 deletions.
There are no files selected for viewing
Empty file.
8 changes: 8 additions & 0 deletions
8
erpnext/erpnext_integrations/doctype/flowkana_settings/flowkana_settings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Flowkana Settings', { | ||
// refresh: function(frm) { | ||
|
||
// } | ||
}); |
74 changes: 74 additions & 0 deletions
74
erpnext/erpnext_integrations/doctype/flowkana_settings/flowkana_settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"creation": "2021-03-19 03:53:40.417764", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"enable_flowkana_section", | ||
"enable_flowkana", | ||
"api_key", | ||
"api_value", | ||
"load_url_in_new_tab", | ||
"url_tab" | ||
], | ||
"fields": [ | ||
{ | ||
"fieldname": "enable_flowkana_section", | ||
"fieldtype": "Section Break", | ||
"label": "Enable Flowkana" | ||
}, | ||
{ | ||
"default": "0", | ||
"fieldname": "enable_flowkana", | ||
"fieldtype": "Check", | ||
"label": "Enable Flowkana" | ||
}, | ||
{ | ||
"depends_on": "eval: doc.enable_flowkana == 1", | ||
"fieldname": "api_key", | ||
"fieldtype": "Data", | ||
"label": "API Key" | ||
}, | ||
{ | ||
"depends_on": "eval: doc.enable_flowkana == 1", | ||
"fieldname": "api_value", | ||
"fieldtype": "Data", | ||
"label": "API Value" | ||
}, | ||
{ | ||
"default": "0", | ||
"depends_on": "eval: doc.enable_flowkana == 1", | ||
"fieldname": "load_url_in_new_tab", | ||
"fieldtype": "Check", | ||
"label": "Load URL in new tab" | ||
}, | ||
{ | ||
"depends_on": "eval: doc.enable_flowkana == 1", | ||
"fieldname": "url_tab", | ||
"fieldtype": "Data", | ||
"label": "URL Tab" | ||
} | ||
], | ||
"issingle": 1, | ||
"modified": "2021-03-19 04:07:51.319530", | ||
"modified_by": "Administrator", | ||
"module": "ERPNext Integrations", | ||
"name": "Flowkana Settings", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"print": 1, | ||
"read": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"quick_entry": 1, | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"track_changes": 1 | ||
} |
115 changes: 115 additions & 0 deletions
115
erpnext/erpnext_integrations/doctype/flowkana_settings/flowkana_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
from __future__ import unicode_literals | ||
import frappe | ||
import datetime | ||
import requests | ||
import json | ||
from six import text_type | ||
from frappe.model.document import Document | ||
|
||
class FlowkanaSettings(Document): | ||
|
||
def validate(self): | ||
self.check_fulfillment_partner() | ||
self.toggle_status() | ||
|
||
def toggle_status(self): | ||
frappe.db.set_value("Fulfillment Partner", "Flowkana", "enable_flowkana", self.enable_flowkana) | ||
|
||
def check_fulfillment_partner(self): | ||
""" | ||
Create a fulfillment partner in case they don't exist. | ||
""" | ||
if self.enable_flowkana and not frappe.db.exists("Fulfillment Partner", "Flowkana"): | ||
partner = frappe.get_doc({ | ||
"doctype": "Fulfillment Partner", | ||
"partner_name": "Flowkana", | ||
"enable": 1 | ||
}).save() | ||
|
||
def send_delivery_request_to_flowkana(sales_order): | ||
""" | ||
Ping flowkana with sales order details and map response to an integration request. | ||
Args: | ||
sales_order_name (string): name of the sales order that needs to be sent to flowkana | ||
""" | ||
#create line items | ||
item_list = [] | ||
for item in sales_order.items: | ||
ivt_id = frappe.get_value("Item", item.item_code, "ivt_id") | ||
line_item = { | ||
"attributes": { | ||
"ivt_id": ivt_id, | ||
"test_batch_id": item.batch_no, | ||
"external_item_code": item.item_code, | ||
"unit_quantity": item.qty, | ||
"unit_price": item.rate | ||
} | ||
} | ||
item_list.append(line_item) | ||
|
||
#prepare response json | ||
request_json = { | ||
"data": { | ||
"attributes": { | ||
"external_order_id": sales_order.name, | ||
"customer_name": sales_order.customer, | ||
"customer_license": sales_order.license, | ||
"delivery_date": str(sales_order.delivery_date), | ||
"note": "Test Note" | ||
}, | ||
"relationships": { | ||
"order_line_items": item_list | ||
} | ||
} | ||
} | ||
|
||
#create integration request | ||
integration_request = frappe.new_doc("Integration Request") | ||
integration_request.update({ | ||
"integration_type": "Host", | ||
"integration_request_service": "Flowkana", | ||
"status": "Queued", | ||
"data": json.dumps(request_json, default=json_handler), | ||
"reference_doctype": "Sales Order", | ||
"reference_docname": sales_order.name | ||
}) | ||
integration_request.save(ignore_permissions=True) | ||
|
||
#fetch and prepare headers from flowkana settings, flag error if missing data | ||
flowkana_settings = frappe.get_cached_doc("Flowkana Settings") | ||
if not flowkana_settings.get("url_tab"): | ||
frappe.throw(_("Please provide an endpoint to send data to.")) | ||
if not flowkana_settings.get("api_key", 0.0): | ||
frappe.throw(_("Please enter API Key in flowkana settings.")) | ||
if not flowkana_settings.get("api_value", 0.0): | ||
frappe.throw(_("Please enter API Value in flowkana settings.")) | ||
|
||
headers = { | ||
flowkana_settings.get("api_key"): flowkana_settings.get("api_value") | ||
} | ||
|
||
print("request_json: ", request_json) | ||
|
||
#ping flowkana with requisite headers and data | ||
response = requests.post( | ||
flowkana_settings.get("url_tab"), | ||
headers=headers, | ||
json=request_json) | ||
response_data = response.json() | ||
|
||
if response.status_code not in [200, 201, 202]: | ||
frappe.throw("The response has the following errors: {0}".format(response_data.get("errors"),"")) | ||
return | ||
|
||
#mark integration request status as queued, update status to queued | ||
integration_request.output = json.dumps(response_data, default=json_handler) | ||
integration_request.save(ignore_permissions=True) | ||
|
||
def json_handler(obj): | ||
if isinstance(obj, (datetime.date, datetime.timedelta, datetime.datetime)): | ||
return text_type(obj) |
10 changes: 10 additions & 0 deletions
10
erpnext/erpnext_integrations/doctype/flowkana_settings/test_flowkana_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors | ||
# See license.txt | ||
from __future__ import unicode_literals | ||
|
||
# import frappe | ||
import unittest | ||
|
||
class TestFlowkanaSettings(unittest.TestCase): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import frappe | ||
|
||
def execute(): | ||
custom_fields = ["column_break_59", "section_break_56", "licenses_sb", "licenses"] | ||
|
||
for field in custom_fields: | ||
frappe.delete_doc_if_exists("Custom Field", field) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
8 changes: 8 additions & 0 deletions
8
erpnext/stock/doctype/fulfillment_partner/fulfillment_partner.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Fulfillment Partner', { | ||
// refresh: function(frm) { | ||
|
||
// } | ||
}); |
48 changes: 48 additions & 0 deletions
48
erpnext/stock/doctype/fulfillment_partner/fulfillment_partner.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"autoname": "field:partner_name", | ||
"creation": "2021-03-19 04:02:49.718866", | ||
"doctype": "DocType", | ||
"editable_grid": 1, | ||
"engine": "InnoDB", | ||
"field_order": [ | ||
"partner_name", | ||
"enable" | ||
], | ||
"fields": [ | ||
{ | ||
"default": "0", | ||
"fieldname": "enable", | ||
"fieldtype": "Check", | ||
"label": "Enable" | ||
}, | ||
{ | ||
"fieldname": "partner_name", | ||
"fieldtype": "Data", | ||
"label": "Partner Name", | ||
"unique": 1 | ||
} | ||
], | ||
"modified": "2021-03-19 04:05:27.925753", | ||
"modified_by": "Administrator", | ||
"module": "Stock", | ||
"name": "Fulfillment Partner", | ||
"owner": "Administrator", | ||
"permissions": [ | ||
{ | ||
"create": 1, | ||
"delete": 1, | ||
"email": 1, | ||
"export": 1, | ||
"print": 1, | ||
"read": 1, | ||
"report": 1, | ||
"role": "System Manager", | ||
"share": 1, | ||
"write": 1 | ||
} | ||
], | ||
"quick_entry": 1, | ||
"sort_field": "modified", | ||
"sort_order": "DESC", | ||
"track_changes": 1 | ||
} |
10 changes: 10 additions & 0 deletions
10
erpnext/stock/doctype/fulfillment_partner/fulfillment_partner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
|
||
from __future__ import unicode_literals | ||
# import frappe | ||
from frappe.model.document import Document | ||
|
||
class FulfillmentPartner(Document): | ||
pass |
Oops, something went wrong.