booking via the schedular

This commit is contained in:
Manas Solanki 2018-05-15 12:58:12 +05:30
parent 0393848f60
commit 0b7f64924d
2 changed files with 77 additions and 32 deletions

View File

@ -41,6 +41,7 @@
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -72,6 +73,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -104,6 +106,7 @@
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -134,6 +137,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -164,6 +168,7 @@
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -196,6 +201,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -229,6 +235,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -262,6 +269,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -293,6 +301,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -324,6 +333,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -355,6 +365,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -386,6 +397,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -418,6 +430,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -450,6 +463,7 @@
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -482,6 +496,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -514,6 +529,38 @@
"reqd": 0,
"search_index": 1,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "voucher_detail_no",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Voucher Detail No",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -545,6 +592,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -576,6 +624,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -608,6 +657,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -640,6 +690,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -672,6 +723,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
@ -704,6 +756,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}
],
@ -718,7 +771,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-12-20 12:40:09.611951",
"modified": "2018-05-15 02:12:50.035755",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
@ -726,7 +779,6 @@
"permissions": [
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@ -746,7 +798,6 @@
},
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@ -766,7 +817,6 @@
},
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@ -794,4 +844,4 @@
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0
}
}

View File

@ -916,36 +916,40 @@ class SalesInvoice(SellingController):
# book the income on the last day, but it will be trigger on the 1st of month at 12:00 AM
# start_date: 1st of the last month or the start date
# end_date: end_date or today-1
gl_entries = []
for item in self.get('items'):
last_gl_entry = False
import pdb
# pdb.set_trace()
booking_start_date = getdate(add_months(today(), -1))
booking_start_date = booked_start_date if booking_start_date>item.service_start_date else item.service_start_date
booking_start_date = booking_start_date if booking_start_date>item.service_start_date else item.service_start_date
booking_end_date = getdate(add_days(today(), -1))
if booking_end_date>=item.service_end_date:
last_gl_entry = True
booking_end_date = item.service_end_date
total_days = date_diff(item.service_end_date, item.service_start_date)
total_booking_days = date_diff(booking_end_date, booking_start_date)
total_booking_days = date_diff(booking_end_date, booking_start_date) + 1
account_currency = get_account_currency(item.income_account)
if not last_gl_entry:
base_amount = flt(item.base_net_amount * total_booking_days / flt(total_days))
base_amount = flt(item.base_net_amount*total_booking_days/flt(total_days), item.precision("base_net_amount"))
if account_currency==self.company_currency:
amount = base_amount
else:
amount = flt(item.net_amount * total_booking_days / flt(total_days))
amount = flt(item.net_amount*total_booking_days/flt(total_days), item.precision("net_amount"))
else:
base_amount = ''
amount = ''
gl_entries_details = frappe.db.sql('''
select sum(credit)-sum(debit) as balance, sum(credit_in_account_currency)-sum(debit_in_account_currency) as
balance_in_account_currency, voucher_no from `tabGL Entry`
where company=%s and account=%s and voucher_type=%s and voucher_no=%s group by voucher_no
''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name), as_dict=True)
select sum(debit) as total_debit, sum(debit_in_account_currency) as total_debit_in_account_currency, voucher_detail_no
from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
group by voucher_detail_no
''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)[0]
base_amount = flt(item.base_net_amount - gl_entries_details.total_debit, item.precision("base_net_amount"))
if account_currency==self.company_currency:
amount = base_amount
else:
amount = flt(item.net_amount - gl_entries_details.total_debit_in_account_currency, item.precision("net_amount"))
# GL Entry for crediting the amount in the income
gl_entries.append(
@ -954,7 +958,8 @@ class SalesInvoice(SellingController):
"against": self.customer,
"credit": base_amount,
"credit_in_account_currency": amount,
"cost_center": item.cost_center
"cost_center": item.cost_center,
'posting_date': booking_end_date
}, account_currency)
)
# GL Entry to debit the amount from the deferred account
@ -964,34 +969,24 @@ class SalesInvoice(SellingController):
"against": self.customer,
"debit": base_amount,
"debit_in_account_currency": amount,
"cost_center": item.cost_center
"cost_center": item.cost_center,
"voucher_detail_no": item.name,
'posting_date': booking_end_date
}, account_currency)
)
# from erpnext.accounts.general_ledger import merge_similar_entries
# gl_entries = merge_similar_entries(gl_entries)
if gl_entries:
from erpnext.accounts.general_ledger import make_gl_entries
make_gl_entries(gl_entries, cancel=(self.docstatus == 2), merge_entries=True)
frappe.throw("stop")
def make_gl_entries_for_deferred_revenue(self, items, gl_entries):
pass
def booked_deferred_revenue():
# check for the sales invoice for which GL entries has to be done
print ("======================")
invoices = frappe.db.sql_list('''
select parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s
''', (today(), add_months(today(), -1)))
print (invoices)
# ToDo also find the list on the basic of the GL entry
# ToDo also find the list on the basic of the GL entry, and make another list
for invoice in invoices:
doc = frappe.get_doc("Sales Invoice", invoice)
doc.book_income_for_deferred_revenue()