예제 #1
0
	def validate_exchange_rates_exist(self):
		"""check if exchange rates exist for all Price List currencies (to company's currency)"""
		company_currency = webnotes.conn.get_value("Company", self.doc.company, "default_currency")
		if not company_currency:
			msgprint(_("Please specify currency in Company") + ": " + self.doc.company,
				raise_exception=ShoppingCartSetupError)
		
		price_list_currency_map = webnotes.conn.get_values("Price List", 
			[d.price_list for d in self.doclist.get({"parentfield": "price_lists"})],
			"currency")
		
		expected_to_exist = [currency + "-" + company_currency 
			for currency in price_list_currency_map.values()
			if currency != company_currency]
			
		if expected_to_exist:
			exists = webnotes.conn.sql_list("""select name from `tabCurrency Exchange`
				where name in (%s)""" % (", ".join(["%s"]*len(expected_to_exist)),),
				tuple(expected_to_exist))
		
			missing = list(set(expected_to_exist).difference(exists))
		
			if missing:
				msgprint(_("Missing Currency Exchange Rates for" + ": " + comma_and(missing)),
					raise_exception=ShoppingCartSetupError)
	def validate_exchange_rates_exist(self):
		"""check if exchange rates exist for all Price List currencies (to company's currency)"""
		company_currency = webnotes.conn.get_value("Company", self.doc.company, "default_currency")
		if not company_currency:
			msgprint(_("Please specify currency in Company") + ": " + self.doc.company,
				raise_exception=ShoppingCartSetupError)
		
		price_list_currency_map = webnotes.conn.get_values("Price List", 
			[d.selling_price_list for d in self.doclist.get({"parentfield": "price_lists"})],
			"currency")
			
		expected_to_exist = [currency + "-" + company_currency 
			for currency in price_list_currency_map.values()
			if currency != company_currency]
			
		if expected_to_exist:
			exists = webnotes.conn.sql_list("""select name from `tabCurrency Exchange`
				where name in (%s)""" % (", ".join(["%s"]*len(expected_to_exist)),),
				tuple(expected_to_exist))
		
			missing = list(set(expected_to_exist).difference(exists))
		
			if missing:
				msgprint(_("Missing Currency Exchange Rates for" + ": " + comma_and(missing)),
					raise_exception=ShoppingCartSetupError)
예제 #3
0
def get_data(rows, company_abbr):
	start_row = 0
	data = []
	start_row_idx = 0
	for i in xrange(len(rows)):
		r = rows[i]
		if r[0]:
			if start_row and i >= start_row:
				if not start_row_idx: start_row_idx = i
				d, acc_dict = webnotes._dict(), webnotes._dict()
				for cidx in xrange(len(columns)):
					d[columns[cidx]] = r[cidx]
					
				if accounts:
					total_debit = total_credit = 0
					for acc_idx in xrange(len(accounts)):
						col_idx = len(columns) + acc_idx
						if flt(r[col_idx]) != 0:
							if not acc_dict.get(accounts[acc_idx]):
								acc_dict[accounts[acc_idx]] = 0
							acc_dict[accounts[acc_idx]] += flt(r[col_idx])
						if flt(r[col_idx]) > 0:
							total_debit += flt(r[col_idx])
						else:
							total_credit += abs(flt(r[col_idx]))
							
					d['total_debit'] = total_debit
					d['total_credit'] = total_credit
				
				data.append([d, acc_dict])
				

			if r[0]=="--------Data----------":
				start_row = i+2
				
				# check for empty columns
				empty_columns = [j+1 for j, c in enumerate(rows[i+1]) if not c]
				if empty_columns:
					raise Exception, """Column No(s). %s %s empty. \
						Please remove them and try again.""" % (comma_and(empty_columns),
						len(empty_columns)==1 and "is" or "are")

				columns = [c.replace(" ", "_").lower() for c in rows[i+1] 
					if not c.endswith(" - " + company_abbr)]
				accounts = [c for c in rows[i+1] if c.endswith(" - " + company_abbr)]

				if not accounts:
					webnotes.msgprint(_("""No Account found in csv file, 
						May be company abbreviation is not correct"""), raise_exception=1)

				if accounts and (len(columns) != rows[i+1].index(accounts[0])):
					webnotes.msgprint(_("""All account columns should be after \
						standard columns and on the right.
						If you entered it properly, next probable reason \
						could be wrong account name.
						Please rectify it in the file and try again."""), raise_exception=1)
				
	return data, start_row_idx
예제 #4
0
def _get_item_code(barcode):
	item_code = webnotes.conn.sql_list("""select name from `tabItem` where barcode=%s""", barcode)
			
	if not item_code:
		msgprint(_("No Item found with Barcode") + ": %s" % barcode, raise_exception=True)
	
	elif len(item_code) > 1:
		msgprint(_("Items") + " %s " % comma_and(item_code) + 
			_("have the same Barcode") + " %s" % barcode, raise_exception=True)
	
	return item_code[0]
예제 #5
0
	def validate_recurring_invoice(self):
		if self.doc.convert_into_recurring_invoice:
			self.validate_notification_email_id()
		
			if not self.doc.recurring_type:
				msgprint(_("Please select: ") + self.meta.get_label("recurring_type"),
				raise_exception=1)
		
			elif not (self.doc.invoice_period_from_date and \
					self.doc.invoice_period_to_date):
				msgprint(comma_and([self.meta.get_label("invoice_period_from_date"),
					self.meta.get_label("invoice_period_to_date")])
					+ _(": Mandatory for a Recurring Invoice."),
					raise_exception=True)
예제 #6
0
파일: utils.py 프로젝트: shinmuteki/erpnext
def _get_item_code(barcode):
    item_code = webnotes.conn.sql_list(
        """select name from `tabItem` where barcode=%s""", barcode)

    if not item_code:
        msgprint(_("No Item found with Barcode") + ": %s" % barcode,
                 raise_exception=True)

    elif len(item_code) > 1:
        msgprint(_("Items") + " %s " % comma_and(item_code) +
                 _("have the same Barcode") + " %s" % barcode,
                 raise_exception=True)

    return item_code[0]
예제 #7
0
	def validate_overlapping_territories(self, parentfield, fieldname):
		# for displaying message
		doctype = self.meta.get_field(parentfield).options
		
		# specify atleast one entry in the table
		self.validate_table_has_rows(parentfield, raise_exception=ShoppingCartSetupError)
		
		territory_name_map = self.get_territory_name_map(parentfield, fieldname)
		for territory, names in territory_name_map.items():
			if len(names) > 1:
				msgprint(_("Error for") + " " + _(doctype) + ": " + comma_and(names) +
					" " + _("have a common territory") + ": " + territory,
					raise_exception=ShoppingCartSetupError)
					
		return territory_name_map
	def validate_overlapping_territories(self, parentfield, fieldname):
		# for displaying message
		doctype = self.meta.get_field(parentfield).options
		
		# specify atleast one entry in the table
		self.validate_table_has_rows(parentfield, raise_exception=ShoppingCartSetupError)
		
		territory_name_map = self.get_territory_name_map(parentfield, fieldname)
		for territory, names in territory_name_map.items():
			if len(names) > 1:
				msgprint(_("Error for") + " " + _(doctype) + ": " + comma_and(names) +
					" " + _("have a common territory") + ": " + territory,
					raise_exception=ShoppingCartSetupError)
					
		return territory_name_map
예제 #9
0
def get_data(rows, company_abbr):
    start_row = 0
    data = []
    start_row_idx = 0
    for i in xrange(len(rows)):
        r = rows[i]
        if r[0]:
            if start_row and i >= start_row:
                if not start_row_idx: start_row_idx = i
                d, acc_dict = webnotes._dict(), webnotes._dict()
                for cidx in xrange(len(columns)):
                    d[columns[cidx]] = r[cidx]

                if accounts:
                    total_debit = total_credit = 0
                    for acc_idx in xrange(len(accounts)):
                        col_idx = len(columns) + acc_idx
                        if flt(r[col_idx]) != 0:
                            if not acc_dict.get(accounts[acc_idx]):
                                acc_dict[accounts[acc_idx]] = 0
                            acc_dict[accounts[acc_idx]] += flt(r[col_idx])
                        if flt(r[col_idx]) > 0:
                            total_debit += flt(r[col_idx])
                        else:
                            total_credit += abs(flt(r[col_idx]))

                    d['total_debit'] = total_debit
                    d['total_credit'] = total_credit

                data.append([d, acc_dict])

            if r[0] == "--------Data----------":
                start_row = i + 2

                # check for empty columns
                empty_columns = [
                    j + 1 for j, c in enumerate(rows[i + 1]) if not c
                ]
                if empty_columns:
                    raise Exception, """Column No(s). %s %s empty. \
						Please remove them and try again.""" % (comma_and(empty_columns),
                                              len(empty_columns) == 1 and "is"
                                              or "are")

                columns = [
                    c.replace(" ", "_").lower() for c in rows[i + 1]
                    if not c.endswith(" - " + company_abbr)
                ]
                accounts = [
                    c for c in rows[i + 1] if c.endswith(" - " + company_abbr)
                ]

                if accounts and (len(columns) != rows[i + 1].index(
                        accounts[0])):
                    raise Exception, _("""All account columns should be after \
						standard columns and on the right.
						If you entered it properly, next probable reason \
						could be wrong account name.
						Please rectify it in the file and try again.""")

    return data, start_row_idx