Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +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 |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 19 | from webnotes.utils import flt |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 20 | from utilities.transaction_base import TransactionBase |
Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +0530 | [diff] [blame] | 21 | |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 22 | class AccountsController(TransactionBase): |
Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +0530 | [diff] [blame] | 23 | def get_gl_dict(self, args, cancel): |
| 24 | """this method populates the common properties of a gl entry record""" |
| 25 | gl_dict = { |
| 26 | 'company': self.doc.company, |
| 27 | 'posting_date': self.doc.posting_date, |
| 28 | 'voucher_type': self.doc.doctype, |
| 29 | 'voucher_no': self.doc.name, |
| 30 | 'aging_date': self.doc.fields.get("aging_date") or self.doc.posting_date, |
| 31 | 'remarks': self.doc.remarks, |
| 32 | 'is_cancelled': cancel and "Yes" or "No", |
| 33 | 'fiscal_year': self.doc.fiscal_year, |
| 34 | 'debit': 0, |
| 35 | 'credit': 0, |
| 36 | 'is_opening': self.doc.fields.get("is_opening") or "No", |
| 37 | } |
| 38 | gl_dict.update(args) |
| 39 | return gl_dict |
Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +0530 | [diff] [blame] | 40 | |
| 41 | def get_stock_in_hand_account(self): |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 42 | stock_in_hand = webnotes.conn.get_value("Company", self.doc.company, "stock_in_hand") |
Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +0530 | [diff] [blame] | 43 | if not stock_in_hand: |
| 44 | webnotes.msgprint("""Please specify "Stock In Hand" account |
| 45 | for company: %s""" % (self.doc.company,), raise_exception=1) |
Nabin Hait | 6f06596 | 2013-01-30 19:23:32 +0530 | [diff] [blame] | 46 | |
Nabin Hait | 2df4d54 | 2013-01-29 11:34:39 +0530 | [diff] [blame] | 47 | return stock_in_hand |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 48 | |
Anand Doshi | 613cb6a | 2013-02-06 17:33:46 +0530 | [diff] [blame] | 49 | def clear_unallocated_advances(self, childtype, parentfield): |
| 50 | self.doclist.remove_items({"parentfield": parentfield, "allocated_amount": ["in", [0, None, ""]]}) |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 51 | |
Anand Doshi | 613cb6a | 2013-02-06 17:33:46 +0530 | [diff] [blame] | 52 | webnotes.conn.sql("""delete from `tab%s` where parentfield=%s and parent = %s |
| 53 | and ifnull(allocated_amount, 0) = 0""" % (childtype, '%s', '%s'), (parentfield, self.doc.name)) |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 54 | |
Anand Doshi | 613cb6a | 2013-02-06 17:33:46 +0530 | [diff] [blame] | 55 | def get_advances(self, account_head, child_doctype, parentfield, dr_or_cr): |
Nabin Hait | fb3fd6e | 2013-01-30 19:16:13 +0530 | [diff] [blame] | 56 | res = webnotes.conn.sql("""select t1.name as jv_no, t1.remark, |
| 57 | t2.%s as amount, t2.name as jv_detail_no |
| 58 | from `tabJournal Voucher` t1, `tabJournal Voucher Detail` t2 |
| 59 | where t1.name = t2.parent and t2.account = %s and t2.is_advance = 'Yes' |
| 60 | and (t2.against_voucher is null or t2.against_voucher = '') |
| 61 | and (t2.against_invoice is null or t2.against_invoice = '') |
| 62 | and (t2.against_jv is null or t2.against_jv = '') |
| 63 | and t1.docstatus = 1 order by t1.posting_date""" % |
| 64 | (dr_or_cr, '%s'), account_head, as_dict=1) |
| 65 | |
| 66 | self.doclist = self.doc.clear_table(self.doclist, parentfield) |
| 67 | for d in res: |
Anand Doshi | 613cb6a | 2013-02-06 17:33:46 +0530 | [diff] [blame] | 68 | self.doclist.append({ |
| 69 | "doctype": child_doctype, |
| 70 | "parentfield": parentfield, |
| 71 | "journal_voucher": d.jv_no, |
| 72 | "jv_detail_no": d.jv_detail_no, |
| 73 | "remarks": d.remark, |
| 74 | "advance_amount": flt(d.amount), |
| 75 | "allocate_amount": 0 |
| 76 | }) |