Anand Doshi | 885e074 | 2015-03-03 14:55:30 +0530 | [diff] [blame] | 1 | # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | # License: GNU General Public License v3. See license.txt |
Anand Doshi | 56a3165 | 2013-11-29 19:15:26 +0530 | [diff] [blame] | 3 | from __future__ import unicode_literals |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 4 | |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 5 | import frappe, erpnext |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 6 | from frappe import _ |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 7 | from frappe.utils import cint, flt, cstr, now |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 8 | from erpnext.stock.utils import get_valuation_method |
Nabin Hait | 26d4655 | 2013-01-09 15:23:05 +0530 | [diff] [blame] | 9 | import json |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 10 | |
Achilles Rasquinha | 361366e | 2018-02-14 17:08:59 +0530 | [diff] [blame] | 11 | from six import iteritems |
| 12 | |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 13 | # future reposting |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 14 | class NegativeStockError(frappe.ValidationError): pass |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 15 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 16 | _exceptions = frappe.local('stockledger_exceptions') |
Pratik Vyas | 16371b7 | 2013-09-18 18:31:03 +0530 | [diff] [blame] | 17 | # _exceptions = [] |
Anand Doshi | 5b004ff | 2013-09-25 19:55:41 +0530 | [diff] [blame] | 18 | |
Nabin Hait | 54c865e | 2015-03-27 15:38:31 +0530 | [diff] [blame] | 19 | def make_sl_entries(sl_entries, is_amended=None, allow_negative_stock=False, via_landed_cost_voucher=False): |
Nabin Hait | ca77574 | 2013-09-26 16:16:44 +0530 | [diff] [blame] | 20 | if sl_entries: |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 21 | from erpnext.stock.utils import update_bin |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 22 | |
Nabin Hait | ca77574 | 2013-09-26 16:16:44 +0530 | [diff] [blame] | 23 | cancel = True if sl_entries[0].get("is_cancelled") == "Yes" else False |
| 24 | if cancel: |
| 25 | set_as_cancel(sl_entries[0].get('voucher_no'), sl_entries[0].get('voucher_type')) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 26 | |
Nabin Hait | ca77574 | 2013-09-26 16:16:44 +0530 | [diff] [blame] | 27 | for sle in sl_entries: |
| 28 | sle_id = None |
| 29 | if sle.get('is_cancelled') == 'Yes': |
| 30 | sle['actual_qty'] = -flt(sle['actual_qty']) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 31 | |
Nabin Hait | 5288bde | 2014-11-03 15:08:21 +0530 | [diff] [blame] | 32 | if sle.get("actual_qty") or sle.get("voucher_type")=="Stock Reconciliation": |
Nabin Hait | 54c865e | 2015-03-27 15:38:31 +0530 | [diff] [blame] | 33 | sle_id = make_entry(sle, allow_negative_stock, via_landed_cost_voucher) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 34 | |
Nabin Hait | ca77574 | 2013-09-26 16:16:44 +0530 | [diff] [blame] | 35 | args = sle.copy() |
| 36 | args.update({ |
| 37 | "sle_id": sle_id, |
| 38 | "is_amended": is_amended |
| 39 | }) |
Nabin Hait | 54c865e | 2015-03-27 15:38:31 +0530 | [diff] [blame] | 40 | update_bin(args, allow_negative_stock, via_landed_cost_voucher) |
Nabin Hait | adeb976 | 2014-10-06 11:53:52 +0530 | [diff] [blame] | 41 | |
Nabin Hait | ca77574 | 2013-09-26 16:16:44 +0530 | [diff] [blame] | 42 | if cancel: |
Nabin Hait | adeb976 | 2014-10-06 11:53:52 +0530 | [diff] [blame] | 43 | delete_cancelled_entry(sl_entries[0].get('voucher_type'), sl_entries[0].get('voucher_no')) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 44 | |
Nabin Hait | 9653f60 | 2013-08-20 15:37:33 +0530 | [diff] [blame] | 45 | def set_as_cancel(voucher_type, voucher_no): |
Anand Doshi | e9baaa6 | 2014-02-26 12:35:33 +0530 | [diff] [blame] | 46 | frappe.db.sql("""update `tabStock Ledger Entry` set is_cancelled='Yes', |
Nabin Hait | 9653f60 | 2013-08-20 15:37:33 +0530 | [diff] [blame] | 47 | modified=%s, modified_by=%s |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 48 | where voucher_no=%s and voucher_type=%s""", |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 49 | (now(), frappe.session.user, voucher_type, voucher_no)) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 50 | |
Nabin Hait | 54c865e | 2015-03-27 15:38:31 +0530 | [diff] [blame] | 51 | def make_entry(args, allow_negative_stock=False, via_landed_cost_voucher=False): |
Nabin Hait | 74c281c | 2013-08-19 16:17:18 +0530 | [diff] [blame] | 52 | args.update({"doctype": "Stock Ledger Entry"}) |
Rushabh Mehta | a504f06 | 2014-04-04 12:16:26 +0530 | [diff] [blame] | 53 | sle = frappe.get_doc(args) |
Anand Doshi | 6dfd430 | 2015-02-10 14:41:27 +0530 | [diff] [blame] | 54 | sle.flags.ignore_permissions = 1 |
Nabin Hait | 4ccd8d3 | 2015-01-23 12:18:01 +0530 | [diff] [blame] | 55 | sle.allow_negative_stock=allow_negative_stock |
Nabin Hait | 54c865e | 2015-03-27 15:38:31 +0530 | [diff] [blame] | 56 | sle.via_landed_cost_voucher = via_landed_cost_voucher |
Nabin Hait | 74c281c | 2013-08-19 16:17:18 +0530 | [diff] [blame] | 57 | sle.insert() |
Nabin Hait | aeba24e | 2013-08-23 15:17:36 +0530 | [diff] [blame] | 58 | sle.submit() |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 59 | return sle.name |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 60 | |
Nabin Hait | 9653f60 | 2013-08-20 15:37:33 +0530 | [diff] [blame] | 61 | def delete_cancelled_entry(voucher_type, voucher_no): |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 62 | frappe.db.sql("""delete from `tabStock Ledger Entry` |
Nabin Hait | 9653f60 | 2013-08-20 15:37:33 +0530 | [diff] [blame] | 63 | where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no)) |
Nabin Hait | 74c281c | 2013-08-19 16:17:18 +0530 | [diff] [blame] | 64 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 65 | class update_entries_after(object): |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 66 | """ |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 67 | update valution rate and qty after transaction |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 68 | from the current time-bucket onwards |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 69 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 70 | :param args: args as dict |
| 71 | |
| 72 | args = { |
| 73 | "item_code": "ABC", |
| 74 | "warehouse": "XYZ", |
| 75 | "posting_date": "2012-12-12", |
| 76 | "posting_time": "12:00" |
| 77 | } |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 78 | """ |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 79 | def __init__(self, args, allow_zero_rate=False, allow_negative_stock=None, via_landed_cost_voucher=False, verbose=1): |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 80 | from frappe.model.meta import get_field_precision |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 81 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 82 | self.exceptions = [] |
| 83 | self.verbose = verbose |
| 84 | self.allow_zero_rate = allow_zero_rate |
| 85 | self.allow_negative_stock = allow_negative_stock |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 86 | self.via_landed_cost_voucher = via_landed_cost_voucher |
Nabin Hait | 43ba7e1 | 2015-03-03 14:07:07 +0530 | [diff] [blame] | 87 | if not self.allow_negative_stock: |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 88 | self.allow_negative_stock = cint(frappe.db.get_single_value("Stock Settings", |
| 89 | "allow_negative_stock")) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 90 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 91 | self.args = args |
Achilles Rasquinha | 361366e | 2018-02-14 17:08:59 +0530 | [diff] [blame] | 92 | for key, value in iteritems(args): |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 93 | setattr(self, key, value) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 94 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 95 | self.previous_sle = self.get_sle_before_datetime() |
| 96 | self.previous_sle = self.previous_sle[0] if self.previous_sle else frappe._dict() |
Nabin Hait | bb77756 | 2013-08-29 18:19:37 +0530 | [diff] [blame] | 97 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 98 | for key in ("qty_after_transaction", "valuation_rate", "stock_value"): |
| 99 | setattr(self, key, flt(self.previous_sle.get(key))) |
| 100 | |
| 101 | self.company = frappe.db.get_value("Warehouse", self.warehouse, "company") |
| 102 | self.precision = get_field_precision(frappe.get_meta("Stock Ledger Entry").get_field("stock_value"), |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 103 | currency=frappe.get_cached_value('Company', self.company, "default_currency")) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 104 | |
Rushabh Mehta | c7a11cc | 2015-02-19 16:28:35 +0530 | [diff] [blame] | 105 | self.prev_stock_value = self.previous_sle.stock_value or 0.0 |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 106 | self.stock_queue = json.loads(self.previous_sle.stock_queue or "[]") |
| 107 | self.valuation_method = get_valuation_method(self.item_code) |
| 108 | self.stock_value_difference = 0.0 |
| 109 | self.build() |
| 110 | |
| 111 | def build(self): |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 112 | # includes current entry! |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 113 | entries_to_fix = self.get_sle_after_datetime() |
Rushabh Mehta | 14a908b | 2015-10-15 12:28:20 +0530 | [diff] [blame] | 114 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 115 | for sle in entries_to_fix: |
| 116 | self.process_sle(sle) |
| 117 | |
| 118 | if self.exceptions: |
| 119 | self.raise_exceptions() |
| 120 | |
| 121 | self.update_bin() |
| 122 | |
| 123 | def update_bin(self): |
| 124 | # update bin |
| 125 | bin_name = frappe.db.get_value("Bin", { |
| 126 | "item_code": self.item_code, |
| 127 | "warehouse": self.warehouse |
| 128 | }) |
| 129 | |
| 130 | if not bin_name: |
| 131 | bin_doc = frappe.get_doc({ |
| 132 | "doctype": "Bin", |
| 133 | "item_code": self.item_code, |
| 134 | "warehouse": self.warehouse |
| 135 | }) |
| 136 | bin_doc.insert(ignore_permissions=True) |
| 137 | else: |
| 138 | bin_doc = frappe.get_doc("Bin", bin_name) |
| 139 | |
| 140 | bin_doc.update({ |
| 141 | "valuation_rate": self.valuation_rate, |
| 142 | "actual_qty": self.qty_after_transaction, |
| 143 | "stock_value": self.stock_value |
| 144 | }) |
Saurabh | b166bcf | 2015-12-28 13:25:35 +0530 | [diff] [blame] | 145 | bin_doc.flags.via_stock_ledger_entry = True |
Rushabh Mehta | 538607e | 2016-06-12 11:03:00 +0530 | [diff] [blame] | 146 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 147 | bin_doc.save(ignore_permissions=True) |
| 148 | |
| 149 | def process_sle(self, sle): |
Anand Doshi | 0dc79f4 | 2015-04-06 12:59:34 +0530 | [diff] [blame] | 150 | if (sle.serial_no and not self.via_landed_cost_voucher) or not cint(self.allow_negative_stock): |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 151 | # validate negative stock for serialized items, fifo valuation |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 152 | # or when negative stock is not allowed for moving average |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 153 | if not self.validate_negative_stock(sle): |
| 154 | self.qty_after_transaction += flt(sle.actual_qty) |
| 155 | return |
Nabin Hait | b96c014 | 2014-10-07 11:25:04 +0530 | [diff] [blame] | 156 | |
Anand Doshi | 1b53186 | 2013-01-10 19:29:51 +0530 | [diff] [blame] | 157 | if sle.serial_no: |
Rushabh Mehta | 2a21bc9 | 2015-02-25 15:08:42 +0530 | [diff] [blame] | 158 | self.get_serialized_values(sle) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 159 | self.qty_after_transaction += flt(sle.actual_qty) |
Rushabh Mehta | 8bb6e53 | 2015-02-18 20:22:59 +0530 | [diff] [blame] | 160 | self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) |
Nabin Hait | b96c014 | 2014-10-07 11:25:04 +0530 | [diff] [blame] | 161 | else: |
| 162 | if sle.voucher_type=="Stock Reconciliation": |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 163 | # assert |
| 164 | self.valuation_rate = sle.valuation_rate |
| 165 | self.qty_after_transaction = sle.qty_after_transaction |
| 166 | self.stock_queue = [[self.qty_after_transaction, self.valuation_rate]] |
Rushabh Mehta | 8bb6e53 | 2015-02-18 20:22:59 +0530 | [diff] [blame] | 167 | self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) |
Nabin Hait | b96c014 | 2014-10-07 11:25:04 +0530 | [diff] [blame] | 168 | else: |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 169 | if self.valuation_method == "Moving Average": |
| 170 | self.get_moving_average_values(sle) |
| 171 | self.qty_after_transaction += flt(sle.actual_qty) |
Rushabh Mehta | 8bb6e53 | 2015-02-18 20:22:59 +0530 | [diff] [blame] | 172 | self.stock_value = flt(self.qty_after_transaction) * flt(self.valuation_rate) |
Nabin Hait | b96c014 | 2014-10-07 11:25:04 +0530 | [diff] [blame] | 173 | else: |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 174 | self.get_fifo_values(sle) |
| 175 | self.qty_after_transaction += flt(sle.actual_qty) |
| 176 | self.stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) |
Nabin Hait | b96c014 | 2014-10-07 11:25:04 +0530 | [diff] [blame] | 177 | |
Rushabh Mehta | 5404778 | 2013-12-26 11:07:46 +0530 | [diff] [blame] | 178 | # rounding as per precision |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 179 | self.stock_value = flt(self.stock_value, self.precision) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 180 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 181 | stock_value_difference = self.stock_value - self.prev_stock_value |
| 182 | self.prev_stock_value = self.stock_value |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 183 | |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 184 | # update current sle |
Rushabh Mehta | 2e0e711 | 2015-02-18 11:38:05 +0530 | [diff] [blame] | 185 | sle.qty_after_transaction = self.qty_after_transaction |
| 186 | sle.valuation_rate = self.valuation_rate |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 187 | sle.stock_value = self.stock_value |
Rushabh Mehta | 2e0e711 | 2015-02-18 11:38:05 +0530 | [diff] [blame] | 188 | sle.stock_queue = json.dumps(self.stock_queue) |
| 189 | sle.stock_value_difference = stock_value_difference |
Rushabh Mehta | 8bb6e53 | 2015-02-18 20:22:59 +0530 | [diff] [blame] | 190 | sle.doctype="Stock Ledger Entry" |
| 191 | frappe.get_doc(sle).db_update() |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 192 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 193 | def validate_negative_stock(self, sle): |
| 194 | """ |
| 195 | validate negative stock for entries current datetime onwards |
| 196 | will not consider cancelled entries |
| 197 | """ |
| 198 | diff = self.qty_after_transaction + flt(sle.actual_qty) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 199 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 200 | if diff < 0 and abs(diff) > 0.0001: |
| 201 | # negative stock! |
| 202 | exc = sle.copy().update({"diff": diff}) |
| 203 | self.exceptions.append(exc) |
| 204 | return False |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 205 | else: |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 206 | return True |
| 207 | |
| 208 | def get_serialized_values(self, sle): |
| 209 | incoming_rate = flt(sle.incoming_rate) |
| 210 | actual_qty = flt(sle.actual_qty) |
| 211 | serial_no = cstr(sle.serial_no).split("\n") |
| 212 | |
| 213 | if incoming_rate < 0: |
| 214 | # wrong incoming rate |
| 215 | incoming_rate = self.valuation_rate |
Rushabh Mehta | 538607e | 2016-06-12 11:03:00 +0530 | [diff] [blame] | 216 | |
Nabin Hait | 2620bf4 | 2016-02-29 11:30:27 +0530 | [diff] [blame] | 217 | stock_value_change = 0 |
| 218 | if incoming_rate: |
| 219 | stock_value_change = actual_qty * incoming_rate |
| 220 | elif actual_qty < 0: |
| 221 | # In case of delivery/stock issue, get average purchase rate |
| 222 | # of serial nos of current entry |
| 223 | stock_value_change = -1 * flt(frappe.db.sql("""select sum(purchase_rate) |
| 224 | from `tabSerial No` where name in (%s)""" % (", ".join(["%s"]*len(serial_no))), |
| 225 | tuple(serial_no))[0][0]) |
Rushabh Mehta | 2a21bc9 | 2015-02-25 15:08:42 +0530 | [diff] [blame] | 226 | |
Nabin Hait | 2620bf4 | 2016-02-29 11:30:27 +0530 | [diff] [blame] | 227 | new_stock_qty = self.qty_after_transaction + actual_qty |
rohitwaghchaure | 0fe6ced | 2018-07-27 10:33:30 +0530 | [diff] [blame] | 228 | |
Nabin Hait | 2620bf4 | 2016-02-29 11:30:27 +0530 | [diff] [blame] | 229 | if new_stock_qty > 0: |
| 230 | new_stock_value = (self.qty_after_transaction * self.valuation_rate) + stock_value_change |
rohitwaghchaure | 0fe6ced | 2018-07-27 10:33:30 +0530 | [diff] [blame] | 231 | if new_stock_value >= 0: |
Nabin Hait | 2620bf4 | 2016-02-29 11:30:27 +0530 | [diff] [blame] | 232 | # calculate new valuation rate only if stock value is positive |
| 233 | # else it remains the same as that of previous entry |
| 234 | self.valuation_rate = new_stock_value / new_stock_qty |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 235 | |
rohitwaghchaure | b1ac979 | 2017-12-01 16:09:02 +0530 | [diff] [blame] | 236 | if not self.valuation_rate and sle.voucher_detail_no: |
| 237 | allow_zero_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) |
| 238 | if not allow_zero_rate: |
| 239 | self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, |
| 240 | sle.voucher_type, sle.voucher_no, self.allow_zero_rate, |
| 241 | currency=erpnext.get_company_currency(sle.company)) |
| 242 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 243 | def get_moving_average_values(self, sle): |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 244 | actual_qty = flt(sle.actual_qty) |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 245 | new_stock_qty = flt(self.qty_after_transaction) + actual_qty |
| 246 | if new_stock_qty >= 0: |
| 247 | if actual_qty > 0: |
| 248 | if flt(self.qty_after_transaction) <= 0: |
| 249 | self.valuation_rate = sle.incoming_rate |
| 250 | else: |
| 251 | new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ |
| 252 | (actual_qty * sle.incoming_rate) |
Rushabh Mehta | 14a908b | 2015-10-15 12:28:20 +0530 | [diff] [blame] | 253 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 254 | self.valuation_rate = new_stock_value / new_stock_qty |
Rushabh Mehta | 14a908b | 2015-10-15 12:28:20 +0530 | [diff] [blame] | 255 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 256 | elif sle.outgoing_rate: |
| 257 | if new_stock_qty: |
| 258 | new_stock_value = (self.qty_after_transaction * self.valuation_rate) + \ |
| 259 | (actual_qty * sle.outgoing_rate) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 260 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 261 | self.valuation_rate = new_stock_value / new_stock_qty |
| 262 | else: |
Nabin Hait | 7590b8f | 2016-07-27 16:44:17 +0530 | [diff] [blame] | 263 | self.valuation_rate = sle.outgoing_rate |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 264 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 265 | else: |
| 266 | if flt(self.qty_after_transaction) >= 0 and sle.outgoing_rate: |
| 267 | self.valuation_rate = sle.outgoing_rate |
Rushabh Mehta | 14a908b | 2015-10-15 12:28:20 +0530 | [diff] [blame] | 268 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 269 | if not self.valuation_rate and actual_qty > 0: |
| 270 | self.valuation_rate = sle.incoming_rate |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 271 | |
Rushabh Mehta | aedaac6 | 2017-05-04 09:35:19 +0530 | [diff] [blame] | 272 | # Get valuation rate from previous SLE or Item master, if item does not have the |
Javier Wong | 9b11d9b | 2017-04-14 18:24:04 +0800 | [diff] [blame] | 273 | # allow zero valuration rate flag set |
Nabin Hait | ea8fab5 | 2017-02-06 17:13:39 +0530 | [diff] [blame] | 274 | if not self.valuation_rate and sle.voucher_detail_no: |
Javier Wong | 9b11d9b | 2017-04-14 18:24:04 +0800 | [diff] [blame] | 275 | allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) |
| 276 | if not allow_zero_valuation_rate: |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 277 | self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, |
| 278 | sle.voucher_type, sle.voucher_no, self.allow_zero_rate, |
| 279 | currency=erpnext.get_company_currency(sle.company)) |
| 280 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 281 | def get_fifo_values(self, sle): |
| 282 | incoming_rate = flt(sle.incoming_rate) |
| 283 | actual_qty = flt(sle.actual_qty) |
Nabin Hait | ada485f | 2015-07-17 15:09:56 +0530 | [diff] [blame] | 284 | outgoing_rate = flt(sle.outgoing_rate) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 285 | |
| 286 | if actual_qty > 0: |
| 287 | if not self.stock_queue: |
| 288 | self.stock_queue.append([0, 0]) |
| 289 | |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 290 | # last row has the same rate, just updated the qty |
| 291 | if self.stock_queue[-1][1]==incoming_rate: |
| 292 | self.stock_queue[-1][0] += actual_qty |
Nabin Hait | 4d74216 | 2014-10-09 19:25:03 +0530 | [diff] [blame] | 293 | else: |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 294 | if self.stock_queue[-1][0] > 0: |
| 295 | self.stock_queue.append([actual_qty, incoming_rate]) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 296 | else: |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 297 | qty = self.stock_queue[-1][0] + actual_qty |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 298 | self.stock_queue[-1] = [qty, incoming_rate] |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 299 | else: |
| 300 | qty_to_pop = abs(actual_qty) |
| 301 | while qty_to_pop: |
| 302 | if not self.stock_queue: |
Nabin Hait | a0b967f | 2017-01-18 18:35:58 +0530 | [diff] [blame] | 303 | # Get valuation rate from last sle if exists or from valuation rate field in item master |
Javier Wong | 9b11d9b | 2017-04-14 18:24:04 +0800 | [diff] [blame] | 304 | allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) |
| 305 | if not allow_zero_valuation_rate: |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 306 | _rate = get_valuation_rate(sle.item_code, sle.warehouse, |
| 307 | sle.voucher_type, sle.voucher_no, self.allow_zero_rate, |
| 308 | currency=erpnext.get_company_currency(sle.company)) |
Nabin Hait | 0a6aaf4 | 2017-02-07 01:23:26 +0530 | [diff] [blame] | 309 | else: |
| 310 | _rate = 0 |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 311 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 312 | self.stock_queue.append([0, _rate]) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 313 | |
Nabin Hait | ada485f | 2015-07-17 15:09:56 +0530 | [diff] [blame] | 314 | index = None |
| 315 | if outgoing_rate > 0: |
| 316 | # Find the entry where rate matched with outgoing rate |
| 317 | for i, v in enumerate(self.stock_queue): |
| 318 | if v[1] == outgoing_rate: |
| 319 | index = i |
| 320 | break |
Rushabh Mehta | 14a908b | 2015-10-15 12:28:20 +0530 | [diff] [blame] | 321 | |
Nabin Hait | ada485f | 2015-07-17 15:09:56 +0530 | [diff] [blame] | 322 | # If no entry found with outgoing rate, collapse stack |
| 323 | if index == None: |
| 324 | new_stock_value = sum((d[0]*d[1] for d in self.stock_queue)) - qty_to_pop*outgoing_rate |
| 325 | new_stock_qty = sum((d[0] for d in self.stock_queue)) - qty_to_pop |
| 326 | self.stock_queue = [[new_stock_qty, new_stock_value/new_stock_qty if new_stock_qty > 0 else outgoing_rate]] |
| 327 | break |
| 328 | else: |
| 329 | index = 0 |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 330 | |
Nabin Hait | ada485f | 2015-07-17 15:09:56 +0530 | [diff] [blame] | 331 | # select first batch or the batch with same rate |
| 332 | batch = self.stock_queue[index] |
Nabin Hait | 8142cd2 | 2015-08-05 18:57:26 +0530 | [diff] [blame] | 333 | if qty_to_pop >= batch[0]: |
| 334 | # consume current batch |
| 335 | qty_to_pop = qty_to_pop - batch[0] |
| 336 | self.stock_queue.pop(index) |
| 337 | if not self.stock_queue and qty_to_pop: |
| 338 | # stock finished, qty still remains to be withdrawn |
| 339 | # negative stock, keep in as a negative batch |
| 340 | self.stock_queue.append([-qty_to_pop, outgoing_rate or batch[1]]) |
| 341 | break |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 342 | |
Nabin Hait | 8142cd2 | 2015-08-05 18:57:26 +0530 | [diff] [blame] | 343 | else: |
| 344 | # qty found in current batch |
| 345 | # consume it and exit |
| 346 | batch[0] = batch[0] - qty_to_pop |
| 347 | qty_to_pop = 0 |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 348 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 349 | stock_value = sum((flt(batch[0]) * flt(batch[1]) for batch in self.stock_queue)) |
| 350 | stock_qty = sum((flt(batch[0]) for batch in self.stock_queue)) |
Nabin Hait | 902e860 | 2013-01-08 18:29:24 +0530 | [diff] [blame] | 351 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 352 | if stock_qty: |
| 353 | self.valuation_rate = stock_value / flt(stock_qty) |
Rushabh Mehta | cca33b2 | 2016-07-08 18:24:46 +0530 | [diff] [blame] | 354 | |
Nabin Hait | 6dfc78b | 2016-06-24 12:28:55 +0530 | [diff] [blame] | 355 | if not self.stock_queue: |
| 356 | self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate]) |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 357 | |
Javier Wong | 9b11d9b | 2017-04-14 18:24:04 +0800 | [diff] [blame] | 358 | def check_if_allow_zero_valuation_rate(self, voucher_type, voucher_detail_no): |
Nabin Hait | 0a6aaf4 | 2017-02-07 01:23:26 +0530 | [diff] [blame] | 359 | ref_item_dt = voucher_type + (" Detail" if voucher_type == "Stock Entry" else " Item") |
Javier Wong | 9b11d9b | 2017-04-14 18:24:04 +0800 | [diff] [blame] | 360 | return frappe.db.get_value(ref_item_dt, voucher_detail_no, "allow_zero_valuation_rate") |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 361 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 362 | def get_sle_before_datetime(self): |
| 363 | """get previous stock ledger entry before current time-bucket""" |
| 364 | return get_stock_ledger_entries(self.args, "<", "desc", "limit 1", for_update=False) |
Nabin Hait | 4d74216 | 2014-10-09 19:25:03 +0530 | [diff] [blame] | 365 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 366 | def get_sle_after_datetime(self): |
| 367 | """get Stock Ledger Entries after a particular datetime, for reposting""" |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 368 | return get_stock_ledger_entries(self.previous_sle or frappe._dict({ |
| 369 | "item_code": self.args.get("item_code"), "warehouse": self.args.get("warehouse") }), |
| 370 | ">", "asc", for_update=True) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 371 | |
| 372 | def raise_exceptions(self): |
| 373 | deficiency = min(e["diff"] for e in self.exceptions) |
Rushabh Mehta | 538607e | 2016-06-12 11:03:00 +0530 | [diff] [blame] | 374 | |
Rushabh Mehta | 649e253 | 2016-07-20 15:30:17 +0530 | [diff] [blame] | 375 | if ((self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"]) in |
| 376 | frappe.local.flags.currently_saving): |
Nabin Hait | 3edefb1 | 2016-07-20 16:13:18 +0530 | [diff] [blame] | 377 | |
Rushabh Mehta | 538607e | 2016-06-12 11:03:00 +0530 | [diff] [blame] | 378 | msg = _("{0} units of {1} needed in {2} to complete this transaction.").format( |
| 379 | abs(deficiency), frappe.get_desk_link('Item', self.item_code), |
| 380 | frappe.get_desk_link('Warehouse', self.warehouse)) |
| 381 | else: |
| 382 | msg = _("{0} units of {1} needed in {2} on {3} {4} for {5} to complete this transaction.").format( |
| 383 | abs(deficiency), frappe.get_desk_link('Item', self.item_code), |
| 384 | frappe.get_desk_link('Warehouse', self.warehouse), |
| 385 | self.exceptions[0]["posting_date"], self.exceptions[0]["posting_time"], |
| 386 | frappe.get_desk_link(self.exceptions[0]["voucher_type"], self.exceptions[0]["voucher_no"])) |
| 387 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 388 | if self.verbose: |
Rushabh Mehta | 538607e | 2016-06-12 11:03:00 +0530 | [diff] [blame] | 389 | frappe.throw(msg, NegativeStockError, title='Insufficent Stock') |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 390 | else: |
cclauss | 6848708 | 2017-07-27 07:08:35 +0200 | [diff] [blame] | 391 | raise NegativeStockError(msg) |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 392 | |
Anand Doshi | 4dc7caa | 2013-01-11 11:44:49 +0530 | [diff] [blame] | 393 | def get_previous_sle(args, for_update=False): |
Anand Doshi | 1b53186 | 2013-01-10 19:29:51 +0530 | [diff] [blame] | 394 | """ |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 395 | get the last sle on or before the current time-bucket, |
Anand Doshi | 1b53186 | 2013-01-10 19:29:51 +0530 | [diff] [blame] | 396 | to get actual qty before transaction, this function |
| 397 | is called from various transaction like stock entry, reco etc |
Nabin Hait | dc82d4f | 2014-04-07 12:02:57 +0530 | [diff] [blame] | 398 | |
Anand Doshi | 1b53186 | 2013-01-10 19:29:51 +0530 | [diff] [blame] | 399 | args = { |
| 400 | "item_code": "ABC", |
| 401 | "warehouse": "XYZ", |
| 402 | "posting_date": "2012-12-12", |
| 403 | "posting_time": "12:00", |
| 404 | "sle": "name of reference Stock Ledger Entry" |
| 405 | } |
| 406 | """ |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 407 | args["name"] = args.get("sle", None) or "" |
| 408 | sle = get_stock_ledger_entries(args, "<=", "desc", "limit 1", for_update=for_update) |
Pratik Vyas | 16371b7 | 2013-09-18 18:31:03 +0530 | [diff] [blame] | 409 | return sle and sle[0] or {} |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 410 | |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 411 | def get_stock_ledger_entries(previous_sle, operator=None, order="desc", limit=None, for_update=False, debug=False): |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 412 | """get stock ledger entries filtered by specific posting datetime conditions""" |
Nabin Hait | b9ce104 | 2018-02-01 14:58:50 +0530 | [diff] [blame] | 413 | conditions = " and timestamp(posting_date, posting_time) {0} timestamp(%(posting_date)s, %(posting_time)s)".format(operator) |
| 414 | if previous_sle.get("warehouse"): |
| 415 | conditions += " and warehouse = %(warehouse)s" |
| 416 | elif previous_sle.get("warehouse_condition"): |
| 417 | conditions += " and " + previous_sle.get("warehouse_condition") |
| 418 | |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 419 | if not previous_sle.get("posting_date"): |
| 420 | previous_sle["posting_date"] = "1900-01-01" |
| 421 | if not previous_sle.get("posting_time"): |
| 422 | previous_sle["posting_time"] = "00:00" |
| 423 | |
| 424 | if operator in (">", "<=") and previous_sle.get("name"): |
| 425 | conditions += " and name!=%(name)s" |
| 426 | |
| 427 | return frappe.db.sql("""select *, timestamp(posting_date, posting_time) as "timestamp" from `tabStock Ledger Entry` |
| 428 | where item_code = %%(item_code)s |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 429 | and ifnull(is_cancelled, 'No')='No' |
Nabin Hait | b9ce104 | 2018-02-01 14:58:50 +0530 | [diff] [blame] | 430 | %(conditions)s |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 431 | order by timestamp(posting_date, posting_time) %(order)s, name %(order)s |
| 432 | %(limit)s %(for_update)s""" % { |
| 433 | "conditions": conditions, |
| 434 | "limit": limit or "", |
| 435 | "for_update": for_update and "for update" or "", |
| 436 | "order": order |
Rushabh Mehta | 50dc4e9 | 2015-02-19 20:05:45 +0530 | [diff] [blame] | 437 | }, previous_sle, as_dict=1, debug=debug) |
Rushabh Mehta | df9e80c | 2015-02-17 19:55:17 +0530 | [diff] [blame] | 438 | |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 439 | def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, |
Nabin Hait | 7ba092e | 2018-02-01 10:51:27 +0530 | [diff] [blame] | 440 | allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True): |
Nabin Hait | a0b967f | 2017-01-18 18:35:58 +0530 | [diff] [blame] | 441 | # Get valuation rate from last sle for the same item and warehouse |
Rohit Waghchaure | a5f4094 | 2017-06-16 15:21:36 +0530 | [diff] [blame] | 442 | if not company: |
| 443 | company = erpnext.get_default_company() |
| 444 | |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 445 | last_valuation_rate = frappe.db.sql("""select valuation_rate |
| 446 | from `tabStock Ledger Entry` |
| 447 | where item_code = %s and warehouse = %s |
rohitwaghchaure | 40a5a30 | 2018-04-02 10:14:49 +0530 | [diff] [blame] | 448 | and valuation_rate >= 0 |
Nabin Hait | 4c952f4 | 2017-01-20 12:50:18 +0530 | [diff] [blame] | 449 | order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse)) |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 450 | |
| 451 | if not last_valuation_rate: |
Nabin Hait | a0b967f | 2017-01-18 18:35:58 +0530 | [diff] [blame] | 452 | # Get valuation rate from last sle for the item against any warehouse |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 453 | last_valuation_rate = frappe.db.sql("""select valuation_rate |
| 454 | from `tabStock Ledger Entry` |
Anand Doshi | 602e825 | 2015-11-16 19:05:46 +0530 | [diff] [blame] | 455 | where item_code = %s and valuation_rate > 0 |
Nabin Hait | 4c952f4 | 2017-01-20 12:50:18 +0530 | [diff] [blame] | 456 | order by posting_date desc, posting_time desc, name desc limit 1""", item_code) |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 457 | |
Nabin Hait | a645f36 | 2018-03-01 10:31:24 +0530 | [diff] [blame] | 458 | if last_valuation_rate: |
| 459 | return flt(last_valuation_rate[0][0]) # as there is previous records, it might come with zero rate |
| 460 | |
| 461 | # If negative stock allowed, and item delivered without any incoming entry, |
| 462 | # system does not found any SLE, then take valuation rate from Item |
| 463 | valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate") |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 464 | |
| 465 | if not valuation_rate: |
Nabin Hait | a645f36 | 2018-03-01 10:31:24 +0530 | [diff] [blame] | 466 | # try Item Standard rate |
| 467 | valuation_rate = frappe.db.get_value("Item", item_code, "standard_rate") |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 468 | |
Rushabh Mehta | aedaac6 | 2017-05-04 09:35:19 +0530 | [diff] [blame] | 469 | if not valuation_rate: |
Nabin Hait | a645f36 | 2018-03-01 10:31:24 +0530 | [diff] [blame] | 470 | # try in price list |
| 471 | valuation_rate = frappe.db.get_value('Item Price', |
| 472 | dict(item_code=item_code, buying=1, currency=currency), |
| 473 | 'price_list_rate') |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 474 | |
Nabin Hait | 7ba092e | 2018-02-01 10:51:27 +0530 | [diff] [blame] | 475 | if not allow_zero_rate and not valuation_rate and raise_error_if_no_rate \ |
Rohit Waghchaure | e9ff191 | 2017-06-19 12:54:59 +0530 | [diff] [blame] | 476 | and cint(erpnext.is_perpetual_inventory_enabled(company)): |
Neil Trini Lasrado | 193c891 | 2017-03-28 17:39:34 +0530 | [diff] [blame] | 477 | frappe.local.message_log = [] |
Javier Wong | 61287e3 | 2017-10-04 18:31:34 +0800 | [diff] [blame] | 478 | frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries for {1} {2}. If the item is transacting as a zero valuation rate item in the {1}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting/cancelling this entry").format(item_code, voucher_type, voucher_no)) |
Nabin Hait | fb6e434 | 2014-10-15 11:34:40 +0530 | [diff] [blame] | 479 | |
| 480 | return valuation_rate |