Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 1 | |
| 2 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 3 | # License: GNU General Public License v3. See license.txt |
| 4 | |
| 5 | from __future__ import unicode_literals |
| 6 | |
| 7 | import frappe |
| 8 | import random |
| 9 | from frappe.utils import random_string |
| 10 | from frappe.desk import query_report |
| 11 | |
| 12 | def work(): |
| 13 | frappe.set_user(frappe.db.get_global('demo_accounts_user')) |
| 14 | |
| 15 | if random.random() < 0.5: |
| 16 | from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice |
| 17 | report = "Ordered Items to be Billed" |
Rushabh Mehta | 92d1b8c | 2016-07-14 15:46:12 +0530 | [diff] [blame] | 18 | for so in list(set([r[0] for r in query_report.run(report)["result"] |
Rushabh Mehta | 8cfe18e | 2016-07-13 11:29:59 +0530 | [diff] [blame] | 19 | if r[0]!="Total"]))[:random.randint(1, 5)]: |
| 20 | si = frappe.get_doc(make_sales_invoice(so)) |
| 21 | si.posting_date = frappe.flags.current_date |
| 22 | for d in si.get("items"): |
| 23 | if not d.income_account: |
| 24 | d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr')) |
| 25 | si.insert() |
| 26 | si.submit() |
| 27 | frappe.db.commit() |
| 28 | |
| 29 | if random.random() < 0.5: |
| 30 | from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice |
| 31 | report = "Received Items to be Billed" |
| 32 | for pr in list(set([r[0] for r in query_report.run(report)["result"] |
| 33 | if r[0]!="Total"]))[:random.randint(1, 5)]: |
| 34 | pi = frappe.get_doc(make_purchase_invoice(pr)) |
| 35 | pi.posting_date = frappe.flags.current_date |
| 36 | pi.bill_no = random_string(6) |
| 37 | pi.insert() |
| 38 | pi.submit() |
| 39 | frappe.db.commit() |
| 40 | |
| 41 | from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice |
| 42 | |
| 43 | if random.random() < 0.5: |
| 44 | report = "Accounts Receivable" |
| 45 | for si in list(set([r[3] for r in query_report.run(report, |
| 46 | {"report_date": frappe.flags.current_date })["result"] |
| 47 | if r[2]=="Sales Invoice"]))[:random.randint(1, 5)]: |
| 48 | jv = frappe.get_doc(get_payment_entry_against_invoice("Sales Invoice", si)) |
| 49 | jv.posting_date = frappe.flags.current_date |
| 50 | jv.cheque_no = random_string(6) |
| 51 | jv.cheque_date = frappe.flags.current_date |
| 52 | jv.insert() |
| 53 | jv.submit() |
| 54 | frappe.db.commit() |
| 55 | |
| 56 | if random.random() < 0.5: |
| 57 | report = "Accounts Payable" |
| 58 | for pi in list(set([r[3] for r in query_report.run(report, |
| 59 | {"report_date": frappe.flags.current_date })["result"] |
| 60 | if r[2]=="Purchase Invoice"]))[:random.randint(1, 5)]: |
| 61 | jv = frappe.get_doc(get_payment_entry_against_invoice("Purchase Invoice", pi)) |
| 62 | jv.posting_date = frappe.flags.current_date |
| 63 | jv.cheque_no = random_string(6) |
| 64 | jv.cheque_date = frappe.flags.current_date |
| 65 | jv.insert() |
| 66 | jv.submit() |
| 67 | frappe.db.commit() |