Exemplo n.º 1
0
	def initialize_taxes(self):
		for tax in self.tax_doclist:
			# initialize totals to 0
			tax.tax_amount = tax.total = tax.total_print = 0
			tax.grand_total_for_current_item = tax.tax_amount_for_current_item = 0
			
			# for actual type, user can mention actual tax amount in tax.tax_amount_print
			if tax.charge_type != "Actual" or tax.rate:
				tax.tax_amount_print = 0
			
			self.validate_on_previous_row(tax)
			self.validate_included_tax(tax)
			
			# round relevant values
			round_doc(tax, self.precision.tax)
Exemplo n.º 2
0
	def calculate_item_values(self):
		def _set_base(item, print_field, base_field):
			"""set values in base currency"""
			item.fields[base_field] = flt((flt(item.fields[print_field],
				self.precision.item[print_field]) * \
				self.doc.fields.get(self.fmap.exchange_rate)),
				self.precision.item[base_field])
		
		for item in self.item_doclist:
			round_doc(item, self.precision.item)
			
			if item.fields.get(self.fmap.discount) == 100:
				if not item.fields.get(self.fmap.print_ref_rate):
					item.fields[self.fmap.print_ref_rate] = \
						item.fields.get(self.fmap.print_rate)
				item.fields[self.fmap.print_rate] = 0
			else:
				if item.fields.get(self.fmap.print_ref_rate):
					item.fields[self.fmap.print_rate] = \
						flt(item.fields.get(self.fmap.print_ref_rate) *
						(1.0 - (item.fields.get(self.fmap.discount) / 100.0)),
						self.precision.item[self.fmap.print_rate])
				else:
					# assume that print rate and discount are specified
					item.fields[self.fmap.print_ref_rate] = \
						flt(item.fields.get(self.fmap.print_rate) / 
						(1.0 - (item.fields.get(self.fmap.discount) / 100.0)),
						self.precision.item[self.fmap.print_ref_rate])
						
			item.fields[self.fmap.print_amount] = \
				flt(item.fields.get(self.fmap.print_rate) * \
				item.fields.get("qty"),
				self.precision.item[self.fmap.print_amount])
				
			_set_base(item, self.fmap.print_ref_rate, self.fmap.ref_rate)
			_set_base(item, self.fmap.print_rate, self.fmap.rate)
			_set_base(item, self.fmap.print_amount, "amount")