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