def get_details(self,serial_no):
		s=webnotes.conn.sql("select item_name from `tabSerial No` where serial_no='"+serial_no+"'",as_list=1)		
		p=s[0][0]
		self.doc.item_name=p
		a=webnotes.conn.sql("select warranty_period from `tabItem` where item_name='"+cstr(self.doc.item_name)+"'",as_list=1)
		if a:
			from webnotes.utils import get_first_day, get_last_day, add_to_date, nowdate, getdate,add_months
   			today = nowdate()
			date=add_days(today,cint(a[0][0])-1)
			d=m=y=0
			y=int(a[0][0])/12
			m=int(a[0][0])%12
			date1=add_to_date(today,years=y,months=m,days=0)
			webnotes.errprint(date1)
			ret={
			   'warranty_start_on':today,
		           'warranty_end_on':date1
			}
			webnotes.errprint(ret)
			return ret		
		return 'hi'
 def get_details(self, serial_no):
     s = webnotes.conn.sql(
         "select item_name from `tabSerial No` where serial_no='" +
         serial_no + "'",
         as_list=1)
     p = s[0][0]
     self.doc.item_name = p
     a = webnotes.conn.sql(
         "select warranty_period from `tabItem` where item_name='" +
         cstr(self.doc.item_name) + "'",
         as_list=1)
     if a:
         from webnotes.utils import get_first_day, get_last_day, add_to_date, nowdate, getdate, add_months
         today = nowdate()
         date = add_days(today, cint(a[0][0]) - 1)
         d = m = y = 0
         y = int(a[0][0]) / 12
         m = int(a[0][0]) % 12
         date1 = add_to_date(today, years=y, months=m, days=0)
         webnotes.errprint(date1)
         ret = {'warranty_start_on': today, 'warranty_end_on': date1}
         webnotes.errprint(ret)
         return ret
     return 'hi'
	def test_recurring_invoice(self):
		from webnotes.utils import now_datetime, get_first_day, get_last_day, add_to_date
		today = now_datetime().date()
		
		base_si = webnotes.bean(copy=test_records[0])
		base_si.doc.fields.update({
			"convert_into_recurring_invoice": 1,
			"recurring_type": "Monthly",
			"notification_email_address": "[email protected], [email protected], [email protected]",
			"repeat_on_day_of_month": today.day,
			"posting_date": today,
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(today)
		})
		
		# monthly
		si1 = webnotes.bean(copy=base_si.doclist)
		si1.insert()
		si1.submit()
		self._test_recurring_invoice(si1, True)
		
		# monthly without a first and last day period
		si2 = webnotes.bean(copy=base_si.doclist)
		si2.doc.fields.update({
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, days=30)
		})
		si2.insert()
		si2.submit()
		self._test_recurring_invoice(si2, False)
		
		# quarterly
		si3 = webnotes.bean(copy=base_si.doclist)
		si3.doc.fields.update({
			"recurring_type": "Quarterly",
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(add_to_date(today, months=3))
		})
		si3.insert()
		si3.submit()
		self._test_recurring_invoice(si3, True)
		
		# quarterly without a first and last day period
		si4 = webnotes.bean(copy=base_si.doclist)
		si4.doc.fields.update({
			"recurring_type": "Quarterly",
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, months=3)
		})
		si4.insert()
		si4.submit()
		self._test_recurring_invoice(si4, False)
		
		# yearly
		si5 = webnotes.bean(copy=base_si.doclist)
		si5.doc.fields.update({
			"recurring_type": "Yearly",
			"invoice_period_from_date": get_first_day(today),
			"invoice_period_to_date": get_last_day(add_to_date(today, years=1))
		})
		si5.insert()
		si5.submit()
		self._test_recurring_invoice(si5, True)
		
		# yearly without a first and last day period
		si6 = webnotes.bean(copy=base_si.doclist)
		si6.doc.fields.update({
			"recurring_type": "Yearly",
			"invoice_period_from_date": today,
			"invoice_period_to_date": add_to_date(today, years=1)
		})
		si6.insert()
		si6.submit()
		self._test_recurring_invoice(si6, False)
		
		# change posting date but keep recuring day to be today
		si7 = webnotes.bean(copy=base_si.doclist)
		si7.doc.fields.update({
			"posting_date": add_to_date(today, days=-3)
		})
		si7.insert()
		si7.submit()
		
		# setting so that _test function works
		si7.doc.posting_date = today
		self._test_recurring_invoice(si7, True)
    def test_recurring_invoice(self):
        from webnotes.utils import get_first_day, get_last_day, add_to_date, nowdate, getdate
        from accounts.utils import get_fiscal_year
        today = nowdate()
        base_si = webnotes.bean(copy=test_records[0])
        base_si.doc.fields.update({
            "convert_into_recurring_invoice":
            1,
            "recurring_type":
            "Monthly",
            "notification_email_address":
            "[email protected], [email protected], [email protected]",
            "repeat_on_day_of_month":
            getdate(today).day,
            "posting_date":
            today,
            "fiscal_year":
            get_fiscal_year(today)[0],
            "invoice_period_from_date":
            get_first_day(today),
            "invoice_period_to_date":
            get_last_day(today)
        })

        # monthly
        si1 = webnotes.bean(copy=base_si.doclist)
        si1.insert()
        si1.submit()
        self._test_recurring_invoice(si1, True)

        # monthly without a first and last day period
        si2 = webnotes.bean(copy=base_si.doclist)
        si2.doc.fields.update({
            "invoice_period_from_date":
            today,
            "invoice_period_to_date":
            add_to_date(today, days=30)
        })
        si2.insert()
        si2.submit()
        self._test_recurring_invoice(si2, False)

        # quarterly
        si3 = webnotes.bean(copy=base_si.doclist)
        si3.doc.fields.update({
            "recurring_type":
            "Quarterly",
            "invoice_period_from_date":
            get_first_day(today),
            "invoice_period_to_date":
            get_last_day(add_to_date(today, months=3))
        })
        si3.insert()
        si3.submit()
        self._test_recurring_invoice(si3, True)

        # quarterly without a first and last day period
        si4 = webnotes.bean(copy=base_si.doclist)
        si4.doc.fields.update({
            "recurring_type":
            "Quarterly",
            "invoice_period_from_date":
            today,
            "invoice_period_to_date":
            add_to_date(today, months=3)
        })
        si4.insert()
        si4.submit()
        self._test_recurring_invoice(si4, False)

        # yearly
        si5 = webnotes.bean(copy=base_si.doclist)
        si5.doc.fields.update({
            "recurring_type":
            "Yearly",
            "invoice_period_from_date":
            get_first_day(today),
            "invoice_period_to_date":
            get_last_day(add_to_date(today, years=1))
        })
        si5.insert()
        si5.submit()
        self._test_recurring_invoice(si5, True)

        # yearly without a first and last day period
        si6 = webnotes.bean(copy=base_si.doclist)
        si6.doc.fields.update({
            "recurring_type":
            "Yearly",
            "invoice_period_from_date":
            today,
            "invoice_period_to_date":
            add_to_date(today, years=1)
        })
        si6.insert()
        si6.submit()
        self._test_recurring_invoice(si6, False)

        # change posting date but keep recuring day to be today
        si7 = webnotes.bean(copy=base_si.doclist)
        si7.doc.fields.update({"posting_date": add_to_date(today, days=-1)})
        si7.insert()
        si7.submit()

        # setting so that _test function works
        si7.doc.posting_date = today
        self._test_recurring_invoice(si7, True)