tracker.py.bak 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2013, Fafadia Tech and contributors
  2. # For license information, please see license.txt
  3. from __future__ import unicode_literals
  4. import frappe
  5. from frappe import _
  6. import datetime
  7. def get_po_total(doc):
  8. currency_symbol = frappe.db.get_value("Currency", doc.currency, "symbol")
  9. return currency_symbol + " " + str(doc.grand_total)
  10. def get_assigned_to(purchase_order):
  11. q = "SELECT _assign FROM `tabPurchase Order` WHERE name='{0}'".format(purchase_order)
  12. results = frappe.db.sql(q)
  13. if len(results) == 0 or len(results[0]) == 0 or not results[0][0]:
  14. return ""
  15. result = eval(results[0][0])
  16. if result:
  17. email = result[0]
  18. q = "SELECT full_name FROM `tabUser` WHERE email='{0}'".format(email)
  19. results = frappe.db.sql(q)
  20. if len(result) > 0:
  21. return results[0][0]
  22. return ""
  23. def get_comment(comment):
  24. if comment:
  25. return comment.replace(".","<br>").strip()
  26. return ""
  27. def get_date_of_email(purchase_order):
  28. results = frappe.get_all("Communication",filters={"reference_name":purchase_order})
  29. if len(results) == 0:
  30. return ""
  31. # first time email doctype
  32. doc_name = results[-1]["name"]
  33. comm_date = frappe.get_value("Communication", doc_name, "communication_date")
  34. if comm_date:
  35. return comm_date
  36. def execute(filters=None):
  37. columns, data = [], []
  38. columns = [
  39. {"fieldname": "date", "label": _("Date"), "fieldtype": "date",},
  40. {"fieldname": "gtl_so_ref", "label": _("GTL SO Ref"), "fieldtype": "data",},
  41. {"fieldname": "so_value", "label": _("SO Value"), "fieldtype":"data"},
  42. {"fieldname": "rfq_no", "label": _("RFQ/GTL Ref"), "fieldtype":"data"},
  43. {"fieldname": "delivery_date", "label": _("Delivery Date"), "fieldtype":"date"},
  44. {"fieldname": "po_rfq_no", "label": _("GTL PO to supplier/RFQ no"), "fieldtype":"data"},
  45. {"fieldname": "supplier", "label": _("Supplier"), "fieldtype":"data"},
  46. {"fieldname": "contact", "label": _("Product/Contact Person"), "fieldtype":"data"},
  47. {"fieldname": "transaction_date", "label": _("Date - PO sent to Supplier"), "fieldtype":"date"},
  48. {"fieldname": "po_grand_total", "label": _("PO Value to Supplier"), "fieldtype":"Currency/currency"},
  49. {"fieldname": "so_po", "label": _("RDD to Supplier"), "fieldtype":"date"},
  50. {"fieldname": "diff_so", "label": _("Current Delivery status"), "fieldtype":"data"},
  51. {"fieldname": "assigned_user", "label": _("Person Handling the order"), "fieldtype":"data"},
  52. {"fieldname": "gtl_pay_status", "label": _("PAID"), "fieldtype":"data"},
  53. {"fieldname": "workflow_status", "label": _("Category"), "fieldtype":"data"},
  54. {"fieldname": "gtl_status", "label": _("Status"), "fieldtype":"data"},
  55. {"fieldname": "gtl_comment", "label": _("Comments"), "fieldtype":"data"},
  56. ]
  57. for vro in frappe.get_all("Purchase Order", filters={"status":["not in",("Draft", "Cancelled")]}):
  58. po_doc = frappe.get_doc("Purchase Order",vro)
  59. for item in po_doc.items:
  60. if item.sales_order:
  61. so_doc = frappe.get_doc("Sales Order",item.sales_order)
  62. data.append({"date": frappe.utils.formatdate(so_doc.transaction_date, "MM-dd-YYYY"),
  63. "gtl_so_ref":so_doc.gtl_so_id,
  64. "so_value":so_doc.grand_total,"rfq_no":so_doc.rfq_no,
  65. "delivery_date": frappe.utils.formatdate(so_doc.delivery_date, "MM-dd-YYYY"),
  66. "po_rfq_no":po_doc.gtl_po_no,
  67. "supplier":po_doc.supplier,"contact":po_doc.contact_display,
  68. "transaction_date":frappe.utils.formatdate(get_date_of_email(po_doc.name), "dd-MMM-YYYY"),
  69. "po_grand_total":get_po_total(po_doc),"workflow_status":so_doc.status,
  70. "gtl_status":po_doc.glt_status,"gtl_pay_status":po_doc.gtl_po_paid,
  71. "so_po":frappe.utils.formatdate(po_doc.schedule_date, "MM-dd-YYYY"),
  72. "diff_so":(so_doc.delivery_date-po_doc.schedule_date).days,
  73. "assigned_user": get_assigned_to(po_doc.name),
  74. "gtl_comment": get_comment(po_doc.gtl_po_comment)
  75. })
  76. break
  77. return columns, data