blob: e7dceb38872d7b953d4ec2b4514f53e83624ee48 [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
Nabin Hait26cad302016-07-21 10:28:54 +053011from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice
12from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053013
14def work():
15 frappe.set_user(frappe.db.get_global('demo_accounts_user'))
16
Nabin Hait26cad302016-07-21 10:28:54 +053017 if random.random() <= 0.6:
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053018 from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
19 report = "Ordered Items to be Billed"
Rushabh Mehta92d1b8c2016-07-14 15:46:12 +053020 for so in list(set([r[0] for r in query_report.run(report)["result"]
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053021 if r[0]!="Total"]))[:random.randint(1, 5)]:
22 si = frappe.get_doc(make_sales_invoice(so))
23 si.posting_date = frappe.flags.current_date
24 for d in si.get("items"):
25 if not d.income_account:
26 d.income_account = "Sales - {}".format(frappe.db.get_value('Company', si.company, 'abbr'))
27 si.insert()
28 si.submit()
29 frappe.db.commit()
30
Nabin Hait26cad302016-07-21 10:28:54 +053031 if random.random() <= 0.6:
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053032 from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
33 report = "Received Items to be Billed"
34 for pr in list(set([r[0] for r in query_report.run(report)["result"]
35 if r[0]!="Total"]))[:random.randint(1, 5)]:
36 pi = frappe.get_doc(make_purchase_invoice(pr))
37 pi.posting_date = frappe.flags.current_date
38 pi.bill_no = random_string(6)
39 pi.insert()
40 pi.submit()
41 frappe.db.commit()
42
Nabin Hait16066262016-07-21 11:00:28 +053043 if random.random() < 0.5:
Nabin Hait26cad302016-07-21 10:28:54 +053044 make_payment_entries("Sales Invoice", "Accounts Receivable")
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053045
Nabin Hait16066262016-07-21 11:00:28 +053046 if random.random() < 0.5:
Nabin Hait26cad302016-07-21 10:28:54 +053047 make_payment_entries("Purchase Invoice", "Accounts Payable")
Rushabh Mehta8cfe18e2016-07-13 11:29:59 +053048
Nabin Hait26cad302016-07-21 10:28:54 +053049def make_payment_entries(ref_doctype, report):
50 outstanding_invoices = list(set([r[3] for r in query_report.run(report,
51 {"report_date": frappe.flags.current_date })["result"] if r[2]==ref_doctype]))
52
Nabin Hait26cad302016-07-21 10:28:54 +053053 # make Payment Entry
Nabin Hait16066262016-07-21 11:00:28 +053054 for inv in outstanding_invoices[:random.randint(1, 2)]:
Nabin Hait26cad302016-07-21 10:28:54 +053055 pe = get_payment_entry(ref_doctype, inv)
56 pe.posting_date = frappe.flags.current_date
57 pe.reference_no = random_string(6)
58 pe.reference_date = frappe.flags.current_date
59 pe.insert()
60 pe.submit()
Nabin Hait16066262016-07-21 11:00:28 +053061 frappe.db.commit()
62 outstanding_invoices.remove(inv)
63
64 # make payment via JV
65 for inv in outstanding_invoices[:1]:
66 jv = frappe.get_doc(get_payment_entry_against_invoice(ref_doctype, inv))
67 jv.posting_date = frappe.flags.current_date
68 jv.cheque_no = random_string(6)
69 jv.cheque_date = frappe.flags.current_date
70 jv.insert()
71 jv.submit()
72 frappe.db.commit()