brotherton-erpnext/erpnext/accounts/report/share_ledger/share_ledger.py
Chillar Anand 915b34391c
chore: Clean up imports (#27302)
* chore: Added isort to pre-commit config

* chore: Sort imports with isort

* chore: Clean up imports with pycln

* chore: Sort imports with isort

* chore: Fix import issues

* chore: Clean up sider issues

* chore: Remove import errors from flake8 ignore list

* chore: Clean up lint issues
2021-09-02 16:44:59 +05:30

64 lines
1.8 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 import _
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)