fixes in setting end_date and manual provision of start&end date
This commit is contained in:
parent
91eae54383
commit
80f5cb05cc
@ -762,7 +762,13 @@ frappe.ui.form.on('Sales Invoice Item', {
|
|||||||
var child = locals[cdt][cdn];
|
var child = locals[cdt][cdn];
|
||||||
|
|
||||||
if(child.service_start_date) {
|
if(child.service_start_date) {
|
||||||
frappe.model.set_value(cdt, cdn, "service_end_date", "");
|
frappe.call({
|
||||||
|
"method": "erpnext.stock.get_item_details.calculate_service_end_date",
|
||||||
|
args: {"args": child},
|
||||||
|
callback: function(r) {
|
||||||
|
frappe.model.set_value(cdt, cdn, "service_end_date", r.message.service_end_date);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@ -547,7 +547,7 @@ class SalesInvoice(SellingController):
|
|||||||
if date_diff(item.service_stop_date, item.service_end_date) > 0:
|
if date_diff(item.service_stop_date, item.service_end_date) > 0:
|
||||||
frappe.throw(_("Service Stop Date cannot be after Service End Date"))
|
frappe.throw(_("Service Stop Date cannot be after Service End Date"))
|
||||||
|
|
||||||
if old_stop_dates[item.name] and item.service_stop_date!=old_stop_dates[item.name]:
|
if old_stop_dates and old_stop_dates[item.name] and item.service_stop_date!=old_stop_dates[item.name]:
|
||||||
frappe.throw(_("Cannot change Service Stop Date for item in row {0}".format(item.idx)))
|
frappe.throw(_("Cannot change Service Stop Date for item in row {0}".format(item.idx)))
|
||||||
|
|
||||||
def update_current_stock(self):
|
def update_current_stock(self):
|
||||||
@ -1090,7 +1090,7 @@ class SalesInvoice(SellingController):
|
|||||||
for item in self.get('items'):
|
for item in self.get('items'):
|
||||||
last_gl_entry = False
|
last_gl_entry = False
|
||||||
|
|
||||||
booking_start_date = getdate(add_months(today(), -1))
|
booking_start_date = getdate(add_months(today(), -1)) if not start_date else start_date
|
||||||
booking_start_date = booking_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
|
||||||
|
|
||||||
if item.service_start_date < booking_start_date:
|
if item.service_start_date < booking_start_date:
|
||||||
@ -1105,21 +1105,16 @@ class SalesInvoice(SellingController):
|
|||||||
else:
|
else:
|
||||||
booking_start_date = getdate(add_days(prev_gl_entry.posting_date, 1))
|
booking_start_date = getdate(add_days(prev_gl_entry.posting_date, 1))
|
||||||
|
|
||||||
booking_end_date = getdate(add_days(today(), -1))
|
booking_end_date = getdate(add_days(today(), -1)) if not end_date else end_date
|
||||||
if booking_end_date.month > item.service_stop_date.month:
|
if item.service_stop_date and booking_end_date.month > item.service_stop_date.month:
|
||||||
continue
|
continue
|
||||||
elif booking_end_date>=item.service_end_date:
|
elif booking_end_date>=item.service_end_date:
|
||||||
last_gl_entry = True
|
last_gl_entry = True
|
||||||
booking_end_date = item.service_end_date
|
booking_end_date = item.service_end_date
|
||||||
elif item.service_stop_date<=booking_end_date:
|
elif item.service_stop_date and item.service_stop_date<=booking_end_date:
|
||||||
last_gl_entry = True
|
last_gl_entry = True
|
||||||
booking_end_date = item.service_stop_date
|
booking_end_date = item.service_stop_date
|
||||||
|
|
||||||
if start_date and end_date:
|
|
||||||
# if start and end date are already provided
|
|
||||||
booking_start_date = start_date
|
|
||||||
booking_end_date = end_date
|
|
||||||
|
|
||||||
total_days = date_diff(item.service_end_date, item.service_start_date)
|
total_days = date_diff(item.service_end_date, item.service_start_date)
|
||||||
total_booking_days = date_diff(booking_end_date, booking_start_date) + 1
|
total_booking_days = date_diff(booking_end_date, booking_start_date) + 1
|
||||||
|
|
||||||
@ -1176,7 +1171,7 @@ def booked_deferred_revenue(start_date=None, end_date=None):
|
|||||||
invoices = frappe.db.sql_list('''
|
invoices = frappe.db.sql_list('''
|
||||||
select parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s
|
select parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s
|
||||||
and enable_deferred_revenue = 1 and docstatus = 1
|
and enable_deferred_revenue = 1 and docstatus = 1
|
||||||
''', (start_date or today(), end_date or add_months(today(), -1)))
|
''', (end_date or today(), start_date or add_months(today(), -1)))
|
||||||
|
|
||||||
# ToDo also find the list on the basic of the GL entry, and make another list
|
# ToDo also find the list on the basic of the GL entry, and make another list
|
||||||
for invoice in invoices:
|
for invoice in invoices:
|
||||||
|
|||||||
@ -274,14 +274,7 @@ def get_basic_details(args, item):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if item.enable_deferred_revenue:
|
if item.enable_deferred_revenue:
|
||||||
service_start_date = args.service_start_date if args.service_start_date else args.transaction_date
|
out.update(calculate_service_end_date(args, item))
|
||||||
service_end_date = add_months(service_start_date, item.no_of_months)
|
|
||||||
out.update({
|
|
||||||
"enable_deferred_revenue": item.enable_deferred_revenue,
|
|
||||||
"deferred_revenue_account": get_default_deferred_revenue_account(args, item),
|
|
||||||
"service_start_date": service_start_date,
|
|
||||||
"service_end_date": service_end_date
|
|
||||||
})
|
|
||||||
|
|
||||||
# calculate conversion factor
|
# calculate conversion factor
|
||||||
if item.stock_uom == args.uom:
|
if item.stock_uom == args.uom:
|
||||||
@ -311,6 +304,22 @@ def get_basic_details(args, item):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def calculate_service_end_date(args, item=None):
|
||||||
|
args = process_args(args)
|
||||||
|
if not item:
|
||||||
|
item = frappe.get_cached_doc("Item", args.item_code)
|
||||||
|
|
||||||
|
service_start_date = args.service_start_date if args.service_start_date else args.transaction_date
|
||||||
|
service_end_date = add_months(service_start_date, item.no_of_months)
|
||||||
|
deferred_detail = {
|
||||||
|
"enable_deferred_revenue": item.enable_deferred_revenue,
|
||||||
|
"deferred_revenue_account": get_default_deferred_revenue_account(args, item),
|
||||||
|
"service_start_date": service_start_date,
|
||||||
|
"service_end_date": service_end_date
|
||||||
|
}
|
||||||
|
|
||||||
|
return deferred_detail
|
||||||
|
|
||||||
def get_default_income_account(args, item, item_group):
|
def get_default_income_account(args, item, item_group):
|
||||||
return (item.get("income_account")
|
return (item.get("income_account")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user