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