Valuation related charges should only go to stock items
This commit is contained in:
		
							parent
							
								
									424b4a4b36
								
							
						
					
					
						commit
						a1ffacaf0b
					
				| @ -231,9 +231,6 @@ class AccountsController(TransactionBase): | |||||||
| 				# tax_amount represents the amount of tax for the current step | 				# tax_amount represents the amount of tax for the current step | ||||||
| 				current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map) | 				current_tax_amount = self.get_current_tax_amount(item, tax, item_tax_map) | ||||||
| 				 | 				 | ||||||
| 				if hasattr(self, "set_item_tax_amount"): |  | ||||||
| 					self.set_item_tax_amount(item, tax, current_tax_amount) |  | ||||||
| 
 |  | ||||||
| 				# case when net total is 0 but there is an actual type charge | 				# case when net total is 0 but there is an actual type charge | ||||||
| 				# in this case add the actual amount to tax.tax_amount | 				# in this case add the actual amount to tax.tax_amount | ||||||
| 				# and tax.grand_total_for_current_item for the first such iteration | 				# and tax.grand_total_for_current_item for the first such iteration | ||||||
|  | |||||||
| @ -163,30 +163,36 @@ class BuyingController(StockController): | |||||||
| 		if not self.meta.get_field("item_tax_amount", parentfield=self.fname): | 		if not self.meta.get_field("item_tax_amount", parentfield=self.fname): | ||||||
| 			for item in self.item_doclist: | 			for item in self.item_doclist: | ||||||
| 				del item.fields["item_tax_amount"] | 				del item.fields["item_tax_amount"] | ||||||
| 				 | 							 | ||||||
| 	def set_item_tax_amount(self, item, tax, current_tax_amount): | 	# update valuation rate | ||||||
|  | 	def update_valuation_rate(self, parentfield): | ||||||
| 		""" | 		""" | ||||||
| 			item_tax_amount is the total tax amount applied on that item | 			item_tax_amount is the total tax amount applied on that item | ||||||
| 			stored for valuation  | 			stored for valuation  | ||||||
| 			 | 			 | ||||||
| 			TODO: rename item_tax_amount to valuation_tax_amount | 			TODO: rename item_tax_amount to valuation_tax_amount | ||||||
| 		""" | 		""" | ||||||
| 		if tax.category in ["Valuation", "Valuation and Total"] and \ | 		stock_items = self.get_stock_items() | ||||||
| 			self.meta.get_field("item_tax_amount", parentfield=self.fname): | 		 | ||||||
| 				item.item_tax_amount += flt(current_tax_amount, self.precision("item_tax_amount", item)) | 		stock_items_amount = sum([flt(d.amount) for d in  | ||||||
| 				 | 			self.doclist.get({"parentfield": parentfield})  | ||||||
| 	# update valuation rate | 			if d.item_code and d.item_code in stock_items]) | ||||||
| 	def update_valuation_rate(self, parentfield): |  | ||||||
| 		for item in self.doclist.get({"parentfield": parentfield}): |  | ||||||
| 			item.conversion_factor = item.conversion_factor or flt(webnotes.conn.get_value( |  | ||||||
| 				"UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom},  |  | ||||||
| 				"conversion_factor")) or 1 |  | ||||||
| 			 | 			 | ||||||
| 			if item.item_code and item.qty: | 		total_valuation_amount = sum([flt(d.tax_amount) for d in  | ||||||
|  | 			self.doclist.get({"parentfield": "purchase_tax_details"})  | ||||||
|  | 			if d.category in ["Valuation", "Valuation and Total"]]) | ||||||
|  | 			 | ||||||
|  | 			 | ||||||
|  | 		for item in self.doclist.get({"parentfield": parentfield}): | ||||||
|  | 			if item.item_code and item.qty and item.item_code in stock_items: | ||||||
|  | 				item.item_tax_amount = flt(flt(item.amount) * total_valuation_amount \ | ||||||
|  | 					/ stock_items_amount, self.precision("item_tax_amount", item)) | ||||||
|  | 
 | ||||||
| 				self.round_floats_in(item) | 				self.round_floats_in(item) | ||||||
| 								 | 				 | ||||||
| 				# if no item code, which is sometimes the case in purchase invoice,  | 				item.conversion_factor = item.conversion_factor or flt(webnotes.conn.get_value( | ||||||
| 				# then it is not possible to track valuation against it | 					"UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom},  | ||||||
|  | 					"conversion_factor")) or 1 | ||||||
| 				qty_in_stock_uom = flt(item.qty * item.conversion_factor) | 				qty_in_stock_uom = flt(item.qty * item.conversion_factor) | ||||||
| 				item.valuation_rate = ((item.amount + item.item_tax_amount + item.rm_supp_cost) | 				item.valuation_rate = ((item.amount + item.item_tax_amount + item.rm_supp_cost) | ||||||
| 					/ qty_in_stock_uom) | 					/ qty_in_stock_uom) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user