Anand Doshi | 756dca7 | 2013-01-15 18:39:21 +0530 | [diff] [blame] | 1 | # ERPNext - web based ERP (http://erpnext.com) |
| 2 | # Copyright (C) 2012 Web Notes Technologies Pvt Ltd |
| 3 | # |
| 4 | # This program is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | from __future__ import unicode_literals |
| 18 | import webnotes |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 19 | from webnotes import _, msgprint |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 20 | from webnotes.utils import flt |
Anand Doshi | 756dca7 | 2013-01-15 18:39:21 +0530 | [diff] [blame] | 21 | |
| 22 | from buying.utils import get_item_details |
Anand Doshi | f8f0c0d | 2013-01-17 20:20:56 +0530 | [diff] [blame] | 23 | from setup.utils import get_company_currency |
Anand Doshi | 756dca7 | 2013-01-15 18:39:21 +0530 | [diff] [blame] | 24 | |
Nabin Hait | 89a94d8 | 2013-03-19 12:01:46 +0530 | [diff] [blame] | 25 | from controllers.stock_controller import StockController |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 26 | |
Rushabh Mehta | ecb36f2 | 2013-05-02 11:34:37 +0530 | [diff] [blame] | 27 | class WrongWarehouseCompany(Exception): pass |
| 28 | |
Nabin Hait | 89a94d8 | 2013-03-19 12:01:46 +0530 | [diff] [blame] | 29 | class BuyingController(StockController): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 30 | def onload_post_render(self): |
| 31 | self.set_price_list_currency("buying") |
| 32 | |
| 33 | # contact, address, item details |
| 34 | self.set_missing_values() |
| 35 | |
| 36 | self.set_taxes("Purchase Taxes and Charges", "purchase_tax_details", "purchase_other_charges") |
| 37 | |
Saurabh | 6f75318 | 2013-03-20 12:55:28 +0530 | [diff] [blame] | 38 | def validate(self): |
| 39 | super(BuyingController, self).validate() |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 40 | self.validate_stock_or_nonstock_items() |
Rushabh Mehta | ecb36f2 | 2013-05-02 11:34:37 +0530 | [diff] [blame] | 41 | self.validate_warehouse_belongs_to_company() |
Anand Doshi | 1dde46a | 2013-05-15 21:15:57 +0530 | [diff] [blame] | 42 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 43 | def set_missing_values(self, for_validate=False): |
| 44 | # set contact and address details for supplier, if they are not mentioned |
| 45 | if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address): |
| 46 | for fieldname, val in self.get_default_address_and_contact("supplier").items(): |
| 47 | if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): |
| 48 | self.doc.fields[fieldname] = val |
| 49 | |
| 50 | self.set_missing_item_details(get_item_details) |
| 51 | |
| 52 | def set_supplier_defaults(self): |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 53 | self.doc.fields.update(self.get_default_supplier_address(self.doc.fields)) |
Saurabh | 6f75318 | 2013-03-20 12:55:28 +0530 | [diff] [blame] | 54 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 55 | def get_purchase_tax_details(self): |
| 56 | self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details") |
Anand Doshi | 27a9816 | 2013-06-10 16:32:55 +0530 | [diff] [blame] | 57 | self.set_taxes("Purchase Taxes and Charges", "purchase_tax_details", "purchase_other_charges") |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 58 | |
Rushabh Mehta | ecb36f2 | 2013-05-02 11:34:37 +0530 | [diff] [blame] | 59 | def validate_warehouse_belongs_to_company(self): |
Rushabh Mehta | c711598 | 2013-05-02 14:22:40 +0530 | [diff] [blame] | 60 | for warehouse, company in webnotes.conn.get_values("Warehouse", |
| 61 | self.doclist.get_distinct_values("warehouse"), "company").items(): |
| 62 | if company and company != self.doc.company: |
Anand Doshi | eb41ffd | 2013-05-02 18:10:19 +0530 | [diff] [blame] | 63 | webnotes.msgprint(_("Company mismatch for Warehouse") + (": %s" % (warehouse,)), |
Rushabh Mehta | ecb36f2 | 2013-05-02 11:34:37 +0530 | [diff] [blame] | 64 | raise_exception=WrongWarehouseCompany) |
Rushabh Mehta | c711598 | 2013-05-02 14:22:40 +0530 | [diff] [blame] | 65 | |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 66 | def validate_stock_or_nonstock_items(self): |
| 67 | items = [d.item_code for d in self.doclist.get({"parentfield": self.fname})] |
Nabin Hait | d58d1b5 | 2013-04-26 17:25:44 +0530 | [diff] [blame] | 68 | if self.stock_items: |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 69 | nonstock_items = list(set(items) - set(self.stock_items)) |
Nabin Hait | d58d1b5 | 2013-04-26 17:25:44 +0530 | [diff] [blame] | 70 | if nonstock_items: |
| 71 | webnotes.msgprint(_("Stock and non-stock items can not be entered in the same ") + |
| 72 | self.doc.doctype + _(""". You should make separate documents for them. |
| 73 | Stock Items: """) + ", ".join(self.stock_items) + _(""" |
| 74 | Non-stock Items: """) + ", ".join(nonstock_items), raise_exception=1) |
Nabin Hait | 205f7ce | 2013-04-26 13:35:06 +0530 | [diff] [blame] | 75 | |
| 76 | elif items and not self.stock_items: |
| 77 | tax_for_valuation = [d.account_head for d in |
| 78 | self.doclist.get({"parentfield": "purchase_tax_details"}) |
| 79 | if d.category in ["Valuation", "Valuation and Total"]] |
| 80 | if tax_for_valuation: |
| 81 | webnotes.msgprint(_("""Tax Category can not be 'Valuation' or 'Valuation and Total' |
| 82 | as all items are non-stock items"""), raise_exception=1) |
| 83 | |
Nabin Hait | d3b6250 | 2013-01-21 17:24:31 +0530 | [diff] [blame] | 84 | def set_total_in_words(self): |
Nabin Hait | 5b4c294 | 2013-01-22 11:12:02 +0530 | [diff] [blame] | 85 | from webnotes.utils import money_in_words |
Nabin Hait | d3b6250 | 2013-01-21 17:24:31 +0530 | [diff] [blame] | 86 | company_currency = get_company_currency(self.doc.company) |
Nabin Hait | 5b4c294 | 2013-01-22 11:12:02 +0530 | [diff] [blame] | 87 | if self.meta.get_field("in_words"): |
| 88 | self.doc.in_words = money_in_words(self.doc.grand_total, company_currency) |
| 89 | if self.meta.get_field("in_words_import"): |
| 90 | self.doc.in_words_import = money_in_words(self.doc.grand_total_import, |
Anand Doshi | 613cb6a | 2013-02-06 17:33:46 +0530 | [diff] [blame] | 91 | self.doc.currency) |
| 92 | |
| 93 | def calculate_taxes_and_totals(self): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 94 | self.other_fname = "purchase_tax_details" |
| 95 | super(BuyingController, self).calculate_taxes_and_totals() |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 96 | self.calculate_total_advance("Purchase Invoice", "advance_allocation_details") |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 97 | |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 98 | def calculate_item_values(self): |
Anand Doshi | b8b1e58 | 2013-05-06 12:52:46 +0530 | [diff] [blame] | 99 | # hack! - cleaned up in _cleanup() |
| 100 | if self.doc.doctype != "Purchase Invoice": |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 101 | df = self.meta.get_field("purchase_rate", parentfield=self.fname) |
| 102 | df.fieldname = "rate" |
Anand Doshi | a1d4b78 | 2013-02-26 18:09:47 +0530 | [diff] [blame] | 103 | |
Anand Doshi | b8b1e58 | 2013-05-06 12:52:46 +0530 | [diff] [blame] | 104 | for item in self.item_doclist: |
Anand Doshi | a1d4b78 | 2013-02-26 18:09:47 +0530 | [diff] [blame] | 105 | # hack! - cleaned up in _cleanup() |
| 106 | if self.doc.doctype != "Purchase Invoice": |
| 107 | item.rate = item.purchase_rate |
Anand Doshi | a1d4b78 | 2013-02-26 18:09:47 +0530 | [diff] [blame] | 108 | |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 109 | self.round_floats_in(item) |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 110 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 111 | if item.discount_rate == 100.0: |
| 112 | item.import_rate = 0.0 |
| 113 | elif item.import_ref_rate: |
| 114 | item.import_rate = flt(item.import_ref_rate * (1.0 - (item.discount_rate / 100.0)), |
| 115 | self.precision("import_rate", item)) |
Anand Doshi | a1d4b78 | 2013-02-26 18:09:47 +0530 | [diff] [blame] | 116 | |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 117 | item.import_amount = flt(item.import_rate * item.qty, |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 118 | self.precision("import_amount", item)) |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 119 | item.item_tax_amount = 0.0; |
Anand Doshi | a1d4b78 | 2013-02-26 18:09:47 +0530 | [diff] [blame] | 120 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 121 | self._set_in_company_currency(item, "import_ref_rate", "purchase_ref_rate") |
| 122 | self._set_in_company_currency(item, "import_rate", "rate") |
| 123 | self._set_in_company_currency(item, "import_amount", "amount") |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 124 | |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 125 | def calculate_net_total(self): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 126 | self.doc.net_total = self.doc.net_total_import = 0.0 |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 127 | |
| 128 | for item in self.item_doclist: |
| 129 | self.doc.net_total += item.amount |
| 130 | self.doc.net_total_import += item.import_amount |
| 131 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 132 | self.round_floats_in(self.doc, ["net_total", "net_total_import"]) |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 133 | |
| 134 | def calculate_totals(self): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 135 | self.doc.grand_total = flt(self.tax_doclist and \ |
| 136 | self.tax_doclist[-1].total or self.doc.net_total, self.precision("grand_total")) |
| 137 | self.doc.grand_total_import = flt(self.doc.grand_total / self.doc.conversion_rate, |
| 138 | self.precision("grand_total_import")) |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 139 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 140 | self.doc.total_tax = flt(self.doc.grand_total - self.doc.net_total, |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 141 | self.precision("total_tax")) |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 142 | |
| 143 | if self.meta.get_field("rounded_total"): |
| 144 | self.doc.rounded_total = round(self.doc.grand_total) |
| 145 | |
| 146 | if self.meta.get_field("rounded_total_import"): |
| 147 | self.doc.rounded_total_import = round(self.doc.grand_total_import) |
| 148 | |
| 149 | def calculate_outstanding_amount(self): |
Anand Doshi | c99853c | 2013-05-14 13:35:09 +0530 | [diff] [blame] | 150 | if self.doc.doctype == "Purchase Invoice" and self.doc.docstatus < 2: |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 151 | self.doc.total_advance = flt(self.doc.total_advance, |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 152 | self.precision("total_advance")) |
Anand Doshi | 9d794fc | 2013-02-27 13:34:22 +0530 | [diff] [blame] | 153 | self.doc.total_amount_to_pay = flt(self.doc.grand_total - flt(self.doc.write_off_amount, |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 154 | self.precision("write_off_amount")), self.precision("total_amount_to_pay")) |
Anand Doshi | 9d794fc | 2013-02-27 13:34:22 +0530 | [diff] [blame] | 155 | self.doc.outstanding_amount = flt(self.doc.total_amount_to_pay - self.doc.total_advance, |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 156 | self.precision("outstanding_amount")) |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 157 | |
| 158 | def _cleanup(self): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 159 | super(BuyingController, self)._cleanup() |
| 160 | |
| 161 | # except in purchase invoice, rate field is purchase_rate |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 162 | # reset fieldname of rate |
| 163 | if self.doc.doctype != "Purchase Invoice": |
| 164 | df = self.meta.get_field("rate", parentfield=self.fname) |
| 165 | df.fieldname = "purchase_rate" |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 166 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 167 | for item in self.item_doclist: |
| 168 | item.purchase_rate = item.rate |
| 169 | del item.fields["rate"] |
Anand Doshi | b392878 | 2013-06-05 17:46:20 +0530 | [diff] [blame] | 170 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 171 | if not self.meta.get_field("item_tax_amount", parentfield=self.fname): |
| 172 | for item in self.item_doclist: |
| 173 | del item.fields["item_tax_amount"] |
| 174 | |
Anand Doshi | 8595fcf | 2013-02-08 19:28:14 +0530 | [diff] [blame] | 175 | def set_item_tax_amount(self, item, tax, current_tax_amount): |
| 176 | """ |
| 177 | item_tax_amount is the total tax amount applied on that item |
| 178 | stored for valuation |
| 179 | |
| 180 | TODO: rename item_tax_amount to valuation_tax_amount |
| 181 | """ |
Anand Doshi | b392878 | 2013-06-05 17:46:20 +0530 | [diff] [blame] | 182 | if tax.category in ["Valuation", "Valuation and Total"] and \ |
| 183 | self.meta.get_field("item_tax_amount", parentfield=self.fname): |
| 184 | item.item_tax_amount += flt(current_tax_amount, self.precision("item_tax_amount", item)) |
Anand Doshi | 4a7248e | 2013-02-27 18:10:30 +0530 | [diff] [blame] | 185 | |
| 186 | # update valuation rate |
| 187 | def update_valuation_rate(self, parentfield): |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 188 | for item in self.doclist.get({"parentfield": parentfield}): |
| 189 | item.conversion_factor = item.conversion_factor or flt(webnotes.conn.get_value( |
| 190 | "UOM Conversion Detail", {"parent": item.item_code, "uom": item.uom}, |
Nabin Hait | 0fc2454 | 2013-03-25 11:06:00 +0530 | [diff] [blame] | 191 | "conversion_factor")) or 1 |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 192 | |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 193 | if item.item_code and item.qty: |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 194 | self.round_floats_in(item) |
| 195 | |
| 196 | purchase_rate = item.rate if self.doc.doctype == "Purchase Invoice" else item.purchase_rate |
| 197 | |
Anand Doshi | 1bfec3a | 2013-02-28 19:17:46 +0530 | [diff] [blame] | 198 | # if no item code, which is sometimes the case in purchase invoice, |
| 199 | # then it is not possible to track valuation against it |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 200 | item.valuation_rate = flt((purchase_rate + |
| 201 | (item.item_tax_amount + item.rm_supp_cost) / item.qty) / item.conversion_factor, |
| 202 | self.precision("valuation_rate", item)) |
Anand Doshi | 4a7248e | 2013-02-27 18:10:30 +0530 | [diff] [blame] | 203 | else: |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 204 | item.valuation_rate = 0.0 |
Nabin Hait | 54d209f | 2013-03-01 18:51:10 +0530 | [diff] [blame] | 205 | |
| 206 | def validate_for_subcontracting(self): |
| 207 | if not self.doc.is_subcontracted and self.sub_contracted_items: |
| 208 | webnotes.msgprint(_("""Please enter whether %s is made for subcontracting or purchasing, |
| 209 | in 'Is Subcontracted' field""" % self.doc.doctype), raise_exception=1) |
| 210 | |
| 211 | if self.doc.doctype == "Purchase Receipt" and self.doc.is_subcontracted=="Yes" \ |
| 212 | and not self.doc.supplier_warehouse: |
| 213 | webnotes.msgprint(_("Supplier Warehouse mandatory subcontracted purchase receipt"), |
| 214 | raise_exception=1) |
| 215 | |
| 216 | def update_raw_materials_supplied(self, raw_material_table): |
| 217 | self.doclist = self.doc.clear_table(self.doclist, raw_material_table) |
| 218 | if self.doc.is_subcontracted=="Yes": |
| 219 | for item in self.doclist.get({"parentfield": self.fname}): |
| 220 | if item.item_code in self.sub_contracted_items: |
| 221 | self.add_bom_items(item, raw_material_table) |
| 222 | |
| 223 | def add_bom_items(self, d, raw_material_table): |
| 224 | bom_items = self.get_items_from_default_bom(d.item_code) |
| 225 | raw_materials_cost = 0 |
| 226 | for item in bom_items: |
| 227 | required_qty = flt(item.qty_consumed_per_unit) * flt(d.qty) * flt(d.conversion_factor) |
| 228 | rm_doclist = { |
| 229 | "parentfield": raw_material_table, |
| 230 | "doctype": self.doc.doctype + " Item Supplied", |
| 231 | "reference_name": d.name, |
| 232 | "bom_detail_no": item.name, |
| 233 | "main_item_code": d.item_code, |
| 234 | "rm_item_code": item.item_code, |
| 235 | "stock_uom": item.stock_uom, |
| 236 | "required_qty": required_qty, |
| 237 | "conversion_factor": d.conversion_factor, |
| 238 | "rate": item.rate, |
| 239 | "amount": required_qty * flt(item.rate) |
| 240 | } |
| 241 | if self.doc.doctype == "Purchase Receipt": |
| 242 | rm_doclist.update({ |
| 243 | "consumed_qty": required_qty, |
| 244 | "description": item.description, |
| 245 | }) |
| 246 | |
| 247 | self.doclist.append(rm_doclist) |
| 248 | |
| 249 | raw_materials_cost += required_qty * flt(item.rate) |
| 250 | |
| 251 | if self.doc.doctype == "Purchase Receipt": |
| 252 | d.rm_supp_cost = raw_materials_cost |
| 253 | |
| 254 | def get_items_from_default_bom(self, item_code): |
| 255 | # print webnotes.conn.sql("""select name from `tabBOM` where item = '_Test FG Item'""") |
| 256 | bom_items = webnotes.conn.sql("""select t2.item_code, t2.qty_consumed_per_unit, |
| 257 | t2.rate, t2.stock_uom, t2.name, t2.description |
| 258 | from `tabBOM` t1, `tabBOM Item` t2 |
| 259 | where t2.parent = t1.name and t1.item = %s and t1.is_default = 1 |
| 260 | and t1.docstatus = 1 and t1.is_active = 1""", item_code, as_dict=1) |
| 261 | if not bom_items: |
| 262 | msgprint(_("No default BOM exists for item: ") + item_code, raise_exception=1) |
| 263 | |
| 264 | return bom_items |
| 265 | |
Nabin Hait | 5418d71 | 2013-02-27 18:11:17 +0530 | [diff] [blame] | 266 | @property |
| 267 | def sub_contracted_items(self): |
| 268 | if not hasattr(self, "_sub_contracted_items"): |
Nabin Hait | ebd5144 | 2013-04-23 15:36:26 +0530 | [diff] [blame] | 269 | self._sub_contracted_items = [] |
Nabin Hait | 5418d71 | 2013-02-27 18:11:17 +0530 | [diff] [blame] | 270 | item_codes = list(set(item.item_code for item in |
| 271 | self.doclist.get({"parentfield": self.fname}))) |
Nabin Hait | ebd5144 | 2013-04-23 15:36:26 +0530 | [diff] [blame] | 272 | if item_codes: |
| 273 | self._sub_contracted_items = [r[0] for r in webnotes.conn.sql("""select name |
| 274 | from `tabItem` where name in (%s) and is_sub_contracted_item='Yes'""" % \ |
| 275 | (", ".join((["%s"]*len(item_codes))),), item_codes)] |
Nabin Hait | 5418d71 | 2013-02-27 18:11:17 +0530 | [diff] [blame] | 276 | |
| 277 | return self._sub_contracted_items |
| 278 | |
| 279 | @property |
| 280 | def purchase_items(self): |
| 281 | if not hasattr(self, "_purchase_items"): |
Nabin Hait | ebd5144 | 2013-04-23 15:36:26 +0530 | [diff] [blame] | 282 | self._purchase_items = [] |
Nabin Hait | 5418d71 | 2013-02-27 18:11:17 +0530 | [diff] [blame] | 283 | item_codes = list(set(item.item_code for item in |
| 284 | self.doclist.get({"parentfield": self.fname}))) |
Nabin Hait | ebd5144 | 2013-04-23 15:36:26 +0530 | [diff] [blame] | 285 | if item_codes: |
| 286 | self._purchase_items = [r[0] for r in webnotes.conn.sql("""select name |
| 287 | from `tabItem` where name in (%s) and is_purchase_item='Yes'""" % \ |
| 288 | (", ".join((["%s"]*len(item_codes))),), item_codes)] |
Nabin Hait | 5418d71 | 2013-02-27 18:11:17 +0530 | [diff] [blame] | 289 | |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 290 | return self._purchase_items |