2016-07-13 05:59:59 +00:00
|
|
|
|
|
|
|
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
import random
|
|
|
|
from frappe.utils import random_string
|
|
|
|
from frappe.desk import query_report
|
2016-07-21 04:58:54 +00:00
|
|
|
from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice
|
|
|
|
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
2016-07-22 08:45:03 +00:00
|
|
|
from frappe.utils.make_random import get_random
|
|
|
|
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request, make_payment_entry
|
2016-07-21 09:20:59 +00:00
|
|
|
from erpnext.demo.user.sales import make_sales_order
|
|
|
|
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
|
|
|
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
2016-07-13 05:59:59 +00:00
|
|
|
|
|
|
|
def work():
|
|
|
|
frappe.set_user(frappe.db.get_global('demo_accounts_user'))
|
|
|
|
|
2016-07-21 04:58:54 +00:00
|
|
|
if random.random() <= 0.6:
|
2016-07-13 05:59:59 +00:00
|
|
|
report = "Ordered Items to be Billed"
|
2016-07-14 10:16:12 +00:00
|
|
|
for so in list(set([r[0] for r in query_report.run(report)["result"]
|
2016-07-13 05:59:59 +00:00
|
|
|
if r[0]!="Total"]))[:random.randint(1, 5)]:
|
2016-12-15 05:57:35 +00:00
|
|
|
try:
|
|
|
|
si = frappe.get_doc(make_sales_invoice(so))
|
|
|
|
si.posting_date = frappe.flags.current_date
|
|
|
|
for d in si.get("items"):
|
|
|
|
if not d.income_account:
|
2018-08-08 11:07:31 +00:00
|
|
|
d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr'))
|
2016-12-15 05:57:35 +00:00
|
|
|
si.insert()
|
|
|
|
si.submit()
|
|
|
|
frappe.db.commit()
|
|
|
|
except frappe.ValidationError:
|
|
|
|
pass
|
2016-07-13 05:59:59 +00:00
|
|
|
|
2016-07-21 04:58:54 +00:00
|
|
|
if random.random() <= 0.6:
|
2016-07-13 05:59:59 +00:00
|
|
|
report = "Received Items to be Billed"
|
|
|
|
for pr in list(set([r[0] for r in query_report.run(report)["result"]
|
|
|
|
if r[0]!="Total"]))[:random.randint(1, 5)]:
|
2016-12-15 05:57:35 +00:00
|
|
|
try:
|
|
|
|
pi = frappe.get_doc(make_purchase_invoice(pr))
|
|
|
|
pi.posting_date = frappe.flags.current_date
|
|
|
|
pi.bill_no = random_string(6)
|
|
|
|
pi.insert()
|
|
|
|
pi.submit()
|
|
|
|
frappe.db.commit()
|
|
|
|
except frappe.ValidationError:
|
|
|
|
pass
|
|
|
|
|
2016-07-13 05:59:59 +00:00
|
|
|
|
2016-07-21 05:30:28 +00:00
|
|
|
if random.random() < 0.5:
|
2016-07-21 04:58:54 +00:00
|
|
|
make_payment_entries("Sales Invoice", "Accounts Receivable")
|
2016-07-13 05:59:59 +00:00
|
|
|
|
2016-07-21 05:30:28 +00:00
|
|
|
if random.random() < 0.5:
|
2016-07-21 04:58:54 +00:00
|
|
|
make_payment_entries("Purchase Invoice", "Accounts Payable")
|
2016-07-13 05:59:59 +00:00
|
|
|
|
2016-07-22 08:45:03 +00:00
|
|
|
if random.random() < 0.1:
|
|
|
|
#make payment request against sales invoice
|
|
|
|
sales_invoice_name = get_random("Sales Invoice", filters={"docstatus": 1})
|
|
|
|
if sales_invoice_name:
|
|
|
|
si = frappe.get_doc("Sales Invoice", sales_invoice_name)
|
|
|
|
if si.outstanding_amount > 0:
|
|
|
|
payment_request = make_payment_request(dt="Sales Invoice", dn=si.name, recipient_id=si.contact_email,
|
|
|
|
submit_doc=True, mute_email=True, use_dummy_message=True)
|
|
|
|
|
2016-07-22 09:47:17 +00:00
|
|
|
payment_entry = frappe.get_doc(make_payment_entry(payment_request.name))
|
|
|
|
payment_entry.posting_date = frappe.flags.current_date
|
|
|
|
payment_entry.submit()
|
2016-07-22 08:45:03 +00:00
|
|
|
|
2016-07-21 09:20:59 +00:00
|
|
|
make_pos_invoice()
|
|
|
|
|
2016-07-21 04:58:54 +00:00
|
|
|
def make_payment_entries(ref_doctype, report):
|
2016-07-22 08:45:03 +00:00
|
|
|
outstanding_invoices = list(set([r[3] for r in query_report.run(report,
|
2016-07-21 04:58:54 +00:00
|
|
|
{"report_date": frappe.flags.current_date })["result"] if r[2]==ref_doctype]))
|
2016-12-15 05:57:35 +00:00
|
|
|
|
2016-07-21 04:58:54 +00:00
|
|
|
# make Payment Entry
|
2016-07-21 05:30:28 +00:00
|
|
|
for inv in outstanding_invoices[:random.randint(1, 2)]:
|
2016-07-21 04:58:54 +00:00
|
|
|
pe = get_payment_entry(ref_doctype, inv)
|
|
|
|
pe.posting_date = frappe.flags.current_date
|
|
|
|
pe.reference_no = random_string(6)
|
|
|
|
pe.reference_date = frappe.flags.current_date
|
|
|
|
pe.insert()
|
|
|
|
pe.submit()
|
2016-07-21 05:30:28 +00:00
|
|
|
frappe.db.commit()
|
|
|
|
outstanding_invoices.remove(inv)
|
2016-07-21 09:20:59 +00:00
|
|
|
|
2016-07-21 05:30:28 +00:00
|
|
|
# make payment via JV
|
|
|
|
for inv in outstanding_invoices[:1]:
|
|
|
|
jv = frappe.get_doc(get_payment_entry_against_invoice(ref_doctype, inv))
|
|
|
|
jv.posting_date = frappe.flags.current_date
|
|
|
|
jv.cheque_no = random_string(6)
|
|
|
|
jv.cheque_date = frappe.flags.current_date
|
|
|
|
jv.insert()
|
|
|
|
jv.submit()
|
2016-07-22 08:45:03 +00:00
|
|
|
frappe.db.commit()
|
2016-07-21 09:20:59 +00:00
|
|
|
|
|
|
|
def make_pos_invoice():
|
|
|
|
make_sales_order()
|
|
|
|
|
|
|
|
for data in frappe.get_all('Sales Order', fields=["name"],
|
|
|
|
filters = [["per_billed", "<", "100"]]):
|
|
|
|
si = frappe.get_doc(make_sales_invoice(data.name))
|
|
|
|
si.is_pos =1
|
|
|
|
si.posting_date = frappe.flags.current_date
|
|
|
|
for d in si.get("items"):
|
|
|
|
if not d.income_account:
|
2018-08-08 11:07:31 +00:00
|
|
|
d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr'))
|
2016-07-21 09:20:59 +00:00
|
|
|
si.set_missing_values()
|
|
|
|
make_payment_entries_for_pos_invoice(si)
|
|
|
|
si.insert()
|
|
|
|
si.submit()
|
|
|
|
|
|
|
|
def make_payment_entries_for_pos_invoice(si):
|
|
|
|
for data in si.payments:
|
|
|
|
data.amount = si.outstanding_amount
|
|
|
|
return
|