Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +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 |
| 19 | import webnotes.model |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 20 | from webnotes import _, _dict |
Anand Doshi | 0fd99e7 | 2012-11-30 16:38:04 +0530 | [diff] [blame] | 21 | from webnotes.utils import cint |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 22 | import json |
| 23 | |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 24 | from webnotes.model.controller import DocListController |
| 25 | |
| 26 | class TransactionController(DocListController): |
| 27 | def __init__(self, doc, doclist): |
| 28 | super(TransactionController, self).__init__(doc, doclist) |
| 29 | self.cur_docstatus = cint(webnotes.conn.get_value(self.doc.doctype, |
| 30 | self.doc.name, "docstatus")) |
| 31 | |
| 32 | @property |
| 33 | def precision(self): |
| 34 | if not hasattr(self, "_precision"): |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 35 | self._precision = _dict() |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 36 | self._precision.main = self.meta.get_precision_map() |
| 37 | self._precision.item = self.meta.get_precision_map(parentfield = \ |
| 38 | self.item_table_field) |
| 39 | if self.meta.get_field(self.fmap.taxes_and_charges): |
| 40 | self._precision.tax = self.meta.get_precision_map(parentfield = \ |
| 41 | self.fmap.taxes_and_charges) |
| 42 | return self._precision |
| 43 | |
| 44 | @property |
| 45 | def item_doclist(self): |
| 46 | if not hasattr(self, "_item_doclist"): |
| 47 | self._item_doclist = self.doclist.get({"parentfield": self.item_table_field}) |
| 48 | return self._item_doclist |
| 49 | |
| 50 | @property |
| 51 | def tax_doclist(self): |
| 52 | if not hasattr(self, "_tax_doclist"): |
| 53 | self._tax_doclist = self.doclist.get( |
| 54 | {"parentfield": self.fmap.taxes_and_charges}) |
| 55 | return self._tax_doclist |
| 56 | |
| 57 | @property |
| 58 | def stock_items(self): |
| 59 | if not hasattr(self, "_stock_items"): |
| 60 | item_codes = list(set(item.item_code for item in self.item_doclist)) |
| 61 | self._stock_items = [r[0] for r in webnotes.conn.sql("""select name |
| 62 | from `tabItem` where name in (%s) and is_stock_item='Yes'""" % \ |
| 63 | (", ".join((["%s"]*len(item_codes))),), item_codes)] |
| 64 | |
| 65 | return self._stock_items |
| 66 | |
| 67 | @property |
| 68 | def fmap(self): |
| 69 | if not hasattr(self, "_fmap"): |
| 70 | if self.doc.doctype in ["Lead", "Quotation", "Sales Order", "Sales Invoice", |
| 71 | "Delivery Note"]: |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 72 | self._fmap = webnotes._dict( { |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 73 | "exchange_rate": "conversion_rate", |
| 74 | "taxes_and_charges": "other_charges", |
| 75 | "taxes_and_charges_master": "charge", |
| 76 | "taxes_and_charges_total": "other_charges_total", |
| 77 | "net_total_print": "net_total_print", |
| 78 | "grand_total_print": "grand_total_export", |
| 79 | "grand_total_in_words": "grand_total_in_words", |
| 80 | "grand_total_in_words_print": "grand_total_in_words_print", |
| 81 | "rounded_total_print": "rounded_total_export", |
| 82 | "rounded_total_in_words": "in_words", |
| 83 | "rounded_total_in_words_print": "in_words_export", |
| 84 | "print_ref_rate": "ref_rate", |
| 85 | "discount": "adj_rate", |
| 86 | "print_rate": "export_rate", |
| 87 | "print_amount": "export_amount", |
| 88 | "ref_rate": "base_ref_rate", |
| 89 | "rate": "basic_rate", |
| 90 | |
| 91 | "plc_exchange_rate": "plc_conversion_rate", |
| 92 | "tax_calculation": "other_charges_calculation", |
Anand Doshi | 188f977 | 2012-12-04 16:17:48 +0530 | [diff] [blame] | 93 | "cost_center": "cost_center_other_charges", |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 94 | }) |
| 95 | else: |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 96 | self._fmap = webnotes._dict({ |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 97 | "exchange_rate": "conversion_rate", |
| 98 | "taxes_and_charges": "purchase_tax_details", |
| 99 | "taxes_and_charges_master": "purchase_other_charges", |
| 100 | "taxes_and_charges_total": "total_tax", |
| 101 | "net_total_print": "net_total_import", |
| 102 | "grand_total_print": "grand_total_import", |
| 103 | "grand_total_in_words": "in_words", |
| 104 | "grand_total_in_words_print": "in_words_import", |
| 105 | "rounded_total_print": "rounded_total_print", |
| 106 | "rounded_total_in_words": "rounded_total_in_words", |
| 107 | "rounded_total_in_words_print": "rounded_total_in_words_print", |
| 108 | "print_ref_rate": "import_ref_rate", |
| 109 | "discount": "discount_rate", |
| 110 | "print_rate": "import_rate", |
| 111 | "print_amount": "import_amount", |
| 112 | "ref_rate": "purchase_ref_rate", |
| 113 | "rate": "purchase_rate", |
| 114 | |
| 115 | "valuation_tax_amount": "item_tax_amount" |
| 116 | }) |
Anand Doshi | 188f977 | 2012-12-04 16:17:48 +0530 | [diff] [blame] | 117 | |
| 118 | if self.doc.doctype == "Purchase Invoice": |
| 119 | self._fmap.update({ |
| 120 | "rate": "rate" |
| 121 | }) |
Anand Doshi | c2fb039 | 2012-11-29 19:55:30 +0530 | [diff] [blame] | 122 | |
Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 123 | return self._fmap or webnotes._dict() |