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 | 756dca7 | 2013-01-15 18:39:21 +0530 | [diff] [blame] | 3 | |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 4 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 5 | import frappe |
marination | 293f6cb | 2021-11-16 14:22:26 +0530 | [diff] [blame] | 6 | from frappe import ValidationError, _, msgprint |
Rohit Waghchaure | f4dc716 | 2018-11-15 17:04:02 +0530 | [diff] [blame] | 7 | from frappe.contacts.doctype.address.address import get_address_display |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 8 | from frappe.utils import cint, cstr, flt, getdate |
Anand Doshi | 756dca7 | 2013-01-15 18:39:21 +0530 | [diff] [blame] | 9 | |
Rohit Waghchaure | 4d4fb6d | 2018-05-15 22:12:44 +0530 | [diff] [blame] | 10 | from erpnext.accounts.doctype.budget.budget import validate_expense_against_budget |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 11 | from erpnext.accounts.party import get_party_details |
| 12 | from erpnext.buying.utils import update_last_purchase_rate, validate_for_items |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 13 | from erpnext.controllers.sales_and_purchase_return import get_rate_for_return |
Rohit Waghchaure | 7b7ceaa | 2021-05-24 20:11:15 +0530 | [diff] [blame] | 14 | from erpnext.controllers.stock_controller import StockController |
Chillar Anand | 915b343 | 2021-09-02 16:44:59 +0530 | [diff] [blame] | 15 | from erpnext.stock.get_item_details import get_conversion_factor |
| 16 | from erpnext.stock.utils import get_incoming_rate |
| 17 | |
marination | 293f6cb | 2021-11-16 14:22:26 +0530 | [diff] [blame] | 18 | |
| 19 | class QtyMismatchError(ValidationError): |
| 20 | pass |
Rohit Waghchaure | 7b7ceaa | 2021-05-24 20:11:15 +0530 | [diff] [blame] | 21 | |
Faris Ansari | bc6a2b2 | 2020-10-27 19:42:58 +0530 | [diff] [blame] | 22 | |
Sagar Sharma | 34bda14 | 2022-05-04 15:21:31 +0530 | [diff] [blame] | 23 | class BuyingController(StockController): |
Rushabh Mehta | c0bb453 | 2014-09-09 16:15:35 +0530 | [diff] [blame] | 24 | def get_feed(self): |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 25 | if self.get("supplier_name"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 26 | return _("From {0} | {1} {2}").format(self.supplier_name, self.currency, self.grand_total) |
Rushabh Mehta | c0bb453 | 2014-09-09 16:15:35 +0530 | [diff] [blame] | 27 | |
Saurabh | 6f75318 | 2013-03-20 12:55:28 +0530 | [diff] [blame] | 28 | def validate(self): |
| 29 | super(BuyingController, self).validate() |
Nabin Hait | 365ae27 | 2014-04-03 17:38:54 +0530 | [diff] [blame] | 30 | if getattr(self, "supplier", None) and not self.supplier_name: |
Nabin Hait | 1d21842 | 2015-07-17 15:19:02 +0530 | [diff] [blame] | 31 | self.supplier_name = frappe.db.get_value("Supplier", self.supplier, "supplier_name") |
Rushabh Mehta | ea0ff23 | 2016-07-07 14:02:26 +0530 | [diff] [blame] | 32 | |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 33 | self.validate_items() |
nabinhait | 614fb75 | 2014-07-14 10:47:50 +0530 | [diff] [blame] | 34 | self.set_qty_as_per_stock_uom() |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 35 | self.validate_stock_or_nonstock_items() |
Anand Doshi | 373680b | 2013-10-10 16:04:40 +0530 | [diff] [blame] | 36 | self.validate_warehouse() |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 37 | self.validate_from_warehouse() |
Rohit Waghchaure | f4dc716 | 2018-11-15 17:04:02 +0530 | [diff] [blame] | 38 | self.set_supplier_address() |
Saqib | 562fd0e | 2020-04-08 12:11:40 +0530 | [diff] [blame] | 39 | self.validate_asset_return() |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 40 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 41 | if self.doctype == "Purchase Invoice": |
Nabin Hait | 14aa9c5 | 2016-04-18 15:54:01 +0530 | [diff] [blame] | 42 | self.validate_purchase_receipt_if_update_stock() |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 43 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 44 | if self.doctype == "Purchase Receipt" or ( |
| 45 | self.doctype == "Purchase Invoice" and self.update_stock |
| 46 | ): |
Rohit Waghchaure | 560ba39 | 2016-08-29 18:19:32 +0530 | [diff] [blame] | 47 | # self.validate_purchase_return() |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 48 | self.validate_rejected_warehouse() |
| 49 | self.validate_accepted_rejected_qty() |
Rushabh Mehta | cc8b2b2 | 2017-03-31 12:44:29 +0530 | [diff] [blame] | 50 | validate_for_items(self) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 51 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 52 | # sub-contracting |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 53 | self.validate_for_subcontracting() |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 54 | self.set_landed_cost_voucher_amount() |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 55 | |
Nabin Hait | 14aa9c5 | 2016-04-18 15:54:01 +0530 | [diff] [blame] | 56 | if self.doctype in ("Purchase Receipt", "Purchase Invoice"): |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 57 | self.update_valuation_rate() |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 58 | |
Rohit Waghchaure | 110e152 | 2021-06-15 17:29:52 +0530 | [diff] [blame] | 59 | def onload(self): |
| 60 | super(BuyingController, self).onload() |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 61 | self.set_onload( |
| 62 | "backflush_based_on", |
| 63 | frappe.db.get_single_value( |
| 64 | "Buying Settings", "backflush_raw_materials_of_subcontract_based_on" |
| 65 | ), |
| 66 | ) |
Rohit Waghchaure | 110e152 | 2021-06-15 17:29:52 +0530 | [diff] [blame] | 67 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 68 | def set_missing_values(self, for_validate=False): |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 69 | super(BuyingController, self).set_missing_values(for_validate) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 70 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 71 | self.set_supplier_from_item_default() |
Nabin Hait | 096d363 | 2013-10-17 17:01:14 +0530 | [diff] [blame] | 72 | self.set_price_list_currency("Buying") |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 73 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 74 | # set contact and address details for supplier, if they are not mentioned |
Nabin Hait | 365ae27 | 2014-04-03 17:38:54 +0530 | [diff] [blame] | 75 | if getattr(self, "supplier", None): |
marination | 78b6b29 | 2022-01-24 13:39:10 +0530 | [diff] [blame] | 76 | self.update_if_missing( |
| 77 | get_party_details( |
| 78 | self.supplier, |
| 79 | party_type="Supplier", |
| 80 | doctype=self.doctype, |
| 81 | company=self.company, |
| 82 | party_address=self.get("supplier_address"), |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 83 | shipping_address=self.get("shipping_address"), |
| 84 | fetch_payment_terms_template=not self.get("ignore_default_payment_terms_template"), |
| 85 | ignore_permissions=self.flags.ignore_permissions, |
marination | 78b6b29 | 2022-01-24 13:39:10 +0530 | [diff] [blame] | 86 | ) |
| 87 | ) |
Rushabh Mehta | 886c9ef | 2013-07-08 12:08:06 +0530 | [diff] [blame] | 88 | |
Nabin Hait | cccc45e | 2016-10-05 17:15:43 +0530 | [diff] [blame] | 89 | self.set_missing_item_details(for_validate) |
Rushabh Mehta | 436467a | 2013-07-08 12:37:59 +0530 | [diff] [blame] | 90 | |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 91 | def set_supplier_from_item_default(self): |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 92 | if self.meta.get_field("supplier") and not self.supplier: |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 93 | for d in self.get("items"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 94 | supplier = frappe.db.get_value( |
| 95 | "Item Default", {"parent": d.item_code, "company": self.company}, "default_supplier" |
| 96 | ) |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 97 | if supplier: |
Anand Doshi | f78d1ae | 2014-03-28 13:55:00 +0530 | [diff] [blame] | 98 | self.supplier = supplier |
Shreya Shah | 3c9839f | 2018-07-17 18:01:44 +0530 | [diff] [blame] | 99 | else: |
| 100 | item_group = frappe.db.get_value("Item", d.item_code, "item_group") |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 101 | supplier = frappe.db.get_value( |
| 102 | "Item Default", {"parent": item_group, "company": self.company}, "default_supplier" |
| 103 | ) |
Shreya Shah | 3c9839f | 2018-07-17 18:01:44 +0530 | [diff] [blame] | 104 | if supplier: |
| 105 | self.supplier = supplier |
Rushabh Mehta | 0b99540 | 2013-08-09 15:29:59 +0530 | [diff] [blame] | 106 | break |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 107 | |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 108 | def validate_stock_or_nonstock_items(self): |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 109 | if self.meta.get_field("taxes") and not self.get_stock_items() and not self.get_asset_items(): |
Deepesh Garg | f17ea2c | 2020-12-11 21:30:39 +0530 | [diff] [blame] | 110 | msg = _('Tax Category has been changed to "Total" because all the Items are non-stock items') |
| 111 | self.update_tax_category(msg) |
| 112 | |
Deepesh Garg | f17ea2c | 2020-12-11 21:30:39 +0530 | [diff] [blame] | 113 | def update_tax_category(self, msg): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 114 | tax_for_valuation = [ |
| 115 | d for d in self.get("taxes") if d.category in ["Valuation", "Valuation and Total"] |
| 116 | ] |
tundebabzy | 9a34620 | 2017-06-16 11:00:14 +0100 | [diff] [blame] | 117 | |
Deepesh Garg | f17ea2c | 2020-12-11 21:30:39 +0530 | [diff] [blame] | 118 | if tax_for_valuation: |
| 119 | for d in tax_for_valuation: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 120 | d.category = "Total" |
Deepesh Garg | f17ea2c | 2020-12-11 21:30:39 +0530 | [diff] [blame] | 121 | |
| 122 | msgprint(msg) |
Marica | 1c8cbd0 | 2020-05-02 17:55:15 +0530 | [diff] [blame] | 123 | |
Saqib | 562fd0e | 2020-04-08 12:11:40 +0530 | [diff] [blame] | 124 | def validate_asset_return(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 125 | if self.doctype not in ["Purchase Receipt", "Purchase Invoice"] or not self.is_return: |
Saqib | 562fd0e | 2020-04-08 12:11:40 +0530 | [diff] [blame] | 126 | return |
| 127 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 128 | purchase_doc_field = ( |
| 129 | "purchase_receipt" if self.doctype == "Purchase Receipt" else "purchase_invoice" |
| 130 | ) |
| 131 | not_cancelled_asset = [ |
| 132 | d.name |
| 133 | for d in frappe.db.get_all("Asset", {purchase_doc_field: self.return_against, "docstatus": 1}) |
| 134 | ] |
Saqib | 562fd0e | 2020-04-08 12:11:40 +0530 | [diff] [blame] | 135 | if self.is_return and len(not_cancelled_asset): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 136 | frappe.throw( |
| 137 | _( |
| 138 | "{} has submitted assets linked to it. You need to cancel the assets to create purchase return." |
| 139 | ).format(self.return_against), |
| 140 | title=_("Not Allowed"), |
| 141 | ) |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 142 | |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 143 | def get_asset_items(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 144 | if self.doctype not in ["Purchase Order", "Purchase Invoice", "Purchase Receipt"]: |
Rohit Waghchaure | d644e6d | 2018-05-12 15:27:18 +0530 | [diff] [blame] | 145 | return [] |
| 146 | |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 147 | return [d.item_code for d in self.items if d.is_fixed_asset] |
| 148 | |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 149 | def set_landed_cost_voucher_amount(self): |
| 150 | for d in self.get("items"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 151 | lc_voucher_data = frappe.db.sql( |
| 152 | """select sum(applicable_charges), cost_center |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 153 | from `tabLanded Cost Item` |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 154 | where docstatus = 1 and purchase_receipt_item = %s""", |
| 155 | d.name, |
| 156 | ) |
rohitwaghchaure | 2e8232e | 2017-08-10 11:32:59 +0530 | [diff] [blame] | 157 | d.landed_cost_voucher_amount = lc_voucher_data[0][0] if lc_voucher_data else 0.0 |
| 158 | if not d.cost_center and lc_voucher_data and lc_voucher_data[0][1]: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 159 | d.db_set("cost_center", lc_voucher_data[0][1]) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 160 | |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 161 | def validate_from_warehouse(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 162 | for item in self.get("items"): |
| 163 | if item.get("from_warehouse") and (item.get("from_warehouse") == item.get("warehouse")): |
| 164 | frappe.throw( |
| 165 | _("Row #{0}: Accepted Warehouse and Supplier Warehouse cannot be same").format(item.idx) |
| 166 | ) |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 167 | |
Sagar Sharma | 409df26 | 2022-04-19 14:57:31 +0530 | [diff] [blame] | 168 | if item.get("from_warehouse") and self.get("is_subcontracted"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 169 | frappe.throw( |
| 170 | _( |
| 171 | "Row #{0}: Cannot select Supplier Warehouse while suppling raw materials to subcontractor" |
| 172 | ).format(item.idx) |
| 173 | ) |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 174 | |
Rohit Waghchaure | f4dc716 | 2018-11-15 17:04:02 +0530 | [diff] [blame] | 175 | def set_supplier_address(self): |
| 176 | address_dict = { |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 177 | "supplier_address": "address_display", |
| 178 | "shipping_address": "shipping_address_display", |
Rohit Waghchaure | f4dc716 | 2018-11-15 17:04:02 +0530 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | for address_field, address_display_field in address_dict.items(): |
| 182 | if self.get(address_field): |
| 183 | self.set(address_display_field, get_address_display(self.get(address_field))) |
| 184 | |
Nabin Hait | d3b6250 | 2013-01-21 17:24:31 +0530 | [diff] [blame] | 185 | def set_total_in_words(self): |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 186 | from frappe.utils import money_in_words |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 187 | |
Nabin Hait | 5690be1 | 2015-02-12 16:09:11 +0530 | [diff] [blame] | 188 | if self.meta.get_field("base_in_words"): |
Nabin Hait | 6b539d6 | 2018-08-29 12:41:12 +0530 | [diff] [blame] | 189 | if self.meta.get_field("base_rounded_total") and not self.is_rounded_total_disabled(): |
| 190 | amount = self.base_rounded_total |
| 191 | else: |
| 192 | amount = self.base_grand_total |
rohitwaghchaure | ae4ff5a | 2018-08-01 18:09:51 +0530 | [diff] [blame] | 193 | self.base_in_words = money_in_words(amount, self.company_currency) |
| 194 | |
Nabin Hait | 5b4c294 | 2013-01-22 11:12:02 +0530 | [diff] [blame] | 195 | if self.meta.get_field("in_words"): |
Nabin Hait | 6b539d6 | 2018-08-29 12:41:12 +0530 | [diff] [blame] | 196 | if self.meta.get_field("rounded_total") and not self.is_rounded_total_disabled(): |
| 197 | amount = self.rounded_total |
| 198 | else: |
| 199 | amount = self.grand_total |
rohitwaghchaure | ae4ff5a | 2018-08-01 18:09:51 +0530 | [diff] [blame] | 200 | |
| 201 | self.in_words = money_in_words(amount, self.currency) |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 202 | |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 203 | # update valuation rate |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 204 | def update_valuation_rate(self, reset_outgoing_rate=True): |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 205 | """ |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 206 | item_tax_amount is the total tax amount applied on that item |
| 207 | stored for valuation |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 208 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 209 | TODO: rename item_tax_amount to valuation_tax_amount |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 210 | """ |
Rohit Waghchaure | 4d81d45 | 2021-06-15 10:21:44 +0530 | [diff] [blame] | 211 | stock_and_asset_items = [] |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 212 | stock_and_asset_items = self.get_stock_items() + self.get_asset_items() |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 213 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 214 | stock_and_asset_items_qty, stock_and_asset_items_amount = 0, 0 |
| 215 | last_item_idx = 1 |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 216 | for d in self.get("items"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 217 | if d.item_code and d.item_code in stock_and_asset_items: |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 218 | stock_and_asset_items_qty += flt(d.qty) |
| 219 | stock_and_asset_items_amount += flt(d.base_net_amount) |
| 220 | last_item_idx = d.idx |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 221 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 222 | total_valuation_amount = sum( |
| 223 | flt(d.base_tax_amount_after_discount_amount) |
| 224 | for d in self.get("taxes") |
| 225 | if d.category in ["Valuation", "Valuation and Total"] |
| 226 | ) |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 227 | |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 228 | valuation_amount_adjustment = total_valuation_amount |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 229 | for i, item in enumerate(self.get("items")): |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 230 | if item.item_code and item.qty and item.item_code in stock_and_asset_items: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 231 | item_proportion = ( |
| 232 | flt(item.base_net_amount) / stock_and_asset_items_amount |
| 233 | if stock_and_asset_items_amount |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 234 | else flt(item.qty) / stock_and_asset_items_qty |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 235 | ) |
Suraj Shetty | 48e9bc3 | 2020-01-29 15:06:18 +0530 | [diff] [blame] | 236 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 237 | if i == (last_item_idx - 1): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 238 | item.item_tax_amount = flt( |
| 239 | valuation_amount_adjustment, self.precision("item_tax_amount", item) |
| 240 | ) |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 241 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 242 | item.item_tax_amount = flt( |
| 243 | item_proportion * total_valuation_amount, self.precision("item_tax_amount", item) |
| 244 | ) |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 245 | valuation_amount_adjustment -= item.item_tax_amount |
| 246 | |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 247 | self.round_floats_in(item) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 248 | if flt(item.conversion_factor) == 0.0: |
| 249 | item.conversion_factor = ( |
| 250 | get_conversion_factor(item.item_code, item.uom).get("conversion_factor") or 1.0 |
| 251 | ) |
Rushabh Mehta | 724f9e5 | 2014-10-07 15:29:58 +0530 | [diff] [blame] | 252 | |
Rushabh Mehta | 5404778 | 2013-12-26 11:07:46 +0530 | [diff] [blame] | 253 | qty_in_stock_uom = flt(item.qty * item.conversion_factor) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 254 | item.valuation_rate = ( |
Sagar Sharma | 213113b | 2022-05-20 11:56:25 +0530 | [diff] [blame^] | 255 | item.base_net_amount + item.item_tax_amount + flt(item.landed_cost_voucher_amount) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 256 | ) / qty_in_stock_uom |
Anand Doshi | 4a7248e | 2013-02-27 18:10:30 +0530 | [diff] [blame] | 257 | else: |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 258 | item.valuation_rate = 0.0 |
Rushabh Mehta | 9f0d625 | 2014-04-14 19:20:45 +0530 | [diff] [blame] | 259 | |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 260 | def set_incoming_rate(self): |
| 261 | if self.doctype not in ("Purchase Receipt", "Purchase Invoice", "Purchase Order"): |
| 262 | return |
| 263 | |
| 264 | ref_doctype_map = { |
| 265 | "Purchase Order": "Sales Order Item", |
| 266 | "Purchase Receipt": "Delivery Note Item", |
| 267 | "Purchase Invoice": "Sales Invoice Item", |
| 268 | } |
| 269 | |
| 270 | ref_doctype = ref_doctype_map.get(self.doctype) |
| 271 | items = self.get("items") |
| 272 | for d in items: |
| 273 | if not cint(self.get("is_return")): |
| 274 | # Get outgoing rate based on original item cost based on valuation method |
| 275 | |
| 276 | if not d.get(frappe.scrub(ref_doctype)): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 277 | outgoing_rate = get_incoming_rate( |
| 278 | { |
| 279 | "item_code": d.item_code, |
| 280 | "warehouse": d.get("from_warehouse"), |
| 281 | "posting_date": self.get("posting_date") or self.get("transation_date"), |
| 282 | "posting_time": self.get("posting_time"), |
| 283 | "qty": -1 * flt(d.get("stock_qty")), |
| 284 | "serial_no": d.get("serial_no"), |
| 285 | "batch_no": d.get("batch_no"), |
| 286 | "company": self.company, |
| 287 | "voucher_type": self.doctype, |
| 288 | "voucher_no": self.name, |
| 289 | "allow_zero_valuation": d.get("allow_zero_valuation"), |
| 290 | }, |
| 291 | raise_error_if_no_rate=False, |
| 292 | ) |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 293 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 294 | rate = flt(outgoing_rate * d.conversion_factor, d.precision("rate")) |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 295 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 296 | rate = frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), "rate") |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 297 | |
| 298 | if self.is_internal_transfer(): |
| 299 | if rate != d.rate: |
| 300 | d.rate = rate |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 301 | frappe.msgprint( |
| 302 | _( |
| 303 | "Row {0}: Item rate has been updated as per valuation rate since its an internal stock transfer" |
| 304 | ).format(d.idx), |
| 305 | alert=1, |
| 306 | ) |
Ankush Menat | ee0a277 | 2022-05-12 18:17:09 +0530 | [diff] [blame] | 307 | d.discount_percentage = 0.0 |
| 308 | d.discount_amount = 0.0 |
| 309 | d.margin_rate_or_amount = 0.0 |
Deepesh Garg | b4be292 | 2021-01-28 13:09:56 +0530 | [diff] [blame] | 310 | |
Nabin Hait | 54d209f | 2013-03-01 18:51:10 +0530 | [diff] [blame] | 311 | def validate_for_subcontracting(self): |
Sagar Sharma | 409df26 | 2022-04-19 14:57:31 +0530 | [diff] [blame] | 312 | if self.is_subcontracted: |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 313 | if self.doctype in ["Purchase Receipt", "Purchase Invoice"] and not self.supplier_warehouse: |
Afshan | 27bcb2a | 2021-03-09 22:25:48 +0530 | [diff] [blame] | 314 | frappe.throw(_("Supplier Warehouse mandatory for sub-contracted {0}").format(self.doctype)) |
ankitjavalkarwork | 5edae0e | 2014-11-05 20:14:53 +0530 | [diff] [blame] | 315 | else: |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 316 | for item in self.get("items"): |
Sagar Sharma | 34bda14 | 2022-05-04 15:21:31 +0530 | [diff] [blame] | 317 | if item.get("bom"): |
ankitjavalkarwork | 5edae0e | 2014-11-05 20:14:53 +0530 | [diff] [blame] | 318 | item.bom = None |
| 319 | |
nabinhait | 614fb75 | 2014-07-14 10:47:50 +0530 | [diff] [blame] | 320 | def set_qty_as_per_stock_uom(self): |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 321 | for d in self.get("items"): |
Nabin Hait | fd4bcd8 | 2015-05-22 16:55:40 +0530 | [diff] [blame] | 322 | if d.meta.get_field("stock_qty"): |
Deepesh Garg | 8b0302b | 2019-08-05 10:14:19 +0530 | [diff] [blame] | 323 | # Check if item code is present |
| 324 | # Conversion factor should not be mandatory for non itemized items |
| 325 | if not d.conversion_factor and d.item_code: |
Nabin Hait | e6e456b | 2015-05-13 17:21:44 +0530 | [diff] [blame] | 326 | frappe.throw(_("Row {0}: Conversion Factor is mandatory").format(d.idx)) |
Rushabh Mehta | 5b51cc8 | 2014-07-21 18:25:45 +0530 | [diff] [blame] | 327 | d.stock_qty = flt(d.qty) * flt(d.conversion_factor) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 328 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 329 | if self.doctype == "Purchase Receipt" and d.meta.get_field("received_stock_qty"): |
marination | d6596a1 | 2020-11-02 15:07:48 +0530 | [diff] [blame] | 330 | # Set Received Qty in Stock UOM |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 331 | d.received_stock_qty = flt(d.received_qty) * flt( |
| 332 | d.conversion_factor, d.precision("conversion_factor") |
| 333 | ) |
marination | d6596a1 | 2020-11-02 15:07:48 +0530 | [diff] [blame] | 334 | |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 335 | def validate_purchase_return(self): |
| 336 | for d in self.get("items"): |
| 337 | if self.is_return and flt(d.rejected_qty) != 0: |
| 338 | frappe.throw(_("Row #{0}: Rejected Qty can not be entered in Purchase Return").format(d.idx)) |
| 339 | |
| 340 | # validate rate with ref PR |
| 341 | |
| 342 | def validate_rejected_warehouse(self): |
| 343 | for d in self.get("items"): |
| 344 | if flt(d.rejected_qty) and not d.rejected_warehouse: |
Saurabh | fbb342c | 2016-04-07 16:41:31 +0530 | [diff] [blame] | 345 | if self.rejected_warehouse: |
| 346 | d.rejected_warehouse = self.rejected_warehouse |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 347 | |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 348 | if not d.rejected_warehouse: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 349 | frappe.throw( |
| 350 | _("Row #{0}: Rejected Warehouse is mandatory against rejected Item {1}").format( |
| 351 | d.idx, d.item_code |
| 352 | ) |
| 353 | ) |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 354 | |
| 355 | # validate accepted and rejected qty |
| 356 | def validate_accepted_rejected_qty(self): |
| 357 | for d in self.get("items"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 358 | self.validate_negative_quantity(d, ["received_qty", "qty", "rejected_qty"]) |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 359 | |
marination | 5fb5a75 | 2021-11-08 13:22:57 +0530 | [diff] [blame] | 360 | if not flt(d.received_qty) and (flt(d.qty) or flt(d.rejected_qty)): |
| 361 | d.received_qty = flt(d.qty) + flt(d.rejected_qty) |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 362 | |
Saurabh | 130c57b | 2016-04-04 15:49:36 +0530 | [diff] [blame] | 363 | # Check Received Qty = Accepted Qty + Rejected Qty |
marination | afe1c45 | 2021-11-15 17:17:29 +0530 | [diff] [blame] | 364 | val = flt(d.qty) + flt(d.rejected_qty) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 365 | if flt(val, d.precision("received_qty")) != flt(d.received_qty, d.precision("received_qty")): |
| 366 | message = _( |
| 367 | "Row #{0}: Received Qty must be equal to Accepted + Rejected Qty for Item {1}" |
| 368 | ).format(d.idx, d.item_code) |
marination | 05ec7cc | 2021-11-15 17:49:14 +0530 | [diff] [blame] | 369 | frappe.throw(msg=message, title=_("Mismatch"), exc=QtyMismatchError) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 370 | |
Saurabh | 4f4d0a8 | 2017-03-13 14:31:48 +0530 | [diff] [blame] | 371 | def validate_negative_quantity(self, item_row, field_list): |
| 372 | if self.is_return: |
| 373 | return |
| 374 | |
| 375 | item_row = item_row.as_dict() |
| 376 | for fieldname in field_list: |
| 377 | if flt(item_row[fieldname]) < 0: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 378 | frappe.throw( |
| 379 | _("Row #{0}: {1} can not be negative for item {2}").format( |
| 380 | item_row["idx"], |
| 381 | frappe.get_meta(item_row.doctype).get_label(fieldname), |
| 382 | item_row["item_code"], |
| 383 | ) |
| 384 | ) |
Saurabh | 4f4d0a8 | 2017-03-13 14:31:48 +0530 | [diff] [blame] | 385 | |
Mangesh-Khairnar | 5e474f4 | 2019-03-06 14:46:38 +0530 | [diff] [blame] | 386 | def check_for_on_hold_or_closed_status(self, ref_doctype, ref_fieldname): |
| 387 | for d in self.get("items"): |
| 388 | if d.get(ref_fieldname): |
| 389 | status = frappe.db.get_value(ref_doctype, d.get(ref_fieldname), "status") |
| 390 | if status in ("Closed", "On Hold"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 391 | frappe.throw(_("{0} {1} is {2}").format(ref_doctype, d.get(ref_fieldname), status)) |
Mangesh-Khairnar | 5e474f4 | 2019-03-06 14:46:38 +0530 | [diff] [blame] | 392 | |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 393 | def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_voucher=False): |
Nabin Hait | 07e5376 | 2018-01-05 18:19:59 +0530 | [diff] [blame] | 394 | self.update_ordered_and_reserved_qty() |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 395 | |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 396 | sl_entries = [] |
| 397 | stock_items = self.get_stock_items() |
| 398 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 399 | for d in self.get("items"): |
Rohit Waghchaure | 0a71cab | 2022-04-04 15:10:57 +0530 | [diff] [blame] | 400 | if d.item_code not in stock_items: |
| 401 | continue |
| 402 | |
Rohit Waghchaure | ac5df1a | 2022-04-04 15:38:42 +0530 | [diff] [blame] | 403 | if d.warehouse: |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 404 | pr_qty = flt(d.qty) * flt(d.conversion_factor) |
| 405 | |
| 406 | if pr_qty: |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 407 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 408 | if d.from_warehouse and ( |
| 409 | (not cint(self.is_return) and self.docstatus == 1) |
| 410 | or (cint(self.is_return) and self.docstatus == 2) |
| 411 | ): |
| 412 | from_warehouse_sle = self.get_sl_entries( |
| 413 | d, |
| 414 | { |
| 415 | "actual_qty": -1 * pr_qty, |
| 416 | "warehouse": d.from_warehouse, |
| 417 | "outgoing_rate": d.rate, |
| 418 | "recalculate_rate": 1, |
| 419 | "dependant_sle_voucher_detail_no": d.name, |
| 420 | }, |
| 421 | ) |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 422 | |
| 423 | sl_entries.append(from_warehouse_sle) |
| 424 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 425 | sle = self.get_sl_entries( |
| 426 | d, {"actual_qty": flt(pr_qty), "serial_no": cstr(d.serial_no).strip()} |
| 427 | ) |
Rohit Waghchaure | 0a71cab | 2022-04-04 15:10:57 +0530 | [diff] [blame] | 428 | |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 429 | if self.is_return: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 430 | outgoing_rate = get_rate_for_return( |
| 431 | self.doctype, self.name, d.item_code, self.return_against, item_row=d |
| 432 | ) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 433 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 434 | sle.update({"outgoing_rate": outgoing_rate, "recalculate_rate": 1}) |
Nabin Hait | a77b8c9 | 2020-12-21 14:45:50 +0530 | [diff] [blame] | 435 | if d.from_warehouse: |
| 436 | sle.dependant_sle_voucher_detail_no = d.name |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 437 | else: |
Nabin Hait | b81ed45 | 2016-05-11 12:52:31 +0530 | [diff] [blame] | 438 | val_rate_db_precision = 6 if cint(self.precision("valuation_rate", d)) <= 6 else 9 |
| 439 | incoming_rate = flt(d.valuation_rate, val_rate_db_precision) |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 440 | sle.update( |
| 441 | { |
| 442 | "incoming_rate": incoming_rate, |
Sagar Sharma | 34bda14 | 2022-05-04 15:21:31 +0530 | [diff] [blame] | 443 | "recalculate_rate": 1 if (self.is_subcontracted and d.fg_item) or d.from_warehouse else 0, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 444 | } |
| 445 | ) |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 446 | sl_entries.append(sle) |
| 447 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 448 | if d.from_warehouse and ( |
| 449 | (not cint(self.is_return) and self.docstatus == 2) |
| 450 | or (cint(self.is_return) and self.docstatus == 1) |
| 451 | ): |
| 452 | from_warehouse_sle = self.get_sl_entries( |
| 453 | d, {"actual_qty": -1 * pr_qty, "warehouse": d.from_warehouse, "recalculate_rate": 1} |
| 454 | ) |
Deepesh Garg | 15ff6a5 | 2020-02-18 12:28:41 +0530 | [diff] [blame] | 455 | |
| 456 | sl_entries.append(from_warehouse_sle) |
| 457 | |
Rohit Waghchaure | 0a71cab | 2022-04-04 15:10:57 +0530 | [diff] [blame] | 458 | if flt(d.rejected_qty) != 0: |
| 459 | sl_entries.append( |
| 460 | self.get_sl_entries( |
| 461 | d, |
| 462 | { |
| 463 | "warehouse": d.rejected_warehouse, |
| 464 | "actual_qty": flt(d.rejected_qty) * flt(d.conversion_factor), |
| 465 | "serial_no": cstr(d.rejected_serial_no).strip(), |
| 466 | "incoming_rate": 0.0, |
| 467 | }, |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 468 | ) |
Rohit Waghchaure | 0a71cab | 2022-04-04 15:10:57 +0530 | [diff] [blame] | 469 | ) |
Saurabh | e29248b | 2016-04-04 11:55:52 +0530 | [diff] [blame] | 470 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 471 | self.make_sl_entries( |
| 472 | sl_entries, |
| 473 | allow_negative_stock=allow_negative_stock, |
| 474 | via_landed_cost_voucher=via_landed_cost_voucher, |
| 475 | ) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 476 | |
Nabin Hait | 07e5376 | 2018-01-05 18:19:59 +0530 | [diff] [blame] | 477 | def update_ordered_and_reserved_qty(self): |
Nabin Hait | 14aa9c5 | 2016-04-18 15:54:01 +0530 | [diff] [blame] | 478 | po_map = {} |
| 479 | for d in self.get("items"): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 480 | if self.doctype == "Purchase Receipt" and d.purchase_order: |
| 481 | po_map.setdefault(d.purchase_order, []).append(d.purchase_order_item) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 482 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 483 | elif self.doctype == "Purchase Invoice" and d.purchase_order and d.po_detail: |
Nabin Hait | 14aa9c5 | 2016-04-18 15:54:01 +0530 | [diff] [blame] | 484 | po_map.setdefault(d.purchase_order, []).append(d.po_detail) |
| 485 | |
| 486 | for po, po_item_rows in po_map.items(): |
| 487 | if po and po_item_rows: |
| 488 | po_obj = frappe.get_doc("Purchase Order", po) |
| 489 | |
| 490 | if po_obj.status in ["Closed", "Cancelled"]: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 491 | frappe.throw( |
| 492 | _("{0} {1} is cancelled or closed").format(_("Purchase Order"), po), |
| 493 | frappe.InvalidStatusError, |
| 494 | ) |
Nabin Hait | 14aa9c5 | 2016-04-18 15:54:01 +0530 | [diff] [blame] | 495 | |
| 496 | po_obj.update_ordered_qty(po_item_rows) |
Rushabh Mehta | b33df4a | 2016-07-04 11:38:37 +0530 | [diff] [blame] | 497 | |
rohitwaghchaure | fe22686 | 2017-12-28 16:11:27 +0530 | [diff] [blame] | 498 | def on_submit(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 499 | if self.get("is_return"): |
rohitwaghchaure | fe22686 | 2017-12-28 16:11:27 +0530 | [diff] [blame] | 500 | return |
| 501 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 502 | if self.doctype in ["Purchase Receipt", "Purchase Invoice"]: |
| 503 | field = "purchase_invoice" if self.doctype == "Purchase Invoice" else "purchase_receipt" |
Rohit Waghchaure | c6deb13 | 2018-05-07 15:58:41 +0530 | [diff] [blame] | 504 | |
| 505 | self.process_fixed_asset() |
| 506 | self.update_fixed_asset(field) |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 507 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 508 | if self.doctype in ["Purchase Order", "Purchase Receipt"]: |
| 509 | update_last_purchase_rate(self, is_submit=1) |
rohitwaghchaure | fe22686 | 2017-12-28 16:11:27 +0530 | [diff] [blame] | 510 | |
| 511 | def on_cancel(self): |
Rohit Waghchaure | 5fa9a7a | 2019-04-01 00:40:38 +0530 | [diff] [blame] | 512 | super(BuyingController, self).on_cancel() |
| 513 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 514 | if self.get("is_return"): |
rohitwaghchaure | fe22686 | 2017-12-28 16:11:27 +0530 | [diff] [blame] | 515 | return |
| 516 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 517 | if self.doctype in ["Purchase Order", "Purchase Receipt"]: |
| 518 | update_last_purchase_rate(self, is_submit=0) |
Rohit Waghchaure | 4d81d45 | 2021-06-15 10:21:44 +0530 | [diff] [blame] | 519 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 520 | if self.doctype in ["Purchase Receipt", "Purchase Invoice"]: |
| 521 | field = "purchase_invoice" if self.doctype == "Purchase Invoice" else "purchase_receipt" |
Rohit Waghchaure | c6deb13 | 2018-05-07 15:58:41 +0530 | [diff] [blame] | 522 | |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 523 | self.delete_linked_asset() |
| 524 | self.update_fixed_asset(field, delete_asset=True) |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 525 | |
Rohit Waghchaure | 4d4fb6d | 2018-05-15 22:12:44 +0530 | [diff] [blame] | 526 | def validate_budget(self): |
| 527 | if self.docstatus == 1: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 528 | for data in self.get("items"): |
rohitwaghchaure | 77a45b4 | 2018-06-15 18:03:31 +0530 | [diff] [blame] | 529 | args = data.as_dict() |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 530 | args.update( |
| 531 | { |
| 532 | "doctype": self.doctype, |
| 533 | "company": self.company, |
| 534 | "posting_date": ( |
| 535 | self.schedule_date if self.doctype == "Material Request" else self.transaction_date |
| 536 | ), |
| 537 | } |
| 538 | ) |
rohitwaghchaure | 77a45b4 | 2018-06-15 18:03:31 +0530 | [diff] [blame] | 539 | |
| 540 | validate_expense_against_budget(args) |
Rohit Waghchaure | 4d4fb6d | 2018-05-15 22:12:44 +0530 | [diff] [blame] | 541 | |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 542 | def process_fixed_asset(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 543 | if self.doctype == "Purchase Invoice" and not self.update_stock: |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 544 | return |
| 545 | |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 546 | asset_items = self.get_asset_items() |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 547 | if asset_items: |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 548 | self.auto_make_assets(asset_items) |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 549 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 550 | def auto_make_assets(self, asset_items): |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 551 | items_data = get_asset_item_details(asset_items) |
Saqib | f37a46e | 2019-11-22 16:32:50 +0530 | [diff] [blame] | 552 | messages = [] |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 553 | |
| 554 | for d in self.items: |
| 555 | if d.is_fixed_asset: |
| 556 | item_data = items_data.get(d.item_code) |
| 557 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 558 | if item_data.get("auto_create_assets"): |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 559 | # If asset has to be auto created |
| 560 | # Check for asset naming series |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 561 | if item_data.get("asset_naming_series"): |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 562 | created_assets = [] |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 563 | if item_data.get("is_grouped_asset"): |
Saqib Ansari | 35a6b58 | 2022-01-18 13:10:23 +0530 | [diff] [blame] | 564 | asset = self.make_asset(d, is_grouped_asset=True) |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 565 | created_assets.append(asset) |
Saqib Ansari | 35a6b58 | 2022-01-18 13:10:23 +0530 | [diff] [blame] | 566 | else: |
| 567 | for qty in range(cint(d.qty)): |
| 568 | asset = self.make_asset(d) |
| 569 | created_assets.append(asset) |
Marica | 1c8cbd0 | 2020-05-02 17:55:15 +0530 | [diff] [blame] | 570 | |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 571 | if len(created_assets) > 5: |
| 572 | # dont show asset form links if more than 5 assets are created |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 573 | messages.append( |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 574 | _("{} Assets created for {}").format(len(created_assets), frappe.bold(d.item_code)) |
| 575 | ) |
| 576 | else: |
| 577 | assets_link = list(map(lambda d: frappe.utils.get_link_to_form("Asset", d), created_assets)) |
| 578 | assets_link = frappe.bold(",".join(assets_link)) |
| 579 | |
| 580 | is_plural = "s" if len(created_assets) != 1 else "" |
| 581 | messages.append( |
| 582 | _("Asset{} {assets_link} created for {}").format( |
| 583 | is_plural, frappe.bold(d.item_code), assets_link=assets_link |
| 584 | ) |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 585 | ) |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 586 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 587 | frappe.throw( |
| 588 | _("Row {}: Asset Naming Series is mandatory for the auto creation for item {}").format( |
| 589 | d.idx, frappe.bold(d.item_code) |
| 590 | ) |
| 591 | ) |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 592 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 593 | messages.append( |
| 594 | _("Assets not created for {0}. You will have to create asset manually.").format( |
| 595 | frappe.bold(d.item_code) |
| 596 | ) |
| 597 | ) |
Saqib | f37a46e | 2019-11-22 16:32:50 +0530 | [diff] [blame] | 598 | |
| 599 | for message in messages: |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 600 | frappe.msgprint(message, title="Success", indicator="green") |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 601 | |
Saqib Ansari | 35a6b58 | 2022-01-18 13:10:23 +0530 | [diff] [blame] | 602 | def make_asset(self, row, is_grouped_asset=False): |
Rohit Waghchaure | aa7b434 | 2018-05-11 01:56:05 +0530 | [diff] [blame] | 603 | if not row.asset_location: |
| 604 | frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code)) |
| 605 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 606 | item_data = frappe.db.get_value( |
| 607 | "Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1 |
| 608 | ) |
Rohit Waghchaure | f2684ae | 2018-05-08 13:22:22 +0530 | [diff] [blame] | 609 | |
Saqib Ansari | 35a6b58 | 2022-01-18 13:10:23 +0530 | [diff] [blame] | 610 | if is_grouped_asset: |
| 611 | purchase_amount = flt(row.base_amount + row.item_tax_amount) |
| 612 | else: |
| 613 | purchase_amount = flt(row.base_rate + row.item_tax_amount) |
| 614 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 615 | asset = frappe.get_doc( |
| 616 | { |
| 617 | "doctype": "Asset", |
| 618 | "item_code": row.item_code, |
| 619 | "asset_name": row.item_name, |
| 620 | "naming_series": item_data.get("asset_naming_series") or "AST", |
| 621 | "asset_category": item_data.get("asset_category"), |
| 622 | "location": row.asset_location, |
| 623 | "company": self.company, |
| 624 | "supplier": self.supplier, |
| 625 | "purchase_date": self.posting_date, |
| 626 | "calculate_depreciation": 1, |
| 627 | "purchase_receipt_amount": purchase_amount, |
| 628 | "gross_purchase_amount": purchase_amount, |
| 629 | "asset_quantity": row.qty if is_grouped_asset else 0, |
| 630 | "purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None, |
| 631 | "purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None, |
| 632 | } |
| 633 | ) |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 634 | |
| 635 | asset.flags.ignore_validate = True |
| 636 | asset.flags.ignore_mandatory = True |
Rohit Waghchaure | aa7b434 | 2018-05-11 01:56:05 +0530 | [diff] [blame] | 637 | asset.set_missing_values() |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 638 | asset.insert() |
| 639 | |
Saqib | bba78f0 | 2020-03-31 10:49:44 +0530 | [diff] [blame] | 640 | return asset.name |
| 641 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 642 | def update_fixed_asset(self, field, delete_asset=False): |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 643 | for d in self.get("items"): |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 644 | if d.is_fixed_asset: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 645 | is_auto_create_enabled = frappe.db.get_value("Item", d.item_code, "auto_create_assets") |
| 646 | assets = frappe.db.get_all("Asset", filters={field: self.name, "item_code": d.item_code}) |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 647 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 648 | for asset in assets: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 649 | asset = frappe.get_doc("Asset", asset.name) |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 650 | if delete_asset and is_auto_create_enabled: |
| 651 | # need to delete movements to delete assets otherwise throws link exists error |
Saqib | cd3976f | 2019-11-25 12:24:34 +0530 | [diff] [blame] | 652 | movements = frappe.db.sql( |
Suraj Shetty | 48e9bc3 | 2020-01-29 15:06:18 +0530 | [diff] [blame] | 653 | """SELECT asm.name |
Saqib | cd3976f | 2019-11-25 12:24:34 +0530 | [diff] [blame] | 654 | FROM `tabAsset Movement` asm, `tabAsset Movement Item` asm_item |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 655 | WHERE asm_item.parent=asm.name and asm_item.asset=%s""", |
| 656 | asset.name, |
| 657 | as_dict=1, |
| 658 | ) |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 659 | for movement in movements: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 660 | frappe.delete_doc("Asset Movement", movement.name, force=1) |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 661 | frappe.delete_doc("Asset", asset.name, force=1) |
| 662 | continue |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 663 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 664 | if self.docstatus in [0, 1] and not asset.get(field): |
| 665 | asset.set(field, self.name) |
| 666 | asset.purchase_date = self.posting_date |
| 667 | asset.supplier = self.supplier |
| 668 | elif self.docstatus == 2: |
Saqib | cd3976f | 2019-11-25 12:24:34 +0530 | [diff] [blame] | 669 | if asset.docstatus == 0: |
| 670 | asset.set(field, None) |
| 671 | asset.supplier = None |
| 672 | if asset.docstatus == 1 and delete_asset: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 673 | frappe.throw( |
| 674 | _( |
| 675 | "Cannot cancel this document as it is linked with submitted asset {0}. Please cancel it to continue." |
| 676 | ).format(frappe.utils.get_link_to_form("Asset", asset.name)) |
| 677 | ) |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 678 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 679 | asset.flags.ignore_validate_update_after_submit = True |
| 680 | asset.flags.ignore_mandatory = True |
| 681 | if asset.docstatus == 0: |
| 682 | asset.flags.ignore_validate = True |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 683 | |
Saqib | d995609 | 2019-11-18 11:46:55 +0530 | [diff] [blame] | 684 | asset.save() |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 685 | |
Rohit Waghchaure | af05995 | 2018-05-07 18:46:53 +0530 | [diff] [blame] | 686 | def delete_linked_asset(self): |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 687 | if self.doctype == "Purchase Invoice" and not self.get("update_stock"): |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 688 | return |
| 689 | |
Nabin Hait | 1e7c32b | 2018-09-26 18:01:00 +0530 | [diff] [blame] | 690 | frappe.db.sql("delete from `tabAsset Movement` where reference_name=%s", self.name) |
rohitwaghchaure | fe22686 | 2017-12-28 16:11:27 +0530 | [diff] [blame] | 691 | |
Nabin Hait | 5a83420 | 2017-10-05 19:51:10 +0530 | [diff] [blame] | 692 | def validate_schedule_date(self): |
Sahil Khan | 34766c0 | 2018-12-20 18:50:24 +0530 | [diff] [blame] | 693 | if not self.get("items"): |
| 694 | return |
Nabin Hait | a113861 | 2019-10-15 12:43:27 +0530 | [diff] [blame] | 695 | |
18alantom | 2a20a03 | 2021-05-05 11:59:15 +0530 | [diff] [blame] | 696 | if any(d.schedule_date for d in self.get("items")): |
| 697 | # Select earliest schedule_date. |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 698 | self.schedule_date = min( |
| 699 | d.schedule_date for d in self.get("items") if d.schedule_date is not None |
| 700 | ) |
Nabin Hait | 5a83420 | 2017-10-05 19:51:10 +0530 | [diff] [blame] | 701 | |
| 702 | if self.schedule_date: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 703 | for d in self.get("items"): |
Nabin Hait | 5a83420 | 2017-10-05 19:51:10 +0530 | [diff] [blame] | 704 | if not d.schedule_date: |
| 705 | d.schedule_date = self.schedule_date |
| 706 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 707 | if ( |
| 708 | d.schedule_date |
| 709 | and self.transaction_date |
| 710 | and getdate(d.schedule_date) < getdate(self.transaction_date) |
| 711 | ): |
Nabin Hait | 96b264b | 2018-01-02 11:50:29 +0530 | [diff] [blame] | 712 | frappe.throw(_("Row #{0}: Reqd by Date cannot be before Transaction Date").format(d.idx)) |
Nabin Hait | 5a83420 | 2017-10-05 19:51:10 +0530 | [diff] [blame] | 713 | else: |
Nabin Hait | 96b264b | 2018-01-02 11:50:29 +0530 | [diff] [blame] | 714 | frappe.throw(_("Please enter Reqd by Date")) |
Rushabh Mehta | 30dc9a1 | 2017-11-17 14:31:09 +0530 | [diff] [blame] | 715 | |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 716 | def validate_items(self): |
| 717 | # validate items to see if they have is_purchase_item or is_subcontracted_item enabled |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 718 | if self.doctype == "Material Request": |
| 719 | return |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 720 | |
Sagar Sharma | 77db843 | 2022-05-05 19:41:05 +0530 | [diff] [blame] | 721 | validate_item_type(self, "is_purchase_item", "purchase") |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 722 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 723 | |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 724 | def get_asset_item_details(asset_items): |
| 725 | asset_items_data = {} |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 726 | for d in frappe.get_all( |
| 727 | "Item", |
| 728 | fields=["name", "auto_create_assets", "asset_naming_series", "is_grouped_asset"], |
| 729 | filters={"name": ("in", asset_items)}, |
| 730 | ): |
Rohit Waghchaure | ab84254 | 2018-04-26 19:18:29 +0530 | [diff] [blame] | 731 | asset_items_data.setdefault(d.name, d) |
| 732 | |
| 733 | return asset_items_data |
Ameya Shenoy | 873e28d | 2018-06-06 05:53:19 +0000 | [diff] [blame] | 734 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 735 | |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 736 | def validate_item_type(doc, fieldname, message): |
| 737 | # iterate through items and check if they are valid sales or purchase items |
Zarrar | 7c088ff | 2018-06-05 10:32:09 +0530 | [diff] [blame] | 738 | items = [d.item_code for d in doc.items if d.item_code] |
| 739 | |
| 740 | # No validation check inase of creating transaction using 'Opening Invoice Creation Tool' |
| 741 | if not items: |
| 742 | return |
| 743 | |
Suraj Shetty | bfc195d | 2018-09-21 10:20:52 +0530 | [diff] [blame] | 744 | item_list = ", ".join(["%s" % frappe.db.escape(d) for d in items]) |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 745 | |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 746 | invalid_items = [ |
| 747 | d[0] |
| 748 | for d in frappe.db.sql( |
| 749 | """ |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 750 | select item_code from tabItem where name in ({0}) and {1}=0 |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 751 | """.format( |
| 752 | item_list, fieldname |
| 753 | ), |
| 754 | as_list=True, |
| 755 | ) |
| 756 | ] |
Zarrar | fc03a04 | 2018-06-04 12:52:52 +0530 | [diff] [blame] | 757 | |
| 758 | if invalid_items: |
Faris Ansari | 2ab6e0e | 2018-09-19 13:13:59 +0530 | [diff] [blame] | 759 | items = ", ".join([d for d in invalid_items]) |
| 760 | |
| 761 | if len(invalid_items) > 1: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 762 | error_message = _( |
| 763 | "Following items {0} are not marked as {1} item. You can enable them as {1} item from its Item master" |
| 764 | ).format(items, message) |
Faris Ansari | 2ab6e0e | 2018-09-19 13:13:59 +0530 | [diff] [blame] | 765 | else: |
Ankush Menat | 494bd9e | 2022-03-28 18:52:46 +0530 | [diff] [blame] | 766 | error_message = _( |
| 767 | "Following item {0} is not marked as {1} item. You can enable them as {1} item from its Item master" |
| 768 | ).format(items, message) |
Faris Ansari | 2ab6e0e | 2018-09-19 13:13:59 +0530 | [diff] [blame] | 769 | |
| 770 | frappe.throw(error_message) |