brotherton-erpnext/erpnext/accounts/report/share_ledger/share_ledger.py
Ameya Shenoy 5c33a04043 Shareholder and related doctypes ()
* Added doctypes related to shares

- Shareholder doctype, the entity who does the transaction
- Share doctype, a child table to kepp list of all shares
- Share Transfer doctype, Logs of all made transactions

* Added logic for share transfer

- update shareholder automatically on share transfer/issue/purchase
- purchase and transfer have method remove_share which doesn't get executed because of some bug

* Added report view for share ledger

* Removed share number tracking

- removed share number tracking from Share Ledger child table for Shareholder doctype
- new doctype Share Type created

* Share Balance report added

- math behind Share Balance report needs fixing

* Changes in shareholder

- Share numbers are not tracked in Shareholder
- Share Ledger doctype deleted
- Share Balance Report bug fixed

* Shareholder

- fixed report for share balance
- remove bug from share transfer by making share type mandatory
- added buttons to shareholder for direct link to report

* Added tests for Share Transfer

* minor codacy fixes

* Added Shareholder to Party Type

* rate in share ledger & balance report is currency

* First attempt at modelling shares after Item

* Share Manager changes

- on creation of shareholder party it should check if the same combo exists
- in shareholder party make report button visible iff folio no exists
- create folio no on creation of share transfer iff it doesnt already exist
- move reports from shareholder to shareholder party

* Shareholder chages

- delete share child table doctype
- autoname added to folio no
- modify tests for share transfer

* minor changes

* removed share_no child doctype

* Restructured Share Transfer Logic (not tested)

- Everything revolves around Share Balance child table in Shareholder Party
- is_company flag still to be utilized

* Tested Share Tranfer

* minor fixes

* started new shareholder structure

* modified shareholder

* renamed Shareholder Party to Shareholder

* Shareholder rewrite complete

* new tests for shareholder written

* codacy fixes

* Added documentation
2018-02-12 11:32:47 +05:30

63 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, cint, getdate
from frappe import msgprint, _
def execute(filters=None):
if not filters: filters = {}
if not filters.get("date"):
frappe.throw(_("Please select date"))
columns = get_columns(filters)
date = filters.get("date")
data = []
if not filters.get("shareholder"):
pass
else:
transfers = get_all_transfers(date, filters.get("shareholder"))
for transfer in transfers:
if transfer.transfer_type == 'Transfer':
if transfer.from_shareholder == filters.get("shareholder"):
transfer.transfer_type += ' to {}'.format(transfer.to_shareholder)
else:
transfer.transfer_type += ' from {}'.format(transfer.from_shareholder)
row = [filters.get("shareholder"), transfer.date, transfer.transfer_type,
transfer.share_type, transfer.no_of_shares, transfer.rate, transfer.amount,
transfer.company, transfer.name]
data.append(row)
return columns, data
def get_columns(filters):
columns = [
_("Shareholder") + ":Link/Shareholder:150",
_("Date") + ":Date:100",
_("Transfer Type") + "::140",
_("Share Type") + "::90",
_("No of Shares") + "::90",
_("Rate") + ":Currency:90",
_("Amount") + ":Currency:90",
_("Company") + "::150",
_("Share Transfer") + ":Link/Share Transfer:90"
]
return columns
def get_all_transfers(date, shareholder):
condition = ' '
# if company:
# condition = 'AND company = %(company)s '
return frappe.db.sql("""SELECT * FROM `tabShare Transfer`
WHERE (DATE(date) <= %(date)s AND from_shareholder = %(shareholder)s {condition})
OR (DATE(date) <= %(date)s AND to_shareholder = %(shareholder)s {condition})
ORDER BY date""".format(condition=condition),
{'date': date, 'shareholder': shareholder}, as_dict=1)