Exemple #1
0
def initialize_gle_map(gl_entries, filters):
    gle_map = OrderedDict()
    group_by = 'account'

    for gle in gl_entries:
        gle_map.setdefault(gle.get(group_by),
                           _dict(totals=get_totals_dict(), entries=[]))
    return gle_map
Exemple #2
0
def get_accountwise_gle(filters, gl_entries, gle_map):
    totals = get_totals_dict()
    entries = []
    consolidated_gle = OrderedDict()
    group_by = 'account'

    def update_value_in_dict(data, key, gle):
        data[key].debit += flt(gle.debit)
        data[key].credit += flt(gle.credit)

        data[key].debit_in_account_currency += flt(
            gle.debit_in_account_currency)
        data[key].credit_in_account_currency += flt(
            gle.credit_in_account_currency)

        if data[key].against_voucher and gle.against_voucher:
            data[key].against_voucher += ', ' + gle.against_voucher

    from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
    for gle in gl_entries:
        if (gle.posting_date < from_date
                or (cstr(gle.is_opening) == "Yes"
                    and not filters.get("show_opening_entries"))):
            update_value_in_dict(gle_map[gle.get(group_by)].totals, 'opening',
                                 gle)
            update_value_in_dict(totals, 'opening', gle)

            update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing',
                                 gle)
            update_value_in_dict(totals, 'closing', gle)

        elif gle.posting_date <= to_date:
            update_value_in_dict(gle_map[gle.get(group_by)].totals, 'total',
                                 gle)
            update_value_in_dict(totals, 'total', gle)
            key = (gle.get("voucher_type"), gle.get("voucher_no"),
                   gle.get("account"), gle.get("cost_center"))
            if key not in consolidated_gle:
                consolidated_gle.setdefault(key, gle)
            else:
                update_value_in_dict(consolidated_gle, key, gle)

            update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing',
                                 gle)
            update_value_in_dict(totals, 'closing', gle)

    for key, value in consolidated_gle.items():
        entries.append(value)

    return totals, entries