Skip to content

Commit

Permalink
feat: Accounting Dimension updation in Payment Request and Entry (#33411
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mergify[bot] authored Dec 26, 2022
1 parent 7a98ece commit e7704b2
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
14 changes: 14 additions & 0 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,8 @@ def get_payment_entry(
pe.setup_party_account_field()
pe.set_missing_values()

update_accounting_dimensions(pe, doc)

if party_account and bank:
pe.set_exchange_rate(ref_doc=reference_doc)
pe.set_amounts()
Expand All @@ -1775,6 +1777,18 @@ def get_payment_entry(
return pe


def update_accounting_dimensions(pe, doc):
"""
Updates accounting dimensions in Payment Entry based on the accounting dimensions in the reference document
"""
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions,
)

for dimension in get_accounting_dimensions():
pe.set(dimension, doc.get(dimension))


def get_bank_cash_account(doc, bank_account):
bank = get_default_bank_cash_account(
doc.company, "Bank", mode_of_payment=doc.get("mode_of_payment"), account=bank_account
Expand Down
28 changes: 27 additions & 1 deletion erpnext/accounts/doctype/payment_request/payment_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"iban",
"branch_code",
"swift_number",
"accounting_dimensions_section",
"cost_center",
"dimension_col_break",
"project",
"recipient_and_message",
"print_format",
"email_to",
Expand Down Expand Up @@ -362,13 +366,35 @@
"label": "Payment Channel",
"options": "\nEmail\nPhone",
"read_only": 1
},
{
"collapsible": 1,
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
},
{
"fieldname": "cost_center",
"fieldtype": "Link",
"label": "Cost Center",
"options": "Cost Center"
},
{
"fieldname": "dimension_col_break",
"fieldtype": "Column Break"
},
{
"fieldname": "project",
"fieldtype": "Link",
"label": "Project",
"options": "Project"
}
],
"in_create": 1,
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2022-09-30 16:19:43.680025",
"modified": "2022-12-21 16:56:40.115737",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Request",
Expand Down
25 changes: 25 additions & 0 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from frappe.utils.background_jobs import enqueue
from payments.utils import get_payment_gateway_controller

from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
get_accounting_dimensions,
)
from erpnext.accounts.doctype.payment_entry.payment_entry import (
get_company_defaults,
get_payment_entry,
Expand Down Expand Up @@ -263,6 +266,17 @@ def create_payment_entry(self, submit=True):
}
)

# Update dimensions
payment_entry.update(
{
"cost_center": self.get("cost_center"),
"project": self.get("project"),
}
)

for dimension in get_accounting_dimensions():
payment_entry.update({dimension: self.get(dimension)})

if payment_entry.difference_amount:
company_details = get_company_defaults(ref_doc.company)

Expand Down Expand Up @@ -442,6 +456,17 @@ def make_payment_request(**args):
}
)

# Update dimensions
pr.update(
{
"cost_center": ref_doc.get("cost_center"),
"project": ref_doc.get("project"),
}
)

for dimension in get_accounting_dimensions():
pr.update({dimension: ref_doc.get(dimension)})

if args.order_type == "Shopping Cart" or args.mute_email:
pr.flags.mute_email = True

Expand Down
3 changes: 2 additions & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,5 @@ erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization
erpnext.patches.v13_0.update_schedule_type_in_loans
erpnext.patches.v14_0.update_partial_tds_fields
erpnext.patches.v14_0.create_incoterms_and_migrate_shipment
erpnext.patches.v14_0.setup_clear_repost_logs
erpnext.patches.v14_0.setup_clear_repost_logs
erpnext.patches.v14_0.create_accounting_dimensions_for_payment_request
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field


def execute():
accounting_dimensions = frappe.db.get_all(
"Accounting Dimension", fields=["fieldname", "label", "document_type", "disabled"]
)

if not accounting_dimensions:
return

doctype = "Payment Request"

for d in accounting_dimensions:
field = frappe.db.get_value("Custom Field", {"dt": doctype, "fieldname": d.fieldname})

if field:
continue

df = {
"fieldname": d.fieldname,
"label": d.label,
"fieldtype": "Link",
"options": d.document_type,
"insert_after": "accounting_dimensions_section",
}

create_custom_field(doctype, df, ignore_validate=True)

frappe.clear_cache(doctype=doctype)

0 comments on commit e7704b2

Please sign in to comment.