コード例 #1
0
ファイル: mis_control.py プロジェクト: Coalas/erpnext
  def define_periods(self, year, period):
    
    # get year start date    
    ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", year)
    ysd = ysd and ysd[0][0] or ''

    self.ysd = ysd

    # year
    if period == 'Annual':
      pn = 'FY'+year
      self.period_list.append(pn)
      self.period_start_date[pn] = ysd
      self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,11))

    # quarter
    if period == 'Quarterly':
      for i in range(4):
        pn = 'Q'+str(i+1)
        self.period_list.append(pn)
      
        self.period_start_date[pn] = get_first_day(ysd,0,i*3)
        self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,((i+1)*3)-1))  

    # month
    if period == 'Monthly':
      mlist = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
      for i in range(12):
        fd = get_first_day(ysd,0,i)
        pn = mlist[fd.month-1]
        self.period_list.append(pn)
      
        self.period_start_date[pn] = fd
        self.period_end_date[pn] = get_last_day(fd)
コード例 #2
0
ファイル: mis_control.py プロジェクト: hbkfabio/erpnext
    def define_periods(self, year, period):

        # get year start date
        ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", year)
        ysd = ysd and ysd[0][0] or ""

        self.ysd = ysd

        # year
        if period == "Annual":
            pn = "FY" + year
            self.period_list.append(pn)
            self.period_start_date[pn] = ysd
            self.period_end_date[pn] = get_last_day(get_first_day(ysd, 0, 11))

            # quarter
        if period == "Quarterly":
            for i in range(4):
                pn = "Q" + str(i + 1)
                self.period_list.append(pn)

                self.period_start_date[pn] = get_first_day(ysd, 0, i * 3)
                self.period_end_date[pn] = get_last_day(get_first_day(ysd, 0, ((i + 1) * 3) - 1))

                # month
        if period == "Monthly":
            mlist = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
            for i in range(12):
                fd = get_first_day(ysd, 0, i)
                pn = mlist[fd.month - 1]
                self.period_list.append(pn)

                self.period_start_date[pn] = fd
                self.period_end_date[pn] = get_last_day(fd)
コード例 #3
0
	def define_periods(self, year, period):
		
		# get year start date		
		ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", year)
		ysd = ysd and ysd[0][0] or ''

		self.ysd = ysd

		# year
		if period == 'Annual':
			pn = 'FY'+year
			self.period_list.append(pn)
			self.period_start_date[pn] = ysd
			self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,11))

		# quarter
		if period == 'Quarterly':
			for i in range(4):
				pn = 'Q'+str(i+1)
				self.period_list.append(pn)
			
				self.period_start_date[pn] = get_first_day(ysd,0,i*3)
				self.period_end_date[pn] = get_last_day(get_first_day(ysd,0,((i+1)*3)-1))	

		# month
		if period == 'Monthly':
			mlist = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
			for i in range(12):
				fd = get_first_day(ysd,0,i)
				pn = mlist[fd.month-1]
				self.period_list.append(pn)
			
				self.period_start_date[pn] = fd
				self.period_end_date[pn] = get_last_day(fd)
コード例 #4
0
ファイル: mis_control.py プロジェクト: Coalas/erpnext
  def bl(self, acc, company):
    dt = getdate(nowdate())

    r = []
    # cur
    r.append(self.get_cur_balance(acc, company))
    # this month
    r.append(self.get_balance(acc, get_first_day(dt), get_last_day(dt), company, self.fiscal_year))
    # last month
    r.append(self.get_balance(acc, get_first_day(dt,0,-1), get_last_day(get_first_day(dt,0,-1)), company, self.fiscal_year))
    return r
コード例 #5
0
ファイル: global_defaults.py プロジェクト: MiteshC/erpnext
	def on_update(self):
		"""update defaults"""
		
		self.validate_session_expiry()
		
		for key in keydict:
			webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
			
		# update year start date and year end date from fiscal_year
		ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` 
			where name=%s""", self.doc.current_fiscal_year)
			
		ysd = ysd and ysd[0][0] or ''
		from webnotes.utils import get_first_day, get_last_day
		if ysd:
			webnotes.conn.set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
			webnotes.conn.set_default('year_end_date', \
				get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
		
		# enable default currency
		if self.doc.default_currency:
			webnotes.conn.set_value("Currency", self.doc.default_currency, "enabled", 1)
		
		# clear cache
		webnotes.clear_cache()
コード例 #6
0
    def bl(self, acc, company):
        dt = getdate(nowdate())

        r = []
        # cur
        r.append(self.get_cur_balance(acc, company))
        # this month
        r.append(
            self.get_balance(acc, get_first_day(dt), get_last_day(dt), company,
                             self.fiscal_year))
        # last month
        r.append(
            self.get_balance(acc, get_first_day(dt, 0, -1),
                             get_last_day(get_first_day(dt, 0, -1)), company,
                             self.fiscal_year))
        return r
コード例 #7
0
ファイル: global_defaults.py プロジェクト: marchon/erpnext-15
    def on_update(self):
        """update defaults"""
        self.validate_session_expiry()
        self.update_control_panel()

        for key in keydict:
            webnotes.conn.set_default(key,
                                      self.doc.fields.get(keydict[key], ''))

        # update year start date and year end date from fiscal_year
        ysd = webnotes.conn.sql(
            """select year_start_date from `tabFiscal Year` 
			where name=%s""", self.doc.current_fiscal_year)

        ysd = ysd and ysd[0][0] or ''
        from webnotes.utils import get_first_day, get_last_day
        if ysd:
            webnotes.conn.set_default('year_start_date',
                                      ysd.strftime('%Y-%m-%d'))
            webnotes.conn.set_default('year_end_date', \
             get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))

        # enable default currency
        if self.doc.default_currency:
            webnotes.conn.set_value("Currency", self.doc.default_currency,
                                    "enabled", 1)

        # clear cache
        webnotes.clear_cache()
コード例 #8
0
ファイル: sales_invoice.py プロジェクト: rohitw1991/erpnext
def make_new_invoice(ref_wrapper, posting_date):
	from webnotes.model.bean import clone
	from accounts.utils import get_fiscal_year
	new_invoice = clone(ref_wrapper)
	
	mcount = month_map[ref_wrapper.doc.recurring_type]
	
	invoice_period_from_date = get_next_date(ref_wrapper.doc.invoice_period_from_date, mcount)
	
	# get last day of the month to maintain period if the from date is first day of its own month 
	# and to date is the last day of its own month
	if (cstr(get_first_day(ref_wrapper.doc.invoice_period_from_date)) == \
			cstr(ref_wrapper.doc.invoice_period_from_date)) and \
		(cstr(get_last_day(ref_wrapper.doc.invoice_period_to_date)) == \
			cstr(ref_wrapper.doc.invoice_period_to_date)):
		invoice_period_to_date = get_last_day(get_next_date(ref_wrapper.doc.invoice_period_to_date,
			mcount))
	else:
		invoice_period_to_date = get_next_date(ref_wrapper.doc.invoice_period_to_date, mcount)
	
	new_invoice.doc.fields.update({
		"posting_date": posting_date,
		"aging_date": posting_date,
		"due_date": add_days(posting_date, cint(date_diff(ref_wrapper.doc.due_date,
			ref_wrapper.doc.posting_date))),
		"invoice_period_from_date": invoice_period_from_date,
		"invoice_period_to_date": invoice_period_to_date,
		"fiscal_year": get_fiscal_year(posting_date)[0],
		"owner": ref_wrapper.doc.owner,
	})
	
	new_invoice.submit()
	
	return new_invoice
コード例 #9
0
ファイル: sales_invoice.py プロジェクト: rajatkapoor/erpnext
def make_new_invoice(ref_wrapper, posting_date):
	from webnotes.model.bean import clone
	from accounts.utils import get_fiscal_year
	new_invoice = clone(ref_wrapper)
	
	mcount = month_map[ref_wrapper.doc.recurring_type]
	
	invoice_period_from_date = get_next_date(ref_wrapper.doc.invoice_period_from_date, mcount)
	
	# get last day of the month to maintain period if the from date is first day of its own month 
	# and to date is the last day of its own month
	if (cstr(get_first_day(ref_wrapper.doc.invoice_period_from_date)) == \
			cstr(ref_wrapper.doc.invoice_period_from_date)) and \
		(cstr(get_last_day(ref_wrapper.doc.invoice_period_to_date)) == \
			cstr(ref_wrapper.doc.invoice_period_to_date)):
		invoice_period_to_date = get_last_day(get_next_date(ref_wrapper.doc.invoice_period_to_date,
			mcount))
	else:
		invoice_period_to_date = get_next_date(ref_wrapper.doc.invoice_period_to_date, mcount)
	
	new_invoice.doc.fields.update({
		"posting_date": posting_date,
		"aging_date": posting_date,
		"due_date": add_days(posting_date, cint(date_diff(ref_wrapper.doc.due_date,
			ref_wrapper.doc.posting_date))),
		"invoice_period_from_date": invoice_period_from_date,
		"invoice_period_to_date": invoice_period_to_date,
		"fiscal_year": get_fiscal_year(posting_date)[0],
		"owner": ref_wrapper.doc.owner,
	})
	
	new_invoice.submit()
	
	return new_invoice
コード例 #10
0
  def set_system_default(self, defkey, defvalue):
    set_default(defkey, defvalue)

    if defkey == 'fiscal_year':
      ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", cstr(defvalue))
      ysd = ysd and ysd[0][0] or ''
      if ysd:
        set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
        set_default('year_end_date', get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
コード例 #11
0
ファイル: mis_control.py プロジェクト: Coalas/erpnext
 def bl_bs(self, acc, company, sd):
   dt = getdate(nowdate())
   r = []
   # cur
   r.append(self.get_cur_balance(acc, company))
   # last month
   r.append(self.get_balance(acc, sd, get_last_day(get_first_day(dt,0,-1)), company, self.fiscal_year))
   # opening
   r.append(self.get_balance(acc, sd, sd, company, self.fiscal_year))
   return r
コード例 #12
0
ファイル: gl_entry.py プロジェクト: Coalas/erpnext
	def validate_posting_date(self):
		fy = sql("select docstatus, year_start_date from `tabFiscal Year` where name=%s ", self.doc.fiscal_year)
		ysd = fy[0][1]
		yed = get_last_day(get_first_day(ysd,0,11))
		pd = getdate(self.doc.posting_date)
		if fy[0][0] == 2:
			msgprint("Fiscal Year is not active. You can restore it from Trash")
			raise Exception
		if pd < ysd or pd > yed:
			msgprint("Posting date must be in the Selected Financial Year")
			raise Exception
コード例 #13
0
ファイル: gl_entry.py プロジェクト: masums/erpnext
	def validate_posting_date(self):
		fy = sql("select docstatus, year_start_date from `tabFiscal Year` where name=%s ", self.doc.fiscal_year)
		ysd = fy[0][1]
		yed = get_last_day(get_first_day(ysd,0,11))
		pd = getdate(self.doc.posting_date)
		if fy[0][0] == 2:
			msgprint("Fiscal Year is not active. You can restore it from Trash")
			raise Exception
		if pd < ysd or pd > yed:
			msgprint("Posting date must be in the Selected Financial Year")
			raise Exception
コード例 #14
0
 def bl_bs(self, acc, company, sd):
     dt = getdate(nowdate())
     r = []
     # cur
     r.append(self.get_cur_balance(acc, company))
     # last month
     r.append(
         self.get_balance(acc, sd, get_last_day(get_first_day(dt, 0, -1)),
                          company, self.fiscal_year))
     # opening
     r.append(self.get_balance(acc, sd, sd, company, self.fiscal_year))
     return r
コード例 #15
0
	def on_update(self):
		"""update defaults"""
		
		for key in keydict:
			webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
			
		# update year start date and year end date from fiscal_year
		ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` 
			where name=%s""", self.doc.current_fiscal_year)
			
		ysd = ysd and ysd[0][0] or ''
		from webnotes.utils import get_first_day, get_last_day
		if ysd:
			webnotes.conn.set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
			webnotes.conn.set_default('year_end_date', \
				get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
コード例 #16
0
ファイル: global_defaults.py プロジェクト: smilekk/erpnext
	def on_update(self):
		"""update defaults"""
		
		for key in keydict:
			webnotes.conn.set_default(key, self.doc.fields.get(keydict[key], ''))
			
		# update year start date and year end date from fiscal_year
		ysd = webnotes.conn.sql("""select year_start_date from `tabFiscal Year` 
			where name=%s""", self.doc.current_fiscal_year)
			
		ysd = ysd and ysd[0][0] or ''
		from webnotes.utils import get_first_day, get_last_day
		if ysd:
			webnotes.conn.set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
			webnotes.conn.set_default('year_end_date', \
				get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))
コード例 #17
0
ファイル: erp_setup.py プロジェクト: ravidey/erpnext
  def on_update(self):

    # fiscal year
    set_default('fiscal_year', self.doc.current_fiscal_year)
    ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", self.doc.current_fiscal_year, as_dict = 1)
    set_default('year_start_date', ysd[0]['year_start_date'].strftime('%Y-%m-%d'))
    set_default('year_end_date', get_last_day(get_first_day(ysd[0]['year_start_date'],0,11)).strftime('%Y-%m-%d'))

    # company
    set_default('company', self.doc.default_company)

    set_default('stock_valuation', self.doc.stock_valuation or 'Moving Average')
    set_default('default_currency', self.doc.default_currency or 'INR')

    # Purchase in transit
    if self.doc.purchase_in_transit_account:
      set_default('purchase_in_transit_account', self.doc.purchase_in_transit_account)
コード例 #18
0
	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)
コード例 #19
0
    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)
コード例 #20
0
ファイル: accounts_setup.py プロジェクト: ravidey/erpnext
 def on_update(self):
   set_default('fiscal_year', self.doc.current_fiscal_year)
   ysd = sql("select year_start_date from `tabFiscal Year` where name=%s", self.doc.current_fiscal_year)[0][0]
   set_default('year_start_date', ysd.strftime('%Y-%m-%d'))
   set_default('year_end_date', get_last_day(get_first_day(ysd,0,11)).strftime('%Y-%m-%d'))