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