Esempio n. 1
0
	def set_price_list_currency(self, buying_or_selling):
		if self.meta.get_field("currency"):
			company_currency = get_company_currency(self.doc.company)
			
			# price list part
			fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
				else "buying_price_list"
			if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
				self.doc.price_list_currency = webnotes.conn.get_value("Price List",
					self.doc.fields.get(fieldname), "currency")
				
				if self.doc.price_list_currency == company_currency:
					self.doc.plc_conversion_rate = 1.0

				elif not self.doc.plc_conversion_rate:
					self.doc.plc_conversion_rate = self.get_exchange_rate(
						self.doc.price_list_currency, company_currency)
			
			# currency
			if not self.doc.currency:
				self.doc.currency = self.doc.price_list_currency
				self.doc.conversion_rate = self.doc.plc_conversion_rate
			elif self.doc.currency == company_currency:
				self.doc.conversion_rate = 1.0
			elif not self.doc.conversion_rate:
				self.doc.conversion_rate = self.get_exchange_rate(self.doc.currency,
					company_currency)
Esempio n. 2
0
    def set_price_list_currency(self, buying_or_selling):
        if self.meta.get_field("currency"):
            company_currency = get_company_currency(self.doc.company)

            # price list part
            fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
             else "buying_price_list"
            if self.meta.get_field(fieldname) and self.doc.fields.get(
                    fieldname):
                self.doc.price_list_currency = webnotes.conn.get_value(
                    "Price List", self.doc.fields.get(fieldname), "currency")

                if self.doc.price_list_currency == company_currency:
                    self.doc.plc_conversion_rate = 1.0

                elif not self.doc.plc_conversion_rate:
                    self.doc.plc_conversion_rate = self.get_exchange_rate(
                        self.doc.price_list_currency, company_currency)

            # currency
            if not self.doc.currency:
                self.doc.currency = self.doc.price_list_currency
                self.doc.conversion_rate = self.doc.plc_conversion_rate
            elif self.doc.currency == company_currency:
                self.doc.conversion_rate = 1.0
            elif not self.doc.conversion_rate:
                self.doc.conversion_rate = self.get_exchange_rate(
                    self.doc.currency, company_currency)
Esempio n. 3
0
    def set_price_list_currency(self, buying_or_selling):
        company_currency = get_company_currency(self.doc.company)
        fieldname = buying_or_selling.lower() + "_price_list"

        # TODO - change this, since price list now has only one currency allowed
        if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
            if not self.doc.price_list_currency:
                self.doc.fields.update(
                    get_price_list_currency(self.doc.fields.get(fieldname)))

            if self.doc.price_list_currency:
                if self.doc.price_list_currency == company_currency:
                    self.doc.plc_conversion_rate = 1.0
                elif not self.doc.plc_conversion_rate:
                    exchange = self.doc.price_list_currency + "-" + company_currency
                    self.doc.plc_conversion_rate = flt(
                        webnotes.conn.get_value("Currency Exchange", exchange,
                                                "exchange_rate"))

                if not self.doc.currency:
                    self.doc.currency = self.doc.price_list_currency
                    self.doc.conversion_rate = self.doc.plc_conversion_rate

        if self.meta.get_field("currency"):
            if self.doc.currency and self.doc.currency != company_currency:
                if not self.doc.conversion_rate:
                    exchange = self.doc.currency + "-" + company_currency
                    self.doc.conversion_rate = flt(
                        webnotes.conn.get_value("Currency Exchange", exchange,
                                                "exchange_rate"))
            else:
                self.doc.conversion_rate = 1
Esempio n. 4
0
    def calculate_taxes_and_totals(self):
        # validate conversion rate
        company_currency = get_company_currency(self.doc.company)
        if not self.doc.currency or self.doc.currency == company_currency:
            self.doc.currency = company_currency
            self.doc.conversion_rate = 1.0
        else:
            validate_conversion_rate(self.doc.currency,
                                     self.doc.conversion_rate,
                                     self.meta.get_label("conversion_rate"),
                                     self.doc.company)

        self.doc.conversion_rate = flt(self.doc.conversion_rate)
        self.item_doclist = self.doclist.get({"parentfield": self.fname})
        self.tax_doclist = self.doclist.get({"parentfield": self.other_fname})

        self.calculate_item_values()
        self.initialize_taxes()

        if hasattr(self, "determine_exclusive_rate"):
            self.determine_exclusive_rate()

        self.calculate_net_total()
        self.calculate_taxes()
        self.calculate_totals()
        self._cleanup()
Esempio n. 5
0
	def set_price_list_currency(self, buying_or_selling):
		company_currency = get_company_currency(self.doc.company)
		fieldname = buying_or_selling.lower() + "_price_list"
		
		# TODO - change this, since price list now has only one currency allowed
		if self.meta.get_field(fieldname) and self.doc.fields.get(fieldname):
			self.doc.fields.update(get_price_list_currency(self.doc.fields.get(fieldname)))
				
			if self.doc.price_list_currency:
				if self.doc.price_list_currency == company_currency:
					self.doc.plc_conversion_rate = 1.0
				elif not self.doc.plc_conversion_rate or \
						(flt(self.doc.plc_conversion_rate)==1 and company_currency!= self.doc.price_list_currency):
					exchange = self.doc.price_list_currency + "-" + company_currency
					self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
						exchange, "exchange_rate"))
					
				if not self.doc.currency:
					self.doc.currency = self.doc.price_list_currency
					self.doc.conversion_rate = self.doc.plc_conversion_rate
						
		if self.meta.get_field("currency"):
			if self.doc.currency and self.doc.currency != company_currency:
				if not self.doc.conversion_rate:
					exchange = self.doc.currency + "-" + company_currency
					self.doc.conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
						exchange, "exchange_rate"))
			else:
				self.doc.conversion_rate = 1
Esempio n. 6
0
    def check_conversion_rate(self, obj):
        default_currency = get_company_currency(obj.doc.company)
        if not default_currency:
            msgprint("Message: Please enter default currency in Company Master")
            raise Exception
        if (
            (obj.doc.currency == default_currency and flt(obj.doc.conversion_rate) != 1.00)
            or not obj.doc.conversion_rate
            or (obj.doc.currency != default_currency and flt(obj.doc.conversion_rate) == 1.00)
        ):
            msgprint(
                "Please Enter Appropriate Conversion Rate for Customer's Currency to Base Currency (%s --> %s)"
                % (obj.doc.currency, default_currency),
                raise_exception=1,
            )

        if (
            (obj.doc.price_list_currency == default_currency and flt(obj.doc.plc_conversion_rate) != 1.00)
            or not obj.doc.plc_conversion_rate
            or (obj.doc.price_list_currency != default_currency and flt(obj.doc.plc_conversion_rate) == 1.00)
        ):
            msgprint(
                "Please Enter Appropriate Conversion Rate for Price List Currency to Base Currency ( (%s --> %s)"
                % (obj.doc.price_list_currency, default_currency),
                raise_exception=1,
            )
Esempio n. 7
0
	def get_appr_user_role(self, det, doctype_name, total, based_on, condition, item, company):
		amt_list, appr_users, appr_roles = [], [], []
		users, roles = '',''
		if det:
			for x in det:
				amt_list.append(flt(x[0]))
			max_amount = max(amt_list)
			
			app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and company = %s %s" % ('%s', '%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on, company))
			
			if not app_dtl:
				app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and ifnull(company,'') = '' %s" % ('%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on)) 
			for d in app_dtl:
				if(d[0]): appr_users.append(d[0])
				if(d[1]): appr_roles.append(d[1])
			
			if not has_common(appr_roles, webnotes.user.get_roles()) and not has_common(appr_users, [session['user']]):
				msg, add_msg = '',''
				if max_amount:
					dcc = get_company_currency(self.doc.company)
					if based_on == 'Grand Total': msg = "since Grand Total exceeds %s. %s" % (dcc, flt(max_amount))
					elif based_on == 'Itemwise Discount': msg = "since Discount exceeds %s for Item Code : %s" % (cstr(max_amount)+'%', item)
					elif based_on == 'Average Discount' or based_on == 'Customerwise Discount': msg = "since Discount exceeds %s" % (cstr(max_amount)+'%')
				
				if appr_users: add_msg = "Users : "+cstr(appr_users)
				if appr_roles: add_msg = "Roles : "+cstr(appr_roles)
				if appr_users and appr_roles: add_msg = "Users : "+cstr(appr_users)+" or "+"Roles : "+cstr(appr_roles)
				msgprint("You are not authorize to submit this %s %s. Please send for approval to %s" % (doctype_name, msg, add_msg))
				raise Exception
Esempio n. 8
0
    def check_conversion_rate(self, obj):
        default_currency = get_company_currency(obj.doc.company)
        if not default_currency:
            msgprint(
                'Message: Please enter default currency in Company Master')
            raise Exception
        if (obj.doc.currency == default_currency
                and flt(obj.doc.conversion_rate) != 1.00
            ) or not obj.doc.conversion_rate or (
                obj.doc.currency != default_currency
                and flt(obj.doc.conversion_rate) == 1.00):
            msgprint(
                "Please Enter Appropriate Conversion Rate for Customer's Currency to Base Currency (%s --> %s)"
                % (obj.doc.currency, default_currency),
                raise_exception=1)

        if (obj.doc.price_list_currency == default_currency
                and flt(obj.doc.plc_conversion_rate) != 1.00
            ) or not obj.doc.plc_conversion_rate or (
                obj.doc.price_list_currency != default_currency
                and flt(obj.doc.plc_conversion_rate) == 1.00):
            msgprint(
                "Please Enter Appropriate Conversion Rate for Price List Currency to Base Currency (%s --> %s)"
                % (obj.doc.price_list_currency, default_currency),
                raise_exception=1)
Esempio n. 9
0
	def set_price_list_currency(self, buying_or_selling):
		company_currency = get_company_currency(self.doc.company)
		# TODO - change this, since price list now has only one currency allowed
		if self.meta.get_field("price_list_name") and self.doc.price_list_name and \
			not self.doc.price_list_currency:
				self.doc.fields.update(get_price_list_currency(self.doc.price_list_name))
				
				if self.doc.price_list_currency:
					if not self.doc.plc_conversion_rate:
						if self.doc.price_list_currency == company_currency:
							self.doc.plc_conversion_rate = 1.0
						else:
							exchange = self.doc.price_list_currency + "-" + company_currency
							self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
								exchange, "exchange_rate"))
						
					if not self.doc.currency:
						self.doc.currency = self.doc.price_list_currency
						self.doc.conversion_rate = self.doc.plc_conversion_rate
						
		if self.meta.get_field("currency") and self.doc.currency != company_currency and \
			not self.doc.conversion_rate:
				exchange = self.doc.currency + "-" + company_currency
				self.doc.conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
					exchange, "exchange_rate"))
Esempio n. 10
0
	def check_conversion_rate(self):
		default_currency = get_company_currency(self.doc.company)		
		if not default_currency:
			msgprint('Message: Please enter default currency in Company Master')
			raise Exception
		if (self.doc.currency == default_currency and flt(self.doc.conversion_rate) != 1.00) or not self.doc.conversion_rate or (self.doc.currency != default_currency and flt(self.doc.conversion_rate) == 1.00):
			msgprint("Message: Please Enter Appropriate Conversion Rate.")
			raise Exception				
Esempio n. 11
0
	def check_conversion_rate(self):
		default_currency = get_company_currency(self.doc.company)		
		if not default_currency:
			msgprint('Message: Please enter default currency in Company Master')
			raise Exception
		if (self.doc.currency == default_currency and flt(self.doc.conversion_rate) != 1.00) or not self.doc.conversion_rate or (self.doc.currency != default_currency and flt(self.doc.conversion_rate) == 1.00):
			msgprint("Message: Please Enter Appropriate Conversion Rate.")
			raise Exception				
Esempio n. 12
0
	def set_total_in_words(self):
		from webnotes.utils import money_in_words
		company_currency = get_company_currency(self.doc.company)
		if self.meta.get_field("in_words"):
			self.doc.in_words = money_in_words(self.doc.grand_total, company_currency)
		if self.meta.get_field("in_words_import"):
			self.doc.in_words_import = money_in_words(self.doc.grand_total_import,
		 		self.doc.currency)
Esempio n. 13
0
 def set_total_in_words(self):
     from webnotes.utils import money_in_words
     company_currency = get_company_currency(self.doc.company)
     if self.meta.get_field("in_words"):
         self.doc.in_words = money_in_words(self.doc.grand_total,
                                            company_currency)
     if self.meta.get_field("in_words_import"):
         self.doc.in_words_import = money_in_words(
             self.doc.grand_total_import, self.doc.currency)
Esempio n. 14
0
	def validate(self):		
		if self.meta.get_field("currency"):
			self.company_currency = get_company_currency(self.doc.company)
			self.validate_conversion_rate("currency", "conversion_rate")
			
			if self.doc.price_list_name and self.doc.price_list_currency:
				self.validate_conversion_rate("price_list_currency", "plc_conversion_rate")
				
			# set total in words
			self.set_total_in_words()
Esempio n. 15
0
	def set_total_in_words(self):
		from webnotes.utils import money_in_words
		company_currency = get_company_currency(self.doc.company)
		
		disable_rounded_total = cint(webnotes.conn.get_value("Global Defaults", None, 
			"disable_rounded_total"))
			
		if self.meta.get_field("in_words"):
			self.doc.in_words = money_in_words(disable_rounded_total and 
				self.doc.grand_total or self.doc.rounded_total, company_currency)
		if self.meta.get_field("in_words_export"):
			self.doc.in_words_export = money_in_words(disable_rounded_total and 
				self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
Esempio n. 16
0
	def validate(self):		
		if self.meta.get_field("currency"):
			self.company_currency = get_company_currency(self.doc.company)
			self.validate_conversion_rate("currency", "conversion_rate")
			
			if self.doc.price_list_name and self.doc.price_list_currency:
				self.validate_conversion_rate("price_list_currency", "plc_conversion_rate")
			
			# IMPORTANT: enable this only when client side code is similar to this one
			# self.calculate_taxes_and_totals()
			
			# set total in words
			self.set_total_in_words()
Esempio n. 17
0
	def set_total_in_words(self):
		from webnotes.utils import money_in_words
		company_currency = get_company_currency(self.doc.company)
		
		disable_rounded_total = cint(webnotes.conn.get_value("Global Defaults", None, 
			"disable_rounded_total"))
			
		if self.meta.get_field("in_words"):
			self.doc.in_words = money_in_words(disable_rounded_total and 
				self.doc.grand_total or self.doc.rounded_total, company_currency)
		if self.meta.get_field("in_words_export"):
			self.doc.in_words_export = money_in_words(disable_rounded_total and 
				self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency)
Esempio n. 18
0
	def validate(self):
		from webnotes.utils import money_in_words
		self.check_existing()
		
		if not (len(self.doclist.get({"parentfield": "earning_details"})) or 
			len(self.doclist.get({"parentfield": "deduction_details"}))):
				self.get_emp_and_leave_details()
		else:
			self.get_leave_details(self.doc.leave_without_pay)

		if not self.doc.net_pay:
			self.calculate_net_pay()
			
		company_currency = get_company_currency(self.doc.company)
		self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency)
Esempio n. 19
0
	def set_print_format_fields(self):
		for d in getlist(self.doclist, 'entries'):
			#msgprint(self.doc.company)
			chk_type = sql("select master_type, account_type from `tabAccount` where name='%s'" % d.account)
			master_type, acc_type = chk_type and cstr(chk_type[0][0]) or '', chk_type and cstr(chk_type[0][1]) or ''
			if master_type in ['Supplier', 'Customer']:
				if not self.doc.pay_to_recd_from:
					self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, ' - '.join(d.account.split(' - ')[:-1]), master_type == 'Customer' and 'customer_name' or 'supplier_name')
			
			if acc_type == 'Bank or Cash':
				company_currency = get_company_currency(self.doc.company)
				amt = flt(d.debit) and d.debit or d.credit	
				self.doc.total_amount = company_currency +' '+ cstr(amt)
				from webnotes.utils import money_in_words
				self.doc.total_amount_in_words = money_in_words(amt, company_currency)
Esempio n. 20
0
	def validate(self):
		from webnotes.utils import money_in_words
		self.check_existing()
		
		if not (len(self.doclist.get({"parentfield": "earning_details"})) or 
			len(self.doclist.get({"parentfield": "deduction_details"}))):
				self.get_emp_and_leave_details()
		else:
			self.get_leave_details(self.doc.leave_without_pay)

		if not self.doc.net_pay:
			self.calculate_net_pay()
			
		company_currency = get_company_currency(self.doc.company)
		self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency)
Esempio n. 21
0
	def validate(self):
		super(BuyingController, self).validate()
		self.validate_stock_or_nonstock_items()
		self.validate_warehouse_belongs_to_company()
		if self.meta.get_field("currency"):
			self.company_currency = get_company_currency(self.doc.company)
			self.validate_conversion_rate("currency", "conversion_rate")
			
			if self.doc.price_list_name and self.doc.price_list_currency:
				self.validate_conversion_rate("price_list_currency", "plc_conversion_rate")
			
			# IMPORTANT: enable this only when client side code is similar to this one
			# self.calculate_taxes_and_totals()
						
			# set total in words
			self.set_total_in_words()
Esempio n. 22
0
    def validate(self):
        super(BuyingController, self).validate()
        self.validate_stock_or_nonstock_items()
        self.validate_warehouse_belongs_to_company()
        if self.meta.get_field("currency"):
            self.company_currency = get_company_currency(self.doc.company)
            self.validate_conversion_rate("currency", "conversion_rate")

            if self.doc.price_list_name and self.doc.price_list_currency:
                self.validate_conversion_rate("price_list_currency",
                                              "plc_conversion_rate")

            # IMPORTANT: enable this only when client side code is similar to this one
            # self.calculate_taxes_and_totals()

            # set total in words
            self.set_total_in_words()
Esempio n. 23
0
	def set_print_format_fields(self):
		for d in getlist(self.doclist, 'entries'):
			account_type, master_type = webnotes.conn.get_value("Account", d.account, 
				["account_type", "master_type"])
				
			if master_type in ['Supplier', 'Customer']:
				if not self.doc.pay_to_recd_from:
					self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, 
						' - '.join(d.account.split(' - ')[:-1]), 
						master_type == 'Customer' and 'customer_name' or 'supplier_name')
			
			if account_type == 'Bank or Cash':
				company_currency = get_company_currency(self.doc.company)
				amt = flt(d.debit) and d.debit or d.credit	
				self.doc.total_amount = company_currency + ' ' + cstr(amt)
				from webnotes.utils import money_in_words
				self.doc.total_amount_in_words = money_in_words(amt, company_currency)
Esempio n. 24
0
	def set_print_format_fields(self):
		for d in getlist(self.doclist, 'entries'):
			account_type, master_type = webnotes.conn.get_value("Account", d.account, 
				["account_type", "master_type"])
				
			if master_type in ['Supplier', 'Customer']:
				if not self.doc.pay_to_recd_from:
					self.doc.pay_to_recd_from = webnotes.conn.get_value(master_type, 
						' - '.join(d.account.split(' - ')[:-1]), 
						master_type == 'Customer' and 'customer_name' or 'supplier_name')
			
			if account_type == 'Bank or Cash':
				company_currency = get_company_currency(self.doc.company)
				amt = flt(d.debit) and d.debit or d.credit	
				self.doc.total_amount = company_currency +' '+ cstr(amt)
				from webnotes.utils import money_in_words
				self.doc.total_amount_in_words = money_in_words(amt, company_currency)
Esempio n. 25
0
    def set_print_format_fields(self):
        for d in getlist(self.doclist, 'entries'):
            #msgprint(self.doc.company)
            chk_type = sql(
                "select master_type, account_type from `tabAccount` where name='%s'"
                % d.account)
            master_type, acc_type = chk_type and cstr(
                chk_type[0][0]) or '', chk_type and cstr(chk_type[0][1]) or ''
            if master_type in ['Supplier', 'Customer']:
                if not self.doc.pay_to_recd_from:
                    self.doc.pay_to_recd_from = webnotes.conn.get_value(
                        master_type, ' - '.join(d.account.split(' - ')[:-1]),
                        master_type == 'Customer' and 'customer_name'
                        or 'supplier_name')

            if acc_type == 'Bank or Cash':
                company_currency = get_company_currency(self.doc.company)
                amt = flt(d.debit) and d.debit or d.credit
                self.doc.total_amount = company_currency + ' ' + cstr(amt)
                from webnotes.utils import money_in_words
                self.doc.total_amount_in_words = money_in_words(
                    amt, company_currency)
Esempio n. 26
0
	def calculate_taxes_and_totals(self):
		# validate conversion rate
		if not self.doc.currency:
			self.doc.currency = get_company_currency(self.doc.company)
			self.doc.conversion_rate = 1.0
		else:
			validate_conversion_rate(self.doc.currency, self.doc.conversion_rate,
				self.meta.get_label("conversion_rate"), self.doc.company)
		
		self.doc.conversion_rate = flt(self.doc.conversion_rate)
		self.item_doclist = self.doclist.get({"parentfield": self.fname})
		self.tax_doclist = self.doclist.get({"parentfield": self.other_fname})
		
		self.calculate_item_values()
		self.initialize_taxes()
		
		if hasattr(self, "determine_exclusive_rate"):
			self.determine_exclusive_rate()
		
		self.calculate_net_total()
		self.calculate_taxes()
		self.calculate_totals()
		self._cleanup()
Esempio n. 27
0
	def validate(self):
		from webnotes.utils import money_in_words
		self.check_existing()
		company_currency = get_company_currency(self.doc.company)
		self.doc.total_in_words = money_in_words(self.doc.rounded_total, company_currency)
Esempio n. 28
0
class DocType(DocListController):
    def __init__(self, d, dl):
        self.doc, self.doclist = d, dl

    def validate(self):
        self.validate_value("calculate_based_on", "in",
                            ["Net Total", "Net Weight"])
        self.shipping_rule_conditions = self.doclist.get(
            {"parentfield": "shipping_rule_conditions"})
        self.validate_from_to_values()
        self.sort_shipping_rule_conditions()
        self.validate_overlapping_shipping_rule_conditions()

    def validate_from_to_values(self):
        zero_to_values = []

        for d in self.shipping_rule_conditions:
            self.round_floats_in(d)

            # values cannot be negative
            self.validate_value("from_value", ">=", 0.0, d)
            self.validate_value("to_value", ">=", 0.0, d)

            if d.to_value == 0:
                zero_to_values.append(d)
            elif d.from_value >= d.to_value:
                msgprint(_("Error") + ": " + _("Row") + " # %d: " % d.idx +
                         _("From Value should be less than To Value"),
                         raise_exception=FromGreaterThanToError)

        # check if more than two or more rows has To Value = 0
        if len(zero_to_values) >= 2:
            msgprint(_(
                '''There can only be one Shipping Rule Condition with 0 or blank value for "To Value"'''
            ),
                     raise_exception=ManyBlankToValuesError)

    def sort_shipping_rule_conditions(self):
        """Sort Shipping Rule Conditions based on increasing From Value"""
        self.shipping_rules_conditions = sorted(
            self.shipping_rule_conditions, key=lambda d: flt(d.from_value))
        for i, d in enumerate(self.shipping_rule_conditions):
            d.idx = i + 1

    def validate_overlapping_shipping_rule_conditions(self):
        def overlap_exists_between((x1, x2), (y1, y2)):
            """
				(x1, x2) and (y1, y2) are two ranges
				if condition x = 100 to 300
				then condition y can only be like 50 to 99 or 301 to 400
				hence, non-overlapping condition = (x1 <= x2 < y1 <= y2) or (y1 <= y2 < x1 <= x2)
			"""
            separate = (x1 <= x2 <= y1 <= y2) or (y1 <= y2 <= x1 <= x2)
            return (not separate)

        overlaps = []
        for i in xrange(0, len(self.shipping_rule_conditions)):
            for j in xrange(i + 1, len(self.shipping_rule_conditions)):
                d1, d2 = self.shipping_rule_conditions[
                    i], self.shipping_rule_conditions[j]
                if d1.fields != d2.fields:
                    # in our case, to_value can be zero, hence pass the from_value if so
                    range_a = (d1.from_value, d1.to_value or d1.from_value)
                    range_b = (d2.from_value, d2.to_value or d2.from_value)
                    if overlap_exists_between(range_a, range_b):
                        overlaps.append([d1, d2])

        if overlaps:
            company_currency = get_company_currency(self.doc.company)
            msgprint(
                _("Error") + ": " + _("Overlapping Conditions found between") +
                ":")
            messages = []
            for d1, d2 in overlaps:
                messages.append(
                    "%s-%s = %s " %
                    (d1.from_value, d1.to_value,
                     fmt_money(d1.shipping_amount, currency=company_currency))
                    + _("and") + " %s-%s = %s" %
                    (d2.from_value, d2.to_value,
                     fmt_money(d2.shipping_amount, currency=company_currency)))

            msgprint("\n".join(messages),
                     raise_exception=OverlappingConditionError)
Esempio n. 29
0
 def validate(self):
     from webnotes.utils import money_in_words
     self.check_existing()
     company_currency = get_company_currency(self.doc.company)
     self.doc.total_in_words = money_in_words(self.doc.rounded_total,
                                              company_currency)