fix: auto separate against accounts
This commit is contained in:
parent
3d00d74fed
commit
ff0343d2cc
@ -676,7 +676,6 @@ class JournalEntry(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def set_against_account(self):
|
def set_against_account(self):
|
||||||
accounts_debited, accounts_credited = [], []
|
|
||||||
if self.voucher_type in ("Deferred Revenue", "Deferred Expense"):
|
if self.voucher_type in ("Deferred Revenue", "Deferred Expense"):
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.reference_type == "Sales Invoice":
|
if d.reference_type == "Sales Invoice":
|
||||||
@ -689,30 +688,40 @@ class JournalEntry(AccountsController):
|
|||||||
d.reference_type, d.reference_name, against_type.lower()
|
d.reference_type, d.reference_name, against_type.lower()
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
for d in self.get("accounts"):
|
self.get_against_accounts()
|
||||||
if flt(d.debit) > 0:
|
|
||||||
accounts_debited.append(d)
|
|
||||||
if flt(d.credit) > 0:
|
|
||||||
accounts_credited.append(d)
|
|
||||||
|
|
||||||
for d in self.get("accounts"):
|
def get_against_accounts(self):
|
||||||
if d.exchange_rate != 1.0:
|
accounts_debited, accounts_credited, against_accounts = [], [], []
|
||||||
d.against_type = d.party_type
|
split_account = {}
|
||||||
d.against_account = d.party
|
separate_against_account_entries = 1
|
||||||
elif flt(d.debit) > 0:
|
for d in self.get("accounts"):
|
||||||
for acc in accounts_credited:
|
if flt(d.debit) > 0 or flt(d.debit_in_account_currency) > 0:
|
||||||
if acc.party == d.party:
|
accounts_debited.append(d)
|
||||||
d.against_type = "Account"
|
elif flt(d.credit) > 0 or flt(d.credit_in_account_currency) > 0:
|
||||||
d.against_account = d.account
|
accounts_credited.append(d)
|
||||||
d.party_type = ""
|
|
||||||
d.party = ""
|
if d.against_account:
|
||||||
elif flt(d.credit) > 0:
|
separate_against_account_entries = 0
|
||||||
for acc in accounts_debited:
|
break
|
||||||
if acc.party == d.party:
|
|
||||||
d.against_type = "Account"
|
if separate_against_account_entries:
|
||||||
d.against_account = d.account
|
if len(accounts_credited) > 1 and len(accounts_debited) > 1:
|
||||||
d.party_type = ""
|
frappe.msgprint(
|
||||||
d.party = ""
|
_(
|
||||||
|
"Unable to automatically determine {0} accounts. Set them up in the {1} table if needed.".format(
|
||||||
|
frappe.bold("against"), frappe.bold("Accounting Entries")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
alert=True,
|
||||||
|
)
|
||||||
|
elif len(accounts_credited) == 1:
|
||||||
|
against_accounts = accounts_debited
|
||||||
|
split_account = accounts_credited[0]
|
||||||
|
elif len(accounts_debited) == 1:
|
||||||
|
against_accounts = accounts_credited
|
||||||
|
split_account = accounts_debited[0]
|
||||||
|
|
||||||
|
return separate_against_account_entries, against_accounts, split_account
|
||||||
|
|
||||||
def validate_debit_credit_amount(self):
|
def validate_debit_credit_amount(self):
|
||||||
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
|
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
|
||||||
@ -909,41 +918,75 @@ class JournalEntry(AccountsController):
|
|||||||
|
|
||||||
def build_gl_map(self):
|
def build_gl_map(self):
|
||||||
gl_map = []
|
gl_map = []
|
||||||
|
separate_against_account_entries, against_accounts, split_account = self.get_against_accounts()
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"):
|
if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"):
|
||||||
r = [d.user_remark, self.remark]
|
r = [d.user_remark, self.remark]
|
||||||
r = [x for x in r if x]
|
r = [x for x in r if x]
|
||||||
remarks = "\n".join(r)
|
remarks = "\n".join(r)
|
||||||
|
|
||||||
gl_map.append(
|
gl_dict = self.get_gl_dict(
|
||||||
self.get_gl_dict(
|
{
|
||||||
{
|
"account": d.account,
|
||||||
"account": d.account,
|
"party_type": d.party_type,
|
||||||
"party_type": d.party_type,
|
"due_date": self.due_date,
|
||||||
"due_date": self.due_date,
|
"party": d.party,
|
||||||
"party": d.party,
|
"debit": flt(d.debit, d.precision("debit")),
|
||||||
"against_type": d.against_type,
|
"credit": flt(d.credit, d.precision("credit")),
|
||||||
"against": d.against_account,
|
"account_currency": d.account_currency,
|
||||||
"debit": flt(d.debit, d.precision("debit")),
|
"debit_in_account_currency": flt(
|
||||||
"credit": flt(d.credit, d.precision("credit")),
|
d.debit_in_account_currency, d.precision("debit_in_account_currency")
|
||||||
"account_currency": d.account_currency,
|
),
|
||||||
"debit_in_account_currency": flt(
|
"credit_in_account_currency": flt(
|
||||||
d.debit_in_account_currency, d.precision("debit_in_account_currency")
|
d.credit_in_account_currency, d.precision("credit_in_account_currency")
|
||||||
),
|
),
|
||||||
"credit_in_account_currency": flt(
|
"against_voucher_type": d.reference_type,
|
||||||
d.credit_in_account_currency, d.precision("credit_in_account_currency")
|
"against_voucher": d.reference_name,
|
||||||
),
|
"remarks": remarks,
|
||||||
"against_voucher_type": d.reference_type,
|
"voucher_detail_no": d.reference_detail_no,
|
||||||
"against_voucher": d.reference_name,
|
"cost_center": d.cost_center,
|
||||||
"remarks": remarks,
|
"project": d.project,
|
||||||
"voucher_detail_no": d.reference_detail_no,
|
"finance_book": self.finance_book,
|
||||||
"cost_center": d.cost_center,
|
},
|
||||||
"project": d.project,
|
item=d,
|
||||||
"finance_book": self.finance_book,
|
|
||||||
},
|
|
||||||
item=d,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not separate_against_account_entries:
|
||||||
|
gl_dict.update({"against_type": d.against_type, "against_account": d.against_account})
|
||||||
|
gl_map.append(gl_dict)
|
||||||
|
|
||||||
|
elif d in against_accounts:
|
||||||
|
gl_dict.update(
|
||||||
|
{
|
||||||
|
"against_type": split_account.party_type or "Account",
|
||||||
|
"against_account": split_account.party or split_account.account,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
gl_map.append(gl_dict)
|
||||||
|
|
||||||
|
else:
|
||||||
|
for against_account in against_accounts:
|
||||||
|
against_account = against_account.as_dict()
|
||||||
|
debit = against_account.credit or against_account.credit_in_account_currency
|
||||||
|
credit = against_account.debit or against_account.debit_in_account_currency
|
||||||
|
gl_dict = gl_dict.copy()
|
||||||
|
gl_dict.update(
|
||||||
|
{
|
||||||
|
"against_type": against_account.party_type or "Account",
|
||||||
|
"against": against_account.party or against_account.account,
|
||||||
|
"debit": flt(debit, d.precision("debit")),
|
||||||
|
"credit": flt(credit, d.precision("credit")),
|
||||||
|
"account_currency": d.account_currency,
|
||||||
|
"debit_in_account_currency": flt(
|
||||||
|
debit / d.exchange_rate, d.precision("debit_in_account_currency")
|
||||||
|
),
|
||||||
|
"credit_in_account_currency": flt(
|
||||||
|
credit / d.exchange_rate, d.precision("credit_in_account_currency")
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
gl_map.append(gl_dict)
|
||||||
|
|
||||||
return gl_map
|
return gl_map
|
||||||
|
|
||||||
def make_gl_entries(self, cancel=0, adv_adj=0):
|
def make_gl_entries(self, cancel=0, adv_adj=0):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user