Merge branch 'master' into develop
This commit is contained in:
		
						commit
						2effad33d0
					
				| @ -271,3 +271,4 @@ erpnext.patches.v7_0.update_project_in_gl_entry | |||||||
| execute:frappe.db.sql('update tabQuotation set status="Cancelled" where docstatus=2') | execute:frappe.db.sql('update tabQuotation set status="Cancelled" where docstatus=2') | ||||||
| execute:frappe.rename_doc("DocType", "Payments", "Sales Invoice Payment", force=True) | execute:frappe.rename_doc("DocType", "Payments", "Sales Invoice Payment", force=True) | ||||||
| erpnext.patches.v7_0.update_mins_to_first_response | erpnext.patches.v7_0.update_mins_to_first_response | ||||||
|  | erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory | ||||||
|  | |||||||
| @ -0,0 +1,10 @@ | |||||||
|  | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | ||||||
|  | # License: GNU General Public License v3. See license.txt | ||||||
|  | 
 | ||||||
|  | from __future__ import unicode_literals | ||||||
|  | import frappe | ||||||
|  | from erpnext.stock.stock_balance import repost | ||||||
|  | 
 | ||||||
|  | def execute(): | ||||||
|  | 	if frappe.db.get_value("Stock Settings", None, "allow_negative_stock"): | ||||||
|  | 		repost(only_actual=True) | ||||||
| @ -192,7 +192,8 @@ class PurchaseReceipt(BuyingController): | |||||||
| 					stock_value_diff = frappe.db.get_value("Stock Ledger Entry",  | 					stock_value_diff = frappe.db.get_value("Stock Ledger Entry",  | ||||||
| 						{"voucher_type": "Purchase Receipt", "voucher_no": self.name,  | 						{"voucher_type": "Purchase Receipt", "voucher_no": self.name,  | ||||||
| 						"voucher_detail_no": d.name}, "stock_value_difference") | 						"voucher_detail_no": d.name}, "stock_value_difference") | ||||||
| 
 | 					if not stock_value_diff: | ||||||
|  | 						continue | ||||||
| 					gl_entries.append(self.get_gl_dict({ | 					gl_entries.append(self.get_gl_dict({ | ||||||
| 						"account": warehouse_account[d.warehouse]["name"], | 						"account": warehouse_account[d.warehouse]["name"], | ||||||
| 						"against": stock_rbnb, | 						"against": stock_rbnb, | ||||||
|  | |||||||
| @ -229,27 +229,35 @@ class update_entries_after(object): | |||||||
| 				# calculate new valuation rate only if stock value is positive | 				# calculate new valuation rate only if stock value is positive | ||||||
| 				# else it remains the same as that of previous entry | 				# else it remains the same as that of previous entry | ||||||
| 				self.valuation_rate = new_stock_value / new_stock_qty | 				self.valuation_rate = new_stock_value / new_stock_qty | ||||||
| 
 | 		 | ||||||
| 	def get_moving_average_values(self, sle): | 	def get_moving_average_values(self, sle): | ||||||
| 		actual_qty = flt(sle.actual_qty) | 		actual_qty = flt(sle.actual_qty) | ||||||
|  | 		new_stock_qty = flt(self.qty_after_transaction) + actual_qty | ||||||
|  | 		if new_stock_qty >= 0: | ||||||
|  | 			if actual_qty > 0: | ||||||
|  | 				if flt(self.qty_after_transaction) <= 0: | ||||||
|  | 					self.valuation_rate = sle.incoming_rate | ||||||
|  | 				else: | ||||||
|  | 					new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ | ||||||
|  | 						(actual_qty * sle.incoming_rate) | ||||||
| 
 | 
 | ||||||
| 		if actual_qty > 0 or flt(sle.outgoing_rate) > 0: | 					self.valuation_rate = new_stock_value / new_stock_qty | ||||||
| 			rate = flt(sle.incoming_rate) if actual_qty > 0 else flt(sle.outgoing_rate) |  | ||||||
| 
 | 
 | ||||||
| 			if self.qty_after_transaction < 0 and not self.valuation_rate: | 			elif sle.outgoing_rate: | ||||||
| 				# if negative stock, take current valuation rate as incoming rate | 				if new_stock_qty: | ||||||
| 				self.valuation_rate = rate | 					new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ | ||||||
|  | 						(actual_qty * sle.outgoing_rate) | ||||||
| 
 | 
 | ||||||
| 			new_stock_qty = abs(self.qty_after_transaction) + actual_qty | 					self.valuation_rate = new_stock_value / new_stock_qty | ||||||
| 			new_stock_value = (abs(self.qty_after_transaction) * self.valuation_rate) + (actual_qty * rate) | 				else: | ||||||
|  | 					self.valuation_rate = self.outgoing_rate | ||||||
| 
 | 
 | ||||||
| 			if new_stock_qty: | 		else: | ||||||
| 				self.valuation_rate = new_stock_value / flt(new_stock_qty) | 			if flt(self.qty_after_transaction) >= 0 and sle.outgoing_rate: | ||||||
|  | 				self.valuation_rate = sle.outgoing_rate | ||||||
| 
 | 
 | ||||||
| 		elif not self.valuation_rate and self.qty_after_transaction <= 0: | 			if not self.valuation_rate and actual_qty > 0: | ||||||
| 			self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, self.allow_zero_rate) | 				self.valuation_rate = sle.incoming_rate | ||||||
| 
 |  | ||||||
| 		self.valuation_rate = abs(flt(self.valuation_rate)) |  | ||||||
| 
 | 
 | ||||||
| 	def get_fifo_values(self, sle): | 	def get_fifo_values(self, sle): | ||||||
| 		incoming_rate = flt(sle.incoming_rate) | 		incoming_rate = flt(sle.incoming_rate) | ||||||
| @ -268,10 +276,7 @@ class update_entries_after(object): | |||||||
| 					self.stock_queue.append([actual_qty, incoming_rate]) | 					self.stock_queue.append([actual_qty, incoming_rate]) | ||||||
| 				else: | 				else: | ||||||
| 					qty = self.stock_queue[-1][0] + actual_qty | 					qty = self.stock_queue[-1][0] + actual_qty | ||||||
| 					if qty == 0: | 					self.stock_queue[-1] = [qty, incoming_rate] | ||||||
| 						self.stock_queue.pop(-1) |  | ||||||
| 					else: |  | ||||||
| 						self.stock_queue[-1] = [qty, incoming_rate] |  | ||||||
| 		else: | 		else: | ||||||
| 			qty_to_pop = abs(actual_qty) | 			qty_to_pop = abs(actual_qty) | ||||||
| 			while qty_to_pop: | 			while qty_to_pop: | ||||||
| @ -298,7 +303,7 @@ class update_entries_after(object): | |||||||
| 						break | 						break | ||||||
| 				else: | 				else: | ||||||
| 					index = 0 | 					index = 0 | ||||||
| 
 | 					 | ||||||
| 				# select first batch or the batch with same rate | 				# select first batch or the batch with same rate | ||||||
| 				batch = self.stock_queue[index] | 				batch = self.stock_queue[index] | ||||||
| 				if qty_to_pop >= batch[0]: | 				if qty_to_pop >= batch[0]: | ||||||
| @ -320,7 +325,11 @@ class update_entries_after(object): | |||||||
| 		stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) | 		stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) | ||||||
| 		stock_qty = sum((flt(batch[0]) for batch in self.stock_queue)) | 		stock_qty = sum((flt(batch[0]) for batch in self.stock_queue)) | ||||||
| 
 | 
 | ||||||
| 		self.valuation_rate = (stock_value / flt(stock_qty)) if stock_qty else 0 | 		if stock_qty: | ||||||
|  | 			self.valuation_rate = stock_value / flt(stock_qty) | ||||||
|  | 		 | ||||||
|  | 		if not self.stock_queue: | ||||||
|  | 			self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate]) | ||||||
| 
 | 
 | ||||||
| 	def get_sle_before_datetime(self): | 	def get_sle_before_datetime(self): | ||||||
| 		"""get previous stock ledger entry before current time-bucket""" | 		"""get previous stock ledger entry before current time-bucket""" | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user