blob: a7dbde1ecef7249f4c3ba9ab8fe8cd9341e197ea [file] [log] [blame]
Anand Doshic2fb0392012-11-29 19:55:30 +05301# 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
17from __future__ import unicode_literals
18import webnotes
19import webnotes.model
Anand Doshi0fd99e72012-11-30 16:38:04 +053020from webnotes import _, DictObj
21from webnotes.utils import cint
Anand Doshic2fb0392012-11-29 19:55:30 +053022import json
23
Anand Doshic2fb0392012-11-29 19:55:30 +053024from webnotes.model.controller import DocListController
25
26class 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"):
35 self._precision = DictObj()
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"]:
72 self._fmap = webnotes.DictObj( {
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",
93 })
94 else:
95 self._fmap = webnotes.DictObj({
96 "exchange_rate": "conversion_rate",
97 "taxes_and_charges": "purchase_tax_details",
98 "taxes_and_charges_master": "purchase_other_charges",
99 "taxes_and_charges_total": "total_tax",
100 "net_total_print": "net_total_import",
101 "grand_total_print": "grand_total_import",
102 "grand_total_in_words": "in_words",
103 "grand_total_in_words_print": "in_words_import",
104 "rounded_total_print": "rounded_total_print",
105 "rounded_total_in_words": "rounded_total_in_words",
106 "rounded_total_in_words_print": "rounded_total_in_words_print",
107 "print_ref_rate": "import_ref_rate",
108 "discount": "discount_rate",
109 "print_rate": "import_rate",
110 "print_amount": "import_amount",
111 "ref_rate": "purchase_ref_rate",
112 "rate": "purchase_rate",
113
114 "valuation_tax_amount": "item_tax_amount"
115 })
116
117 return self._fmap or webnotes.DictObj()