mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 21:59:13 +00:00
feat: change make_gl_entries to work with new data structure
This commit is contained in:
@@ -7,12 +7,8 @@ from __future__ import unicode_literals
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cint, flt, getdate
|
from frappe.utils import getdate
|
||||||
from six import string_types
|
|
||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
|
||||||
get_accounting_dimensions,
|
|
||||||
)
|
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries
|
from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries
|
||||||
from erpnext.controllers.accounts_controller import AccountsController
|
from erpnext.controllers.accounts_controller import AccountsController
|
||||||
|
|
||||||
@@ -50,42 +46,35 @@ class Dunning(AccountsController):
|
|||||||
def make_gl_entries(self):
|
def make_gl_entries(self):
|
||||||
if not self.dunning_amount:
|
if not self.dunning_amount:
|
||||||
return
|
return
|
||||||
gl_entries = []
|
|
||||||
invoice_fields = ["project", "cost_center", "debit_to", "party_account_currency", "conversion_rate", "cost_center"]
|
|
||||||
inv = frappe.db.get_value("Sales Invoice", self.sales_invoice, invoice_fields, as_dict=1)
|
|
||||||
|
|
||||||
accounting_dimensions = get_accounting_dimensions()
|
cost_center = self.cost_center or frappe.get_cached_value("Company", self.company, "cost_center")
|
||||||
invoice_fields.extend(accounting_dimensions)
|
|
||||||
|
|
||||||
dunning_in_company_currency = flt(self.dunning_amount * inv.conversion_rate)
|
make_gl_entries(
|
||||||
default_cost_center = frappe.get_cached_value("Company", self.company, "cost_center")
|
[
|
||||||
|
self.get_gl_dict({
|
||||||
gl_entries.append(
|
"account": self.debit_to,
|
||||||
self.get_gl_dict({
|
"party_type": "Customer",
|
||||||
"account": inv.debit_to,
|
"party": self.customer,
|
||||||
"party_type": "Customer",
|
"due_date": self.due_date,
|
||||||
"party": self.customer,
|
"against": self.income_account,
|
||||||
"due_date": self.due_date,
|
"debit": self.dunning_amount,
|
||||||
"against": self.income_account,
|
"debit_in_account_currency": self.dunning_amount,
|
||||||
"debit": dunning_in_company_currency,
|
"against_voucher": self.name,
|
||||||
"debit_in_account_currency": self.dunning_amount,
|
"against_voucher_type": "Dunning",
|
||||||
"against_voucher": self.name,
|
"cost_center": cost_center
|
||||||
"against_voucher_type": "Dunning",
|
}),
|
||||||
"cost_center": inv.cost_center or default_cost_center,
|
self.get_gl_dict({
|
||||||
"project": inv.project
|
"account": self.income_account,
|
||||||
}, inv.party_account_currency, item=inv)
|
"against": self.customer,
|
||||||
|
"credit": self.dunning_amount,
|
||||||
|
"cost_center": cost_center,
|
||||||
|
"credit_in_account_currency": self.dunning_amount
|
||||||
|
})
|
||||||
|
],
|
||||||
|
cancel=(self.docstatus == 2),
|
||||||
|
update_outstanding="No",
|
||||||
|
merge_entries=False
|
||||||
)
|
)
|
||||||
gl_entries.append(
|
|
||||||
self.get_gl_dict({
|
|
||||||
"account": self.income_account,
|
|
||||||
"against": self.customer,
|
|
||||||
"credit": dunning_in_company_currency,
|
|
||||||
"cost_center": inv.cost_center or default_cost_center,
|
|
||||||
"credit_in_account_currency": self.dunning_amount,
|
|
||||||
"project": inv.project
|
|
||||||
}, item=inv)
|
|
||||||
)
|
|
||||||
make_gl_entries(gl_entries, cancel=(self.docstatus == 2), update_outstanding="No", merge_entries=False)
|
|
||||||
|
|
||||||
|
|
||||||
def resolve_dunning(doc, state):
|
def resolve_dunning(doc, state):
|
||||||
@@ -100,7 +89,7 @@ def resolve_dunning(doc, state):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_dunning_letter_text(dunning_type, doc, language=None):
|
def get_dunning_letter_text(dunning_type, doc, language=None):
|
||||||
if isinstance(doc, string_types):
|
if isinstance(doc, str):
|
||||||
doc = json.loads(doc)
|
doc = json.loads(doc)
|
||||||
if language:
|
if language:
|
||||||
filters = {"parent": dunning_type, "language": language}
|
filters = {"parent": dunning_type, "language": language}
|
||||||
|
|||||||
Reference in New Issue
Block a user