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