fix: rounding adjustment while both inclusive tax and discount amount present
This commit is contained in:
		
							parent
							
								
									6e8a9286c2
								
							
						
					
					
						commit
						f32fc230f7
					
				| @ -312,11 +312,19 @@ class calculate_taxes_and_totals(object): | |||||||
| 			last_tax = self.doc.get("taxes")[-1] | 			last_tax = self.doc.get("taxes")[-1] | ||||||
| 			non_inclusive_tax_amount = sum([flt(d.tax_amount_after_discount_amount) | 			non_inclusive_tax_amount = sum([flt(d.tax_amount_after_discount_amount) | ||||||
| 				for d in self.doc.get("taxes") if not d.included_in_print_rate]) | 				for d in self.doc.get("taxes") if not d.included_in_print_rate]) | ||||||
|  | 
 | ||||||
| 			diff = self.doc.total + non_inclusive_tax_amount \ | 			diff = self.doc.total + non_inclusive_tax_amount \ | ||||||
| 				- flt(last_tax.total, last_tax.precision("total")) | 				- flt(last_tax.total, last_tax.precision("total")) | ||||||
|  | 
 | ||||||
|  | 			# If discount amount applied, deduct the discount amount | ||||||
|  | 			# because self.doc.total is always without discount, but last_tax.total is after discount | ||||||
|  | 			if self.discount_amount_applied and self.doc.discount_amount: | ||||||
|  | 				diff -= flt(self.doc.discount_amount) | ||||||
|  | 
 | ||||||
|  | 			diff = flt(diff, self.doc.precision("rounding_adjustment")) | ||||||
|  | 
 | ||||||
| 			if diff and abs(diff) <= (5.0 / 10**last_tax.precision("tax_amount")): | 			if diff and abs(diff) <= (5.0 / 10**last_tax.precision("tax_amount")): | ||||||
| 				self.doc.rounding_adjustment = flt(flt(self.doc.rounding_adjustment) + | 				self.doc.rounding_adjustment = diff | ||||||
| 					flt(diff), self.doc.precision("rounding_adjustment")) |  | ||||||
| 
 | 
 | ||||||
| 	def calculate_totals(self): | 	def calculate_totals(self): | ||||||
| 		self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(self.doc.rounding_adjustment) \ | 		self.doc.grand_total = flt(self.doc.get("taxes")[-1].total) + flt(self.doc.rounding_adjustment) \ | ||||||
|  | |||||||
| @ -388,9 +388,14 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ | |||||||
| 				var diff = me.frm.doc.total + non_inclusive_tax_amount | 				var diff = me.frm.doc.total + non_inclusive_tax_amount | ||||||
| 					- flt(last_tax.total, precision("grand_total")); | 					- flt(last_tax.total, precision("grand_total")); | ||||||
| 
 | 
 | ||||||
|  | 				if(me.discount_amount_applied && me.frm.doc.discount_amount) { | ||||||
|  | 					diff -= flt(me.frm.doc.discount_amount); | ||||||
|  | 				} | ||||||
|  | 
 | ||||||
|  | 				diff = flt(diff, precision("rounding_adjustment")); | ||||||
|  | 
 | ||||||
| 				if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) { | 				if ( diff && Math.abs(diff) <= (5.0 / Math.pow(10, precision("tax_amount", last_tax))) ) { | ||||||
| 					this.frm.doc.rounding_adjustment = flt(flt(this.frm.doc.rounding_adjustment) + diff, | 					me.frm.doc.rounding_adjustment = diff; | ||||||
| 						precision("rounding_adjustment")); |  | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user