Example #1
0
	def update_vat(self, event=None):
		price = self.var_price.get().strip()
		if self.check_price(price):
			price = D(price)
			vat_o = None
			for vatcat in self.vatcats:
				if vatcat.name == self.var_vatcat.get():
					vat_o = vatcat
			if vat_o:
				rate = vat_o.rate
				vat = price * rate / 100
				vat = vat.quantize(D('0.01'))
				self.var_vat.set(vat)
Example #2
0
	def save(self, event=None):
		barcode = unicode(self.var_barcode.get().strip())
		name = unicode(self.var_name.get().strip())
		price = self.var_price.get().strip()
		vat_o = None
		for vatcat in self.vatcats:
			if vatcat.name == unicode(self.var_vatcat.get()):
				vat_o = vatcat
		vat = self.var_vat.get().strip()
		category_o = None
		for category in self.cats:
			if category.name == unicode(self.var_cat.get()):
				category_o = category
		stock = self.var_stock.get()
		stock_warning_level = self.var_stock_warn.get()
		error = ''
		if len(name) < 1:
			error += 'The name cannot be blank.\n'
		if not self.check_price(price):
			error += 'The price contains invalid characters.\n'
		if not vat_o:
			error += 'You must select a VAT category\n'
		if not self.check_price(vat):
			error += 'The VAT contains invalid characters.\n'
		if stock < 0:
			error += 'The stock cannot be negative.\n'
		if stock_warning_level < 0:
			error += 'The stock warning level cannot be negative.\n'
		if error:
			showerror('Starfish Till Manager', error)
		else:
			price = D(price).quantize(D('0.01'))
			vatrate = vat_o.rate
			vat = price * vatrate / 100
			vat = vat.quantize(D('0.01'))
			self.current_product.barcode = barcode
			self.current_product.name = name
			self.current_product.price = D(price)
			self.current_product.vat_o = vat_o
			self.current_product.vat = vat
			if category_o:
				self.current_product.category_o = category_o
			self.current_product.stock = stock
			self.current_product.stock_warning_level = stock_warning_level
			self.current_product.available = 1
			if not self.current_product.id:
				self.store.add(self.current_product)
			self.store.commit()
			self.update_list()
			self.properties(self.current_product.id)