Merge pull request #35868 from ruthra-kumar/get_base_grand_total_while_pulling_reference_details
fix: incorrect outstanding and total amount in reference table of payment entry
diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml
index d5f0052..e2d8957 100644
--- a/.github/workflows/patch.yml
+++ b/.github/workflows/patch.yml
@@ -43,9 +43,11 @@
fi
- name: Setup Python
- uses: "gabrielfalcao/pyenv-action@v9"
+ uses: "actions/setup-python@v4"
with:
- versions: 3.10:latest, 3.7:latest
+ python-version: |
+ 3.7
+ 3.10
- name: Setup Node
uses: actions/setup-node@v2
@@ -92,7 +94,6 @@
- name: Install
run: |
pip install frappe-bench
- pyenv global $(pyenv versions | grep '3.10')
bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
env:
DB: mariadb
@@ -107,7 +108,6 @@
git -C "apps/frappe" remote set-url upstream https://github.com/frappe/frappe.git
git -C "apps/erpnext" remote set-url upstream https://github.com/frappe/erpnext.git
- pyenv global $(pyenv versions | grep '3.7')
for version in $(seq 12 13)
do
echo "Updating to v$version"
@@ -120,7 +120,7 @@
git -C "apps/erpnext" checkout -q -f $branch_name
rm -rf ~/frappe-bench/env
- bench setup env
+ bench setup env --python python3.7
bench pip install -e ./apps/payments
bench pip install -e ./apps/erpnext
@@ -132,9 +132,8 @@
git -C "apps/frappe" checkout -q -f "${GITHUB_BASE_REF:-${GITHUB_REF##*/}}"
git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA"
- pyenv global $(pyenv versions | grep '3.10')
rm -rf ~/frappe-bench/env
- bench -v setup env
+ bench -v setup env --python python3.10
bench pip install -e ./apps/payments
bench pip install -e ./apps/erpnext
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
index 8a6b021..6f0b6fc 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.js
@@ -68,6 +68,16 @@
frm.refresh_field("dimensions");
frm.trigger('setup_filters');
},
+ apply_restriction_on_values: function(frm) {
+ /** If restriction on values is not applied, we should set "allow_or_restrict" to "Restrict" with an empty allowed dimension table.
+ * Hence it's not "restricted" on any value.
+ */
+ if (!frm.doc.apply_restriction_on_values) {
+ frm.set_value("allow_or_restrict", "Restrict");
+ frm.clear_table("dimensions");
+ frm.refresh_field("dimensions");
+ }
+ }
});
frappe.ui.form.on('Allowed Dimension', {
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
index 0f3fbc0..2bd6c12 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.json
@@ -10,6 +10,7 @@
"disabled",
"column_break_2",
"company",
+ "apply_restriction_on_values",
"allow_or_restrict",
"section_break_4",
"accounts",
@@ -24,94 +25,80 @@
"fieldtype": "Select",
"in_list_view": 1,
"label": "Accounting Dimension",
- "reqd": 1,
- "show_days": 1,
- "show_seconds": 1
+ "reqd": 1
},
{
"fieldname": "column_break_2",
- "fieldtype": "Column Break",
- "show_days": 1,
- "show_seconds": 1
+ "fieldtype": "Column Break"
},
{
"fieldname": "section_break_4",
"fieldtype": "Section Break",
- "hide_border": 1,
- "show_days": 1,
- "show_seconds": 1
+ "hide_border": 1
},
{
"fieldname": "column_break_6",
- "fieldtype": "Column Break",
- "show_days": 1,
- "show_seconds": 1
+ "fieldtype": "Column Break"
},
{
+ "depends_on": "eval:doc.apply_restriction_on_values == 1;",
"fieldname": "allow_or_restrict",
"fieldtype": "Select",
"label": "Allow Or Restrict Dimension",
"options": "Allow\nRestrict",
- "reqd": 1,
- "show_days": 1,
- "show_seconds": 1
+ "reqd": 1
},
{
"fieldname": "accounts",
"fieldtype": "Table",
"label": "Applicable On Account",
"options": "Applicable On Account",
- "reqd": 1,
- "show_days": 1,
- "show_seconds": 1
+ "reqd": 1
},
{
- "depends_on": "eval:doc.accounting_dimension",
+ "depends_on": "eval:doc.accounting_dimension && doc.apply_restriction_on_values",
"fieldname": "dimensions",
"fieldtype": "Table",
"label": "Applicable Dimension",
- "options": "Allowed Dimension",
- "reqd": 1,
- "show_days": 1,
- "show_seconds": 1
+ "mandatory_depends_on": "eval:doc.apply_restriction_on_values == 1;",
+ "options": "Allowed Dimension"
},
{
"default": "0",
"fieldname": "disabled",
"fieldtype": "Check",
- "label": "Disabled",
- "show_days": 1,
- "show_seconds": 1
+ "label": "Disabled"
},
{
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company",
- "reqd": 1,
- "show_days": 1,
- "show_seconds": 1
+ "reqd": 1
},
{
"fieldname": "dimension_filter_help",
"fieldtype": "HTML",
- "label": "Dimension Filter Help",
- "show_days": 1,
- "show_seconds": 1
+ "label": "Dimension Filter Help"
},
{
"fieldname": "section_break_10",
- "fieldtype": "Section Break",
- "show_days": 1,
- "show_seconds": 1
+ "fieldtype": "Section Break"
+ },
+ {
+ "default": "1",
+ "fieldname": "apply_restriction_on_values",
+ "fieldtype": "Check",
+ "label": "Apply restriction on dimension values"
}
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2021-02-03 12:04:58.678402",
+ "modified": "2023-06-07 14:59:41.869117",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Accounting Dimension Filter",
+ "naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
@@ -154,5 +141,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
+ "states": [],
"track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
index 80f736f..de1b82c 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/accounting_dimension_filter.py
@@ -8,6 +8,12 @@
class AccountingDimensionFilter(Document):
+ def before_save(self):
+ # If restriction is not applied on values, then remove all the dimensions and set allow_or_restrict to Restrict
+ if not self.apply_restriction_on_values:
+ self.allow_or_restrict = "Restrict"
+ self.set("dimensions", [])
+
def validate(self):
self.validate_applicable_accounts()
@@ -44,12 +50,12 @@
a.applicable_on_account, d.dimension_value, p.accounting_dimension,
p.allow_or_restrict, a.is_mandatory
FROM
- `tabApplicable On Account` a, `tabAllowed Dimension` d,
+ `tabApplicable On Account` a,
`tabAccounting Dimension Filter` p
+ LEFT JOIN `tabAllowed Dimension` d ON d.parent = p.name
WHERE
p.name = a.parent
AND p.disabled = 0
- AND p.name = d.parent
""",
as_dict=1,
)
@@ -76,4 +82,5 @@
(dimension, account),
{"allowed_dimensions": [], "is_mandatory": is_mandatory, "allow_or_restrict": allow_or_restrict},
)
- map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)
+ if filter_value:
+ map_object[(dimension, account)]["allowed_dimensions"].append(filter_value)
diff --git a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
index f13f2f9..6aba2ab 100644
--- a/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
+++ b/erpnext/accounts/doctype/accounting_dimension_filter/test_accounting_dimension_filter.py
@@ -64,6 +64,7 @@
"accounting_dimension": "Cost Center",
"allow_or_restrict": "Allow",
"company": "_Test Company",
+ "apply_restriction_on_values": 1,
"accounts": [
{
"applicable_on_account": "Sales - _TC",
@@ -85,6 +86,7 @@
"doctype": "Accounting Dimension Filter",
"accounting_dimension": "Department",
"allow_or_restrict": "Allow",
+ "apply_restriction_on_values": 1,
"company": "_Test Company",
"accounts": [{"applicable_on_account": "Sales - _TC", "is_mandatory": 1}],
"dimensions": [{"accounting_dimension": "Department", "dimension_value": "Accounts - _TC"}],
diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation_account/exchange_rate_revaluation_account.json b/erpnext/accounts/doctype/exchange_rate_revaluation_account/exchange_rate_revaluation_account.json
index 0a7d057..fd2d931 100644
--- a/erpnext/accounts/doctype/exchange_rate_revaluation_account/exchange_rate_revaluation_account.json
+++ b/erpnext/accounts/doctype/exchange_rate_revaluation_account/exchange_rate_revaluation_account.json
@@ -73,6 +73,7 @@
"fieldname": "current_exchange_rate",
"fieldtype": "Float",
"label": "Current Exchange Rate",
+ "precision": "9",
"read_only": 1
},
{
@@ -148,7 +149,7 @@
],
"istable": 1,
"links": [],
- "modified": "2023-06-20 07:21:40.743460",
+ "modified": "2023-06-22 12:39:56.446722",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Exchange Rate Revaluation Account",
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index 6d9e320..a51e38e 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -8,7 +8,7 @@
frappe.ui.form.on("Journal Entry", {
setup: function(frm) {
frm.add_fetch("bank_account", "account", "account");
- frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', "Repost Payment Ledger", 'Asset Depreciation Schedule'];
+ frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice', 'Journal Entry', "Repost Payment Ledger", 'Asset', 'Asset Movement', 'Asset Depreciation Schedule'];
},
refresh: function(frm) {
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 74fd559..83312db 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -326,12 +326,10 @@
d.db_update()
def unlink_asset_reference(self):
- if self.voucher_type != "Depreciation Entry":
- return
-
for d in self.get("accounts"):
if (
- d.reference_type == "Asset"
+ self.voucher_type == "Depreciation Entry"
+ and d.reference_type == "Asset"
and d.reference_name
and d.account_type == "Depreciation"
and d.debit
@@ -370,6 +368,15 @@
else:
asset.db_set("value_after_depreciation", asset.value_after_depreciation + d.debit)
asset.set_status()
+ elif self.voucher_type == "Journal Entry" and d.reference_type == "Asset" and d.reference_name:
+ journal_entry_for_scrap = frappe.db.get_value(
+ "Asset", d.reference_name, "journal_entry_for_scrap"
+ )
+
+ if journal_entry_for_scrap == self.name:
+ frappe.throw(
+ _("Journal Entry for Asset scrapping cannot be cancelled. Please restore the Asset.")
+ )
def unlink_inter_company_jv(self):
if (
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index 9f55ba1..bac84db 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -155,6 +155,7 @@
frm.events.hide_unhide_fields(frm);
frm.events.set_dynamic_labels(frm);
frm.events.show_general_ledger(frm);
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(frm);
},
validate_company: (frm) => {
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index 2e4e3b0..a709740 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -336,6 +336,7 @@
entry_list = []
dr_or_cr_notes = []
+ difference_entries = []
for row in self.get("allocation"):
reconciled_entry = []
if row.invoice_number and row.allocated_amount:
@@ -348,13 +349,15 @@
reconciled_entry.append(payment_details)
if payment_details.difference_amount:
- self.make_difference_entry(payment_details)
+ difference_entries.append(
+ self.make_difference_entry(payment_details, do_not_save_and_submit=bool(dr_or_cr_notes))
+ )
if entry_list:
reconcile_against_document(entry_list, skip_ref_details_update_for_pe)
if dr_or_cr_notes:
- reconcile_dr_cr_note(dr_or_cr_notes, self.company)
+ reconcile_dr_cr_note(dr_or_cr_notes, difference_entries, self.company)
@frappe.whitelist()
def reconcile(self):
@@ -382,7 +385,7 @@
self.get_unreconciled_entries()
- def make_difference_entry(self, row):
+ def make_difference_entry(self, row, do_not_save_and_submit=False):
journal_entry = frappe.new_doc("Journal Entry")
journal_entry.voucher_type = "Exchange Gain Or Loss"
journal_entry.company = self.company
@@ -430,8 +433,11 @@
journal_entry.append("accounts", journal_account)
- journal_entry.save()
- journal_entry.submit()
+ if not do_not_save_and_submit:
+ journal_entry.save()
+ journal_entry.submit()
+
+ return journal_entry
def get_payment_details(self, row, dr_or_cr):
return frappe._dict(
@@ -597,7 +603,14 @@
return condition
-def reconcile_dr_cr_note(dr_cr_notes, company):
+def reconcile_dr_cr_note(dr_cr_notes, difference_entries, company):
+ def find_difference_entry(voucher_type, voucher_no):
+ for jv in difference_entries:
+ accounts = iter(jv.accounts)
+ for account in accounts:
+ if account.reference_type == voucher_type and account.reference_name == voucher_no:
+ return next(accounts)
+
for inv in dr_cr_notes:
voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note"
@@ -642,5 +655,9 @@
],
}
)
+
+ if difference_entry := find_difference_entry(inv.against_voucher_type, inv.against_voucher):
+ jv.append("accounts", difference_entry)
+
jv.flags.ignore_mandatory = True
jv.submit()
diff --git a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
index 3be11ae..2ac7df0 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/test_payment_reconciliation.py
@@ -11,10 +11,13 @@
from erpnext import get_default_cost_center
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
+from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
from erpnext.accounts.party import get_party_account
from erpnext.stock.doctype.item.test_item import create_item
+test_dependencies = ["Item"]
+
class TestPaymentReconciliation(FrappeTestCase):
def setUp(self):
@@ -163,7 +166,9 @@
def create_payment_reconciliation(self):
pr = frappe.new_doc("Payment Reconciliation")
pr.company = self.company
- pr.party_type = "Customer"
+ pr.party_type = (
+ self.party_type if hasattr(self, "party_type") and self.party_type else "Customer"
+ )
pr.party = self.customer
pr.receivable_payable_account = get_party_account(pr.party_type, pr.party, pr.company)
pr.from_invoice_date = pr.to_invoice_date = pr.from_payment_date = pr.to_payment_date = nowdate()
@@ -890,6 +895,42 @@
self.assertEqual(pr.allocation[0].allocated_amount, 85)
self.assertEqual(pr.allocation[0].difference_amount, 0)
+ def test_reconciliation_purchase_invoice_against_return(self):
+ pi = make_purchase_invoice(
+ supplier="_Test Supplier USD", currency="USD", conversion_rate=50
+ ).submit()
+
+ pi_return = frappe.get_doc(pi.as_dict())
+ pi_return.name = None
+ pi_return.docstatus = 0
+ pi_return.is_return = 1
+ pi_return.conversion_rate = 80
+ pi_return.items[0].qty = -pi_return.items[0].qty
+ pi_return.submit()
+
+ self.company = "_Test Company"
+ self.party_type = "Supplier"
+ self.customer = "_Test Supplier USD"
+
+ pr = self.create_payment_reconciliation()
+ pr.get_unreconciled_entries()
+
+ invoices = []
+ payments = []
+ for invoice in pr.invoices:
+ if invoice.invoice_number == pi.name:
+ invoices.append(invoice.as_dict())
+ break
+ for payment in pr.payments:
+ if payment.reference_name == pi_return.name:
+ payments.append(payment.as_dict())
+ break
+
+ pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
+
+ # Should not raise frappe.exceptions.ValidationError: Total Debit must be equal to Total Credit.
+ pr.reconcile()
+
def make_customer(customer_name, currency=None):
if not frappe.db.exists("Customer", customer_name):
diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js
index ea18ade..6046c13 100644
--- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js
+++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.js
@@ -2,7 +2,11 @@
// For license information, please see license.txt
frappe.ui.form.on('Payment Terms Template', {
- setup: function(frm) {
+ refresh: function(frm) {
+ frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms);
+ },
+ allocate_payment_based_on_payment_terms: function(frm) {
+ frm.fields_dict.terms.grid.toggle_reqd("payment_term", frm.doc.allocate_payment_based_on_payment_terms);
}
});
diff --git a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py
index ea3b76c..7b04a68 100644
--- a/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py
+++ b/erpnext/accounts/doctype/payment_terms_template/payment_terms_template.py
@@ -11,7 +11,7 @@
class PaymentTermsTemplate(Document):
def validate(self):
self.validate_invoice_portion()
- self.check_duplicate_terms()
+ self.validate_terms()
def validate_invoice_portion(self):
total_portion = 0
@@ -23,9 +23,12 @@
_("Combined invoice portion must equal 100%"), raise_exception=1, indicator="red"
)
- def check_duplicate_terms(self):
+ def validate_terms(self):
terms = []
for term in self.terms:
+ if self.allocate_payment_based_on_payment_terms and not term.payment_term:
+ frappe.throw(_("Row {0}: Payment Term is mandatory").format(term.idx))
+
term_info = (term.payment_term, term.credit_days, term.credit_months, term.due_date_based_on)
if term_info in terms:
frappe.msgprint(
diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
index e6d9fe2..a6c0102 100644
--- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
+++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
@@ -123,22 +123,29 @@
row.expected_amount = row.opening_amount;
}
- const pos_inv_promises = frm.doc.pos_transactions.map(
- row => frappe.db.get_doc("POS Invoice", row.pos_invoice)
- );
-
- const pos_invoices = await Promise.all(pos_inv_promises);
-
- for (let doc of pos_invoices) {
- frm.doc.grand_total += flt(doc.grand_total);
- frm.doc.net_total += flt(doc.net_total);
- frm.doc.total_quantity += flt(doc.total_qty);
- refresh_payments(doc, frm);
- refresh_taxes(doc, frm);
- refresh_fields(frm);
- set_html_data(frm);
- }
-
+ await Promise.all([
+ frappe.call({
+ method: 'erpnext.accounts.doctype.pos_closing_entry.pos_closing_entry.get_pos_invoices',
+ args: {
+ start: frappe.datetime.get_datetime_as_string(frm.doc.period_start_date),
+ end: frappe.datetime.get_datetime_as_string(frm.doc.period_end_date),
+ pos_profile: frm.doc.pos_profile,
+ user: frm.doc.user
+ },
+ callback: (r) => {
+ let pos_invoices = r.message;
+ for (let doc of pos_invoices) {
+ frm.doc.grand_total += flt(doc.grand_total);
+ frm.doc.net_total += flt(doc.net_total);
+ frm.doc.total_quantity += flt(doc.total_qty);
+ refresh_payments(doc, frm);
+ refresh_taxes(doc, frm);
+ refresh_fields(frm);
+ set_html_data(frm);
+ }
+ }
+ })
+ ])
frappe.dom.unfreeze();
}
});
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
index 03abc93..5307ccb 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html
@@ -1,6 +1,6 @@
<div class="page-break">
<div id="header-html" class="hidden-pdf">
- {% if letter_head %}
+ {% if letter_head.content %}
<div class="letter-head text-center">{{ letter_head.content }}</div>
<hr style="height:2px;border-width:0;color:black;background-color:black;">
{% endif %}
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
index 7dd5ef3..cec48c1 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.js
@@ -65,6 +65,20 @@
frm.set_value('to_date', frappe.datetime.get_today());
}
},
+ report: function(frm){
+ let filters = {
+ 'company': frm.doc.company,
+ }
+ if(frm.doc.report == 'Accounts Receivable'){
+ filters['account_type'] = 'Receivable';
+ }
+ frm.set_query("account", function() {
+ return {
+ filters: filters
+ };
+ });
+
+ },
customer_collection: function(frm){
frm.set_value('collection_name', '');
if(frm.doc.customer_collection){
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
index e23620f..8004659 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.json
@@ -6,17 +6,24 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
+ "report",
"section_break_11",
"from_date",
+ "posting_date",
"company",
"account",
"group_by",
"cost_center",
+ "territory",
"column_break_14",
"to_date",
"finance_book",
"currency",
"project",
+ "payment_terms_template",
+ "sales_partner",
+ "sales_person",
+ "based_on_payment_terms",
"section_break_3",
"customer_collection",
"collection_name",
@@ -67,14 +74,14 @@
"reqd": 1
},
{
- "depends_on": "eval:doc.enable_auto_email == 0;",
+ "depends_on": "eval:(doc.enable_auto_email == 0 && doc.report == 'General Ledger');",
"fieldname": "from_date",
"fieldtype": "Date",
"label": "From Date",
"mandatory_depends_on": "eval:doc.frequency == '';"
},
{
- "depends_on": "eval:doc.enable_auto_email == 0;",
+ "depends_on": "eval:(doc.enable_auto_email == 0 && doc.report == 'General Ledger');",
"fieldname": "to_date",
"fieldtype": "Date",
"label": "To Date",
@@ -87,6 +94,7 @@
"options": "PSOA Cost Center"
},
{
+ "depends_on": "eval: (doc.report == 'General Ledger');",
"fieldname": "project",
"fieldtype": "Table MultiSelect",
"label": "Project",
@@ -104,7 +112,7 @@
{
"fieldname": "section_break_11",
"fieldtype": "Section Break",
- "label": "General Ledger Filters"
+ "label": "Report Filters"
},
{
"fieldname": "column_break_14",
@@ -164,12 +172,14 @@
},
{
"default": "Group by Voucher (Consolidated)",
+ "depends_on": "eval:(doc.report == 'General Ledger');",
"fieldname": "group_by",
"fieldtype": "Select",
"label": "Group By",
"options": "\nGroup by Voucher\nGroup by Voucher (Consolidated)"
},
{
+ "depends_on": "eval: (doc.report == 'General Ledger');",
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
@@ -297,6 +307,7 @@
},
{
"default": "0",
+ "depends_on": "eval: (doc.report == 'General Ledger');",
"fieldname": "show_net_values_in_party_account",
"fieldtype": "Check",
"label": "Show Net Values in Party Account"
@@ -310,10 +321,59 @@
{
"fieldname": "column_break_ocfq",
"fieldtype": "Column Break"
+ },
+ {
+ "fieldname": "report",
+ "fieldtype": "Select",
+ "label": "Report",
+ "options": "General Ledger\nAccounts Receivable",
+ "reqd": 1
+ },
+ {
+ "default": "Today",
+ "depends_on": "eval:(doc.report == 'Accounts Receivable');",
+ "fieldname": "posting_date",
+ "fieldtype": "Date",
+ "label": "Posting Date"
+ },
+ {
+ "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+ "fieldname": "payment_terms_template",
+ "fieldtype": "Link",
+ "label": "Payment Terms Template",
+ "options": "Payment Terms Template"
+ },
+ {
+ "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+ "fieldname": "sales_partner",
+ "fieldtype": "Link",
+ "label": "Sales Partner",
+ "options": "Sales Partner"
+ },
+ {
+ "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+ "fieldname": "sales_person",
+ "fieldtype": "Link",
+ "label": "Sales Person",
+ "options": "Sales Person"
+ },
+ {
+ "depends_on": "eval: (doc.report == 'Accounts Receivable');",
+ "fieldname": "territory",
+ "fieldtype": "Link",
+ "label": "Territory",
+ "options": "Territory"
+ },
+ {
+ "default": "0",
+ "depends_on": "eval:(doc.report == 'Accounts Receivable');",
+ "fieldname": "based_on_payment_terms",
+ "fieldtype": "Check",
+ "label": "Based On Payment Terms"
}
],
"links": [],
- "modified": "2023-04-26 12:46:43.645455",
+ "modified": "2023-06-23 10:13:15.051950",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Process Statement Of Accounts",
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
index 67dbe09..08f4cf4 100644
--- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py
@@ -15,6 +15,7 @@
from erpnext import get_company_currency
from erpnext.accounts.party import get_party_account_currency
+from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute as get_ar_soa
from erpnext.accounts.report.accounts_receivable_summary.accounts_receivable_summary import (
execute as get_ageing,
)
@@ -43,29 +44,10 @@
def get_report_pdf(doc, consolidated=True):
statement_dict = {}
ageing = ""
- base_template_path = "frappe/www/printview.html"
- template_path = (
- "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html"
- )
for entry in doc.customers:
if doc.include_ageing:
- ageing_filters = frappe._dict(
- {
- "company": doc.company,
- "report_date": doc.to_date,
- "ageing_based_on": doc.ageing_based_on,
- "range1": 30,
- "range2": 60,
- "range3": 90,
- "range4": 120,
- "customer": entry.customer,
- }
- )
- col1, ageing = get_ageing(ageing_filters)
-
- if ageing:
- ageing[0]["ageing_based_on"] = doc.ageing_based_on
+ ageing = set_ageing(doc, entry)
tax_id = frappe.get_doc("Customer", entry.customer).tax_id
presentation_currency = (
@@ -73,60 +55,25 @@
or doc.currency
or get_company_currency(doc.company)
)
- if doc.letter_head:
- from frappe.www.printview import get_letter_head
- letter_head = get_letter_head(doc, 0)
+ filters = get_common_filters(doc)
- filters = frappe._dict(
- {
- "from_date": doc.from_date,
- "to_date": doc.to_date,
- "company": doc.company,
- "finance_book": doc.finance_book if doc.finance_book else None,
- "account": [doc.account] if doc.account else None,
- "party_type": "Customer",
- "party": [entry.customer],
- "party_name": [entry.customer_name] if entry.customer_name else None,
- "presentation_currency": presentation_currency,
- "group_by": doc.group_by,
- "currency": doc.currency,
- "cost_center": [cc.cost_center_name for cc in doc.cost_center],
- "project": [p.project_name for p in doc.project],
- "show_opening_entries": 0,
- "include_default_book_entries": 0,
- "tax_id": tax_id if tax_id else None,
- "show_net_values_in_party_account": doc.show_net_values_in_party_account,
- }
- )
- col, res = get_soa(filters)
+ if doc.report == "General Ledger":
+ filters.update(get_gl_filters(doc, entry, tax_id, presentation_currency))
+ else:
+ filters.update(get_ar_filters(doc, entry))
- for x in [0, -2, -1]:
- res[x]["account"] = res[x]["account"].replace("'", "")
+ if doc.report == "General Ledger":
+ col, res = get_soa(filters)
+ for x in [0, -2, -1]:
+ res[x]["account"] = res[x]["account"].replace("'", "")
+ if len(res) == 3:
+ continue
+ else:
+ ar_res = get_ar_soa(filters)
+ col, res = ar_res[0], ar_res[1]
- if len(res) == 3:
- continue
-
- html = frappe.render_template(
- template_path,
- {
- "filters": filters,
- "data": res,
- "ageing": ageing[0] if (doc.include_ageing and ageing) else None,
- "letter_head": letter_head if doc.letter_head else None,
- "terms_and_conditions": frappe.db.get_value(
- "Terms and Conditions", doc.terms_and_conditions, "terms"
- )
- if doc.terms_and_conditions
- else None,
- },
- )
-
- html = frappe.render_template(
- base_template_path,
- {"body": html, "css": get_print_style(), "title": "Statement For " + entry.customer},
- )
- statement_dict[entry.customer] = html
+ statement_dict[entry.customer] = get_html(doc, filters, entry, col, res, ageing)
if not bool(statement_dict):
return False
@@ -140,6 +87,110 @@
return statement_dict
+def set_ageing(doc, entry):
+ ageing_filters = frappe._dict(
+ {
+ "company": doc.company,
+ "report_date": doc.to_date,
+ "ageing_based_on": doc.ageing_based_on,
+ "range1": 30,
+ "range2": 60,
+ "range3": 90,
+ "range4": 120,
+ "customer": entry.customer,
+ }
+ )
+ col1, ageing = get_ageing(ageing_filters)
+
+ if ageing:
+ ageing[0]["ageing_based_on"] = doc.ageing_based_on
+
+ return ageing
+
+
+def get_common_filters(doc):
+ return frappe._dict(
+ {
+ "company": doc.company,
+ "finance_book": doc.finance_book if doc.finance_book else None,
+ "account": [doc.account] if doc.account else None,
+ "cost_center": [cc.cost_center_name for cc in doc.cost_center],
+ }
+ )
+
+
+def get_gl_filters(doc, entry, tax_id, presentation_currency):
+ return {
+ "from_date": doc.from_date,
+ "to_date": doc.to_date,
+ "party_type": "Customer",
+ "party": [entry.customer],
+ "party_name": [entry.customer_name] if entry.customer_name else None,
+ "presentation_currency": presentation_currency,
+ "group_by": doc.group_by,
+ "currency": doc.currency,
+ "project": [p.project_name for p in doc.project],
+ "show_opening_entries": 0,
+ "include_default_book_entries": 0,
+ "tax_id": tax_id if tax_id else None,
+ "show_net_values_in_party_account": doc.show_net_values_in_party_account,
+ }
+
+
+def get_ar_filters(doc, entry):
+ return {
+ "report_date": doc.posting_date if doc.posting_date else None,
+ "customer_name": entry.customer,
+ "payment_terms_template": doc.payment_terms_template if doc.payment_terms_template else None,
+ "sales_partner": doc.sales_partner if doc.sales_partner else None,
+ "sales_person": doc.sales_person if doc.sales_person else None,
+ "territory": doc.territory if doc.territory else None,
+ "based_on_payment_terms": doc.based_on_payment_terms,
+ "report_name": "Accounts Receivable",
+ "ageing_based_on": doc.ageing_based_on,
+ "range1": 30,
+ "range2": 60,
+ "range3": 90,
+ "range4": 120,
+ }
+
+
+def get_html(doc, filters, entry, col, res, ageing):
+ base_template_path = "frappe/www/printview.html"
+ template_path = (
+ "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.html"
+ if doc.report == "General Ledger"
+ else "erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html"
+ )
+
+ if doc.letter_head:
+ from frappe.www.printview import get_letter_head
+
+ letter_head = get_letter_head(doc, 0)
+
+ html = frappe.render_template(
+ template_path,
+ {
+ "filters": filters,
+ "data": res,
+ "report": {"report_name": doc.report, "columns": col},
+ "ageing": ageing[0] if (doc.include_ageing and ageing) else None,
+ "letter_head": letter_head if doc.letter_head else None,
+ "terms_and_conditions": frappe.db.get_value(
+ "Terms and Conditions", doc.terms_and_conditions, "terms"
+ )
+ if doc.terms_and_conditions
+ else None,
+ },
+ )
+
+ html = frappe.render_template(
+ base_template_path,
+ {"body": html, "css": get_print_style(), "title": "Statement For " + entry.customer},
+ )
+ return html
+
+
def get_customers_based_on_territory_or_customer_group(customer_collection, collection_name):
fields_dict = {
"Customer Group": "customer_group",
diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html
new file mode 100644
index 0000000..07e1896
--- /dev/null
+++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts_accounts_receivable.html
@@ -0,0 +1,348 @@
+<style>
+ .print-format {
+ padding: 4mm;
+ font-size: 8.0pt !important;
+ }
+ .print-format td {
+ vertical-align:middle !important;
+ }
+ </style>
+
+ <h2 class="text-center" style="margin-top:0">{{ _(report.report_name) }}</h2>
+ <h4 class="text-center">
+ {% if (filters.customer_name) %}
+ {{ filters.customer_name }}
+ {% else %}
+ {{ filters.customer ~ filters.supplier }}
+ {% endif %}
+ </h4>
+ <h6 class="text-center">
+ {% if (filters.tax_id) %}
+ {{ _("Tax Id: ") }}{{ filters.tax_id }}
+ {% endif %}
+ </h6>
+ <h5 class="text-center">
+ {{ _(filters.ageing_based_on) }}
+ {{ _("Until") }}
+ {{ frappe.format(filters.report_date, 'Date') }}
+ </h5>
+
+ <div class="clearfix">
+ <div class="pull-left">
+ {% if(filters.payment_terms) %}
+ <strong>{{ _("Payment Terms") }}:</strong> {{ filters.payment_terms }}
+ {% endif %}
+ </div>
+ <div class="pull-right">
+ {% if(filters.credit_limit) %}
+ <strong>{{ _("Credit Limit") }}:</strong> {{ frappe.utils.fmt_money(filters.credit_limit) }}
+ {% endif %}
+ </div>
+ </div>
+
+ {% if(filters.show_future_payments) %}
+ {% set balance_row = data.slice(-1).pop() %}
+ {% for i in report.columns %}
+ {% if i.fieldname == 'age' %}
+ {% set elem = i %}
+ {% endif %}
+ {% endfor %}
+ {% set start = report.columns.findIndex(elem) %}
+ {% set range1 = report.columns[start].label %}
+ {% set range2 = report.columns[start+1].label %}
+ {% set range3 = report.columns[start+2].label %}
+ {% set range4 = report.columns[start+3].label %}
+ {% set range5 = report.columns[start+4].label %}
+ {% set range6 = report.columns[start+5].label %}
+
+ {% if(balance_row) %}
+ <table class="table table-bordered table-condensed">
+ <caption class="text-right">(Amount in {{ data[0]["currency"] ~ "" }})</caption>
+ <colgroup>
+ <col style="width: 30mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ <col style="width: 18mm;">
+ </colgroup>
+
+ <thead>
+ <tr>
+ <th>{{ _(" ") }}</th>
+ <th>{{ _(range1) }}</th>
+ <th>{{ _(range2) }}</th>
+ <th>{{ _(range3) }}</th>
+ <th>{{ _(range4) }}</th>
+ <th>{{ _(range5) }}</th>
+ <th>{{ _(range6) }}</th>
+ <th>{{ _("Total") }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{ _("Total Outstanding") }}</td>
+ <td class="text-right">
+ {{ format_number(balance_row["age"], null, 2) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(balance_row["range1"], data[data.length-1]["currency"]) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(balance_row["range2"], data[data.length-1]["currency"]) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(balance_row["range3"], data[data.length-1]["currency"]) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(balance_row["range4"], data[data.length-1]["currency"]) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(balance_row["range5"], data[data.length-1]["currency"]) }}
+ </td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(flt(balance_row["outstanding"]), data[data.length-1]["currency"]) }}
+ </td>
+ </tr>
+ <td>{{ _("Future Payments") }}</td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td class="text-right">
+ {{ frappe.utils.fmt_money(flt(balance_row[("future_amount")]), data[data.length-1]["currency"]) }}
+ </td>
+ <tr class="cvs-footer">
+ <th class="text-left">{{ _("Cheques Required") }}</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ <th></th>
+ <th></th>
+ <th></th>
+ <th class="text-right">
+ {{ frappe.utils.fmt_money(flt(balance_row["outstanding"] - balance_row[("future_amount")]), data[data.length-1]["currency"]) }}</th>
+ </tr>
+ </tbody>
+
+ </table>
+ {% endif %}
+ {% endif %}
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ {% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
+ <th style="width: 10%">{{ _("Date") }}</th>
+ <th style="width: 4%">{{ _("Age (Days)") }}</th>
+
+ {% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+ <th style="width: 14%">{{ _("Reference") }}</th>
+ <th style="width: 10%">{{ _("Sales Person") }}</th>
+ {% else %}
+ <th style="width: 24%">{{ _("Reference") }}</th>
+ {% endif %}
+ {% if not(filters.show_future_payments) %}
+ <th style="width: 20%">
+ {% if (filters.customer or filters.supplier or filters.customer_name) %}
+ {{ _("Remarks") }}
+ {% else %}
+ {{ _("Party") }}
+ {% endif %}
+ </th>
+ {% endif %}
+ <th style="width: 10%; text-align: right">{{ _("Invoiced Amount") }}</th>
+ {% if not(filters.show_future_payments) %}
+ <th style="width: 10%; text-align: right">{{ _("Paid Amount") }}</th>
+ <th style="width: 10%; text-align: right">
+ {% if report.report_name == "Accounts Receivable" %}
+ {{ _('Credit Note') }}
+ {% else %}
+ {{ _('Debit Note') }}
+ {% endif %}
+ </th>
+ {% endif %}
+ <th style="width: 10%; text-align: right">{{ _("Outstanding Amount") }}</th>
+ {% if(filters.show_future_payments) %}
+ {% if(report.report_name == "Accounts Receivable") %}
+ <th style="width: 12%">{{ _("Customer LPO No.") }}</th>
+ {% endif %}
+ <th style="width: 10%">{{ _("Future Payment Ref") }}</th>
+ <th style="width: 10%">{{ _("Future Payment Amount") }}</th>
+ <th style="width: 10%">{{ _("Remaining Balance") }}</th>
+ {% endif %}
+ {% else %}
+ <th style="width: 40%">
+ {% if (filters.customer or filters.supplier or filters.customer_name) %}
+ {{ _("Remarks")}}
+ {% else %}
+ {{ _("Party") }}
+ {% endif %}
+ </th>
+ <th style="width: 15%">{{ _("Total Invoiced Amount") }}</th>
+ <th style="width: 15%">{{ _("Total Paid Amount") }}</th>
+ <th style="width: 15%">
+ {% if report.report_name == "Accounts Receivable Summary" %}
+ {{ _('Credit Note Amount') }}
+ {% else %}
+ {{ _('Debit Note Amount') }}
+ {% endif %}
+ </th>
+ <th style="width: 15%">{{ _("Total Outstanding Amount") }}</th>
+ {% endif %}
+ </tr>
+ </thead>
+ <tbody>
+ {% for i in range(data|length) %}
+ <tr>
+ {% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
+ {% if(data[i]["party"]) %}
+ <td>{{ (data[i]["posting_date"]) }}</td>
+ <td style="text-align: right">{{ data[i]["age"] }}</td>
+ <td>
+ {% if not(filters.show_future_payments) %}
+ {{ data[i]["voucher_type"] }}
+ <br>
+ {% endif %}
+ {{ data[i]["voucher_no"] }}
+ </td>
+
+ {% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+ <td>{{ data[i]["sales_person"] }}</td>
+ {% endif %}
+
+ {% if not (filters.show_future_payments) %}
+ <td>
+ {% if(not(filters.customer or filters.supplier or filters.customer_name)) %}
+ {{ data[i]["party"] }}
+ {% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
+ <br> {{ data[i]["customer_name"] }}
+ {% elif(data[i]["supplier_name"] != data[i]["party"]) %}
+ <br> {{ data[i]["supplier_name"] }}
+ {% endif %}
+ {% endif %}
+ <div>
+ {% if data[i]["remarks"] %}
+ {{ _("Remarks") }}:
+ {{ data[i]["remarks"] }}
+ {% endif %}
+ </div>
+ </td>
+ {% endif %}
+
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
+
+ {% if not(filters.show_future_payments) %}
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
+ {% endif %}
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+
+ {% if(filters.show_future_payments) %}
+ {% if(report.report_name == "Accounts Receivable") %}
+ <td style="text-align: right">
+ {{ data[i]["po_no"] }}</td>
+ {% endif %}
+ <td style="text-align: right">{{ data[i]["future_ref"] }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
+ {% endif %}
+ {% else %}
+ <td></td>
+ {% if not(filters.show_future_payments) %}
+ <td></td>
+ {% endif %}
+ {% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
+ <td></td>
+ {% endif %}
+ <td></td>
+ <td style="text-align: right"><b>{{ _("Total") }}</b></td>
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["invoiced"], data[i]["currency"]) }}</td>
+
+ {% if not(filters.show_future_payments) %}
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }} </td>
+ {% endif %}
+ <td style="text-align: right">
+ {{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+
+ {% if(filters.show_future_payments) %}
+ {% if(report.report_name == "Accounts Receivable") %}
+ <td style="text-align: right">
+ {{ data[i]["po_no"] }}</td>
+ {% endif %}
+ <td style="text-align: right">{{ data[i]["future_ref"] }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
+ {% endif %}
+ {% endif %}
+ {% else %}
+ {% if(data[i]["party"] or " ") %}
+ {% if not(data[i]["is_total_row"]) %}
+ <td>
+ {% if(not(filters.customer | filters.supplier)) %}
+ {{ data[i]["party"] }}
+ {% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
+ <br> {{ data[i]["customer_name"] }}
+ {% elif(data[i]["supplier_name"] != data[i]["party"]) %}
+ <br> {{ data[i]["supplier_name"] }}
+ {% endif %}
+ {% endif %}
+ <br>{{ _("Remarks") }}:
+ {{ data[i]["remarks"] }}
+ </td>
+ {% else %}
+ <td><b>{{ _("Total") }}</b></td>
+ {% endif %}
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
+ <td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
+ {% endif %}
+ {% endif %}
+ </tr>
+ {% endfor %}
+ <td></td>
+ <td></td>
+ <td></td>
+ <td></td>
+ <td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="invoiced"), currency=data[0]["currency"]) }}</b></td>
+ <td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="paid"), currency=data[0]["currency"]) }}</b></td>
+ <td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="credit_note"), currency=data[0]["currency"]) }}</b></td>
+ <td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="outstanding"), currency=data[0]["currency"]) }}</b></td>
+ </tbody>
+ </table>
+ <br>
+ {% if ageing %}
+ <h4 class="text-center">{{ _("Ageing Report based on ") }} {{ ageing.ageing_based_on }}
+ {{ _("up to " ) }} {{ frappe.format(filters.report_date, 'Date')}}
+ </h4>
+ <table class="table table-bordered">
+ <thead>
+ <tr>
+ <th style="width: 25%">30 Days</th>
+ <th style="width: 25%">60 Days</th>
+ <th style="width: 25%">90 Days</th>
+ <th style="width: 25%">120 Days</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{ frappe.utils.fmt_money(ageing.range1, currency=data[0]["currency"]) }}</td>
+ <td>{{ frappe.utils.fmt_money(ageing.range2, currency=data[0]["currency"]) }}</td>
+ <td>{{ frappe.utils.fmt_money(ageing.range3, currency=data[0]["currency"]) }}</td>
+ <td>{{ frappe.utils.fmt_money(ageing.range4, currency=data[0]["currency"]) }}</td>
+ </tr>
+ </tbody>
+ </table>
+ {% endif %}
+ <p class="text-right text-muted">{{ _("Printed On ") }}{{ frappe.utils.now() }}</p>
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index ab7884d..6a558ca 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -54,9 +54,11 @@
hide_fields(this.frm.doc);
// Show / Hide button
this.show_general_ledger();
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
- if(doc.update_stock==1 && doc.docstatus==1) {
+ if(doc.update_stock==1) {
this.show_stock_ledger();
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
}
if(!doc.is_return && doc.docstatus == 1 && doc.outstanding_amount != 0){
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
index 8cb2950..68407e0 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js
@@ -88,8 +88,12 @@
}
this.show_general_ledger();
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
- if(doc.update_stock) this.show_stock_ledger();
+ if(doc.update_stock){
+ this.show_stock_ledger();
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+ }
if (doc.docstatus == 1 && doc.outstanding_amount!=0
&& !(cint(doc.is_return) && doc.return_against)) {
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index ab4aab3..f0d3f72 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -2157,7 +2157,7 @@
"link_fieldname": "consolidated_invoice"
}
],
- "modified": "2023-06-19 16:02:05.309332",
+ "modified": "2023-06-21 16:02:18.988799",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
index f2bf942..ed3b991 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html
@@ -284,4 +284,4 @@
{% } %}
</tbody>
</table>
- <p class="text-right text-muted">{{ __("Printed On ") }}{%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
+ <p class="text-right text-muted">{{ __("Printed On ") }}{%= frappe.datetime.str_to_user(frappe.datetime.get_datetime_as_string()) %}</p>
\ No newline at end of file
diff --git a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
index d34c213..924c14b 100644
--- a/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
+++ b/erpnext/accounts/report/item_wise_purchase_register/item_wise_purchase_register.py
@@ -87,7 +87,7 @@
"project": d.project,
"company": d.company,
"purchase_order": d.purchase_order,
- "purchase_receipt": d.purchase_receipt,
+ "purchase_receipt": purchase_receipt,
"expense_account": expense_account,
"stock_qty": d.stock_qty,
"stock_uom": d.stock_uom,
@@ -241,7 +241,7 @@
},
{
"label": _("Purchase Receipt"),
- "fieldname": "Purchase Receipt",
+ "fieldname": "purchase_receipt",
"fieldtype": "Link",
"options": "Purchase Receipt",
"width": 100,
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 0ee06e8..a5cb324 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -237,11 +237,6 @@
if not (frappe.flags.ignore_account_permission or ignore_account_permission):
acc.check_permission("read")
- if report_type == "Profit and Loss":
- # for pl accounts, get balance within a fiscal year
- cond.append(
- "posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" % year_start_date
- )
# different filter for group and ledger - improved performance
if acc.is_group:
cond.append(
diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js
index 01fcb11..6d55d77 100644
--- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js
+++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.js
@@ -15,7 +15,6 @@
}
refresh() {
- erpnext.hide_company();
this.show_general_ledger();
if ((this.frm.doc.stock_items && this.frm.doc.stock_items.length) || !this.frm.doc.target_is_fixed_asset) {
this.show_stock_ledger();
@@ -129,10 +128,6 @@
return this.get_target_item_details();
}
- target_asset() {
- return this.get_target_asset_details();
- }
-
item_code(doc, cdt, cdn) {
var row = frappe.get_doc(cdt, cdn);
if (cdt === "Asset Capitalization Stock Item") {
@@ -247,26 +242,6 @@
}
}
- get_target_asset_details() {
- var me = this;
-
- if (me.frm.doc.target_asset) {
- return me.frm.call({
- method: "erpnext.assets.doctype.asset_capitalization.asset_capitalization.get_target_asset_details",
- child: me.frm.doc,
- args: {
- asset: me.frm.doc.target_asset,
- company: me.frm.doc.company,
- },
- callback: function (r) {
- if (!r.exc) {
- me.frm.refresh_fields();
- }
- }
- });
- }
- }
-
get_consumed_stock_item_details(row) {
var me = this;
diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.json b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.json
index 01b35f6..04b0c4e 100644
--- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.json
+++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.json
@@ -11,13 +11,14 @@
"naming_series",
"entry_type",
"target_item_code",
+ "target_asset",
"target_item_name",
"target_is_fixed_asset",
"target_has_batch_no",
"target_has_serial_no",
"column_break_9",
- "target_asset",
"target_asset_name",
+ "target_asset_location",
"target_warehouse",
"target_qty",
"target_stock_uom",
@@ -85,14 +86,13 @@
"fieldtype": "Column Break"
},
{
- "depends_on": "eval:doc.entry_type=='Capitalization'",
"fieldname": "target_asset",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Target Asset",
- "mandatory_depends_on": "eval:doc.entry_type=='Capitalization'",
"no_copy": 1,
- "options": "Asset"
+ "options": "Asset",
+ "read_only": 1
},
{
"depends_on": "eval:doc.entry_type=='Capitalization'",
@@ -108,11 +108,11 @@
"fieldtype": "Column Break"
},
{
- "fetch_from": "asset.company",
"fieldname": "company",
"fieldtype": "Link",
"label": "Company",
"options": "Company",
+ "remember_last_selected_value": 1,
"reqd": 1
},
{
@@ -158,7 +158,7 @@
"read_only": 1
},
{
- "depends_on": "eval:doc.docstatus == 0 || (doc.stock_items && doc.stock_items.length)",
+ "depends_on": "eval:doc.entry_type=='Capitalization' && (doc.docstatus == 0 || (doc.stock_items && doc.stock_items.length))",
"fieldname": "section_break_16",
"fieldtype": "Section Break",
"label": "Consumed Stock Items"
@@ -189,7 +189,7 @@
"fieldname": "target_qty",
"fieldtype": "Float",
"label": "Target Qty",
- "read_only_depends_on": "target_is_fixed_asset"
+ "read_only_depends_on": "eval:doc.entry_type=='Capitalization'"
},
{
"fetch_from": "target_item_code.stock_uom",
@@ -227,7 +227,7 @@
"depends_on": "eval:doc.docstatus == 0 || (doc.asset_items && doc.asset_items.length)",
"fieldname": "section_break_26",
"fieldtype": "Section Break",
- "label": "Consumed Asset Items"
+ "label": "Consumed Assets"
},
{
"fieldname": "asset_items",
@@ -266,7 +266,7 @@
"options": "Finance Book"
},
{
- "depends_on": "eval:doc.docstatus == 0 || (doc.service_items && doc.service_items.length)",
+ "depends_on": "eval:doc.entry_type=='Capitalization' && (doc.docstatus == 0 || (doc.service_items && doc.service_items.length))",
"fieldname": "service_expenses_section",
"fieldtype": "Section Break",
"label": "Service Expenses"
@@ -329,12 +329,20 @@
"label": "Target Fixed Asset Account",
"options": "Account",
"read_only": 1
+ },
+ {
+ "depends_on": "eval:doc.entry_type=='Capitalization'",
+ "fieldname": "target_asset_location",
+ "fieldtype": "Link",
+ "label": "Target Asset Location",
+ "mandatory_depends_on": "eval:doc.entry_type=='Capitalization'",
+ "options": "Location"
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2022-10-12 15:09:40.771332",
+ "modified": "2023-06-22 14:17:07.995120",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Capitalization",
diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
index 6841c56..a883bec 100644
--- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
+++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
@@ -19,9 +19,6 @@
reverse_depreciation_entry_made_after_disposal,
)
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
-from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import (
- make_new_active_asset_depr_schedules_and_cancel_current_ones,
-)
from erpnext.controllers.stock_controller import StockController
from erpnext.setup.doctype.brand.brand import get_brand_defaults
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
@@ -45,7 +42,6 @@
"target_has_batch_no",
"target_stock_uom",
"stock_uom",
- "target_fixed_asset_account",
"fixed_asset_account",
"valuation_rate",
]
@@ -56,7 +52,6 @@
self.validate_posting_time()
self.set_missing_values(for_validate=True)
self.validate_target_item()
- self.validate_target_asset()
self.validate_consumed_stock_item()
self.validate_consumed_asset_item()
self.validate_service_item()
@@ -71,11 +66,12 @@
def before_submit(self):
self.validate_source_mandatory()
+ if self.entry_type == "Capitalization":
+ self.create_target_asset()
def on_submit(self):
self.update_stock_ledger()
self.make_gl_entries()
- self.update_target_asset()
def on_cancel(self):
self.ignore_linked_doctypes = (
@@ -86,7 +82,7 @@
)
self.update_stock_ledger()
self.make_gl_entries()
- self.update_target_asset()
+ self.restore_consumed_asset_items()
def set_title(self):
self.title = self.target_asset_name or self.target_item_name or self.target_item_code
@@ -97,15 +93,6 @@
if self.meta.has_field(k) and (not self.get(k) or k in force_fields):
self.set(k, v)
- # Remove asset if item not a fixed asset
- if not self.target_is_fixed_asset:
- self.target_asset = None
-
- target_asset_details = get_target_asset_details(self.target_asset, self.company)
- for k, v in target_asset_details.items():
- if self.meta.has_field(k) and (not self.get(k) or k in force_fields):
- self.set(k, v)
-
for d in self.stock_items:
args = self.as_dict()
args.update(d.as_dict())
@@ -157,9 +144,6 @@
if not target_item.is_stock_item:
self.target_warehouse = None
- if not target_item.is_fixed_asset:
- self.target_asset = None
- self.target_fixed_asset_account = None
if not target_item.has_batch_no:
self.target_batch_no = None
if not target_item.has_serial_no:
@@ -170,17 +154,6 @@
self.validate_item(target_item)
- def validate_target_asset(self):
- if self.target_asset:
- target_asset = self.get_asset_for_validation(self.target_asset)
-
- if target_asset.item_code != self.target_item_code:
- frappe.throw(
- _("Asset {0} does not belong to Item {1}").format(self.target_asset, self.target_item_code)
- )
-
- self.validate_asset(target_asset)
-
def validate_consumed_stock_item(self):
for d in self.stock_items:
if d.item_code:
@@ -386,7 +359,11 @@
gl_entries, target_account, target_against, precision
)
+ if not self.stock_items and not self.service_items and self.are_all_asset_items_non_depreciable:
+ return []
+
self.get_gl_entries_for_target_item(gl_entries, target_against, precision)
+
return gl_entries
def get_target_account(self):
@@ -429,11 +406,14 @@
def get_gl_entries_for_consumed_asset_items(
self, gl_entries, target_account, target_against, precision
):
+ self.are_all_asset_items_non_depreciable = True
+
# Consumed Assets
for item in self.asset_items:
- asset = self.get_asset(item)
+ asset = frappe.get_doc("Asset", item.asset)
if asset.calculate_depreciation:
+ self.are_all_asset_items_non_depreciable = False
notes = _(
"This schedule was created when Asset {0} was consumed through Asset Capitalization {1}."
).format(
@@ -519,40 +499,46 @@
)
)
- def update_target_asset(self):
+ def create_target_asset(self):
total_target_asset_value = flt(self.total_value, self.precision("total_value"))
- if self.docstatus == 1 and self.entry_type == "Capitalization":
- asset_doc = frappe.get_doc("Asset", self.target_asset)
- asset_doc.purchase_date = self.posting_date
- asset_doc.gross_purchase_amount = total_target_asset_value
- asset_doc.purchase_receipt_amount = total_target_asset_value
- notes = _(
- "This schedule was created when target Asset {0} was updated through Asset Capitalization {1}."
- ).format(
- get_link_to_form(asset_doc.doctype, asset_doc.name), get_link_to_form(self.doctype, self.name)
- )
- make_new_active_asset_depr_schedules_and_cancel_current_ones(asset_doc, notes)
- asset_doc.flags.ignore_validate_update_after_submit = True
- asset_doc.save()
- elif self.docstatus == 2:
- for item in self.asset_items:
- asset = self.get_asset(item)
- asset.db_set("disposal_date", None)
- self.set_consumed_asset_status(asset)
+ asset_doc = frappe.new_doc("Asset")
+ asset_doc.company = self.company
+ asset_doc.item_code = self.target_item_code
+ asset_doc.is_existing_asset = 1
+ asset_doc.location = self.target_asset_location
+ asset_doc.available_for_use_date = self.posting_date
+ asset_doc.purchase_date = self.posting_date
+ asset_doc.gross_purchase_amount = total_target_asset_value
+ asset_doc.purchase_receipt_amount = total_target_asset_value
+ asset_doc.flags.ignore_validate = True
+ asset_doc.insert()
- if asset.calculate_depreciation:
- reverse_depreciation_entry_made_after_disposal(asset, self.posting_date)
- notes = _(
- "This schedule was created when Asset {0} was restored on Asset Capitalization {1}'s cancellation."
- ).format(
- get_link_to_form(asset.doctype, asset.name), get_link_to_form(self.doctype, self.name)
- )
- reset_depreciation_schedule(asset, self.posting_date, notes)
+ self.target_asset = asset_doc.name
- def get_asset(self, item):
- asset = frappe.get_doc("Asset", item.asset)
- self.check_finance_books(item, asset)
- return asset
+ self.target_fixed_asset_account = get_asset_category_account(
+ "fixed_asset_account", item=self.target_item_code, company=asset_doc.company
+ )
+
+ frappe.msgprint(
+ _(
+ "Asset {0} has been created. Please set the depreciation details if any and submit it."
+ ).format(get_link_to_form("Asset", asset_doc.name))
+ )
+
+ def restore_consumed_asset_items(self):
+ for item in self.asset_items:
+ asset = frappe.get_doc("Asset", item.asset)
+ asset.db_set("disposal_date", None)
+ self.set_consumed_asset_status(asset)
+
+ if asset.calculate_depreciation:
+ reverse_depreciation_entry_made_after_disposal(asset, self.posting_date)
+ notes = _(
+ "This schedule was created when Asset {0} was restored on Asset Capitalization {1}'s cancellation."
+ ).format(
+ get_link_to_form(asset.doctype, asset.name), get_link_to_form(self.doctype, self.name)
+ )
+ reset_depreciation_schedule(asset, self.posting_date, notes)
def set_consumed_asset_status(self, asset):
if self.docstatus == 1:
@@ -603,33 +589,6 @@
@frappe.whitelist()
-def get_target_asset_details(asset=None, company=None):
- out = frappe._dict()
-
- # Get Asset Details
- asset_details = frappe._dict()
- if asset:
- asset_details = frappe.db.get_value("Asset", asset, ["asset_name", "item_code"], as_dict=1)
- if not asset_details:
- frappe.throw(_("Asset {0} does not exist").format(asset))
-
- # Re-set item code from Asset
- out.target_item_code = asset_details.item_code
-
- # Set Asset Details
- out.asset_name = asset_details.asset_name
-
- if asset_details.item_code:
- out.target_fixed_asset_account = get_asset_category_account(
- "fixed_asset_account", item=asset_details.item_code, company=company
- )
- else:
- out.target_fixed_asset_account = None
-
- return out
-
-
-@frappe.whitelist()
def get_consumed_stock_item_details(args):
if isinstance(args, str):
args = json.loads(args)
diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
index 5345d0e..6e0a685 100644
--- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
+++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
@@ -47,13 +47,6 @@
total_amount = 103000
- # Create assets
- target_asset = create_asset(
- asset_name="Asset Capitalization Target Asset",
- submit=1,
- warehouse="Stores - TCP1",
- company=company,
- )
consumed_asset = create_asset(
asset_name="Asset Capitalization Consumable Asset",
asset_value=consumed_asset_value,
@@ -65,7 +58,8 @@
# Create and submit Asset Captitalization
asset_capitalization = create_asset_capitalization(
entry_type="Capitalization",
- target_asset=target_asset.name,
+ target_item_code="Macbook Pro",
+ target_asset_location="Test Location",
stock_qty=stock_qty,
stock_rate=stock_rate,
consumed_asset=consumed_asset.name,
@@ -94,7 +88,7 @@
self.assertEqual(asset_capitalization.target_incoming_rate, total_amount)
# Test Target Asset values
- target_asset.reload()
+ target_asset = frappe.get_doc("Asset", asset_capitalization.target_asset)
self.assertEqual(target_asset.gross_purchase_amount, total_amount)
self.assertEqual(target_asset.purchase_receipt_amount, total_amount)
@@ -142,13 +136,6 @@
total_amount = 103000
- # Create assets
- target_asset = create_asset(
- asset_name="Asset Capitalization Target Asset",
- submit=1,
- warehouse="Stores - _TC",
- company=company,
- )
consumed_asset = create_asset(
asset_name="Asset Capitalization Consumable Asset",
asset_value=consumed_asset_value,
@@ -160,7 +147,8 @@
# Create and submit Asset Captitalization
asset_capitalization = create_asset_capitalization(
entry_type="Capitalization",
- target_asset=target_asset.name,
+ target_item_code="Macbook Pro",
+ target_asset_location="Test Location",
stock_qty=stock_qty,
stock_rate=stock_rate,
consumed_asset=consumed_asset.name,
@@ -189,7 +177,7 @@
self.assertEqual(asset_capitalization.target_incoming_rate, total_amount)
# Test Target Asset values
- target_asset.reload()
+ target_asset = frappe.get_doc("Asset", asset_capitalization.target_asset)
self.assertEqual(target_asset.gross_purchase_amount, total_amount)
self.assertEqual(target_asset.purchase_receipt_amount, total_amount)
@@ -364,6 +352,7 @@
"posting_time": args.posting_time or now.strftime("%H:%M:%S.%f"),
"target_item_code": target_item_code,
"target_asset": target_asset.name,
+ "target_asset_location": "Test Location",
"target_warehouse": target_warehouse,
"target_qty": flt(args.target_qty) or 1,
"target_batch_no": args.target_batch_no,
diff --git a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
index f810819..6911f94 100644
--- a/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
+++ b/erpnext/assets/report/fixed_asset_register/fixed_asset_register.py
@@ -115,7 +115,11 @@
depreciation_amount_map = get_asset_depreciation_amount_map(filters, finance_book)
for asset in assets_record:
- if assets_linked_to_fb and asset.asset_id not in assets_linked_to_fb:
+ if (
+ assets_linked_to_fb
+ and asset.calculate_depreciation
+ and asset.asset_id not in assets_linked_to_fb
+ ):
continue
asset_value = get_asset_value_after_depreciation(
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index cdbf6c7..5137e03 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -845,6 +845,149 @@
gl_entries.append(self.get_gl_dict(gl_entry, item=item))
+@frappe.whitelist()
+def show_accounting_ledger_preview(company, doctype, docname):
+ filters = {"company": company, "include_dimensions": 1}
+ doc = frappe.get_doc(doctype, docname)
+
+ gl_columns, gl_data = get_accounting_ledger_preview(doc, filters)
+
+ frappe.db.rollback()
+
+ return {"gl_columns": gl_columns, "gl_data": gl_data}
+
+
+@frappe.whitelist()
+def show_stock_ledger_preview(company, doctype, docname):
+ filters = {"company": company}
+ doc = frappe.get_doc(doctype, docname)
+
+ sl_columns, sl_data = get_stock_ledger_preview(doc, filters)
+
+ frappe.db.rollback()
+
+ return {
+ "sl_columns": sl_columns,
+ "sl_data": sl_data,
+ }
+
+
+def get_accounting_ledger_preview(doc, filters):
+ from erpnext.accounts.report.general_ledger.general_ledger import get_columns as get_gl_columns
+
+ gl_columns, gl_data = [], []
+ fields = [
+ "posting_date",
+ "account",
+ "debit",
+ "credit",
+ "against",
+ "party",
+ "party_type",
+ "cost_center",
+ "against_voucher_type",
+ "against_voucher",
+ ]
+
+ doc.docstatus = 1
+
+ if doc.get("update_stock") or doc.doctype in ("Purchase Receipt", "Delivery Note"):
+ doc.update_stock_ledger()
+
+ doc.make_gl_entries()
+ columns = get_gl_columns(filters)
+ gl_entries = get_gl_entries_for_preview(doc.doctype, doc.name, fields)
+
+ gl_columns = get_columns(columns, fields)
+ gl_data = get_data(fields, gl_entries)
+
+ return gl_columns, gl_data
+
+
+def get_stock_ledger_preview(doc, filters):
+ from erpnext.stock.report.stock_ledger.stock_ledger import get_columns as get_sl_columns
+
+ sl_columns, sl_data = [], []
+ fields = [
+ "item_code",
+ "stock_uom",
+ "actual_qty",
+ "qty_after_transaction",
+ "warehouse",
+ "incoming_rate",
+ "valuation_rate",
+ "stock_value",
+ "stock_value_difference",
+ ]
+ columns_fields = [
+ "item_code",
+ "stock_uom",
+ "in_qty",
+ "out_qty",
+ "qty_after_transaction",
+ "warehouse",
+ "incoming_rate",
+ "in_out_rate",
+ "stock_value",
+ "stock_value_difference",
+ ]
+
+ if doc.get("update_stock") or doc.doctype in ("Purchase Receipt", "Delivery Note"):
+ doc.docstatus = 1
+ doc.update_stock_ledger()
+ columns = get_sl_columns(filters)
+ sl_entries = get_sl_entries_for_preview(doc.doctype, doc.name, fields)
+
+ sl_columns = get_columns(columns, columns_fields)
+ sl_data = get_data(columns_fields, sl_entries)
+
+ return sl_columns, sl_data
+
+
+def get_sl_entries_for_preview(doctype, docname, fields):
+ sl_entries = frappe.get_all(
+ "Stock Ledger Entry", filters={"voucher_type": doctype, "voucher_no": docname}, fields=fields
+ )
+
+ for entry in sl_entries:
+ if entry.actual_qty > 0:
+ entry["in_qty"] = entry.actual_qty
+ entry["out_qty"] = 0
+ else:
+ entry["out_qty"] = abs(entry.actual_qty)
+ entry["in_qty"] = 0
+
+ entry["in_out_rate"] = entry["valuation_rate"]
+
+ return sl_entries
+
+
+def get_gl_entries_for_preview(doctype, docname, fields):
+ return frappe.get_all(
+ "GL Entry", filters={"voucher_type": doctype, "voucher_no": docname}, fields=fields
+ )
+
+
+def get_columns(raw_columns, fields):
+ return [
+ {"name": d.get("label"), "editable": False, "width": 110}
+ for d in raw_columns
+ if not d.get("hidden") and d.get("fieldname") in fields
+ ]
+
+
+def get_data(raw_columns, raw_data):
+ datatable_data = []
+ for row in raw_data:
+ data_row = []
+ for column in raw_columns:
+ data_row.append(row.get(column) or "")
+
+ datatable_data.append(data_row)
+
+ return datatable_data
+
+
def repost_required_for_queue(doc: StockController) -> bool:
"""check if stock document contains repeated item-warehouse with queue based valuation.
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js
index 45a59cf..4898691 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.js
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js
@@ -99,7 +99,7 @@
}, __('Create'));
}
- if (frm.doc.mr_items && !in_list(['Material Requested', 'Closed'], frm.doc.status)) {
+ if (frm.doc.mr_items && frm.doc.mr_items.length && !in_list(['Material Requested', 'Closed'], frm.doc.status)) {
frm.add_custom_button(__("Material Request"), ()=> {
frm.trigger("make_material_request");
}, __('Create'));
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 0800bdd..6dc1ff6 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -515,6 +515,9 @@
self.show_list_created_message("Work Order", wo_list)
self.show_list_created_message("Purchase Order", po_list)
+ if not wo_list:
+ frappe.msgprint(_("No Work Orders were created"))
+
def make_work_order_for_finished_goods(self, wo_list, default_warehouses):
items_data = self.get_production_items()
@@ -618,6 +621,9 @@
def create_work_order(self, item):
from erpnext.manufacturing.doctype.work_order.work_order import OverProductionError
+ if item.get("qty") <= 0:
+ return
+
wo = frappe.new_doc("Work Order")
wo.update(item)
wo.planned_start_date = item.get("planned_start_date") or item.get("schedule_date")
diff --git a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
index 75b43ec..fcfba7f 100644
--- a/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/test_production_plan.py
@@ -76,6 +76,13 @@
"Work Order", fields=["name"], filters={"production_plan": pln.name}, as_list=1
)
+ pln.make_work_order()
+ nwork_orders = frappe.get_all(
+ "Work Order", fields=["name"], filters={"production_plan": pln.name}, as_list=1
+ )
+
+ self.assertTrue(len(work_orders), len(nwork_orders))
+
self.assertTrue(len(work_orders), len(pln.po_items))
for name in material_requests:
diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
index 123a82a..a3f0d00 100644
--- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
+++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.js
@@ -30,7 +30,7 @@
"fieldname":"based_on_document",
"label": __("Based On Document"),
"fieldtype": "Select",
- "options": ["Sales Order", "Delivery Note", "Quotation"],
+ "options": ["Sales Order", "Sales Invoice", "Delivery Note", "Quotation"],
"default": "Sales Order",
"reqd": 1
},
diff --git a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
index d3bce83..daef7f6 100644
--- a/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
+++ b/erpnext/manufacturing/report/exponential_smoothing_forecasting/exponential_smoothing_forecasting.py
@@ -99,7 +99,9 @@
parent = frappe.qb.DocType(self.doctype)
child = frappe.qb.DocType(self.child_doctype)
- date_field = "posting_date" if self.doctype == "Delivery Note" else "transaction_date"
+ date_field = (
+ "posting_date" if self.doctype in ("Delivery Note", "Sales Invoice") else "transaction_date"
+ )
query = (
frappe.qb.from_(parent)
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 18bd10f..8c0fa6b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -339,3 +339,4 @@
execute:frappe.delete_doc('DocType', 'Cash Flow Mapping Template', ignore_missing=True)
execute:frappe.delete_doc('DocType', 'Cash Flow Mapping Accounts', ignore_missing=True)
erpnext.patches.v14_0.cleanup_workspaces
+erpnext.patches.v14_0.set_report_in_process_SOA
diff --git a/erpnext/patches/v14_0/set_report_in_process_SOA.py b/erpnext/patches/v14_0/set_report_in_process_SOA.py
new file mode 100644
index 0000000..9eb5e3a
--- /dev/null
+++ b/erpnext/patches/v14_0/set_report_in_process_SOA.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
+# License: MIT. See LICENSE
+
+import frappe
+
+
+def execute():
+ process_soa = frappe.qb.DocType("Process Statement Of Accounts")
+ q = frappe.qb.update(process_soa).set(process_soa.report, "General Ledger")
+ q.run()
diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js
index d346357..720423b 100644
--- a/erpnext/public/js/controllers/stock_controller.js
+++ b/erpnext/public/js/controllers/stock_controller.js
@@ -66,7 +66,7 @@
}
show_general_ledger() {
- var me = this;
+ let me = this;
if(this.frm.doc.docstatus > 0) {
cur_frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.route_options = {
diff --git a/erpnext/public/js/erpnext.bundle.js b/erpnext/public/js/erpnext.bundle.js
index cc020fc..4e028e4 100644
--- a/erpnext/public/js/erpnext.bundle.js
+++ b/erpnext/public/js/erpnext.bundle.js
@@ -17,6 +17,7 @@
import "./utils/supplier_quick_entry";
import "./call_popup/call_popup";
import "./utils/dimension_tree_filter";
+import "./utils/ledger_preview.js"
import "./utils/barcode_scanner";
import "./telephony";
import "./templates/call_link.html";
diff --git a/erpnext/public/js/utils/ledger_preview.js b/erpnext/public/js/utils/ledger_preview.js
new file mode 100644
index 0000000..85d4a7d
--- /dev/null
+++ b/erpnext/public/js/utils/ledger_preview.js
@@ -0,0 +1,78 @@
+frappe.provide('erpnext.accounts');
+
+erpnext.accounts.ledger_preview = {
+ show_accounting_ledger_preview(frm) {
+ let me = this;
+ if(!frm.is_new() && frm.doc.docstatus == 0) {
+ frm.add_custom_button(__('Accounting Ledger'), function() {
+ frappe.call({
+ "type": "GET",
+ "method": "erpnext.controllers.stock_controller.show_accounting_ledger_preview",
+ "args": {
+ "company": frm.doc.company,
+ "doctype": frm.doc.doctype,
+ "docname": frm.doc.name
+ },
+ "callback": function(response) {
+ me.make_dialog("Accounting Ledger Preview", "accounting_ledger_preview_html", response.message.gl_columns, response.message.gl_data);
+ }
+ })
+ }, __("Preview"));
+ }
+ },
+
+ show_stock_ledger_preview(frm) {
+ let me = this
+ if(!frm.is_new() && frm.doc.docstatus == 0) {
+ frm.add_custom_button(__('Stock Ledger'), function() {
+ frappe.call({
+ "type": "GET",
+ "method": "erpnext.controllers.stock_controller.show_stock_ledger_preview",
+ "args": {
+ "company": frm.doc.company,
+ "doctype": frm.doc.doctype,
+ "docname": frm.doc.name
+ },
+ "callback": function(response) {
+ me.make_dialog("Stock Ledger Preview", "stock_ledger_preview_html", response.message.sl_columns, response.message.sl_data);
+ }
+ })
+ }, __("Preview"));
+ }
+ },
+
+ make_dialog(label, fieldname, columns, data) {
+ let me = this;
+ let dialog = new frappe.ui.Dialog({
+ "size": "extra-large",
+ "title": __(label),
+ "fields": [
+ {
+ "fieldtype": "HTML",
+ "fieldname": fieldname,
+ },
+ ]
+ });
+
+ setTimeout(function() {
+ me.get_datatable(columns, data, dialog.get_field(fieldname).wrapper);
+ }, 200);
+
+ dialog.show();
+ },
+
+ get_datatable(columns, data, wrapper) {
+ const datatable_options = {
+ columns: columns,
+ data: data,
+ dynamicRowHeight: true,
+ checkboxColumn: false,
+ inlineFilters: true,
+ };
+
+ new frappe.DataTable(
+ wrapper,
+ datatable_options
+ );
+ }
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 77545e0..a648195 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -200,6 +200,9 @@
}
}
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+
if (doc.docstatus > 0) {
this.show_stock_ledger();
if (erpnext.is_perpetual_inventory_enabled(doc.company)) {
diff --git a/erpnext/stock/doctype/item_reorder/item_reorder.json b/erpnext/stock/doctype/item_reorder/item_reorder.json
index fb4c558..a03bd45 100644
--- a/erpnext/stock/doctype/item_reorder/item_reorder.json
+++ b/erpnext/stock/doctype/item_reorder/item_reorder.json
@@ -81,7 +81,7 @@
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
- "reqd": 1,
+ "reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
@@ -147,7 +147,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2016-07-28 19:15:38.270046",
+ "modified": "2023-06-21 15:13:38.270046",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item Reorder",
@@ -158,4 +158,4 @@
"read_only_onload": 0,
"sort_order": "ASC",
"track_seen": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index dc3e0d9..35aad78 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -121,6 +121,10 @@
refresh() {
var me = this;
super.refresh();
+
+ erpnext.accounts.ledger_preview.show_accounting_ledger_preview(this.frm);
+ erpnext.accounts.ledger_preview.show_stock_ledger_preview(this.frm);
+
if(this.frm.doc.docstatus > 0) {
this.show_stock_ledger();
//removed for temporary
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index 1986722..c6c84ca 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -72,6 +72,11 @@
self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5)
def test_make_purchase_invoice(self):
+ from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_term
+
+ create_payment_term("_Test Payment Term 1 for Purchase Invoice")
+ create_payment_term("_Test Payment Term 2 for Purchase Invoice")
+
if not frappe.db.exists(
"Payment Terms Template", "_Test Payment Terms Template For Purchase Invoice"
):
@@ -83,12 +88,14 @@
"terms": [
{
"doctype": "Payment Terms Template Detail",
+ "payment_term": "_Test Payment Term 1 for Purchase Invoice",
"invoice_portion": 50.00,
"credit_days_based_on": "Day(s) after invoice date",
"credit_days": 00,
},
{
"doctype": "Payment Terms Template Detail",
+ "payment_term": "_Test Payment Term 2 for Purchase Invoice",
"invoice_portion": 50.00,
"credit_days_based_on": "Day(s) after invoice date",
"credit_days": 30,
diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py
index 136c78f..9075608 100644
--- a/erpnext/stock/reorder_item.py
+++ b/erpnext/stock/reorder_item.py
@@ -67,7 +67,7 @@
else:
projected_qty = flt(item_warehouse_projected_qty.get(item_code, {}).get(warehouse))
- if (reorder_level or reorder_qty) and projected_qty < reorder_level:
+ if (reorder_level or reorder_qty) and projected_qty <= reorder_level:
deficiency = reorder_level - projected_qty
if deficiency > reorder_qty:
reorder_qty = deficiency
diff --git a/erpnext/translations/de.csv b/erpnext/translations/de.csv
index 68358c6..f9ec689 100644
--- a/erpnext/translations/de.csv
+++ b/erpnext/translations/de.csv
@@ -9905,3 +9905,7 @@
Select an item from each set to be used in the Sales Order.,"Wählen Sie aus den Alternativen jeweils einen Artikel aus, der in die Auftragsbestätigung übernommen werden soll.",
Is Alternative,Ist Alternative,
Alternative Items,Alternativpositionen,
+Add Template,Vorlage einfügen,
+Prepend the template to the email message,Vorlage oberhalb der Email-Nachricht einfügen,
+Clear & Add Template,Leeren und Vorlage einfügen,
+Clear the email message and add the template,Email-Feld leeren und Vorlage einfügen,