blob: d3df6278c0b966b264b88c1b668eb4b93d943440 [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"
Rushabh Mehta92d1b8c2016-07-14 15:46:12 +053018 for so in list(set([r[0] for r in query_report.run(report)["result"]
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053019 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()