def test_prepaid_subscriptions_with_prorate_true(self): settings = frappe.get_single('Subscription Settings') to_prorate = settings.prorate settings.prorate = 1 settings.save() subscription = frappe.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.generate_invoice_at_period_start = True subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() subscription.cancel_subscription() self.assertEqual(len(subscription.invoices), 1) current_inv = subscription.get_current_invoice() self.assertEqual(current_inv.status, "Unpaid") diff = flt(date_diff(nowdate(), subscription.current_invoice_start) + 1) plan_days = flt(date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1) prorate_factor = flt(diff / plan_days) self.assertEqual(flt(current_inv.grand_total, 2), flt(prorate_factor * 900, 2)) settings.prorate = to_prorate settings.save() subscription.delete()
def test_subscription_cancellation_invoices(self): settings = frappe.get_single('Subscription Settings') to_prorate = settings.prorate settings.prorate = 1 settings.save() subscription = frappe.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() self.assertEqual(subscription.status, 'Active') subscription.cancel_subscription() # Invoice must have been generated self.assertEqual(len(subscription.invoices), 1) invoice = subscription.get_current_invoice() diff = flt(date_diff(nowdate(), subscription.current_invoice_start) + 1) plan_days = flt(date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1) prorate_factor = flt(diff/plan_days) self.assertEqual( flt( get_prorata_factor(subscription.current_invoice_end, subscription.current_invoice_start), 2), flt(prorate_factor, 2) ) self.assertEqual(flt(invoice.grand_total, 2), flt(prorate_factor * 900, 2)) self.assertEqual(subscription.status, 'Cancelled') subscription.delete() settings.prorate = to_prorate settings.save()
def hourly(): """ Expires unused points of the customers s after specified time""" customers=frappe.get_all("Customer",fields=["customer_id"]) for customer in customers: customer_id=customer.get("customer_id") doc=frappe.get_doc("Customer",customer_id) if doc.get("points_table")!=None: for raw in doc.get("points_table"): startdate=data.getdate(raw.purchase_date) enddate=data.getdate(datetime.datetime.now()) print data.date_diff(enddate,startdate) rule_engine=frappe.get_all("Rule Engine",fields=['rule_type','points_expiry_duration'], filters={"status":"Active","docstatus":1}) for rule in rule_engine: if rule.get('points_expiry_duration')=="1 Year": if data.date_diff(enddate,startdate)==365 or data.date_diff(enddate,startdate)>365: raw.status="Expired" print raw.status doc.save() if rule.get('points_expiry_duration')=="3 Months": if data.date_diff(enddate,startdate)==90 or data.date_diff(enddate,startdate)>90: raw.status="Expired" print raw.status doc.save() if rule.get('points_expiry_duration')=="6 Months": if data.date_diff(enddate,startdate)==180 or data.date_diff(enddate,startdate)>180: raw.status="Expired" print raw.status doc.save()
def test_subscription_cancellation_invoices_with_prorata_true(self): settings = frappe.get_single('Subscription Settings') to_prorate = settings.prorate settings.prorate = 1 settings.save() subscription = frappe.new_doc('Subscription') subscription.customer = '_Test Customer' subscription.append('plans', {'plan': '_Test Plan Name', 'qty': 1}) subscription.save() subscription.cancel_subscription() invoice = subscription.get_current_invoice() diff = flt(date_diff(nowdate(), subscription.current_invoice_start) + 1) plan_days = flt(date_diff(subscription.current_invoice_end, subscription.current_invoice_start) + 1) prorate_factor = flt(diff / plan_days) self.assertEqual(flt(invoice.grand_total, 2), flt(prorate_factor * 900, 2)) settings.prorate = to_prorate settings.save() subscription.delete()
def get_day_diff(filters): return date_diff(filters.get('to_date'), filters.get('from_date'))
def get_prorata_factor(period_end, period_start): diff = flt(date_diff(nowdate(), period_start) + 1) plan_days = flt(date_diff(period_end, period_start) + 1) prorate_factor = diff / plan_days return prorate_factor
def _compute_days(latest_date, record): print(record) record_with_day = record record_with_day['days'] = date_diff(latest_date, record['date_admitted']) return record_with_day
def calculate_age(dob): return math.floor(date_diff(today(), dob) / 365)
def get_rows_for_div(calStartDate, house, from_price, to_price, from_size, to_size): rows = [] from_price = int(from_price) to_price = int(to_price) from_size = from_size to_size = to_size #houses = alle haeuser if house != 'All': house_filter = " AND `name` = '{house}'".format(house=house) else: house_filter = '' houses = frappe.db.sql("""SELECT `name` FROM `tabHouse` WHERE `disabled` = 0{house_filter} ORDER BY `name` ASC""".format(house_filter=house_filter), as_list=True) for _house in houses: house = _house[0] row_string = '<div class="planner-zeile">' # hinzufuegen zeile: haus apartment_qty = int(frappe.db.sql("""SELECT COUNT(`name`) FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} AND `apartment_size` >= '{3}' AND `apartment_size` <= '{4}' ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True)[0][0]) #apartment_qty = int(frappe.db.sql("""SELECT COUNT(`name`) FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True)[0][0]) row_string += '<div class="house a{0}"><span>{1}</span></div>'.format(apartment_qty * 2, house) #hinzufuegen appartments inkl. infos apartments = frappe.db.sql("""SELECT `name`, `apartment_size`, `position`, `price_per_month`, `service_price_per_month`, `price_per_day`, `service_price_per_day`, `remarks`, `special_apartment`, `special_color` FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} AND `apartment_size` >= '{3}' AND `apartment_size` <= '{4}' ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True) #apartments = frappe.db.sql("""SELECT `name`, `apartment_size`, `position`, `price_per_month`, `service_price_per_month`, `price_per_day`, `service_price_per_day`, `remarks` FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True) apartment_int = 1 for _apartment in apartments: apartment = _apartment[0] apartment_size = _apartment[1] position = _apartment[2] price_per_month = int(_apartment[3]) service_price_per_month = int(_apartment[4]) price_per_day = _apartment[5] service_price_per_day = _apartment[6] remarks = _apartment[7] special_apartment = _apartment[8] special_color = _apartment[9] #throw(str(apartment) + " /// " + str(special_apartment) + " /// " + str(special_color)) if str(special_apartment) == '1': apartment_color_style = ' style="background-color: {special_color} !important;"'.format(special_color=str(special_color)) else: apartment_color_style = '' # sum_per_month = float(price_per_month) + float(service_price_per_month) # sum_per_day = float(price_per_day) + float(service_price_per_day) buchung_weit_in_zukunft = '' if int(frappe.db.sql("""SELECT COUNT(`name`) FROM `tabBooking` WHERE `appartment` = '{0}' AND `start_date` >= '{1}'""".format(apartment, add_days(calStartDate, 60)), as_list=True)[0][0]) >= 1: buchung_weit_in_zukunft = ' <i class="fa fa-exclamation-circle"></i>' row_string += '<div class="apartment pos-{0}"{3} onclick="open_apartment({2})"><span>{1}{4}</span></div>'.format(apartment_int, apartment, "'" + apartment + "'", apartment_color_style, buchung_weit_in_zukunft) row_string += '<div class="room pos-{0}"><span>{1}</span></div>'.format(apartment_int, apartment_size) row_string += '<div class="position pos-{0}"><span>{1}</span></div>'.format(apartment_int, position) row_string += '<div class="pricePM pos-{0}"><span>{1}</span></div>'.format(apartment_int, price_per_month) row_string += '<div class="pricePD pos-{0}"><span>{1}</span></div>'.format(apartment_int, service_price_per_month) #row_string += '<div class="newBookingPlaceHolder a2 s1 d61 z0 pos-{0}" onclick="new_booking({1})"></div>'.format(apartment_int, "'" + apartment + "'") row_string += '<div class="remarks pos-{0}">{1}</div>'.format(apartment_int + 1, remarks) for_loop_count = 1 while for_loop_count < 62: row_string += '<div class="newBookingPlaceHolder a2 s{2} d1 z0 pos-{0}" onclick="new_booking({1}, {2})"></div>'.format(apartment_int, "'" + apartment + "'", for_loop_count) for_loop_count += 1 #hinzufuegen buchungen pro appartment qty_bookings = int(frappe.db.sql("""SELECT COUNT(`name`) FROM `tabBooking` WHERE `appartment` = '{0}' AND `end_date` >= '{1}'""".format(apartment, calStartDate), as_list=True)[0][0]) if qty_bookings > 0: overlap_control_list = [] bookings = frappe.db.sql("""SELECT `name`, `start_date`, `end_date`, `booking_status`, `is_checked`, `customer`, `mv_terminated`, `diff_invoice_partner`, `diff_guest` FROM `tabBooking` WHERE `appartment` = '{0}' AND `end_date` >= '{1}' AND `start_date` <= '{2}' AND `booking_status` != 'Service-Cleaning' ORDER BY (CASE `booking_status` WHEN 'Booked' THEN 1 WHEN 'Reserved' THEN 2 ELSE 10 END)""".format(apartment, calStartDate, add_days(calStartDate, 61)), as_list=True) z_index = 1 for _booking in bookings: booking = _booking[0] start = _booking[1] end = _booking[2] bookingType = _booking[3] is_checked = _booking[4] customer = _booking[5] mv_terminated = _booking[6] diff_invoice_partner = _booking[7] diff_guest = _booking[8] datediff = date_diff(start, calStartDate) if datediff <= 0: s_start = 1 dauer = date_diff(end, calStartDate) + 1 else: s_start = datediff + 1 dauer = date_diff(end, start) + 1 if bookingType == 'Reserved': color = 'b-yellow' if diff_guest: bookingType = diff_guest elif bookingType == 'Booked': if mv_terminated == 1: color = 'b-darkgrey' else: color = 'b-blue' elif bookingType == 'End-Cleaning': #check if checked bookingType = "End-R" if is_checked == 1: color = 'b-green' elif is_checked == 0: color = 'b-red' else: color = 'b-orange' elif bookingType == 'Sub-Cleaning': bookingType = "Sub-R" color = 'b-red' elif bookingType == 'Service-Cleaning': bookingType = "Service" color = 'b-darkgrey' elif bookingType == 'Renovation': color = 'b-darkgrey' elif bookingType == 'Control-Cleaning': bookingType = "Control" color = 'b-darkgrey' if dauer > 61: dauer = 61 if qty_bookings > 1: if overlap_control_list: for control_date in overlap_control_list: if overlap_control(control_date, [[start.strftime("%Y"), start.strftime("%-m"), start.strftime("%d")], [end.strftime("%Y"), end.strftime("%-m"), end.strftime("%d")]]) > 0: z_index += 1 overlap_control_list.append([[start.strftime("%Y"), start.strftime("%-m"), start.strftime("%d")], [end.strftime("%Y"), end.strftime("%-m"), end.strftime("%d")]]) if customer: customer = frappe.get_doc("Customer", customer) if diff_invoice_partner: rechnungsempfaenger = ", " + frappe.get_doc("Customer", diff_invoice_partner).customer_name else: rechnungsempfaenger = '' if diff_guest: diff_guest = ', ' + diff_guest else: diff_guest = '' customer_name = customer.customer_name + rechnungsempfaenger + diff_guest # if len(customer_name) > 6: # shortet = customer_name[:6] + '...' # customer_name = u'{shortet}'.format(shortet=shortet) if dauer < 2: customer_name = customer_name[:6] + '...' if s_start > 61: s_start = 99 row_string += '<div class="buchung pos-{0} s{1} d{2} z{4} {3}" onclick="show_booking({5})">{6}</div>'.format(apartment_int, s_start, dauer, color, z_index, "'" + booking + "'", customer_name) else: if s_start > 61: s_start = 99 row_string += '<div class="buchung pos-{0} s{1} d{2} z{4} {3}" onclick="show_booking({5})">{6}</div>'.format(apartment_int, s_start, dauer, color, z_index, "'" + booking + "'", _(bookingType)) z_index = 1 apartment_int += 2 row_string += '</div>' rows.append(row_string) return rows
def berechnung_anzahl_urlaubstage_ganz(von, bis, employee): anzahl_urlaubstage = 0 # ganze Tage: # --> innerhalb periode innerhalb = frappe.db.sql( """SELECT `total_leave_days` FROM `tabLeave Application` WHERE `from_date` >= '{von}' AND `to_date` <= '{bis}' AND `employee` = '{employee}' AND `half_day` = 0 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if innerhalb: for bezogene_urlaubs_tage in innerhalb: anzahl_urlaubstage += bezogene_urlaubs_tage.total_leave_days # --> start ausserhalb periode ausserhalb = frappe.db.sql( """SELECT `to_date` FROM `tabLeave Application` WHERE `from_date` < '{von}' AND `to_date` <= '{bis}' AND `to_date` >= '{von}' AND `employee` = '{employee}' AND `half_day` = 0 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if ausserhalb: for bezogene_urlaubs_tage in ausserhalb: anzahl_urlaubstage += date_diff(bezogene_urlaubs_tage.to_date, von) + 1 # --> ende ausserhalb periode ende_ausserhalb = frappe.db.sql( """SELECT `from_date` FROM `tabLeave Application` WHERE `from_date` >= '{von}' AND `from_date` <= '{bis}' AND `to_date` > '{bis}' AND `employee` = '{employee}' AND `half_day` = 0 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if ende_ausserhalb: for bezogene_urlaubs_tage in ende_ausserhalb: anzahl_urlaubstage += date_diff( bis, bezogene_urlaubs_tage.from_date) + 1 # --> start und ende ausserhalb periode # sollte es nie geben. # halbe Tage # --> innerhalb periode halbe_innerhalb = frappe.db.sql( """SELECT `total_leave_days` FROM `tabLeave Application` WHERE `from_date` >= '{von}' AND `to_date` <= '{bis}' AND `employee` = '{employee}' AND `half_day` = 1 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if halbe_innerhalb: for bezogene_urlaubs_tage in halbe_innerhalb: anzahl_urlaubstage += bezogene_urlaubs_tage.total_leave_days # --> start ausserhalb periode halbe_ausserhalb = frappe.db.sql( """SELECT `to_date`, `half_day_date` FROM `tabLeave Application` WHERE `from_date` < '{von}' AND `to_date` <= '{bis}' AND `to_date` >= '{von}' AND `employee` = '{employee}' AND `half_day` = 1 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if halbe_ausserhalb: for bezogene_urlaubs_tage in halbe_ausserhalb: if getdate(bezogene_urlaubs_tage.half_day_date) >= getdate(von): anzahl_urlaubstage += date_diff(bezogene_urlaubs_tage.to_date, von) + 0.5 else: anzahl_urlaubstage += date_diff(bezogene_urlaubs_tage.to_date, von) + 1 # --> ende ausserhalb periode halbe_ende_ausserhalb = frappe.db.sql( """SELECT `from_date`, `half_day_date` FROM `tabLeave Application` WHERE `from_date` >= '{von}' AND `from_date` <= '{bis}' AND `to_date` > '{bis}' AND `employee` = '{employee}' AND `half_day` = 1 AND `status` = 'Approved' AND `docstatus` = 1""" .format(von=von, bis=bis, employee=employee.name), as_dict=True) if halbe_ende_ausserhalb: for bezogene_urlaubs_tage in halbe_ende_ausserhalb: if getdate(bezogene_urlaubs_tage.half_day_date) <= getdate(bis): anzahl_urlaubstage += date_diff( bis, bezogene_urlaubs_tage.from_date) + 0.5 else: anzahl_urlaubstage += date_diff( bis, bezogene_urlaubs_tage.from_date) + 1 # --> start und ende ausserhalb periode # sollte es nie geben. return anzahl_urlaubstage
def get_cleaning_rows_for_div(calStartDate, house, from_price, to_price, from_size, to_size): rows = [] default_cleanings = {} from_price = int(from_price) to_price = int(to_price) from_size = from_size to_size = to_size if house != 'All': house_filter = " AND `name` = '{house}'".format(house=house) else: house_filter = '' #houses = alle haeuser houses = frappe.db.sql("""SELECT `name` FROM `tabHouse` WHERE `disabled` = 0{house_filter} ORDER BY `name` ASC""".format(house_filter=house_filter), as_list=True) for _house in houses: house = _house[0] row_string = '<div class="planner-zeile">' # hinzufuegen zeile: haus apartment_qty = int(frappe.db.sql("""SELECT COUNT(`name`) FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} AND `apartment_size` >= '{3}' AND `apartment_size` <= '{4}' ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True)[0][0]) row_string += '<div class="house a{0}"><span>{1}</span></div>'.format(apartment_qty, house) #hinzufuegen appartments inkl. infos apartments = frappe.db.sql("""SELECT `name`, `apartment_size`, `position`, `price_per_month`, `service_price_per_month`, `price_per_day`, `service_price_per_day`, `remarks`, `cleaning_day`, `special_apartment`, `special_color` FROM `tabAppartment` WHERE `house` = '{0}' AND `disabled` = 0 AND `price_per_month` >= {1} AND `price_per_month` <= {2} AND `apartment_size` >= '{3}' AND `apartment_size` <= '{4}' ORDER BY `name` ASC""".format(house, from_price, to_price, from_size, to_size), as_list=True) apartment_int = 1 for _apartment in apartments: booking_time_ref = [] er_ref = [] apartment = _apartment[0] apartment_size = _apartment[1] position = _apartment[2] price_per_month = int(_apartment[3]) service_price_per_month = int(_apartment[4]) price_per_day = _apartment[5] service_price_per_day = _apartment[6] remarks = _apartment[7] cleaning_day = _apartment[8] special_apartment = _apartment[9] special_color = _apartment[10] if str(special_apartment) == '1': apartment_color_style = ' style="background-color: {special_color} !important;"'.format(special_color=str(special_color)) else: apartment_color_style = '' # sum_per_month = float(price_per_month) + float(service_price_per_month) # sum_per_day = float(price_per_day) + float(service_price_per_day) row_string += '<div class="apartment pos-{0}"{3} onclick="open_apartment({2})"><span>{1}</span></div>'.format(apartment_int, apartment, "'" + apartment + "'", apartment_color_style) row_string += '<div class="room pos-{0}"><span>{1}</span></div>'.format(apartment_int, apartment_size) row_string += '<div class="position pos-{0}"><span>{1}</span></div>'.format(apartment_int, position) row_string += '<div class="pricePM pos-{0}"><span>{1}</span></div>'.format(apartment_int, price_per_month) row_string += '<div class="pricePD pos-{0}"><span>{1}</span></div>'.format(apartment_int, service_price_per_month) #row_string += '<div class="newBookingPlaceHolder a1 s1 d61 z0 pos-{0}" onclick="new_cleaning_booking({1})"></div>'.format(apartment_int, "'" + apartment + "'") for_loop_count = 1 while for_loop_count < 62: row_string += '<div class="newBookingPlaceHolder a1 s{2} d1 pos-{0}" style="z-index: 1;" onclick="new_cleaning_booking({1}, {2})"></div>'.format(apartment_int, "'" + apartment + "'", for_loop_count) for_loop_count += 1 #hinzufuegen buchungen pro appartment bookings = frappe.db.sql("""SELECT `name`, `start_date`, `end_date`, `booking_status`, `is_checked`, `customer` FROM `tabBooking` WHERE `appartment` = '{0}' AND `end_date` >= '{1}' AND `start_date` <= '{2}' AND (`booking_status` = 'End-Cleaning' OR `booking_status` = 'Sub-Cleaning' OR `booking_status` = 'Service-Cleaning' OR `booking_status` = 'Booked' OR `booking_status` = 'Control-Cleaning')""".format(apartment, calStartDate, add_days(calStartDate, 61)), as_list=True) for _booking in bookings: z_index = 3 booking = _booking[0] start = _booking[1] end = _booking[2] bookingType = _booking[3] is_checked = _booking[4] datediff = date_diff(start, calStartDate) on_click_detail = ' onclick="show_cleaning_booking({0})"'.format("'" + booking + "'") cursor_style = '' if datediff <= 0: s_start = 1 dauer = date_diff(end, calStartDate) + 1 else: s_start = datediff + 1 dauer = date_diff(end, start) + 1 if bookingType == 'End-Cleaning': bookingType = "End-R" er_ref.append(s_start) #check if checked if is_checked == 1: color = 'b-green' elif is_checked == 0: color = 'b-red' else: color = 'b-orange' elif bookingType == 'Sub-Cleaning': bookingType = "Sub-R" color = 'b-red' elif bookingType == 'Service-Cleaning': bookingType = "Service" color = 'b-darkgrey' elif bookingType == 'Control-Cleaning': bookingType = "Control" color = 'b-darkgrey' elif bookingType == 'Booked': color = 'b-lightblue' z_index = 0 booking_time_ref.append([s_start, (s_start + dauer - 1),_booking[5]]) on_click_detail = '' cursor_style = ' cursor: default !important;' else: color = 'b-darkgrey' if dauer > 61: dauer = 61 if s_start > 61: s_start = 99 row_string += '<div class="clean-buchung pos-{0} s{1} d{2} z{4} {3}" style="height: 36px !important; margin-top: 0px !important;{8}"{7}>{6}</div>'.format(apartment_int, s_start, dauer, color, z_index, "'" + booking + "'", _(bookingType), on_click_detail, cursor_style) all_days = createCleaningHeaders(calStartDate, add_to_date(calStartDate, months=1)) s_start = 1 for days in all_days["headers"]: if days["weekday"] == cleaning_day: for bookong_ref in booking_time_ref: if s_start >= bookong_ref[0] and s_start <= bookong_ref[1]: row_string += '<div class="clean-buchung pos-{0} s{1} d{2} {3}" style="z-index: 2;" onclick="new_cleaning_booking({5})">Default</div>'.format(apartment_int, s_start, 1, 'b-darkgrey', 0, "'" + apartment + "', '" + str(s_start) + "'") if s_start not in er_ref: if str(s_start) in default_cleanings: default_cleanings[str(s_start)].append([apartment, bookong_ref[2]]) else: default_cleanings[str(s_start)] = [] default_cleanings[str(s_start)].append([apartment, bookong_ref[2]]) s_start += 1 apartment_int += 1 row_string += '</div>' rows.append(row_string) return {'rows': rows, 'default_cleanings': default_cleanings}
def create_sales_order(apartment, customer, booking, start_date, end_date, guest='', invoice_partner=''): order = frappe.new_doc("Sales Order") delivery_date = start_date if guest == 'none' or guest == '': guest = 'Please add Guest' if invoice_partner == 'none' or invoice_partner == '': order.update({ "apartment": apartment.name, "customer": customer, "booking": booking.name, "guest": guest }) else: vertrags_adresse = frappe.db.sql("""SELECT `name` FROM `tabAddress` WHERE `is_shipping_address` = 1 AND `name` IN (SELECT `parent` FROM `tabDynamic Link` WHERE `parenttype` = 'Address' AND `link_name` = '{link_name}') LIMIT 1""".format(link_name=customer), as_list=True) if vertrags_adresse: vertrags_adresse = vertrags_adresse[0][0] else: vertrags_adresse = '' order.update({ "apartment": apartment.name, "customer": invoice_partner, "contractual_partner": customer, "contractual_partner_address": vertrags_adresse, "booking": booking.name, "guest": guest }) mietdauer = date_diff(end_date, start_date) + 1 #throw(str(apartment.name)) #_apartment = frappe.get_doc("Apartment", apartment.name) # Miete von Parkplatz --> if apartment.parking == 1: anz_monate = 1 items = [] items.append( { "item_code": "Miete mt 7.7%", "qty": "1", "rate": apartment.price_per_month, "delivery_date": delivery_date } ) while add_months(end_date, 0) > add_months(start_date, anz_monate): anz_monate += 1 items.append( { "item_code": "Miete mt 7.7%", "qty": "1", "rate": apartment.price_per_month, "delivery_date": add_months(delivery_date, (anz_monate - 1)) } ) #throw(str(anz_monate)) if anz_monate < 4: taxes = 'Kleiner Gleich 3 Monate - AAS' else: taxes = 'Grösser 3 Monate - AAS' order.update({ "items": items, "taxes_and_charges": taxes, "change_depot": 1, "remove_depot": 1, "change_service": 1, "remove_service": 1, "change_end_cleaning": 1, "remove_end_cleaning": 1 }) else: # Miete von Appartments --> # reine tagesmiete if mietdauer <= 19: taxes = 'Kleiner Gleich 3 Monate - AAS' miet_qty = mietdauer mietpreis = apartment.price_per_day mietservice = apartment.service_price_per_day order.update({ "items": [ { "item_code": "Depot", "qty": "1", "rate": apartment.price_per_month + apartment.service_price_per_month, "delivery_date": delivery_date }, { "item_code": "Miete 3.7 Tag", "qty": miet_qty, "rate": mietpreis, "delivery_date": delivery_date }, { "item_code": "Service 3.7 Tag", "qty": miet_qty, "rate": mietservice, "delivery_date": delivery_date }, { "item_code": "Endreinigung", "qty": "1", "rate": apartment.price_end_cleaning, "delivery_date": delivery_date } ], "taxes_and_charges": taxes }) else: items = [] items.append( { "item_code": "Depot", "qty": "1", "rate": apartment.price_per_month + apartment.service_price_per_month, "delivery_date": delivery_date } ) items.append( { "item_code": "Endreinigung", "qty": "1", "rate": apartment.price_end_cleaning, "delivery_date": delivery_date } ) #definition ob dauer >= 3Monate oder < 3Monate if end_date <= add_months(start_date, 3): monats_miete = 'Miete 3.7 Mt' monats_service = 'Service 3.7 Mt' tages_miete = 'Miete 3.7 Tag' tages_service = 'Service 3.7 Tag' taxes = 'Kleiner Gleich 3 Monate - AAS' else: monats_miete = 'Miete mt' monats_service = 'Service 7.7 Mt' tages_miete = 'Miete Tag' tages_service = 'Service 7.7 Tag' taxes = 'Grösser 3 Monate - AAS' start_monat = start_date folgemonat = add_months(start_date, 1) while getdate(str(end_date)) >= getdate(str(folgemonat)): items.append( { "item_code": monats_miete, "qty": "1", "rate": apartment.price_per_month, "delivery_date": str(start_monat) } ) items.append( { "item_code": monats_service, "qty": "1", "rate": apartment.service_price_per_month, "delivery_date": str(start_monat) } ) start_monat = folgemonat folgemonat = add_months(start_monat, 1) rest_tage = date_diff(end_date, start_monat) if rest_tage > 0 and rest_tage < 20: items.append( { "item_code": tages_miete, "qty": rest_tage, "rate": apartment.price_per_day, "delivery_date": str(start_monat) } ) items.append( { "item_code": tages_service, "qty": rest_tage, "rate": apartment.service_price_per_day, "delivery_date": str(start_monat) } ) else: if rest_tage > 0: items.append( { "item_code": monats_miete, "qty": "1", "rate": apartment.price_per_month, "delivery_date": str(start_monat) } ) items.append( { "item_code": monats_service, "qty": "1", "rate": apartment.service_price_per_month, "delivery_date": str(start_monat) } ) order.update({ "items": items, "taxes_and_charges": taxes }) order.insert(ignore_permissions=True) order.run_method("calculate_taxes_and_totals") order.save() frappe.db.commit() return order
def max_tage(jahr, monat): return date_diff(get_last_day(jahr + "-" + monat + "-15"), get_first_day(jahr + "-" + monat + "-15")) + 1
def get_target_time(filters, employee): degrees = get_degrees(employee) # if more than one degree if len(degrees) > 1: working_hours = 0 target_per_day = get_daily_hours(filters) degree_list = [] i = 0 i_max = len(degrees) - 1 while i < len(degrees): data = {} if i != i_max: data["start"] = degrees[i].date.strftime("%Y-%m-%d") data["end"] = add_days( degrees[i + 1].date.strftime("%Y-%m-%d"), -1) data["degree"] = degrees[i].degree else: data["start"] = degrees[i].date.strftime("%Y-%m-%d") data["end"] = filters.to_date data["degree"] = degrees[i].degree degree_list.append(data) i += 1 employee_joining_date = frappe.get_doc("Employee", employee).date_of_joining if getdate(employee_joining_date) < getdate(filters.from_date): start_date = getdate(filters.from_date) else: start_date = getdate(employee_joining_date) end_date = getdate(filters.to_date) delta = timedelta(days=1) while start_date <= end_date: for degree_range in degree_list: if getdate(degree_range["start"]) <= start_date <= getdate( degree_range["end"]): working_hours += (( (1 - get_off_days(start_date.strftime("%Y-%m-%d"), start_date.strftime("%Y-%m-%d"), filters.company)) * target_per_day) / 100) * degree_range["degree"] start_date += delta return working_hours # if only one degree or no degrees else: employee_joining_date = frappe.get_doc("Employee", employee).date_of_joining if getdate(employee_joining_date) < getdate(filters.from_date): start_date = filters.from_date else: start_date = employee_joining_date days = date_diff(filters.to_date, start_date) + 1 off_days = get_off_days(start_date, filters.to_date, filters.company) if len(degrees) > 0: target_per_day = (get_daily_hours(filters) / 100) * degrees[0].degree else: target_per_day = get_daily_hours(filters) target_time = (days - off_days) * target_per_day return target_time