Skip to content

Commit

Permalink
Merge branch 'develop' into early-payment-loss
Browse files Browse the repository at this point in the history
  • Loading branch information
marination authored Mar 13, 2023
2 parents caa1a3d + b8a61be commit e1d2806
Show file tree
Hide file tree
Showing 10 changed files with 4,597 additions and 4,392 deletions.
1 change: 0 additions & 1 deletion .github/workflows/server-tests-mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- '**.css'
- '**.md'
- '**.html'
- '**.csv'
push:
branches: [ develop ]
paths-ignore:
Expand Down
1 change: 0 additions & 1 deletion erpnext/accounts/doctype/payment_entry/payment_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ frappe.ui.form.on('Payment Entry', {
frm.toggle_display("set_exchange_gain_loss",
frm.doc.paid_amount && frm.doc.received_amount && frm.doc.difference_amount);

frm.refresh_fields();
},

set_dynamic_labels: function(frm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ def prepare_companywise_opening_balance(asset_data, liability_data, equity_data,
for data in [asset_data, liability_data, equity_data]:
if data:
account_name = get_root_account_name(data[0].root_type, company)
opening_value += get_opening_balance(account_name, data, company) or 0.0
if account_name:
opening_value += get_opening_balance(account_name, data, company) or 0.0

opening_balance[company] = opening_value

Expand All @@ -155,7 +156,7 @@ def get_opening_balance(account_name, data, company):


def get_root_account_name(root_type, company):
return frappe.get_all(
root_account = frappe.get_all(
"Account",
fields=["account_name"],
filters={
Expand All @@ -165,7 +166,10 @@ def get_root_account_name(root_type, company):
"parent_account": ("is", "not set"),
},
as_list=1,
)[0][0]
)

if root_account:
return root_account[0][0]


def get_profit_loss_data(fiscal_year, companies, columns, filters):
Expand Down
17 changes: 7 additions & 10 deletions erpnext/controllers/website_list_for_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,9 @@ def get_transaction_list(
ignore_permissions = False

if not filters:
filters = []
filters = {}

if doctype in ["Supplier Quotation", "Purchase Invoice"]:
filters.append((doctype, "docstatus", "<", 2))
else:
filters.append((doctype, "docstatus", "=", 1))
filters["docstatus"] = ["<", "2"] if doctype in ["Supplier Quotation", "Purchase Invoice"] else 1

if (user != "Guest" and is_website_user()) or doctype == "Request for Quotation":
parties_doctype = (
Expand All @@ -92,12 +89,12 @@ def get_transaction_list(

if customers:
if doctype == "Quotation":
filters.append(("quotation_to", "=", "Customer"))
filters.append(("party_name", "in", customers))
filters["quotation_to"] = "Customer"
filters["party_name"] = ["in", customers]
else:
filters.append(("customer", "in", customers))
filters["customer"] = ["in", customers]
elif suppliers:
filters.append(("supplier", "in", suppliers))
filters["supplier"] = ["in", suppliers]
elif not custom:
return []

Expand All @@ -110,7 +107,7 @@ def get_transaction_list(

if not customers and not suppliers and custom:
ignore_permissions = False
filters = []
filters = {}

transactions = get_list_for_transactions(
doctype,
Expand Down
3 changes: 1 addition & 2 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,5 @@ erpnext.patches.v14_0.update_entry_type_for_journal_entry
erpnext.patches.v14_0.change_autoname_for_tax_withheld_vouchers
erpnext.patches.v14_0.set_pick_list_status
erpnext.patches.v15_0.update_asset_value_for_manual_depr_entries
# below 2 migration patches should always run last
# below migration patches should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.patches.v14_0.migrate_remarks_from_gl_to_payment_ledger
52 changes: 28 additions & 24 deletions erpnext/patches/v14_0/migrate_gl_to_payment_ledger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import frappe
from frappe import qb
from frappe.query_builder import Case, CustomFunction
from frappe.query_builder import CustomFunction
from frappe.query_builder.custom import ConstantColumn
from frappe.query_builder.functions import Count, IfNull
from frappe.utils import flt
Expand All @@ -18,9 +18,21 @@ def create_accounting_dimension_fields():
make_dimension_in_accounting_doctypes(dimension, ["Payment Ledger Entry"])


def generate_name_for_payment_ledger_entries(gl_entries, start):
def generate_name_and_calculate_amount(gl_entries, start, receivable_accounts):
for index, entry in enumerate(gl_entries, 0):
entry.name = start + index
if entry.account in receivable_accounts:
entry.account_type = "Receivable"
entry.amount = entry.debit - entry.credit
entry.amount_in_account_currency = (
entry.debit_in_account_currency - entry.credit_in_account_currency
)
else:
entry.account_type = "Payable"
entry.amount = entry.credit - entry.debit
entry.amount_in_account_currency = (
entry.credit_in_account_currency - entry.debit_in_account_currency
)


def get_columns():
Expand Down Expand Up @@ -49,6 +61,9 @@ def get_columns():
"finance_book",
]

if frappe.db.has_column("Payment Ledger Entry", "remarks"):
columns.append("remarks")

dimensions_and_defaults = get_dimensions()
if dimensions_and_defaults:
for dimension in dimensions_and_defaults[0]:
Expand Down Expand Up @@ -99,12 +114,17 @@ def execute():
ifelse = CustomFunction("IF", ["condition", "then", "else"])

# Get Records Count
accounts = (
relavant_accounts = (
qb.from_(account)
.select(account.name)
.select(account.name, account.account_type)
.where((account.account_type == "Receivable") | (account.account_type == "Payable"))
.orderby(account.name)
.run(as_dict=True)
)

receivable_accounts = [x.name for x in relavant_accounts if x.account_type == "Receivable"]
accounts = [x.name for x in relavant_accounts]

un_processed = (
qb.from_(gl)
.select(Count(gl.name))
Expand All @@ -122,37 +142,21 @@ def execute():

while True:
if last_name:
where_clause = gl.name.gt(last_name) & (gl.is_cancelled == 0)
where_clause = gl.name.gt(last_name) & gl.account.isin(accounts) & gl.is_cancelled == 0
else:
where_clause = gl.is_cancelled == 0
where_clause = gl.account.isin(accounts) & gl.is_cancelled == 0

gl_entries = (
qb.from_(gl)
.inner_join(account)
.on((gl.account == account.name) & (account.account_type.isin(["Receivable", "Payable"])))
.select(
gl.star,
ConstantColumn(1).as_("docstatus"),
account.account_type.as_("account_type"),
IfNull(
ifelse(gl.against_voucher_type == "", None, gl.against_voucher_type), gl.voucher_type
).as_("against_voucher_type"),
IfNull(ifelse(gl.against_voucher == "", None, gl.against_voucher), gl.voucher_no).as_(
"against_voucher_no"
),
# convert debit/credit to amount
Case()
.when(account.account_type == "Receivable", gl.debit - gl.credit)
.else_(gl.credit - gl.debit)
.as_("amount"),
# convert debit/credit in account currency to amount in account currency
Case()
.when(
account.account_type == "Receivable",
gl.debit_in_account_currency - gl.credit_in_account_currency,
)
.else_(gl.credit_in_account_currency - gl.debit_in_account_currency)
.as_("amount_in_account_currency"),
)
.where(where_clause)
.orderby(gl.name)
Expand All @@ -163,8 +167,8 @@ def execute():
if gl_entries:
last_name = gl_entries[-1].name

# primary key(name) for payment ledger records
generate_name_for_payment_ledger_entries(gl_entries, processed)
# add primary key(name) and calculate based on debit and credit
generate_name_and_calculate_amount(gl_entries, processed, receivable_accounts)

try:
insert_query = build_insert_query()
Expand Down
98 changes: 0 additions & 98 deletions erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import add_days, nowdate
from frappe.utils import add_days, add_months, nowdate

from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
Expand All @@ -15,9 +15,16 @@


class TestPaymentTermsStatusForSalesOrder(FrappeTestCase):
def setUp(self):
self.cleanup_old_entries()

def tearDown(self):
frappe.db.rollback()

def cleanup_old_entries(self):
frappe.db.delete("Sales Invoice", filters={"company": "_Test Company"})
frappe.db.delete("Sales Order", filters={"company": "_Test Company"})

def create_payment_terms_template(self):
# create template for 50-50 payments
template = None
Expand Down Expand Up @@ -348,7 +355,7 @@ def test_04_due_date_filter(self):
item = create_item(item_code="_Test Excavator 1", is_stock_item=0)
transaction_date = nowdate()
so = make_sales_order(
transaction_date=add_days(transaction_date, -30),
transaction_date=add_months(transaction_date, -1),
delivery_date=add_days(transaction_date, -15),
item=item.item_code,
qty=10,
Expand All @@ -369,13 +376,15 @@ def test_04_due_date_filter(self):
sinv.items[0].qty = 6
sinv.insert()
sinv.submit()

first_due_date = add_days(add_months(transaction_date, -1), 15)
columns, data, message, chart = execute(
frappe._dict(
{
"company": "_Test Company",
"item": item.item_code,
"from_due_date": add_days(transaction_date, -30),
"to_due_date": add_days(transaction_date, -15),
"from_due_date": add_months(transaction_date, -1),
"to_due_date": first_due_date,
}
)
)
Expand All @@ -384,11 +393,11 @@ def test_04_due_date_filter(self):
{
"name": so.name,
"customer": so.customer,
"submitted": datetime.date.fromisoformat(add_days(transaction_date, -30)),
"submitted": datetime.date.fromisoformat(add_months(transaction_date, -1)),
"status": "Completed",
"payment_term": None,
"description": "_Test 50-50",
"due_date": datetime.date.fromisoformat(add_days(transaction_date, -15)),
"due_date": datetime.date.fromisoformat(first_due_date),
"invoice_portion": 50.0,
"currency": "INR",
"base_payment_amount": 500000.0,
Expand Down
Loading

0 comments on commit e1d2806

Please sign in to comment.