Merge remote-tracking branch 'upstream/develop' into feat/so-po-advance-payment-status
This commit is contained in:
commit
c2f0fadb6e
@ -112,7 +112,8 @@ class AutoMatchbyPartyNameDescription:
|
||||
|
||||
for party in parties:
|
||||
filters = {"status": "Active"} if party == "Employee" else {"disabled": 0}
|
||||
names = frappe.get_all(party, filters=filters, pluck=party.lower() + "_name")
|
||||
field = party.lower() + "_name"
|
||||
names = frappe.get_all(party, filters=filters, fields=[f"{field} as party_name", "name"])
|
||||
|
||||
for field in ["bank_party_name", "description"]:
|
||||
if not self.get(field):
|
||||
@ -131,7 +132,11 @@ class AutoMatchbyPartyNameDescription:
|
||||
|
||||
def fuzzy_search_and_return_result(self, party, names, field) -> Union[Tuple, None]:
|
||||
skip = False
|
||||
result = process.extract(query=self.get(field), choices=names, scorer=fuzz.token_set_ratio)
|
||||
result = process.extract(
|
||||
query=self.get(field),
|
||||
choices={row.get("name"): row.get("party_name") for row in names},
|
||||
scorer=fuzz.token_set_ratio,
|
||||
)
|
||||
party_name, skip = self.process_fuzzy_result(result)
|
||||
|
||||
if not party_name:
|
||||
@ -149,14 +154,14 @@ class AutoMatchbyPartyNameDescription:
|
||||
|
||||
Returns: Result, Skip (whether or not to discontinue matching)
|
||||
"""
|
||||
PARTY, SCORE, CUTOFF = 0, 1, 80
|
||||
SCORE, PARTY_ID, CUTOFF = 1, 2, 80
|
||||
|
||||
if not result or not len(result):
|
||||
return None, False
|
||||
|
||||
first_result = result[0]
|
||||
if len(result) == 1:
|
||||
return (first_result[PARTY] if first_result[SCORE] > CUTOFF else None), True
|
||||
return (first_result[PARTY_ID] if first_result[SCORE] > CUTOFF else None), True
|
||||
|
||||
second_result = result[1]
|
||||
if first_result[SCORE] > CUTOFF:
|
||||
@ -165,7 +170,7 @@ class AutoMatchbyPartyNameDescription:
|
||||
if first_result[SCORE] == second_result[SCORE]:
|
||||
return None, True
|
||||
|
||||
return first_result[PARTY], True
|
||||
return first_result[PARTY_ID], True
|
||||
else:
|
||||
return None, False
|
||||
|
||||
|
@ -53,10 +53,18 @@ frappe.ui.form.on('Chart of Accounts Importer', {
|
||||
of Accounts. Please enter the account names and add more rows as per your requirement.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
label : "Company",
|
||||
fieldname: "company",
|
||||
fieldtype: "Link",
|
||||
reqd: 1,
|
||||
hidden: 1,
|
||||
default: frm.doc.company,
|
||||
},
|
||||
],
|
||||
primary_action: function() {
|
||||
var data = d.get_values();
|
||||
let data = d.get_values();
|
||||
|
||||
if (!data.template_type) {
|
||||
frappe.throw(__('Please select <b>Template Type</b> to download template'));
|
||||
@ -66,7 +74,8 @@ frappe.ui.form.on('Chart of Accounts Importer', {
|
||||
'/api/method/erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.download_template',
|
||||
{
|
||||
file_type: data.file_type,
|
||||
template_type: data.template_type
|
||||
template_type: data.template_type,
|
||||
company: data.company
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -8,6 +8,7 @@ from functools import reduce
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.desk.form.linked_with import get_linked_fields
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import cint, cstr
|
||||
from frappe.utils.csvutils import UnicodeWriter
|
||||
@ -294,10 +295,8 @@ def build_response_as_excel(writer):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def download_template(file_type, template_type):
|
||||
data = frappe._dict(frappe.local.form_dict)
|
||||
|
||||
writer = get_template(template_type)
|
||||
def download_template(file_type, template_type, company):
|
||||
writer = get_template(template_type, company)
|
||||
|
||||
if file_type == "CSV":
|
||||
# download csv file
|
||||
@ -308,8 +307,7 @@ def download_template(file_type, template_type):
|
||||
build_response_as_excel(writer)
|
||||
|
||||
|
||||
def get_template(template_type):
|
||||
|
||||
def get_template(template_type, company):
|
||||
fields = [
|
||||
"Account Name",
|
||||
"Parent Account",
|
||||
@ -335,34 +333,17 @@ def get_template(template_type):
|
||||
["", "", "", "", 0, account_type.get("account_type"), account_type.get("root_type")]
|
||||
)
|
||||
else:
|
||||
writer = get_sample_template(writer)
|
||||
writer = get_sample_template(writer, company)
|
||||
|
||||
return writer
|
||||
|
||||
|
||||
def get_sample_template(writer):
|
||||
template = [
|
||||
["Application Of Funds(Assets)", "", "", "", 1, "", "Asset"],
|
||||
["Sources Of Funds(Liabilities)", "", "", "", 1, "", "Liability"],
|
||||
["Equity", "", "", "", 1, "", "Equity"],
|
||||
["Expenses", "", "", "", 1, "", "Expense"],
|
||||
["Income", "", "", "", 1, "", "Income"],
|
||||
["Bank Accounts", "Application Of Funds(Assets)", "", "", 1, "Bank", "Asset"],
|
||||
["Cash In Hand", "Application Of Funds(Assets)", "", "", 1, "Cash", "Asset"],
|
||||
["Stock Assets", "Application Of Funds(Assets)", "", "", 1, "Stock", "Asset"],
|
||||
["Cost Of Goods Sold", "Expenses", "", "", 0, "Cost of Goods Sold", "Expense"],
|
||||
["Asset Depreciation", "Expenses", "", "", 0, "Depreciation", "Expense"],
|
||||
["Fixed Assets", "Application Of Funds(Assets)", "", "", 0, "Fixed Asset", "Asset"],
|
||||
["Accounts Payable", "Sources Of Funds(Liabilities)", "", "", 0, "Payable", "Liability"],
|
||||
["Accounts Receivable", "Application Of Funds(Assets)", "", "", 1, "Receivable", "Asset"],
|
||||
["Stock Expenses", "Expenses", "", "", 0, "Stock Adjustment", "Expense"],
|
||||
["Sample Bank", "Bank Accounts", "", "", 0, "Bank", "Asset"],
|
||||
["Cash", "Cash In Hand", "", "", 0, "Cash", "Asset"],
|
||||
["Stores", "Stock Assets", "", "", 0, "Stock", "Asset"],
|
||||
]
|
||||
|
||||
for row in template:
|
||||
writer.writerow(row)
|
||||
def get_sample_template(writer, company):
|
||||
currency = frappe.db.get_value("Company", company, "default_currency")
|
||||
with open(os.path.join(os.path.dirname(__file__), "coa_sample_template.csv"), "r") as f:
|
||||
for row in f:
|
||||
row = row.strip().split(",") + [currency]
|
||||
writer.writerow(row)
|
||||
|
||||
return writer
|
||||
|
||||
@ -453,14 +434,11 @@ def get_mandatory_account_types():
|
||||
|
||||
|
||||
def unset_existing_data(company):
|
||||
linked = frappe.db.sql(
|
||||
'''select fieldname from tabDocField
|
||||
where fieldtype="Link" and options="Account" and parent="Company"''',
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
# remove accounts data from company
|
||||
update_values = {d.fieldname: "" for d in linked}
|
||||
|
||||
fieldnames = get_linked_fields("Account").get("Company", {}).get("fieldname", [])
|
||||
linked = [{"fieldname": name} for name in fieldnames]
|
||||
update_values = {d.get("fieldname"): "" for d in linked}
|
||||
frappe.db.set_value("Company", company, update_values, update_values)
|
||||
|
||||
# remove accounts data from various doctypes
|
||||
|
@ -0,0 +1,17 @@
|
||||
Application Of Funds(Assets),,,,1,,Asset
|
||||
Sources Of Funds(Liabilities),,,,1,,Liability
|
||||
Equity,,,,1,,Equity
|
||||
Expenses,,,,1,Expense Account,Expense
|
||||
Income,,,,1,Income Account,Income
|
||||
Bank Accounts,Application Of Funds(Assets),,,1,Bank,Asset
|
||||
Cash In Hand,Application Of Funds(Assets),,,1,Cash,Asset
|
||||
Stock Assets,Application Of Funds(Assets),,,1,Stock,Asset
|
||||
Cost Of Goods Sold,Expenses,,,0,Cost of Goods Sold,Expense
|
||||
Asset Depreciation,Expenses,,,0,Depreciation,Expense
|
||||
Fixed Assets,Application Of Funds(Assets),,,0,Fixed Asset,Asset
|
||||
Accounts Payable,Sources Of Funds(Liabilities),,,0,Payable,Liability
|
||||
Accounts Receivable,Application Of Funds(Assets),,,1,Receivable,Asset
|
||||
Stock Expenses,Expenses,,,0,Stock Adjustment,Expense
|
||||
Sample Bank,Bank Accounts,,,0,Bank,Asset
|
||||
Cash,Cash In Hand,,,0,Cash,Asset
|
||||
Stores,Stock Assets,,,0,Stock,Asset
|
|
@ -154,7 +154,7 @@ frappe.ui.form.on('Payment Entry', {
|
||||
frm.events.set_dynamic_labels(frm);
|
||||
frm.events.show_general_ledger(frm);
|
||||
erpnext.accounts.ledger_preview.show_accounting_ledger_preview(frm);
|
||||
if(frm.doc.references.find((elem) => {return elem.exchange_gain_loss != 0})) {
|
||||
if((frm.doc.references) && (frm.doc.references.find((elem) => {return elem.exchange_gain_loss != 0}))) {
|
||||
frm.add_custom_button(__("View Exchange Gain/Loss Journals"), function() {
|
||||
frappe.set_route("List", "Journal Entry", {"voucher_type": "Exchange Gain Or Loss", "reference_name": frm.doc.name});
|
||||
}, __('Actions'));
|
||||
|
@ -595,6 +595,7 @@
|
||||
"fieldname": "status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "\nDraft\nSubmitted\nCancelled",
|
||||
"read_only": 1
|
||||
},
|
||||
@ -750,7 +751,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-06-23 18:07:38.023010",
|
||||
"modified": "2023-11-08 21:51:03.482709",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry",
|
||||
|
@ -33,6 +33,7 @@ from erpnext.accounts.utils import (
|
||||
get_account_currency,
|
||||
get_balance_on,
|
||||
get_outstanding_invoices,
|
||||
get_party_types_from_account_type,
|
||||
)
|
||||
from erpnext.controllers.accounts_controller import (
|
||||
AccountsController,
|
||||
@ -83,7 +84,6 @@ class PaymentEntry(AccountsController):
|
||||
self.apply_taxes()
|
||||
self.set_amounts_after_tax()
|
||||
self.clear_unallocated_reference_document_rows()
|
||||
self.validate_payment_against_negative_invoice()
|
||||
self.validate_transaction_reference()
|
||||
self.set_title()
|
||||
self.set_remarks()
|
||||
@ -952,35 +952,6 @@ class PaymentEntry(AccountsController):
|
||||
self.name,
|
||||
)
|
||||
|
||||
def validate_payment_against_negative_invoice(self):
|
||||
if (self.payment_type != "Pay" or self.party_type != "Customer") and (
|
||||
self.payment_type != "Receive" or self.party_type != "Supplier"
|
||||
):
|
||||
return
|
||||
|
||||
total_negative_outstanding = sum(
|
||||
abs(flt(d.outstanding_amount)) for d in self.get("references") if flt(d.outstanding_amount) < 0
|
||||
)
|
||||
|
||||
paid_amount = self.paid_amount if self.payment_type == "Receive" else self.received_amount
|
||||
additional_charges = sum(flt(d.amount) for d in self.deductions)
|
||||
|
||||
if not total_negative_outstanding:
|
||||
if self.party_type == "Customer":
|
||||
msg = _("Cannot pay to Customer without any negative outstanding invoice")
|
||||
else:
|
||||
msg = _("Cannot receive from Supplier without any negative outstanding invoice")
|
||||
|
||||
frappe.throw(msg, InvalidPaymentEntry)
|
||||
|
||||
elif paid_amount - additional_charges > total_negative_outstanding:
|
||||
frappe.throw(
|
||||
_("Paid Amount cannot be greater than total negative outstanding amount {0}").format(
|
||||
fmt_money(total_negative_outstanding)
|
||||
),
|
||||
InvalidPaymentEntry,
|
||||
)
|
||||
|
||||
def set_title(self):
|
||||
if frappe.flags.in_import and self.title:
|
||||
# do not set title dynamically if title exists during data import.
|
||||
@ -1083,9 +1054,7 @@ class PaymentEntry(AccountsController):
|
||||
item=self,
|
||||
)
|
||||
|
||||
dr_or_cr = (
|
||||
"credit" if erpnext.get_party_account_type(self.party_type) == "Receivable" else "debit"
|
||||
)
|
||||
dr_or_cr = "credit" if self.payment_type == "Receive" else "debit"
|
||||
|
||||
for d in self.get("references"):
|
||||
cost_center = self.cost_center
|
||||
@ -1103,10 +1072,27 @@ class PaymentEntry(AccountsController):
|
||||
against_voucher_type = d.reference_doctype
|
||||
against_voucher = d.reference_name
|
||||
|
||||
reverse_dr_or_cr, standalone_note = 0, 0
|
||||
if d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||
is_return, return_against = frappe.db.get_value(
|
||||
d.reference_doctype, d.reference_name, ["is_return", "return_against"]
|
||||
)
|
||||
payable_party_types = get_party_types_from_account_type("Payable")
|
||||
receivable_party_types = get_party_types_from_account_type("Receivable")
|
||||
if is_return and self.party_type in receivable_party_types and (self.payment_type == "Pay"):
|
||||
reverse_dr_or_cr = 1
|
||||
elif (
|
||||
is_return and self.party_type in payable_party_types and (self.payment_type == "Receive")
|
||||
):
|
||||
reverse_dr_or_cr = 1
|
||||
|
||||
if is_return and not return_against and not reverse_dr_or_cr:
|
||||
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
||||
|
||||
gle.update(
|
||||
{
|
||||
dr_or_cr: allocated_amount_in_company_currency,
|
||||
dr_or_cr + "_in_account_currency": d.allocated_amount,
|
||||
dr_or_cr: abs(allocated_amount_in_company_currency),
|
||||
dr_or_cr + "_in_account_currency": abs(d.allocated_amount),
|
||||
"against_voucher_type": against_voucher_type,
|
||||
"against_voucher": against_voucher,
|
||||
"cost_center": cost_center,
|
||||
@ -1698,13 +1684,42 @@ def get_outstanding_reference_documents(args, validate=False):
|
||||
return data
|
||||
|
||||
|
||||
def split_invoices_based_on_payment_terms(outstanding_invoices, company):
|
||||
invoice_ref_based_on_payment_terms = {}
|
||||
def split_invoices_based_on_payment_terms(outstanding_invoices, company) -> list:
|
||||
"""Split a list of invoices based on their payment terms."""
|
||||
exc_rates = get_currency_data(outstanding_invoices, company)
|
||||
|
||||
outstanding_invoices_after_split = []
|
||||
for entry in outstanding_invoices:
|
||||
if entry.voucher_type in ["Sales Invoice", "Purchase Invoice"]:
|
||||
if payment_term_template := frappe.db.get_value(
|
||||
entry.voucher_type, entry.voucher_no, "payment_terms_template"
|
||||
):
|
||||
split_rows = get_split_invoice_rows(entry, payment_term_template, exc_rates)
|
||||
if not split_rows:
|
||||
continue
|
||||
|
||||
frappe.msgprint(
|
||||
_("Splitting {0} {1} into {2} rows as per Payment Terms").format(
|
||||
_(entry.voucher_type), frappe.bold(entry.voucher_no), len(split_rows)
|
||||
),
|
||||
alert=True,
|
||||
)
|
||||
outstanding_invoices_after_split += split_rows
|
||||
continue
|
||||
|
||||
# If not an invoice or no payment terms template, add as it is
|
||||
outstanding_invoices_after_split.append(entry)
|
||||
|
||||
return outstanding_invoices_after_split
|
||||
|
||||
|
||||
def get_currency_data(outstanding_invoices: list, company: str = None) -> dict:
|
||||
"""Get currency and conversion data for a list of invoices."""
|
||||
exc_rates = frappe._dict()
|
||||
company_currency = (
|
||||
frappe.db.get_value("Company", company, "default_currency") if company else None
|
||||
)
|
||||
exc_rates = frappe._dict()
|
||||
|
||||
for doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||
invoices = [x.voucher_no for x in outstanding_invoices if x.voucher_type == doctype]
|
||||
for x in frappe.db.get_all(
|
||||
@ -1719,72 +1734,54 @@ def split_invoices_based_on_payment_terms(outstanding_invoices, company):
|
||||
company_currency=company_currency,
|
||||
)
|
||||
|
||||
for idx, d in enumerate(outstanding_invoices):
|
||||
if d.voucher_type in ["Sales Invoice", "Purchase Invoice"]:
|
||||
payment_term_template = frappe.db.get_value(
|
||||
d.voucher_type, d.voucher_no, "payment_terms_template"
|
||||
return exc_rates
|
||||
|
||||
|
||||
def get_split_invoice_rows(invoice: dict, payment_term_template: str, exc_rates: dict) -> list:
|
||||
"""Split invoice based on its payment schedule table."""
|
||||
split_rows = []
|
||||
allocate_payment_based_on_payment_terms = frappe.db.get_value(
|
||||
"Payment Terms Template", payment_term_template, "allocate_payment_based_on_payment_terms"
|
||||
)
|
||||
|
||||
if not allocate_payment_based_on_payment_terms:
|
||||
return [invoice]
|
||||
|
||||
payment_schedule = frappe.get_all(
|
||||
"Payment Schedule", filters={"parent": invoice.voucher_no}, fields=["*"], order_by="due_date"
|
||||
)
|
||||
for payment_term in payment_schedule:
|
||||
if not payment_term.outstanding > 0.1:
|
||||
continue
|
||||
|
||||
doc_details = exc_rates.get(payment_term.parent, None)
|
||||
is_multi_currency_acc = (doc_details.currency != doc_details.company_currency) and (
|
||||
doc_details.party_account_currency != doc_details.company_currency
|
||||
)
|
||||
payment_term_outstanding = flt(payment_term.outstanding)
|
||||
if not is_multi_currency_acc:
|
||||
payment_term_outstanding = doc_details.conversion_rate * flt(payment_term.outstanding)
|
||||
|
||||
split_rows.append(
|
||||
frappe._dict(
|
||||
{
|
||||
"due_date": invoice.due_date,
|
||||
"currency": invoice.currency,
|
||||
"voucher_no": invoice.voucher_no,
|
||||
"voucher_type": invoice.voucher_type,
|
||||
"posting_date": invoice.posting_date,
|
||||
"invoice_amount": flt(invoice.invoice_amount),
|
||||
"outstanding_amount": payment_term_outstanding
|
||||
if payment_term_outstanding
|
||||
else invoice.outstanding_amount,
|
||||
"payment_term_outstanding": payment_term_outstanding,
|
||||
"payment_amount": payment_term.payment_amount,
|
||||
"payment_term": payment_term.payment_term,
|
||||
}
|
||||
)
|
||||
if payment_term_template:
|
||||
allocate_payment_based_on_payment_terms = frappe.get_cached_value(
|
||||
"Payment Terms Template", payment_term_template, "allocate_payment_based_on_payment_terms"
|
||||
)
|
||||
if allocate_payment_based_on_payment_terms:
|
||||
payment_schedule = frappe.get_all(
|
||||
"Payment Schedule", filters={"parent": d.voucher_no}, fields=["*"]
|
||||
)
|
||||
)
|
||||
|
||||
for payment_term in payment_schedule:
|
||||
if payment_term.outstanding > 0.1:
|
||||
doc_details = exc_rates.get(payment_term.parent, None)
|
||||
is_multi_currency_acc = (doc_details.currency != doc_details.company_currency) and (
|
||||
doc_details.party_account_currency != doc_details.company_currency
|
||||
)
|
||||
payment_term_outstanding = flt(payment_term.outstanding)
|
||||
if not is_multi_currency_acc:
|
||||
payment_term_outstanding = doc_details.conversion_rate * flt(payment_term.outstanding)
|
||||
|
||||
invoice_ref_based_on_payment_terms.setdefault(idx, [])
|
||||
invoice_ref_based_on_payment_terms[idx].append(
|
||||
frappe._dict(
|
||||
{
|
||||
"due_date": d.due_date,
|
||||
"currency": d.currency,
|
||||
"voucher_no": d.voucher_no,
|
||||
"voucher_type": d.voucher_type,
|
||||
"posting_date": d.posting_date,
|
||||
"invoice_amount": flt(d.invoice_amount),
|
||||
"outstanding_amount": payment_term_outstanding
|
||||
if payment_term_outstanding
|
||||
else d.outstanding_amount,
|
||||
"payment_term_outstanding": payment_term_outstanding,
|
||||
"payment_amount": payment_term.payment_amount,
|
||||
"payment_term": payment_term.payment_term,
|
||||
"account": d.account,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
outstanding_invoices_after_split = []
|
||||
if invoice_ref_based_on_payment_terms:
|
||||
for idx, ref in invoice_ref_based_on_payment_terms.items():
|
||||
voucher_no = ref[0]["voucher_no"]
|
||||
voucher_type = ref[0]["voucher_type"]
|
||||
|
||||
frappe.msgprint(
|
||||
_("Spliting {} {} into {} row(s) as per Payment Terms").format(
|
||||
voucher_type, voucher_no, len(ref)
|
||||
),
|
||||
alert=True,
|
||||
)
|
||||
|
||||
outstanding_invoices_after_split += invoice_ref_based_on_payment_terms[idx]
|
||||
|
||||
existing_row = list(filter(lambda x: x.get("voucher_no") == voucher_no, outstanding_invoices))
|
||||
index = outstanding_invoices.index(existing_row[0])
|
||||
outstanding_invoices.pop(index)
|
||||
|
||||
outstanding_invoices_after_split += outstanding_invoices
|
||||
return outstanding_invoices_after_split
|
||||
return split_rows
|
||||
|
||||
|
||||
def get_orders_to_be_billed(
|
||||
|
@ -6,10 +6,11 @@ import unittest
|
||||
import frappe
|
||||
from frappe import qb
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
from frappe.utils import flt, nowdate
|
||||
from frappe.utils import add_days, flt, nowdate
|
||||
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import (
|
||||
InvalidPaymentEntry,
|
||||
get_outstanding_reference_documents,
|
||||
get_payment_entry,
|
||||
get_reference_details,
|
||||
)
|
||||
@ -683,17 +684,6 @@ class TestPaymentEntry(FrappeTestCase):
|
||||
self.validate_gl_entries(pe.name, expected_gle)
|
||||
|
||||
def test_payment_against_negative_sales_invoice(self):
|
||||
pe1 = frappe.new_doc("Payment Entry")
|
||||
pe1.payment_type = "Pay"
|
||||
pe1.company = "_Test Company"
|
||||
pe1.party_type = "Customer"
|
||||
pe1.party = "_Test Customer"
|
||||
pe1.paid_from = "_Test Cash - _TC"
|
||||
pe1.paid_amount = 100
|
||||
pe1.received_amount = 100
|
||||
|
||||
self.assertRaises(InvalidPaymentEntry, pe1.validate)
|
||||
|
||||
si1 = create_sales_invoice()
|
||||
|
||||
# create full payment entry against si1
|
||||
@ -751,8 +741,6 @@ class TestPaymentEntry(FrappeTestCase):
|
||||
|
||||
# pay more than outstanding against si1
|
||||
pe3 = get_payment_entry("Sales Invoice", si1.name, bank_account="_Test Cash - _TC")
|
||||
pe3.paid_amount = pe3.received_amount = 300
|
||||
self.assertRaises(InvalidPaymentEntry, pe3.validate)
|
||||
|
||||
# pay negative outstanding against si1
|
||||
pe3.paid_to = "Debtors - _TC"
|
||||
@ -1262,6 +1250,78 @@ class TestPaymentEntry(FrappeTestCase):
|
||||
so.reload()
|
||||
self.assertEqual(so.advance_paid, so.rounded_total)
|
||||
|
||||
def test_outstanding_invoices_api(self):
|
||||
"""
|
||||
Test if `get_outstanding_reference_documents` fetches invoices in the right order.
|
||||
"""
|
||||
customer = create_customer("Max Mustermann", "INR")
|
||||
create_payment_terms_template()
|
||||
|
||||
# SI has an earlier due date and SI2 has a later due date
|
||||
si = create_sales_invoice(
|
||||
qty=1, rate=100, customer=customer, posting_date=add_days(nowdate(), -4)
|
||||
)
|
||||
si2 = create_sales_invoice(do_not_save=1, qty=1, rate=100, customer=customer)
|
||||
si2.payment_terms_template = "Test Receivable Template"
|
||||
si2.submit()
|
||||
|
||||
args = {
|
||||
"posting_date": nowdate(),
|
||||
"company": "_Test Company",
|
||||
"party_type": "Customer",
|
||||
"payment_type": "Pay",
|
||||
"party": customer,
|
||||
"party_account": "Debtors - _TC",
|
||||
}
|
||||
args.update(
|
||||
{
|
||||
"get_outstanding_invoices": True,
|
||||
"from_posting_date": add_days(nowdate(), -4),
|
||||
"to_posting_date": add_days(nowdate(), 2),
|
||||
}
|
||||
)
|
||||
references = get_outstanding_reference_documents(args)
|
||||
|
||||
self.assertEqual(len(references), 3)
|
||||
self.assertEqual(references[0].voucher_no, si.name)
|
||||
self.assertEqual(references[1].voucher_no, si2.name)
|
||||
self.assertEqual(references[2].voucher_no, si2.name)
|
||||
self.assertEqual(references[1].payment_term, "Basic Amount Receivable")
|
||||
self.assertEqual(references[2].payment_term, "Tax Receivable")
|
||||
|
||||
def test_receive_payment_from_payable_party_type(self):
|
||||
pe = create_payment_entry(
|
||||
party_type="Supplier",
|
||||
party="_Test Supplier",
|
||||
payment_type="Receive",
|
||||
paid_from="Creditors - _TC",
|
||||
paid_to="_Test Cash - _TC",
|
||||
save=True,
|
||||
submit=True,
|
||||
)
|
||||
self.voucher_no = pe.name
|
||||
self.expected_gle = [
|
||||
{"account": "_Test Cash - _TC", "debit": 1000.0, "credit": 0.0},
|
||||
{"account": "Creditors - _TC", "debit": 0.0, "credit": 1000.0},
|
||||
]
|
||||
self.check_gl_entries()
|
||||
|
||||
def check_gl_entries(self):
|
||||
gle = frappe.qb.DocType("GL Entry")
|
||||
gl_entries = (
|
||||
frappe.qb.from_(gle)
|
||||
.select(
|
||||
gle.account,
|
||||
gle.debit,
|
||||
gle.credit,
|
||||
)
|
||||
.where((gle.voucher_no == self.voucher_no) & (gle.is_cancelled == 0))
|
||||
.orderby(gle.account)
|
||||
).run(as_dict=True)
|
||||
for row in range(len(self.expected_gle)):
|
||||
for field in ["account", "debit", "credit"]:
|
||||
self.assertEqual(self.expected_gle[row][field], gl_entries[row][field])
|
||||
|
||||
|
||||
def create_payment_entry(**args):
|
||||
payment_entry = frappe.new_doc("Payment Entry")
|
||||
@ -1322,6 +1382,9 @@ def create_payment_terms_template():
|
||||
def create_payment_terms_template_with_discount(
|
||||
name=None, discount_type=None, discount=None, template_name=None
|
||||
):
|
||||
"""
|
||||
Create a Payment Terms Template with % or amount discount.
|
||||
"""
|
||||
create_payment_term(name or "30 Credit Days with 10% Discount")
|
||||
template_name = template_name or "Test Discount Template"
|
||||
|
||||
|
@ -65,7 +65,8 @@
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Voucher Type",
|
||||
"options": "DocType"
|
||||
"options": "DocType",
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "voucher_no",
|
||||
@ -73,14 +74,16 @@
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Voucher No",
|
||||
"options": "voucher_type"
|
||||
"options": "voucher_type",
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "against_voucher_type",
|
||||
"fieldtype": "Link",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Against Voucher Type",
|
||||
"options": "DocType"
|
||||
"options": "DocType",
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "against_voucher_no",
|
||||
@ -88,7 +91,8 @@
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Against Voucher No",
|
||||
"options": "against_voucher_type"
|
||||
"options": "against_voucher_type",
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "amount",
|
||||
@ -148,13 +152,14 @@
|
||||
{
|
||||
"fieldname": "voucher_detail_no",
|
||||
"fieldtype": "Data",
|
||||
"label": "Voucher Detail No"
|
||||
"label": "Voucher Detail No",
|
||||
"search_index": 1
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-30 16:15:00.470283",
|
||||
"modified": "2023-11-03 16:39:58.904113",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Ledger Entry",
|
||||
|
@ -109,6 +109,8 @@ class PaymentReconciliation(Document):
|
||||
"t2.against_account like %(bank_cash_account)s" if self.bank_cash_account else "1=1"
|
||||
)
|
||||
|
||||
limit = f"limit {self.payment_limit}" if self.payment_limit else " "
|
||||
|
||||
# nosemgrep
|
||||
journal_entries = frappe.db.sql(
|
||||
"""
|
||||
@ -132,11 +134,13 @@ class PaymentReconciliation(Document):
|
||||
ELSE {bank_account_condition}
|
||||
END)
|
||||
order by t1.posting_date
|
||||
{limit}
|
||||
""".format(
|
||||
**{
|
||||
"dr_or_cr": dr_or_cr,
|
||||
"bank_account_condition": bank_account_condition,
|
||||
"condition": condition,
|
||||
"limit": limit,
|
||||
}
|
||||
),
|
||||
{
|
||||
@ -162,7 +166,7 @@ class PaymentReconciliation(Document):
|
||||
if self.payment_name:
|
||||
conditions.append(doc.name.like(f"%{self.payment_name}%"))
|
||||
|
||||
self.return_invoices = (
|
||||
self.return_invoices_query = (
|
||||
qb.from_(doc)
|
||||
.select(
|
||||
ConstantColumn(voucher_type).as_("voucher_type"),
|
||||
@ -170,8 +174,11 @@ class PaymentReconciliation(Document):
|
||||
doc.return_against,
|
||||
)
|
||||
.where(Criterion.all(conditions))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
if self.payment_limit:
|
||||
self.return_invoices_query = self.return_invoices_query.limit(self.payment_limit)
|
||||
|
||||
self.return_invoices = self.return_invoices_query.run(as_dict=True)
|
||||
|
||||
def get_dr_or_cr_notes(self):
|
||||
|
||||
|
@ -223,13 +223,6 @@ class PaymentRequest(Document):
|
||||
if self.payment_url:
|
||||
self.db_set("payment_url", self.payment_url)
|
||||
|
||||
if (
|
||||
self.payment_url
|
||||
or not self.payment_gateway_account
|
||||
or (self.payment_gateway_account and self.payment_channel == "Phone")
|
||||
):
|
||||
self.db_set("status", "Initiated")
|
||||
|
||||
def get_payment_url(self):
|
||||
if self.reference_doctype != "Fees":
|
||||
data = frappe.db.get_value(
|
||||
|
@ -6,7 +6,6 @@ import unittest
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import add_days, nowdate
|
||||
|
||||
from erpnext.accounts.doctype.pos_invoice.pos_invoice import make_sales_return
|
||||
from erpnext.accounts.doctype.pos_profile.test_pos_profile import make_pos_profile
|
||||
@ -126,64 +125,70 @@ class TestPOSInvoice(unittest.TestCase):
|
||||
self.assertEqual(inv.grand_total, 5474.0)
|
||||
|
||||
def test_tax_calculation_with_item_tax_template(self):
|
||||
import json
|
||||
inv = create_pos_invoice(qty=84, rate=4.6, do_not_save=1)
|
||||
item_row = inv.get("items")[0]
|
||||
|
||||
from erpnext.stock.get_item_details import get_item_details
|
||||
|
||||
# set tax template in item
|
||||
item = frappe.get_cached_doc("Item", "_Test Item")
|
||||
item.set(
|
||||
"taxes",
|
||||
[
|
||||
{
|
||||
"item_tax_template": "_Test Account Excise Duty @ 15 - _TC",
|
||||
"valid_from": add_days(nowdate(), -5),
|
||||
}
|
||||
],
|
||||
)
|
||||
item.save()
|
||||
|
||||
# create POS invoice with item
|
||||
pos_inv = create_pos_invoice(qty=84, rate=4.6, do_not_save=True)
|
||||
item_details = get_item_details(
|
||||
doc=pos_inv,
|
||||
args={
|
||||
"item_code": item.item_code,
|
||||
"company": pos_inv.company,
|
||||
"doctype": "POS Invoice",
|
||||
"conversion_rate": 1.0,
|
||||
},
|
||||
)
|
||||
tax_map = json.loads(item_details.item_tax_rate)
|
||||
for tax in tax_map:
|
||||
pos_inv.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": tax,
|
||||
"rate": tax_map[tax],
|
||||
"description": "Test",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
},
|
||||
)
|
||||
pos_inv.submit()
|
||||
pos_inv.load_from_db()
|
||||
|
||||
# check if correct tax values are applied from tax template
|
||||
self.assertEqual(pos_inv.net_total, 386.4)
|
||||
|
||||
expected_taxes = [
|
||||
{
|
||||
"tax_amount": 57.96,
|
||||
"total": 444.36,
|
||||
},
|
||||
add_items = [
|
||||
(54, "_Test Account Excise Duty @ 12 - _TC"),
|
||||
(288, "_Test Account Excise Duty @ 15 - _TC"),
|
||||
(144, "_Test Account Excise Duty @ 20 - _TC"),
|
||||
(430, "_Test Item Tax Template 1 - _TC"),
|
||||
]
|
||||
for qty, item_tax_template in add_items:
|
||||
item_row_copy = copy.deepcopy(item_row)
|
||||
item_row_copy.qty = qty
|
||||
item_row_copy.item_tax_template = item_tax_template
|
||||
inv.append("items", item_row_copy)
|
||||
|
||||
for i in range(len(expected_taxes)):
|
||||
for key in expected_taxes[i]:
|
||||
self.assertEqual(expected_taxes[i][key], pos_inv.get("taxes")[i].get(key))
|
||||
inv.append(
|
||||
"taxes",
|
||||
{
|
||||
"account_head": "_Test Account Excise Duty - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "Excise Duty",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 11,
|
||||
},
|
||||
)
|
||||
inv.append(
|
||||
"taxes",
|
||||
{
|
||||
"account_head": "_Test Account Education Cess - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "Education Cess",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 0,
|
||||
},
|
||||
)
|
||||
inv.append(
|
||||
"taxes",
|
||||
{
|
||||
"account_head": "_Test Account S&H Education Cess - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "S&H Education Cess",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 3,
|
||||
},
|
||||
)
|
||||
inv.insert()
|
||||
|
||||
self.assertEqual(pos_inv.get("base_total_taxes_and_charges"), 57.96)
|
||||
self.assertEqual(inv.net_total, 4600)
|
||||
|
||||
self.assertEqual(inv.get("taxes")[0].tax_amount, 502.41)
|
||||
self.assertEqual(inv.get("taxes")[0].total, 5102.41)
|
||||
|
||||
self.assertEqual(inv.get("taxes")[1].tax_amount, 197.80)
|
||||
self.assertEqual(inv.get("taxes")[1].total, 5300.21)
|
||||
|
||||
self.assertEqual(inv.get("taxes")[2].tax_amount, 375.36)
|
||||
self.assertEqual(inv.get("taxes")[2].total, 5675.57)
|
||||
|
||||
self.assertEqual(inv.grand_total, 5675.57)
|
||||
self.assertEqual(inv.rounding_adjustment, 0.43)
|
||||
self.assertEqual(inv.rounded_total, 5676.0)
|
||||
|
||||
def test_tax_calculation_with_multiple_items_and_discount(self):
|
||||
inv = create_pos_invoice(qty=1, rate=75, do_not_save=True)
|
||||
|
@ -110,7 +110,7 @@
|
||||
"in_create": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2023-04-21 17:36:26.642617",
|
||||
"modified": "2023-11-02 11:32:12.254018",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Payment Reconciliation Log",
|
||||
@ -125,7 +125,19 @@
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"role": "Accounts Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Accounts User",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
|
@ -384,7 +384,8 @@
|
||||
"label": "Supplier Invoice No",
|
||||
"oldfieldname": "bill_no",
|
||||
"oldfieldtype": "Data",
|
||||
"print_hide": 1
|
||||
"print_hide": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_15",
|
||||
@ -407,7 +408,8 @@
|
||||
"no_copy": 1,
|
||||
"options": "Purchase Invoice",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
"read_only": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_addresses",
|
||||
@ -1602,7 +1604,7 @@
|
||||
"idx": 204,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-16 16:24:51.886231",
|
||||
"modified": "2023-11-03 15:47:30.319200",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice",
|
||||
@ -1665,4 +1667,4 @@
|
||||
"timeline_field": "supplier",
|
||||
"title_field": "title",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
@ -1783,9 +1783,14 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
||||
set_advance_flag(company="_Test Company", flag=0, default_account="")
|
||||
|
||||
def test_gl_entries_for_standalone_debit_note(self):
|
||||
make_purchase_invoice(qty=5, rate=500, update_stock=True)
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
returned_inv = make_purchase_invoice(qty=-5, rate=5, update_stock=True, is_return=True)
|
||||
item_code = make_item(properties={"is_stock_item": 1})
|
||||
make_purchase_invoice(item_code=item_code, qty=5, rate=500, update_stock=True)
|
||||
|
||||
returned_inv = make_purchase_invoice(
|
||||
item_code=item_code, qty=-5, rate=5, update_stock=True, is_return=True
|
||||
)
|
||||
|
||||
# override the rate with valuation rate
|
||||
sle = frappe.get_all(
|
||||
@ -1795,7 +1800,7 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
||||
)[0]
|
||||
|
||||
rate = flt(sle.stock_value_difference) / flt(sle.actual_qty)
|
||||
self.assertAlmostEqual(returned_inv.items[0].rate, rate)
|
||||
self.assertAlmostEqual(rate, 500)
|
||||
|
||||
def test_payment_allocation_for_payment_terms(self):
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import (
|
||||
@ -1898,6 +1903,12 @@ class TestPurchaseInvoice(FrappeTestCase, StockTestMixin):
|
||||
disable_dimension()
|
||||
|
||||
def test_repost_accounting_entries(self):
|
||||
# update repost settings
|
||||
settings = frappe.get_doc("Repost Accounting Ledger Settings")
|
||||
if not [x for x in settings.allowed_types if x.document_type == "Purchase Invoice"]:
|
||||
settings.append("allowed_types", {"document_type": "Purchase Invoice", "allowed": True})
|
||||
settings.save()
|
||||
|
||||
pi = make_purchase_invoice(
|
||||
rate=1000,
|
||||
price_list_rate=1000,
|
||||
|
@ -5,9 +5,7 @@ frappe.ui.form.on("Repost Accounting Ledger", {
|
||||
setup: function(frm) {
|
||||
frm.fields_dict['vouchers'].grid.get_field('voucher_type').get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
name: ['in', ['Purchase Invoice', 'Sales Invoice', 'Payment Entry', 'Journal Entry']],
|
||||
}
|
||||
query: "erpnext.accounts.doctype.repost_accounting_ledger.repost_accounting_ledger.get_repost_allowed_types"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,12 @@ from frappe.utils.data import comma_and
|
||||
class RepostAccountingLedger(Document):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(RepostAccountingLedger, self).__init__(*args, **kwargs)
|
||||
self._allowed_types = set(
|
||||
["Purchase Invoice", "Sales Invoice", "Payment Entry", "Journal Entry"]
|
||||
)
|
||||
self._allowed_types = [
|
||||
x.document_type
|
||||
for x in frappe.db.get_all(
|
||||
"Repost Allowed Types", filters={"allowed": True}, fields=["distinct(document_type)"]
|
||||
)
|
||||
]
|
||||
|
||||
def validate(self):
|
||||
self.validate_vouchers()
|
||||
@ -157,7 +160,7 @@ def start_repost(account_repost_doc=str) -> None:
|
||||
doc.docstatus = 1
|
||||
doc.make_gl_entries()
|
||||
|
||||
elif doc.doctype in ["Payment Entry", "Journal Entry"]:
|
||||
elif doc.doctype in ["Payment Entry", "Journal Entry", "Expense Claim"]:
|
||||
if not repost_doc.delete_cancelled_entries:
|
||||
doc.make_gl_entries(1)
|
||||
doc.make_gl_entries()
|
||||
@ -186,3 +189,18 @@ def validate_docs_for_deferred_accounting(sales_docs, purchase_docs):
|
||||
frappe.bold(comma_and([x[0] for x in docs_with_deferred_expense + docs_with_deferred_revenue]))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_repost_allowed_types(doctype, txt, searchfield, start, page_len, filters):
|
||||
filters = {"allowed": True}
|
||||
|
||||
if txt:
|
||||
filters.update({"document_type": ("like", f"%{txt}%")})
|
||||
|
||||
if allowed_types := frappe.db.get_all(
|
||||
"Repost Allowed Types", filters=filters, fields=["distinct(document_type)"], as_list=1
|
||||
):
|
||||
return allowed_types
|
||||
return []
|
||||
|
@ -20,10 +20,18 @@ class TestRepostAccountingLedger(AccountsTestMixin, FrappeTestCase):
|
||||
self.create_company()
|
||||
self.create_customer()
|
||||
self.create_item()
|
||||
self.update_repost_settings()
|
||||
|
||||
def teadDown(self):
|
||||
frappe.db.rollback()
|
||||
|
||||
def update_repost_settings(self):
|
||||
allowed_types = ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]
|
||||
repost_settings = frappe.get_doc("Repost Accounting Ledger Settings")
|
||||
for x in allowed_types:
|
||||
repost_settings.append("allowed_types", {"document_type": x, "allowed": True})
|
||||
repost_settings.save()
|
||||
|
||||
def test_01_basic_functions(self):
|
||||
si = create_sales_invoice(
|
||||
item=self.item,
|
||||
|
@ -0,0 +1,8 @@
|
||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
// frappe.ui.form.on("Repost Accounting Ledger Settings", {
|
||||
// refresh(frm) {
|
||||
|
||||
// },
|
||||
// });
|
@ -0,0 +1,46 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2023-11-07 09:57:20.619939",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"allowed_types"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "allowed_types",
|
||||
"fieldtype": "Table",
|
||||
"label": "Allowed Doctypes",
|
||||
"options": "Repost Allowed Types"
|
||||
}
|
||||
],
|
||||
"in_create": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-07 14:24:13.321522",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Repost Accounting Ledger Settings",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Administrator",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"read": 1,
|
||||
"role": "System Manager",
|
||||
"select": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class RepostAccountingLedgerSettings(Document):
|
||||
pass
|
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
|
||||
class TestRepostAccountingLedgerSettings(FrappeTestCase):
|
||||
pass
|
@ -0,0 +1,45 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"creation": "2023-11-07 09:58:03.595382",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"document_type",
|
||||
"column_break_sfzb",
|
||||
"allowed"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "document_type",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Doctype",
|
||||
"options": "DocType"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "allowed",
|
||||
"fieldtype": "Check",
|
||||
"in_list_view": 1,
|
||||
"label": "Allowed"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_sfzb",
|
||||
"fieldtype": "Column Break"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-07 10:01:39.217861",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Repost Allowed Types",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
class RepostAllowedTypes(Document):
|
||||
pass
|
@ -187,7 +187,6 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e
|
||||
erpnext.accounts.unreconcile_payments.add_unreconcile_btn(me.frm);
|
||||
}
|
||||
|
||||
|
||||
make_maintenance_schedule() {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.make_maintenance_schedule",
|
||||
@ -563,15 +562,6 @@ cur_frm.fields_dict.write_off_cost_center.get_query = function(doc) {
|
||||
}
|
||||
}
|
||||
|
||||
// Income Account in Details Table
|
||||
// --------------------------------
|
||||
cur_frm.set_query("income_account", "items", function(doc) {
|
||||
return{
|
||||
query: "erpnext.controllers.queries.get_income_account",
|
||||
filters: {'company': doc.company}
|
||||
}
|
||||
});
|
||||
|
||||
// Cost Center in Details Table
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function(doc) {
|
||||
@ -666,6 +656,16 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("income_account", "items", function() {
|
||||
return{
|
||||
query: "erpnext.controllers.queries.get_income_account",
|
||||
filters: {
|
||||
'company': frm.doc.company,
|
||||
"disabled": 0
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frm.custom_make_buttons = {
|
||||
'Delivery Note': 'Delivery',
|
||||
'Sales Invoice': 'Return / Credit Note',
|
||||
|
@ -26,6 +26,7 @@
|
||||
"is_return",
|
||||
"return_against",
|
||||
"update_billed_amount_in_sales_order",
|
||||
"update_billed_amount_in_delivery_note",
|
||||
"is_debit_note",
|
||||
"amended_from",
|
||||
"accounting_dimensions_section",
|
||||
@ -2153,6 +2154,13 @@
|
||||
"fieldname": "use_company_roundoff_cost_center",
|
||||
"fieldtype": "Check",
|
||||
"label": "Use Company default Cost Center for Round off"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval: doc.is_return",
|
||||
"fieldname": "update_billed_amount_in_delivery_note",
|
||||
"fieldtype": "Check",
|
||||
"label": "Update Billed Amount in Delivery Note"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-file-text",
|
||||
@ -2165,7 +2173,7 @@
|
||||
"link_fieldname": "consolidated_invoice"
|
||||
}
|
||||
],
|
||||
"modified": "2023-07-25 16:02:18.988799",
|
||||
"modified": "2023-11-03 14:39:38.012346",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice",
|
||||
|
@ -253,6 +253,7 @@ class SalesInvoice(SellingController):
|
||||
|
||||
self.update_status_updater_args()
|
||||
self.update_prevdoc_status()
|
||||
|
||||
self.update_billing_status_in_dn()
|
||||
self.clear_unallocated_mode_of_payments()
|
||||
|
||||
@ -1019,7 +1020,7 @@ class SalesInvoice(SellingController):
|
||||
|
||||
def make_customer_gl_entry(self, gl_entries):
|
||||
# Checked both rounding_adjustment and rounded_total
|
||||
# because rounded_total had value even before introcution of posting GLE based on rounded total
|
||||
# because rounded_total had value even before introduction of posting GLE based on rounded total
|
||||
grand_total = (
|
||||
self.rounded_total if (self.rounding_adjustment and self.rounded_total) else self.grand_total
|
||||
)
|
||||
@ -1267,7 +1268,7 @@ class SalesInvoice(SellingController):
|
||||
if skip_change_gl_entries and payment_mode.account == self.account_for_change_amount:
|
||||
payment_mode.base_amount -= flt(self.change_amount)
|
||||
|
||||
if payment_mode.amount:
|
||||
if payment_mode.base_amount:
|
||||
# POS, make payment entries
|
||||
gl_entries.append(
|
||||
self.get_gl_dict(
|
||||
@ -1429,6 +1430,8 @@ class SalesInvoice(SellingController):
|
||||
)
|
||||
|
||||
def update_billing_status_in_dn(self, update_modified=True):
|
||||
if self.is_return and not self.update_billed_amount_in_delivery_note:
|
||||
return
|
||||
updated_delivery_notes = []
|
||||
for d in self.get("items"):
|
||||
if d.dn_detail:
|
||||
|
@ -516,72 +516,70 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
self.assertEqual(si.grand_total, 5474.0)
|
||||
|
||||
def test_tax_calculation_with_item_tax_template(self):
|
||||
import json
|
||||
|
||||
from erpnext.stock.get_item_details import get_item_details
|
||||
|
||||
# set tax template in item
|
||||
item = frappe.get_cached_doc("Item", "_Test Item")
|
||||
item.set(
|
||||
"taxes",
|
||||
[
|
||||
{
|
||||
"item_tax_template": "_Test Item Tax Template 1 - _TC",
|
||||
"valid_from": add_days(nowdate(), -5),
|
||||
}
|
||||
],
|
||||
)
|
||||
item.save()
|
||||
|
||||
# create sales invoice with item
|
||||
si = create_sales_invoice(qty=84, rate=4.6, do_not_save=True)
|
||||
item_details = get_item_details(
|
||||
doc=si,
|
||||
args={
|
||||
"item_code": item.item_code,
|
||||
"company": si.company,
|
||||
"doctype": "Sales Invoice",
|
||||
"conversion_rate": 1.0,
|
||||
item_row = si.get("items")[0]
|
||||
|
||||
add_items = [
|
||||
(54, "_Test Account Excise Duty @ 12 - _TC"),
|
||||
(288, "_Test Account Excise Duty @ 15 - _TC"),
|
||||
(144, "_Test Account Excise Duty @ 20 - _TC"),
|
||||
(430, "_Test Item Tax Template 1 - _TC"),
|
||||
]
|
||||
for qty, item_tax_template in add_items:
|
||||
item_row_copy = copy.deepcopy(item_row)
|
||||
item_row_copy.qty = qty
|
||||
item_row_copy.item_tax_template = item_tax_template
|
||||
si.append("items", item_row_copy)
|
||||
|
||||
si.append(
|
||||
"taxes",
|
||||
{
|
||||
"account_head": "_Test Account Excise Duty - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "Excise Duty",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 11,
|
||||
},
|
||||
)
|
||||
tax_map = json.loads(item_details.item_tax_rate)
|
||||
for tax in tax_map:
|
||||
si.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": tax,
|
||||
"rate": tax_map[tax],
|
||||
"description": "Test",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
},
|
||||
)
|
||||
si.submit()
|
||||
si.load_from_db()
|
||||
|
||||
# check if correct tax values are applied from tax template
|
||||
self.assertEqual(si.net_total, 386.4)
|
||||
|
||||
expected_taxes = [
|
||||
si.append(
|
||||
"taxes",
|
||||
{
|
||||
"tax_amount": 19.32,
|
||||
"total": 405.72,
|
||||
"account_head": "_Test Account Education Cess - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "Education Cess",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 0,
|
||||
},
|
||||
)
|
||||
si.append(
|
||||
"taxes",
|
||||
{
|
||||
"tax_amount": 38.64,
|
||||
"total": 444.36,
|
||||
"account_head": "_Test Account S&H Education Cess - _TC",
|
||||
"charge_type": "On Net Total",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "S&H Education Cess",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"rate": 3,
|
||||
},
|
||||
{
|
||||
"tax_amount": 57.96,
|
||||
"total": 502.32,
|
||||
},
|
||||
]
|
||||
)
|
||||
si.insert()
|
||||
|
||||
for i in range(len(expected_taxes)):
|
||||
for key in expected_taxes[i]:
|
||||
self.assertEqual(expected_taxes[i][key], si.get("taxes")[i].get(key))
|
||||
self.assertEqual(si.net_total, 4600)
|
||||
|
||||
self.assertEqual(si.get("base_total_taxes_and_charges"), 115.92)
|
||||
self.assertEqual(si.get("taxes")[0].tax_amount, 502.41)
|
||||
self.assertEqual(si.get("taxes")[0].total, 5102.41)
|
||||
|
||||
self.assertEqual(si.get("taxes")[1].tax_amount, 197.80)
|
||||
self.assertEqual(si.get("taxes")[1].total, 5300.21)
|
||||
|
||||
self.assertEqual(si.get("taxes")[2].tax_amount, 375.36)
|
||||
self.assertEqual(si.get("taxes")[2].total, 5675.57)
|
||||
|
||||
self.assertEqual(si.grand_total, 5675.57)
|
||||
self.assertEqual(si.rounding_adjustment, 0.43)
|
||||
self.assertEqual(si.rounded_total, 5676.0)
|
||||
|
||||
def test_tax_calculation_with_multiple_items_and_discount(self):
|
||||
si = create_sales_invoice(qty=1, rate=75, do_not_save=True)
|
||||
|
@ -31,7 +31,12 @@ from erpnext.accounts.utils import get_fiscal_year
|
||||
from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen
|
||||
from erpnext.utilities.regional import temporary_flag
|
||||
|
||||
PURCHASE_TRANSACTION_TYPES = {"Purchase Order", "Purchase Receipt", "Purchase Invoice"}
|
||||
PURCHASE_TRANSACTION_TYPES = {
|
||||
"Supplier Quotation",
|
||||
"Purchase Order",
|
||||
"Purchase Receipt",
|
||||
"Purchase Invoice",
|
||||
}
|
||||
SALES_TRANSACTION_TYPES = {
|
||||
"Quotation",
|
||||
"Sales Order",
|
||||
|
@ -143,7 +143,18 @@ frappe.query_reports["Accounts Payable"] = {
|
||||
"fieldname": "show_future_payments",
|
||||
"label": __("Show Future Payments"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "in_party_currency",
|
||||
"label": __("In Party Currency"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "ignore_accounts",
|
||||
"label": __("Group by Voucher"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
|
||||
],
|
||||
|
||||
"formatter": function(value, row, column, data, default_formatter) {
|
||||
@ -175,4 +186,4 @@ function get_party_type_options() {
|
||||
});
|
||||
});
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"in_party_currency": 1,
|
||||
}
|
||||
|
||||
data = execute(filters)
|
||||
|
@ -110,6 +110,11 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
||||
"fieldname":"based_on_payment_terms",
|
||||
"label": __("Based On Payment Terms"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "for_revaluation_journals",
|
||||
"label": __("Revaluation Journals"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
],
|
||||
|
||||
|
@ -114,10 +114,13 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "customer_group",
|
||||
"fieldname":"customer_group",
|
||||
"label": __("Customer Group"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group"
|
||||
"fieldtype": "MultiSelectList",
|
||||
"options": "Customer Group",
|
||||
get_data: function(txt) {
|
||||
return frappe.db.get_link_options('Customer Group', txt);
|
||||
}
|
||||
},
|
||||
{
|
||||
"fieldname": "payment_terms_template",
|
||||
@ -172,7 +175,24 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
"fieldname": "show_remarks",
|
||||
"label": __("Show Remarks"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "in_party_currency",
|
||||
"label": __("In Party Currency"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "for_revaluation_journals",
|
||||
"label": __("Revaluation Journals"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "ignore_accounts",
|
||||
"label": __("Group by Voucher"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
|
||||
|
||||
],
|
||||
|
||||
"formatter": function(value, row, column, data, default_formatter) {
|
||||
@ -205,4 +225,4 @@ function get_party_type_options() {
|
||||
});
|
||||
});
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
96
erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Executable file → Normal file
96
erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Executable file → Normal file
@ -14,7 +14,7 @@ from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_dimension_with_children,
|
||||
)
|
||||
from erpnext.accounts.utils import get_currency_precision
|
||||
from erpnext.accounts.utils import get_currency_precision, get_party_types_from_account_type
|
||||
|
||||
# This report gives a summary of all Outstanding Invoices considering the following
|
||||
|
||||
@ -28,8 +28,8 @@ from erpnext.accounts.utils import get_currency_precision
|
||||
# 6. Configurable Ageing Groups (0-30, 30-60 etc) can be set via filters
|
||||
# 7. For overpayment against an invoice with payment terms, there will be an additional row
|
||||
# 8. Invoice details like Sales Persons, Delivery Notes are also fetched comma separated
|
||||
# 9. Report amounts are in "Party Currency" if party is selected, or company currency for multi-party
|
||||
# 10. This reports is based on all GL Entries that are made against account_type "Receivable" or "Payable"
|
||||
# 9. Report amounts are in party currency if in_party_currency is selected, otherwise company currency
|
||||
# 10. This report is based on Payment Ledger Entries
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@ -72,9 +72,7 @@ class ReceivablePayableReport(object):
|
||||
self.currency_precision = get_currency_precision() or 2
|
||||
self.dr_or_cr = "debit" if self.filters.account_type == "Receivable" else "credit"
|
||||
self.account_type = self.filters.account_type
|
||||
self.party_type = frappe.db.get_all(
|
||||
"Party Type", {"account_type": self.account_type}, pluck="name"
|
||||
)
|
||||
self.party_type = get_party_types_from_account_type(self.account_type)
|
||||
self.party_details = {}
|
||||
self.invoices = set()
|
||||
self.skip_total_row = 0
|
||||
@ -84,6 +82,9 @@ class ReceivablePayableReport(object):
|
||||
self.total_row_map = {}
|
||||
self.skip_total_row = 1
|
||||
|
||||
if self.filters.get("in_party_currency"):
|
||||
self.skip_total_row = 1
|
||||
|
||||
def get_data(self):
|
||||
self.get_ple_entries()
|
||||
self.get_sales_invoices_or_customers_based_on_sales_person()
|
||||
@ -116,7 +117,12 @@ class ReceivablePayableReport(object):
|
||||
# build all keys, since we want to exclude vouchers beyond the report date
|
||||
for ple in self.ple_entries:
|
||||
# get the balance object for voucher_type
|
||||
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)
|
||||
|
||||
if self.filters.get("ignore_accounts"):
|
||||
key = (ple.voucher_type, ple.voucher_no, ple.party)
|
||||
else:
|
||||
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)
|
||||
|
||||
if not key in self.voucher_balance:
|
||||
self.voucher_balance[key] = frappe._dict(
|
||||
voucher_type=ple.voucher_type,
|
||||
@ -140,7 +146,7 @@ class ReceivablePayableReport(object):
|
||||
if self.filters.get("group_by_party"):
|
||||
self.init_subtotal_row(ple.party)
|
||||
|
||||
if self.filters.get("group_by_party"):
|
||||
if self.filters.get("group_by_party") and not self.filters.get("in_party_currency"):
|
||||
self.init_subtotal_row("Total")
|
||||
|
||||
def get_invoices(self, ple):
|
||||
@ -183,7 +189,10 @@ class ReceivablePayableReport(object):
|
||||
):
|
||||
return
|
||||
|
||||
key = (ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
||||
if self.filters.get("ignore_accounts"):
|
||||
key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
||||
else:
|
||||
key = (ple.account, ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
||||
|
||||
# If payment is made against credit note
|
||||
# and credit note is made against a Sales Invoice
|
||||
@ -192,13 +201,19 @@ class ReceivablePayableReport(object):
|
||||
if ple.against_voucher_no in self.return_entries:
|
||||
return_against = self.return_entries.get(ple.against_voucher_no)
|
||||
if return_against:
|
||||
key = (ple.account, ple.against_voucher_type, return_against, ple.party)
|
||||
if self.filters.get("ignore_accounts"):
|
||||
key = (ple.against_voucher_type, return_against, ple.party)
|
||||
else:
|
||||
key = (ple.account, ple.against_voucher_type, return_against, ple.party)
|
||||
|
||||
row = self.voucher_balance.get(key)
|
||||
|
||||
if not row:
|
||||
# no invoice, this is an invoice / stand-alone payment / credit note
|
||||
row = self.voucher_balance.get((ple.account, ple.voucher_type, ple.voucher_no, ple.party))
|
||||
if self.filters.get("ignore_accounts"):
|
||||
row = self.voucher_balance.get((ple.voucher_type, ple.voucher_no, ple.party))
|
||||
else:
|
||||
row = self.voucher_balance.get((ple.account, ple.voucher_type, ple.voucher_no, ple.party))
|
||||
|
||||
row.party_type = ple.party_type
|
||||
return row
|
||||
@ -210,8 +225,7 @@ class ReceivablePayableReport(object):
|
||||
if not row:
|
||||
return
|
||||
|
||||
# amount in "Party Currency", if its supplied. If not, amount in company currency
|
||||
if self.filters.get("party_type") and self.filters.get("party"):
|
||||
if self.filters.get("in_party_currency"):
|
||||
amount = ple.amount_in_account_currency
|
||||
else:
|
||||
amount = ple.amount
|
||||
@ -242,8 +256,10 @@ class ReceivablePayableReport(object):
|
||||
def update_sub_total_row(self, row, party):
|
||||
total_row = self.total_row_map.get(party)
|
||||
|
||||
for field in self.get_currency_fields():
|
||||
total_row[field] += row.get(field, 0.0)
|
||||
if total_row:
|
||||
for field in self.get_currency_fields():
|
||||
total_row[field] += row.get(field, 0.0)
|
||||
total_row["currency"] = row.get("currency", "")
|
||||
|
||||
def append_subtotal_row(self, party):
|
||||
sub_total_row = self.total_row_map.get(party)
|
||||
@ -267,11 +283,20 @@ class ReceivablePayableReport(object):
|
||||
|
||||
row.invoice_grand_total = row.invoiced
|
||||
|
||||
if (abs(row.outstanding) > 1.0 / 10**self.currency_precision) and (
|
||||
(abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision)
|
||||
or (row.voucher_no in self.err_journals)
|
||||
):
|
||||
must_consider = False
|
||||
if self.filters.get("for_revaluation_journals"):
|
||||
if (abs(row.outstanding) > 1.0 / 10**self.currency_precision) or (
|
||||
(abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision)
|
||||
):
|
||||
must_consider = True
|
||||
else:
|
||||
if (abs(row.outstanding) > 1.0 / 10**self.currency_precision) and (
|
||||
(abs(row.outstanding_in_account_currency) > 1.0 / 10**self.currency_precision)
|
||||
or (row.voucher_no in self.err_journals)
|
||||
):
|
||||
must_consider = True
|
||||
|
||||
if must_consider:
|
||||
# non-zero oustanding, we must consider this row
|
||||
|
||||
if self.is_invoice(row) and self.filters.based_on_payment_terms:
|
||||
@ -295,7 +320,7 @@ class ReceivablePayableReport(object):
|
||||
if self.filters.get("group_by_party"):
|
||||
self.append_subtotal_row(self.previous_party)
|
||||
if self.data:
|
||||
self.data.append(self.total_row_map.get("Total"))
|
||||
self.data.append(self.total_row_map.get("Total", {}))
|
||||
|
||||
def append_row(self, row):
|
||||
self.allocate_future_payments(row)
|
||||
@ -426,7 +451,7 @@ class ReceivablePayableReport(object):
|
||||
party_details = self.get_party_details(row.party) or {}
|
||||
row.update(party_details)
|
||||
|
||||
if self.filters.get("party_type") and self.filters.get("party"):
|
||||
if self.filters.get("in_party_currency"):
|
||||
row.currency = row.account_currency
|
||||
else:
|
||||
row.currency = self.company_currency
|
||||
@ -718,6 +743,7 @@ class ReceivablePayableReport(object):
|
||||
query = (
|
||||
qb.from_(ple)
|
||||
.select(
|
||||
ple.name,
|
||||
ple.account,
|
||||
ple.voucher_type,
|
||||
ple.voucher_no,
|
||||
@ -731,13 +757,15 @@ class ReceivablePayableReport(object):
|
||||
ple.account_currency,
|
||||
ple.amount,
|
||||
ple.amount_in_account_currency,
|
||||
ple.remarks,
|
||||
)
|
||||
.where(ple.delinked == 0)
|
||||
.where(Criterion.all(self.qb_selection_filter))
|
||||
.where(Criterion.any(self.or_filters))
|
||||
)
|
||||
|
||||
if self.filters.get("show_remarks"):
|
||||
query = query.select(ple.remarks)
|
||||
|
||||
if self.filters.get("group_by_party"):
|
||||
query = query.orderby(self.ple.party, self.ple.posting_date)
|
||||
else:
|
||||
@ -823,7 +851,13 @@ class ReceivablePayableReport(object):
|
||||
self.customer = qb.DocType("Customer")
|
||||
|
||||
if self.filters.get("customer_group"):
|
||||
self.get_hierarchical_filters("Customer Group", "customer_group")
|
||||
groups = get_customer_group_with_children(self.filters.customer_group)
|
||||
customers = (
|
||||
qb.from_(self.customer)
|
||||
.select(self.customer.name)
|
||||
.where(self.customer["customer_group"].isin(groups))
|
||||
)
|
||||
self.qb_selection_filter.append(self.ple.party.isin(customers))
|
||||
|
||||
if self.filters.get("territory"):
|
||||
self.get_hierarchical_filters("Territory", "territory")
|
||||
@ -1115,3 +1149,19 @@ class ReceivablePayableReport(object):
|
||||
.run()
|
||||
)
|
||||
self.err_journals = [x[0] for x in results] if results else []
|
||||
|
||||
|
||||
def get_customer_group_with_children(customer_groups):
|
||||
if not isinstance(customer_groups, list):
|
||||
customer_groups = [d.strip() for d in customer_groups.strip().split(",") if d]
|
||||
|
||||
all_customer_groups = []
|
||||
for d in customer_groups:
|
||||
if frappe.db.exists("Customer Group", d):
|
||||
lft, rgt = frappe.db.get_value("Customer Group", d, ["lft", "rgt"])
|
||||
children = frappe.get_all("Customer Group", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
|
||||
all_customer_groups += [c.name for c in children]
|
||||
else:
|
||||
frappe.throw(_("Customer Group: {0} does not exist").format(d))
|
||||
|
||||
return list(set(all_customer_groups))
|
||||
|
@ -475,6 +475,30 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 0)
|
||||
|
||||
def test_multi_customer_group_filter(self):
|
||||
si = self.create_sales_invoice()
|
||||
cus_group = frappe.db.get_value("Customer", self.customer, "customer_group")
|
||||
# Create a list of customer groups, e.g., ["Group1", "Group2"]
|
||||
cus_groups_list = [cus_group, "_Test Customer Group 1"]
|
||||
|
||||
filters = {
|
||||
"company": self.company,
|
||||
"report_date": today(),
|
||||
"range1": 30,
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"customer_group": cus_groups_list, # Use the list of customer groups
|
||||
}
|
||||
report = execute(filters)[1]
|
||||
|
||||
# Assert that the report contains data for the specified customer groups
|
||||
self.assertTrue(len(report) > 0)
|
||||
|
||||
for row in report:
|
||||
# Assert that the customer group of each row is in the list of customer groups
|
||||
self.assertIn(row.customer_group, cus_groups_list)
|
||||
|
||||
def test_party_account_filter(self):
|
||||
si1 = self.create_sales_invoice()
|
||||
self.customer2 = (
|
||||
@ -557,6 +581,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"in_party_currency": 1,
|
||||
}
|
||||
|
||||
si = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
|
||||
|
@ -139,6 +139,11 @@ frappe.query_reports["Accounts Receivable Summary"] = {
|
||||
"label": __("Show GL Balance"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "for_revaluation_journals",
|
||||
"label": __("Revaluation Journals"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
],
|
||||
|
||||
onload: function(report) {
|
||||
|
@ -8,6 +8,7 @@ from frappe.utils import cint, flt
|
||||
|
||||
from erpnext.accounts.party import get_partywise_advanced_payment_amount
|
||||
from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport
|
||||
from erpnext.accounts.utils import get_party_types_from_account_type
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@ -22,9 +23,7 @@ def execute(filters=None):
|
||||
class AccountsReceivableSummary(ReceivablePayableReport):
|
||||
def run(self, args):
|
||||
self.account_type = args.get("account_type")
|
||||
self.party_type = frappe.db.get_all(
|
||||
"Party Type", {"account_type": self.account_type}, pluck="name"
|
||||
)
|
||||
self.party_type = get_party_types_from_account_type(self.account_type)
|
||||
self.party_naming_by = frappe.db.get_value(
|
||||
args.get("naming_by")[0], None, args.get("naming_by")[1]
|
||||
)
|
||||
|
@ -31,6 +31,18 @@ frappe.query_reports["Asset Depreciation Ledger"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Asset"
|
||||
},
|
||||
{
|
||||
"fieldname":"asset_category",
|
||||
"label": __("Asset Category"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Asset Category"
|
||||
},
|
||||
{
|
||||
"fieldname":"cost_center",
|
||||
"label": __("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"fieldname":"finance_book",
|
||||
"label": __("Finance Book"),
|
||||
@ -38,10 +50,10 @@ frappe.query_reports["Asset Depreciation Ledger"] = {
|
||||
"options": "Finance Book"
|
||||
},
|
||||
{
|
||||
"fieldname":"asset_category",
|
||||
"label": __("Asset Category"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Asset Category"
|
||||
}
|
||||
"fieldname": "include_default_book_assets",
|
||||
"label": __("Include Default FB Assets"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
},
|
||||
]
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"add_total_row": 0,
|
||||
"columns": [],
|
||||
"creation": "2016-04-08 14:49:58.133098",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"filters": [],
|
||||
"idx": 2,
|
||||
"idx": 6,
|
||||
"is_standard": "Yes",
|
||||
"letterhead": null,
|
||||
"modified": "2023-07-26 21:05:33.554778",
|
||||
"modified": "2023-11-08 20:17:05.774211",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Asset Depreciation Ledger",
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
from frappe.utils import cstr, flt
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@ -32,7 +32,6 @@ def get_data(filters):
|
||||
filters_data.append(["against_voucher", "=", filters.get("asset")])
|
||||
|
||||
if filters.get("asset_category"):
|
||||
|
||||
assets = frappe.db.sql_list(
|
||||
"""select name from tabAsset
|
||||
where asset_category = %s and docstatus=1""",
|
||||
@ -41,12 +40,27 @@ def get_data(filters):
|
||||
|
||||
filters_data.append(["against_voucher", "in", assets])
|
||||
|
||||
if filters.get("finance_book"):
|
||||
filters_data.append(["finance_book", "in", ["", filters.get("finance_book")]])
|
||||
company_fb = frappe.get_cached_value("Company", filters.get("company"), "default_finance_book")
|
||||
|
||||
if filters.get("include_default_book_assets") and company_fb:
|
||||
if filters.get("finance_book") and cstr(filters.get("finance_book")) != cstr(company_fb):
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default FB Assets'"))
|
||||
else:
|
||||
finance_book = company_fb
|
||||
elif filters.get("finance_book"):
|
||||
finance_book = filters.get("finance_book")
|
||||
else:
|
||||
finance_book = None
|
||||
|
||||
if finance_book:
|
||||
or_filters_data = [["finance_book", "in", ["", finance_book]], ["finance_book", "is", "not set"]]
|
||||
else:
|
||||
or_filters_data = [["finance_book", "in", [""]], ["finance_book", "is", "not set"]]
|
||||
|
||||
gl_entries = frappe.get_all(
|
||||
"GL Entry",
|
||||
filters=filters_data,
|
||||
or_filters=or_filters_data,
|
||||
fields=["against_voucher", "debit_in_account_currency as debit", "voucher_no", "posting_date"],
|
||||
order_by="against_voucher, posting_date",
|
||||
)
|
||||
@ -61,7 +75,9 @@ def get_data(filters):
|
||||
asset_data = assets_details.get(d.against_voucher)
|
||||
if asset_data:
|
||||
if not asset_data.get("accumulated_depreciation_amount"):
|
||||
asset_data.accumulated_depreciation_amount = d.debit
|
||||
asset_data.accumulated_depreciation_amount = d.debit + asset_data.get(
|
||||
"opening_accumulated_depreciation"
|
||||
)
|
||||
else:
|
||||
asset_data.accumulated_depreciation_amount += d.debit
|
||||
|
||||
@ -70,7 +86,7 @@ def get_data(filters):
|
||||
{
|
||||
"depreciation_amount": d.debit,
|
||||
"depreciation_date": d.posting_date,
|
||||
"amount_after_depreciation": (
|
||||
"value_after_depreciation": (
|
||||
flt(row.gross_purchase_amount) - flt(row.accumulated_depreciation_amount)
|
||||
),
|
||||
"depreciation_entry": d.voucher_no,
|
||||
@ -88,10 +104,12 @@ def get_assets_details(assets):
|
||||
fields = [
|
||||
"name as asset",
|
||||
"gross_purchase_amount",
|
||||
"opening_accumulated_depreciation",
|
||||
"asset_category",
|
||||
"status",
|
||||
"depreciation_method",
|
||||
"purchase_date",
|
||||
"cost_center",
|
||||
]
|
||||
|
||||
for d in frappe.get_all("Asset", fields=fields, filters={"name": ("in", assets)}):
|
||||
@ -121,6 +139,12 @@ def get_columns():
|
||||
"fieldtype": "Currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Opening Accumulated Depreciation"),
|
||||
"fieldname": "opening_accumulated_depreciation",
|
||||
"fieldtype": "Currency",
|
||||
"width": 140,
|
||||
},
|
||||
{
|
||||
"label": _("Depreciation Amount"),
|
||||
"fieldname": "depreciation_amount",
|
||||
@ -134,8 +158,8 @@ def get_columns():
|
||||
"width": 210,
|
||||
},
|
||||
{
|
||||
"label": _("Amount After Depreciation"),
|
||||
"fieldname": "amount_after_depreciation",
|
||||
"label": _("Value After Depreciation"),
|
||||
"fieldname": "value_after_depreciation",
|
||||
"fieldtype": "Currency",
|
||||
"width": 180,
|
||||
},
|
||||
@ -153,12 +177,13 @@ def get_columns():
|
||||
"options": "Asset Category",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Current Status"), "fieldname": "status", "fieldtype": "Data", "width": 120},
|
||||
{
|
||||
"label": _("Depreciation Method"),
|
||||
"fieldname": "depreciation_method",
|
||||
"fieldtype": "Data",
|
||||
"width": 130,
|
||||
"label": _("Cost Center"),
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "cost_center",
|
||||
"options": "Cost Center",
|
||||
"width": 100,
|
||||
},
|
||||
{"label": _("Current Status"), "fieldname": "status", "fieldtype": "Data", "width": 120},
|
||||
{"label": _("Purchase Date"), "fieldname": "purchase_date", "fieldtype": "Date", "width": 120},
|
||||
]
|
||||
|
@ -17,7 +17,7 @@ frappe.query_reports["Balance Sheet"]["filters"].push({
|
||||
|
||||
frappe.query_reports["Balance Sheet"]["filters"].push({
|
||||
fieldname: "include_default_book_entries",
|
||||
label: __("Include Default Book Entries"),
|
||||
label: __("Include Default FB Entries"),
|
||||
fieldtype: "Check",
|
||||
default: 1,
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ frappe.query_reports["Cash Flow"]["filters"].splice(8, 1);
|
||||
frappe.query_reports["Cash Flow"]["filters"].push(
|
||||
{
|
||||
"fieldname": "include_default_book_entries",
|
||||
"label": __("Include Default Book Entries"),
|
||||
"label": __("Include Default FB Entries"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ frappe.query_reports["Consolidated Financial Statement"] = {
|
||||
},
|
||||
{
|
||||
"fieldname": "include_default_book_entries",
|
||||
"label": __("Include Default Book Entries"),
|
||||
"label": __("Include Default FB Entries"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
},
|
||||
|
@ -561,9 +561,7 @@ def apply_additional_conditions(doctype, query, from_date, ignore_closing_entrie
|
||||
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||
|
||||
if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb):
|
||||
frappe.throw(
|
||||
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||
)
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default FB Entries'"))
|
||||
|
||||
query = query.where(
|
||||
(gl_entry.finance_book.isin([cstr(filters.finance_book), cstr(company_fb), ""]))
|
||||
|
@ -79,7 +79,9 @@ class General_Payment_Ledger_Comparison(object):
|
||||
.select(
|
||||
gle.company,
|
||||
gle.account,
|
||||
gle.voucher_type,
|
||||
gle.voucher_no,
|
||||
gle.party_type,
|
||||
gle.party,
|
||||
outstanding,
|
||||
)
|
||||
@ -89,7 +91,9 @@ class General_Payment_Ledger_Comparison(object):
|
||||
& (gle.account.isin(val.accounts))
|
||||
)
|
||||
.where(Criterion.all(filter_criterion))
|
||||
.groupby(gle.company, gle.account, gle.voucher_no, gle.party)
|
||||
.groupby(
|
||||
gle.company, gle.account, gle.voucher_type, gle.voucher_no, gle.party_type, gle.party
|
||||
)
|
||||
.run()
|
||||
)
|
||||
|
||||
@ -112,7 +116,13 @@ class General_Payment_Ledger_Comparison(object):
|
||||
self.account_types[acc_type].ple = (
|
||||
qb.from_(ple)
|
||||
.select(
|
||||
ple.company, ple.account, ple.voucher_no, ple.party, Sum(ple.amount).as_("outstanding")
|
||||
ple.company,
|
||||
ple.account,
|
||||
ple.voucher_type,
|
||||
ple.voucher_no,
|
||||
ple.party_type,
|
||||
ple.party,
|
||||
Sum(ple.amount).as_("outstanding"),
|
||||
)
|
||||
.where(
|
||||
(ple.company == self.filters.company)
|
||||
@ -120,7 +130,9 @@ class General_Payment_Ledger_Comparison(object):
|
||||
& (ple.account.isin(val.accounts))
|
||||
)
|
||||
.where(Criterion.all(filter_criterion))
|
||||
.groupby(ple.company, ple.account, ple.voucher_no, ple.party)
|
||||
.groupby(
|
||||
ple.company, ple.account, ple.voucher_type, ple.voucher_no, ple.party_type, ple.party
|
||||
)
|
||||
.run()
|
||||
)
|
||||
|
||||
@ -138,12 +150,12 @@ class General_Payment_Ledger_Comparison(object):
|
||||
self.diff = frappe._dict({})
|
||||
|
||||
for x in self.variation_in_payment_ledger:
|
||||
self.diff[(x[0], x[1], x[2], x[3])] = frappe._dict({"gl_balance": x[4]})
|
||||
self.diff[(x[0], x[1], x[2], x[3], x[4], x[5])] = frappe._dict({"gl_balance": x[6]})
|
||||
|
||||
for x in self.variation_in_general_ledger:
|
||||
self.diff.setdefault((x[0], x[1], x[2], x[3]), frappe._dict({"gl_balance": 0.0})).update(
|
||||
frappe._dict({"pl_balance": x[4]})
|
||||
)
|
||||
self.diff.setdefault(
|
||||
(x[0], x[1], x[2], x[3], x[4], x[5]), frappe._dict({"gl_balance": 0.0})
|
||||
).update(frappe._dict({"pl_balance": x[6]}))
|
||||
|
||||
def generate_data(self):
|
||||
self.data = []
|
||||
@ -151,8 +163,12 @@ class General_Payment_Ledger_Comparison(object):
|
||||
self.data.append(
|
||||
frappe._dict(
|
||||
{
|
||||
"voucher_no": key[2],
|
||||
"party": key[3],
|
||||
"company": key[0],
|
||||
"account": key[1],
|
||||
"voucher_type": key[2],
|
||||
"voucher_no": key[3],
|
||||
"party_type": key[4],
|
||||
"party": key[5],
|
||||
"gl_balance": val.gl_balance,
|
||||
"pl_balance": val.pl_balance,
|
||||
}
|
||||
@ -162,12 +178,52 @@ class General_Payment_Ledger_Comparison(object):
|
||||
def get_columns(self):
|
||||
self.columns = []
|
||||
options = None
|
||||
self.columns.append(
|
||||
dict(
|
||||
label=_("Company"),
|
||||
fieldname="company",
|
||||
fieldtype="Link",
|
||||
options="Company",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
||||
self.columns.append(
|
||||
dict(
|
||||
label=_("Account"),
|
||||
fieldname="account",
|
||||
fieldtype="Link",
|
||||
options="Account",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
||||
self.columns.append(
|
||||
dict(
|
||||
label=_("Voucher Type"),
|
||||
fieldname="voucher_type",
|
||||
fieldtype="Link",
|
||||
options="DocType",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
||||
self.columns.append(
|
||||
dict(
|
||||
label=_("Voucher No"),
|
||||
fieldname="voucher_no",
|
||||
fieldtype="Data",
|
||||
options=options,
|
||||
fieldtype="Dynamic Link",
|
||||
options="voucher_type",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
||||
self.columns.append(
|
||||
dict(
|
||||
label=_("Party Type"),
|
||||
fieldname="party_type",
|
||||
fieldtype="Link",
|
||||
options="DocType",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
@ -176,8 +232,8 @@ class General_Payment_Ledger_Comparison(object):
|
||||
dict(
|
||||
label=_("Party"),
|
||||
fieldname="party",
|
||||
fieldtype="Data",
|
||||
options=options,
|
||||
fieldtype="Dynamic Link",
|
||||
options="party_type",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
@ -50,7 +50,11 @@ class TestGeneralAndPaymentLedger(FrappeTestCase, AccountsTestMixin):
|
||||
self.assertEqual(len(data), 1)
|
||||
|
||||
expected = {
|
||||
"company": sinv.company,
|
||||
"account": sinv.debit_to,
|
||||
"voucher_type": sinv.doctype,
|
||||
"voucher_no": sinv.name,
|
||||
"party_type": "Customer",
|
||||
"party": sinv.customer,
|
||||
"gl_balance": sinv.grand_total,
|
||||
"pl_balance": sinv.grand_total - 1,
|
||||
|
@ -175,7 +175,7 @@ frappe.query_reports["General Ledger"] = {
|
||||
},
|
||||
{
|
||||
"fieldname": "include_default_book_entries",
|
||||
"label": __("Include Default Book Entries"),
|
||||
"label": __("Include Default FB Entries"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
},
|
||||
@ -193,7 +193,13 @@ frappe.query_reports["General Ledger"] = {
|
||||
"fieldname": "add_values_in_transaction_currency",
|
||||
"label": __("Add Columns in Transaction Currency"),
|
||||
"fieldtype": "Check"
|
||||
},
|
||||
{
|
||||
"fieldname": "show_remarks",
|
||||
"label": __("Show Remarks"),
|
||||
"fieldtype": "Check"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -163,6 +163,9 @@ def get_gl_entries(filters, accounting_dimensions):
|
||||
select_fields = """, debit, credit, debit_in_account_currency,
|
||||
credit_in_account_currency """
|
||||
|
||||
if filters.get("show_remarks"):
|
||||
select_fields += """,remarks"""
|
||||
|
||||
order_by_statement = "order by posting_date, account, creation"
|
||||
|
||||
if filters.get("include_dimensions"):
|
||||
@ -195,7 +198,7 @@ def get_gl_entries(filters, accounting_dimensions):
|
||||
voucher_type, voucher_no, {dimension_fields}
|
||||
cost_center, project, {transaction_currency_fields}
|
||||
against_voucher_type, against_voucher, account_currency,
|
||||
remarks, against, is_opening, creation {select_fields}
|
||||
against, is_opening, creation {select_fields}
|
||||
from `tabGL Entry`
|
||||
where company=%(company)s {conditions}
|
||||
{order_by_statement}
|
||||
@ -256,9 +259,7 @@ def get_conditions(filters):
|
||||
if filters.get("company_fb") and cstr(filters.get("finance_book")) != cstr(
|
||||
filters.get("company_fb")
|
||||
):
|
||||
frappe.throw(
|
||||
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||
)
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default FB Entries'"))
|
||||
else:
|
||||
conditions.append("(finance_book in (%(finance_book)s, '') OR finance_book IS NULL)")
|
||||
else:
|
||||
@ -631,8 +632,10 @@ def get_columns(filters):
|
||||
"width": 100,
|
||||
},
|
||||
{"label": _("Supplier Invoice No"), "fieldname": "bill_no", "fieldtype": "Data", "width": 100},
|
||||
{"label": _("Remarks"), "fieldname": "remarks", "width": 400},
|
||||
]
|
||||
)
|
||||
|
||||
if filters.get("show_remarks"):
|
||||
columns.extend([{"label": _("Remarks"), "fieldname": "remarks", "width": 400}])
|
||||
|
||||
return columns
|
||||
|
@ -47,6 +47,7 @@ def get_result(
|
||||
out = []
|
||||
for name, details in gle_map.items():
|
||||
tax_amount, total_amount, grand_total, base_total = 0, 0, 0, 0
|
||||
bill_no, bill_date = "", ""
|
||||
tax_withholding_category = tax_category_map.get(name)
|
||||
rate = tax_rate_map.get(tax_withholding_category)
|
||||
|
||||
@ -70,7 +71,10 @@ def get_result(
|
||||
if net_total_map.get(name):
|
||||
if voucher_type == "Journal Entry" and tax_amount and rate:
|
||||
# back calcalute total amount from rate and tax_amount
|
||||
total_amount = grand_total = base_total = tax_amount / (rate / 100)
|
||||
if rate:
|
||||
total_amount = grand_total = base_total = tax_amount / (rate / 100)
|
||||
elif voucher_type == "Purchase Invoice":
|
||||
total_amount, grand_total, base_total, bill_no, bill_date = net_total_map.get(name)
|
||||
else:
|
||||
total_amount, grand_total, base_total = net_total_map.get(name)
|
||||
else:
|
||||
@ -96,7 +100,7 @@ def get_result(
|
||||
|
||||
row.update(
|
||||
{
|
||||
"section_code": tax_withholding_category,
|
||||
"section_code": tax_withholding_category or "",
|
||||
"entity_type": party_map.get(party, {}).get(party_type),
|
||||
"rate": rate,
|
||||
"total_amount": total_amount,
|
||||
@ -106,10 +110,14 @@ def get_result(
|
||||
"transaction_date": posting_date,
|
||||
"transaction_type": voucher_type,
|
||||
"ref_no": name,
|
||||
"supplier_invoice_no": bill_no,
|
||||
"supplier_invoice_date": bill_date,
|
||||
}
|
||||
)
|
||||
out.append(row)
|
||||
|
||||
out.sort(key=lambda x: x["section_code"])
|
||||
|
||||
return out
|
||||
|
||||
|
||||
@ -157,14 +165,14 @@ def get_gle_map(documents):
|
||||
def get_columns(filters):
|
||||
pan = "pan" if frappe.db.has_column(filters.party_type, "pan") else "tax_id"
|
||||
columns = [
|
||||
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 60},
|
||||
{
|
||||
"label": _(filters.get("party_type")),
|
||||
"fieldname": "party",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"options": "party_type",
|
||||
"width": 180,
|
||||
"label": _("Section Code"),
|
||||
"options": "Tax Withholding Category",
|
||||
"fieldname": "section_code",
|
||||
"fieldtype": "Link",
|
||||
"width": 90,
|
||||
},
|
||||
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 60},
|
||||
]
|
||||
|
||||
if filters.naming_series == "Naming Series":
|
||||
@ -179,51 +187,60 @@ def get_columns(filters):
|
||||
|
||||
columns.extend(
|
||||
[
|
||||
{
|
||||
"label": _("Date of Transaction"),
|
||||
"fieldname": "transaction_date",
|
||||
"fieldtype": "Date",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Section Code"),
|
||||
"options": "Tax Withholding Category",
|
||||
"fieldname": "section_code",
|
||||
"fieldtype": "Link",
|
||||
"width": 90,
|
||||
},
|
||||
{"label": _("Entity Type"), "fieldname": "entity_type", "fieldtype": "Data", "width": 100},
|
||||
{
|
||||
"label": _("Total Amount"),
|
||||
"fieldname": "total_amount",
|
||||
"fieldtype": "Float",
|
||||
"width": 90,
|
||||
},
|
||||
]
|
||||
)
|
||||
if filters.party_type == "Supplier":
|
||||
columns.extend(
|
||||
[
|
||||
{
|
||||
"label": _("Supplier Invoice No"),
|
||||
"fieldname": "supplier_invoice_no",
|
||||
"fieldtype": "Data",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Supplier Invoice Date"),
|
||||
"fieldname": "supplier_invoice_date",
|
||||
"fieldtype": "Date",
|
||||
"width": 120,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
columns.extend(
|
||||
[
|
||||
{
|
||||
"label": _("TDS Rate %") if filters.get("party_type") == "Supplier" else _("TCS Rate %"),
|
||||
"fieldname": "rate",
|
||||
"fieldtype": "Percent",
|
||||
"width": 90,
|
||||
"width": 60,
|
||||
},
|
||||
{
|
||||
"label": _("Tax Amount"),
|
||||
"fieldname": "tax_amount",
|
||||
"label": _("Total Amount"),
|
||||
"fieldname": "total_amount",
|
||||
"fieldtype": "Float",
|
||||
"width": 90,
|
||||
},
|
||||
{
|
||||
"label": _("Grand Total"),
|
||||
"fieldname": "grand_total",
|
||||
"fieldtype": "Float",
|
||||
"width": 90,
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Base Total"),
|
||||
"fieldname": "base_total",
|
||||
"fieldtype": "Float",
|
||||
"width": 90,
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Transaction Type"), "fieldname": "transaction_type", "width": 100},
|
||||
{
|
||||
"label": _("Tax Amount"),
|
||||
"fieldname": "tax_amount",
|
||||
"fieldtype": "Float",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Grand Total"),
|
||||
"fieldname": "grand_total",
|
||||
"fieldtype": "Float",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Transaction Type"), "fieldname": "transaction_type", "width": 130},
|
||||
{
|
||||
"label": _("Reference No."),
|
||||
"fieldname": "ref_no",
|
||||
@ -231,6 +248,12 @@ def get_columns(filters):
|
||||
"options": "transaction_type",
|
||||
"width": 180,
|
||||
},
|
||||
{
|
||||
"label": _("Date of Transaction"),
|
||||
"fieldname": "transaction_date",
|
||||
"fieldtype": "Date",
|
||||
"width": 100,
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
@ -253,27 +276,7 @@ def get_tds_docs(filters):
|
||||
"Tax Withholding Account", {"company": filters.get("company")}, pluck="account"
|
||||
)
|
||||
|
||||
query_filters = {
|
||||
"account": ("in", tds_accounts),
|
||||
"posting_date": ("between", [filters.get("from_date"), filters.get("to_date")]),
|
||||
"is_cancelled": 0,
|
||||
"against": ("not in", bank_accounts),
|
||||
}
|
||||
|
||||
party = frappe.get_all(filters.get("party_type"), pluck="name")
|
||||
or_filters.update({"against": ("in", party), "voucher_type": "Journal Entry"})
|
||||
|
||||
if filters.get("party"):
|
||||
del query_filters["account"]
|
||||
del query_filters["against"]
|
||||
or_filters = {"against": filters.get("party"), "party": filters.get("party")}
|
||||
|
||||
tds_docs = frappe.get_all(
|
||||
"GL Entry",
|
||||
filters=query_filters,
|
||||
or_filters=or_filters,
|
||||
fields=["voucher_no", "voucher_type", "against", "party"],
|
||||
)
|
||||
tds_docs = get_tds_docs_query(filters, bank_accounts, tds_accounts).run(as_dict=True)
|
||||
|
||||
for d in tds_docs:
|
||||
if d.voucher_type == "Purchase Invoice":
|
||||
@ -309,6 +312,47 @@ def get_tds_docs(filters):
|
||||
)
|
||||
|
||||
|
||||
def get_tds_docs_query(filters, bank_accounts, tds_accounts):
|
||||
if not tds_accounts:
|
||||
frappe.throw(
|
||||
_("No {0} Accounts found for this company.").format(frappe.bold("Tax Withholding")),
|
||||
title=_("Accounts Missing Error"),
|
||||
)
|
||||
gle = frappe.qb.DocType("GL Entry")
|
||||
query = (
|
||||
frappe.qb.from_(gle)
|
||||
.select("voucher_no", "voucher_type", "against", "party")
|
||||
.where((gle.is_cancelled == 0))
|
||||
)
|
||||
|
||||
if filters.get("from_date"):
|
||||
query = query.where(gle.posting_date >= filters.get("from_date"))
|
||||
if filters.get("to_date"):
|
||||
query = query.where(gle.posting_date <= filters.get("to_date"))
|
||||
|
||||
if bank_accounts:
|
||||
query = query.where(gle.against.notin(bank_accounts))
|
||||
|
||||
if filters.get("party"):
|
||||
party = [filters.get("party")]
|
||||
query = query.where(
|
||||
((gle.account.isin(tds_accounts) & gle.against.isin(party)))
|
||||
| ((gle.voucher_type == "Journal Entry") & (gle.party == filters.get("party")))
|
||||
| gle.party.isin(party)
|
||||
)
|
||||
else:
|
||||
party = frappe.get_all(filters.get("party_type"), pluck="name")
|
||||
query = query.where(
|
||||
((gle.account.isin(tds_accounts) & gle.against.isin(party)))
|
||||
| (
|
||||
(gle.voucher_type == "Journal Entry")
|
||||
& ((gle.party_type == filters.get("party_type")) | (gle.party_type == ""))
|
||||
)
|
||||
| gle.party.isin(party)
|
||||
)
|
||||
return query
|
||||
|
||||
|
||||
def get_journal_entry_party_map(journal_entries):
|
||||
journal_entry_party_map = {}
|
||||
for d in frappe.db.get_all(
|
||||
@ -335,6 +379,8 @@ def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None):
|
||||
"base_tax_withholding_net_total",
|
||||
"grand_total",
|
||||
"base_total",
|
||||
"bill_no",
|
||||
"bill_date",
|
||||
],
|
||||
"Sales Invoice": ["base_net_total", "grand_total", "base_total"],
|
||||
"Payment Entry": [
|
||||
@ -353,7 +399,13 @@ def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None):
|
||||
for entry in entries:
|
||||
tax_category_map.update({entry.name: entry.tax_withholding_category})
|
||||
if doctype == "Purchase Invoice":
|
||||
value = [entry.base_tax_withholding_net_total, entry.grand_total, entry.base_total]
|
||||
value = [
|
||||
entry.base_tax_withholding_net_total,
|
||||
entry.grand_total,
|
||||
entry.base_total,
|
||||
entry.bill_no,
|
||||
entry.bill_date,
|
||||
]
|
||||
elif doctype == "Sales Invoice":
|
||||
value = [entry.base_net_total, entry.grand_total, entry.base_total]
|
||||
elif doctype == "Payment Entry":
|
||||
|
@ -95,7 +95,7 @@ frappe.query_reports["Trial Balance"] = {
|
||||
},
|
||||
{
|
||||
"fieldname": "include_default_book_entries",
|
||||
"label": __("Include Default Book Entries"),
|
||||
"label": __("Include Default FB Entries"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
},
|
||||
|
@ -275,9 +275,7 @@ def get_opening_balance(
|
||||
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||
|
||||
if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb):
|
||||
frappe.throw(
|
||||
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||
)
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default FB Entries'"))
|
||||
|
||||
opening_balance = opening_balance.where(
|
||||
(closing_balance.finance_book.isin([cstr(filters.finance_book), cstr(company_fb), ""]))
|
||||
|
@ -10,7 +10,7 @@ import frappe.defaults
|
||||
from frappe import _, qb, throw
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.query_builder import AliasedQuery, Criterion, Table
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.query_builder.functions import Round, Sum
|
||||
from frappe.query_builder.utils import DocType
|
||||
from frappe.utils import (
|
||||
cint,
|
||||
@ -536,6 +536,8 @@ def check_if_advance_entry_modified(args):
|
||||
)
|
||||
|
||||
else:
|
||||
precision = frappe.get_precision("Payment Entry", "unallocated_amount")
|
||||
|
||||
payment_entry = frappe.qb.DocType("Payment Entry")
|
||||
payment_ref = frappe.qb.DocType("Payment Entry Reference")
|
||||
|
||||
@ -557,7 +559,10 @@ def check_if_advance_entry_modified(args):
|
||||
.where(payment_ref.allocated_amount == args.get("unreconciled_amount"))
|
||||
)
|
||||
else:
|
||||
q = q.where(payment_entry.unallocated_amount == args.get("unreconciled_amount"))
|
||||
q = q.where(
|
||||
Round(payment_entry.unallocated_amount, precision)
|
||||
== Round(args.get("unreconciled_amount"), precision)
|
||||
)
|
||||
|
||||
ret = q.run(as_dict=True)
|
||||
|
||||
@ -2041,3 +2046,7 @@ def create_gain_loss_journal(
|
||||
journal_entry.save()
|
||||
journal_entry.submit()
|
||||
return journal_entry.name
|
||||
|
||||
|
||||
def get_party_types_from_account_type(account_type):
|
||||
return frappe.db.get_all("Party Type", {"account_type": account_type}, pluck="name")
|
||||
|
@ -818,7 +818,7 @@ def get_item_details(item_code, asset_category, gross_purchase_amount):
|
||||
"depreciation_method": d.depreciation_method,
|
||||
"total_number_of_depreciations": d.total_number_of_depreciations,
|
||||
"frequency_of_depreciation": d.frequency_of_depreciation,
|
||||
"daily_depreciation": d.daily_depreciation,
|
||||
"daily_prorata_based": d.daily_prorata_based,
|
||||
"salvage_value_percentage": d.salvage_value_percentage,
|
||||
"expected_value_after_useful_life": flt(gross_purchase_amount)
|
||||
* flt(d.salvage_value_percentage / 100),
|
||||
|
@ -780,6 +780,15 @@ def get_disposal_account_and_cost_center(company):
|
||||
def get_value_after_depreciation_on_disposal_date(asset, disposal_date, finance_book=None):
|
||||
asset_doc = frappe.get_doc("Asset", asset)
|
||||
|
||||
if asset_doc.available_for_use_date > getdate(disposal_date):
|
||||
frappe.throw(
|
||||
"Disposal date {0} cannot be before available for use date {1} of the asset.".format(
|
||||
disposal_date, asset_doc.available_for_use_date
|
||||
)
|
||||
)
|
||||
elif asset_doc.available_for_use_date == getdate(disposal_date):
|
||||
return flt(asset_doc.gross_purchase_amount - asset_doc.opening_accumulated_depreciation)
|
||||
|
||||
if not asset_doc.calculate_depreciation:
|
||||
return flt(asset_doc.value_after_depreciation)
|
||||
|
||||
|
@ -755,7 +755,9 @@ class TestDepreciationMethods(AssetSetup):
|
||||
|
||||
self.assertEqual(schedules, expected_schedules)
|
||||
|
||||
def test_schedule_for_straight_line_method_with_daily_depreciation(self):
|
||||
def test_schedule_for_straight_line_method_with_daily_prorata_based(
|
||||
self,
|
||||
):
|
||||
asset = create_asset(
|
||||
calculate_depreciation=1,
|
||||
available_for_use_date="2023-01-01",
|
||||
@ -764,7 +766,7 @@ class TestDepreciationMethods(AssetSetup):
|
||||
depreciation_start_date="2023-01-31",
|
||||
total_number_of_depreciations=12,
|
||||
frequency_of_depreciation=1,
|
||||
daily_depreciation=1,
|
||||
daily_prorata_based=1,
|
||||
)
|
||||
|
||||
expected_schedules = [
|
||||
@ -1760,7 +1762,7 @@ def create_asset(**args):
|
||||
"total_number_of_depreciations": args.total_number_of_depreciations or 5,
|
||||
"expected_value_after_useful_life": args.expected_value_after_useful_life or 0,
|
||||
"depreciation_start_date": args.depreciation_start_date,
|
||||
"daily_depreciation": args.daily_depreciation or 0,
|
||||
"daily_prorata_based": args.daily_prorata_based or 0,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
"depreciation_method",
|
||||
"total_number_of_depreciations",
|
||||
"rate_of_depreciation",
|
||||
"daily_depreciation",
|
||||
"daily_prorata_based",
|
||||
"column_break_8",
|
||||
"frequency_of_depreciation",
|
||||
"expected_value_after_useful_life",
|
||||
@ -179,9 +179,9 @@
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.depreciation_method == \"Straight Line\" || doc.depreciation_method == \"Manual\"",
|
||||
"fieldname": "daily_depreciation",
|
||||
"fieldname": "daily_prorata_based",
|
||||
"fieldtype": "Check",
|
||||
"label": "Daily Depreciation",
|
||||
"label": "Depreciate based on daily pro-rata",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
}
|
||||
@ -189,7 +189,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-08-10 22:22:09.722968",
|
||||
"modified": "2023-11-03 21:32:15.021796",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Depreciation Schedule",
|
||||
|
@ -153,7 +153,7 @@ class AssetDepreciationSchedule(Document):
|
||||
self.frequency_of_depreciation = row.frequency_of_depreciation
|
||||
self.rate_of_depreciation = row.rate_of_depreciation
|
||||
self.expected_value_after_useful_life = row.expected_value_after_useful_life
|
||||
self.daily_depreciation = row.daily_depreciation
|
||||
self.daily_prorata_based = row.daily_prorata_based
|
||||
self.status = "Draft"
|
||||
|
||||
def make_depr_schedule(
|
||||
@ -573,7 +573,7 @@ def get_straight_line_or_manual_depr_amount(
|
||||
)
|
||||
# if the Depreciation Schedule is being modified after Asset Value Adjustment due to decrease in asset value
|
||||
elif asset.flags.decrease_in_asset_value_due_to_value_adjustment:
|
||||
if row.daily_depreciation:
|
||||
if row.daily_prorata_based:
|
||||
daily_depr_amount = (
|
||||
flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)
|
||||
) / date_diff(
|
||||
@ -618,7 +618,7 @@ def get_straight_line_or_manual_depr_amount(
|
||||
) / number_of_pending_depreciations
|
||||
# if the Depreciation Schedule is being prepared for the first time
|
||||
else:
|
||||
if row.daily_depreciation:
|
||||
if row.daily_prorata_based:
|
||||
daily_depr_amount = (
|
||||
flt(asset.gross_purchase_amount)
|
||||
- flt(asset.opening_accumulated_depreciation)
|
||||
|
@ -8,7 +8,7 @@
|
||||
"finance_book",
|
||||
"depreciation_method",
|
||||
"total_number_of_depreciations",
|
||||
"daily_depreciation",
|
||||
"daily_prorata_based",
|
||||
"column_break_5",
|
||||
"frequency_of_depreciation",
|
||||
"depreciation_start_date",
|
||||
@ -86,23 +86,23 @@
|
||||
"fieldtype": "Percent",
|
||||
"label": "Rate of Depreciation"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.depreciation_method == \"Straight Line\" || doc.depreciation_method == \"Manual\"",
|
||||
"fieldname": "daily_depreciation",
|
||||
"fieldtype": "Check",
|
||||
"label": "Daily Depreciation"
|
||||
},
|
||||
{
|
||||
"fieldname": "salvage_value_percentage",
|
||||
"fieldtype": "Percent",
|
||||
"label": "Salvage Value Percentage"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.depreciation_method == \"Straight Line\" || doc.depreciation_method == \"Manual\"",
|
||||
"fieldname": "daily_prorata_based",
|
||||
"fieldtype": "Check",
|
||||
"label": "Depreciate based on daily pro-rata"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-29 15:39:52.740594",
|
||||
"modified": "2023-11-03 21:30:24.266601",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Finance Book",
|
||||
|
@ -13,25 +13,22 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu
|
||||
class TestAssetMaintenance(unittest.TestCase):
|
||||
def setUp(self):
|
||||
set_depreciation_settings_in_company()
|
||||
create_asset_data()
|
||||
create_maintenance_team()
|
||||
|
||||
def test_create_asset_maintenance(self):
|
||||
pr = make_purchase_receipt(
|
||||
self.pr = make_purchase_receipt(
|
||||
item_code="Photocopier", qty=1, rate=100000.0, location="Test Location"
|
||||
)
|
||||
self.asset_name = frappe.db.get_value("Asset", {"purchase_receipt": self.pr.name}, "name")
|
||||
self.asset_doc = frappe.get_doc("Asset", self.asset_name)
|
||||
|
||||
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, "name")
|
||||
asset_doc = frappe.get_doc("Asset", asset_name)
|
||||
def test_create_asset_maintenance_with_log(self):
|
||||
month_end_date = get_last_day(nowdate())
|
||||
|
||||
purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)
|
||||
|
||||
asset_doc.available_for_use_date = purchase_date
|
||||
asset_doc.purchase_date = purchase_date
|
||||
self.asset_doc.available_for_use_date = purchase_date
|
||||
self.asset_doc.purchase_date = purchase_date
|
||||
|
||||
asset_doc.calculate_depreciation = 1
|
||||
asset_doc.append(
|
||||
self.asset_doc.calculate_depreciation = 1
|
||||
self.asset_doc.append(
|
||||
"finance_books",
|
||||
{
|
||||
"expected_value_after_useful_life": 200,
|
||||
@ -42,97 +39,40 @@ class TestAssetMaintenance(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
|
||||
asset_doc.save()
|
||||
self.asset_doc.save()
|
||||
|
||||
if not frappe.db.exists("Asset Maintenance", "Photocopier"):
|
||||
asset_maintenance = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Asset Maintenance",
|
||||
"asset_name": "Photocopier",
|
||||
"maintenance_team": "Team Awesome",
|
||||
"company": "_Test Company",
|
||||
"asset_maintenance_tasks": get_maintenance_tasks(),
|
||||
}
|
||||
).insert()
|
||||
asset_maintenance = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Asset Maintenance",
|
||||
"asset_name": self.asset_name,
|
||||
"maintenance_team": "Team Awesome",
|
||||
"company": "_Test Company",
|
||||
"asset_maintenance_tasks": get_maintenance_tasks(),
|
||||
}
|
||||
).insert()
|
||||
|
||||
next_due_date = calculate_next_due_date(nowdate(), "Monthly")
|
||||
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)
|
||||
|
||||
def test_create_asset_maintenance_log(self):
|
||||
if not frappe.db.exists("Asset Maintenance Log", "Photocopier"):
|
||||
asset_maintenance_log = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Asset Maintenance Log",
|
||||
"asset_maintenance": "Photocopier",
|
||||
"task": "Change Oil",
|
||||
"completion_date": add_days(nowdate(), 2),
|
||||
"maintenance_status": "Completed",
|
||||
}
|
||||
).insert()
|
||||
asset_maintenance = frappe.get_doc("Asset Maintenance", "Photocopier")
|
||||
next_due_date = calculate_next_due_date(asset_maintenance_log.completion_date, "Monthly")
|
||||
next_due_date = calculate_next_due_date(nowdate(), "Monthly")
|
||||
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)
|
||||
|
||||
asset_maintenance_log = frappe.db.get_value(
|
||||
"Asset Maintenance Log",
|
||||
{"asset_maintenance": asset_maintenance.name, "task_name": "Change Oil"},
|
||||
"name",
|
||||
)
|
||||
|
||||
def create_asset_data():
|
||||
if not frappe.db.exists("Asset Category", "Equipment"):
|
||||
create_asset_category()
|
||||
|
||||
if not frappe.db.exists("Location", "Test Location"):
|
||||
frappe.get_doc({"doctype": "Location", "location_name": "Test Location"}).insert()
|
||||
|
||||
if not frappe.db.exists("Item", "Photocopier"):
|
||||
meta = frappe.get_meta("Asset")
|
||||
naming_series = meta.get_field("naming_series").options
|
||||
frappe.get_doc(
|
||||
asset_maintenance_log_doc = frappe.get_doc("Asset Maintenance Log", asset_maintenance_log)
|
||||
asset_maintenance_log_doc.update(
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "Photocopier",
|
||||
"item_name": "Photocopier",
|
||||
"item_group": "All Item Groups",
|
||||
"company": "_Test Company",
|
||||
"is_fixed_asset": 1,
|
||||
"is_stock_item": 0,
|
||||
"asset_category": "Equipment",
|
||||
"auto_create_assets": 1,
|
||||
"asset_naming_series": naming_series,
|
||||
"completion_date": add_days(nowdate(), 2),
|
||||
"maintenance_status": "Completed",
|
||||
}
|
||||
).insert()
|
||||
)
|
||||
|
||||
asset_maintenance_log_doc.save()
|
||||
next_due_date = calculate_next_due_date(asset_maintenance_log_doc.completion_date, "Monthly")
|
||||
|
||||
def create_maintenance_team():
|
||||
user_list = ["marcus@abc.com", "thalia@abc.com", "mathias@abc.com"]
|
||||
if not frappe.db.exists("Role", "Technician"):
|
||||
frappe.get_doc({"doctype": "Role", "role_name": "Technician"}).insert()
|
||||
for user in user_list:
|
||||
if not frappe.db.get_value("User", user):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": user,
|
||||
"first_name": user,
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Technician"}],
|
||||
}
|
||||
).insert()
|
||||
|
||||
if not frappe.db.exists("Asset Maintenance Team", "Team Awesome"):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Asset Maintenance Team",
|
||||
"maintenance_manager": "marcus@abc.com",
|
||||
"maintenance_team_name": "Team Awesome",
|
||||
"company": "_Test Company",
|
||||
"maintenance_team_members": get_maintenance_team(user_list),
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def get_maintenance_team(user_list):
|
||||
return [
|
||||
{"team_member": user, "full_name": user, "maintenance_role": "Technician"}
|
||||
for user in user_list[1:]
|
||||
]
|
||||
asset_maintenance.reload()
|
||||
self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)
|
||||
|
||||
|
||||
def get_maintenance_tasks():
|
||||
@ -156,23 +96,6 @@ def get_maintenance_tasks():
|
||||
]
|
||||
|
||||
|
||||
def create_asset_category():
|
||||
asset_category = frappe.new_doc("Asset Category")
|
||||
asset_category.asset_category_name = "Equipment"
|
||||
asset_category.total_number_of_depreciations = 3
|
||||
asset_category.frequency_of_depreciation = 3
|
||||
asset_category.append(
|
||||
"accounts",
|
||||
{
|
||||
"company_name": "_Test Company",
|
||||
"fixed_asset_account": "_Test Fixed Asset - _TC",
|
||||
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
|
||||
"depreciation_expense_account": "_Test Depreciations - _TC",
|
||||
},
|
||||
)
|
||||
asset_category.insert()
|
||||
|
||||
|
||||
def set_depreciation_settings_in_company():
|
||||
company = frappe.get_doc("Company", "_Test Company")
|
||||
company.accumulated_depreciation_account = "_Test Accumulated Depreciations - _TC"
|
||||
|
68
erpnext/assets/doctype/asset_maintenance/test_records.json
Normal file
68
erpnext/assets/doctype/asset_maintenance/test_records.json
Normal file
@ -0,0 +1,68 @@
|
||||
[
|
||||
{
|
||||
"doctype": "Asset Category",
|
||||
"asset_category_name": "Equipment",
|
||||
"total_number_of_depreciations": 3,
|
||||
"frequency_of_depreciation": 3,
|
||||
"accounts": [
|
||||
{
|
||||
"company_name": "_Test Company",
|
||||
"fixed_asset_account": "_Test Fixed Asset - _TC",
|
||||
"accumulated_depreciation_account": "_Test Accumulated Depreciations - _TC",
|
||||
"depreciation_expense_account": "_Test Depreciations - _TC"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Location",
|
||||
"location_name": "Test Location"
|
||||
},
|
||||
{
|
||||
"doctype": "Role",
|
||||
"role_name": "Technician"
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "marcus@abc.com",
|
||||
"first_name": "marcus@abc.com",
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Technician"}]
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "thalia@abc.com",
|
||||
"first_name": "thalia@abc.com",
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Technician"}]
|
||||
},
|
||||
{
|
||||
"doctype": "User",
|
||||
"email": "mathias@abc.com",
|
||||
"first_name": "mathias@abc.com",
|
||||
"new_password": "password",
|
||||
"roles": [{"doctype": "Has Role", "role": "Technician"}]
|
||||
},
|
||||
{
|
||||
"doctype": "Asset Maintenance Team",
|
||||
"maintenance_manager": "marcus@abc.com",
|
||||
"maintenance_team_name": "Team Awesome",
|
||||
"company": "_Test Company",
|
||||
"maintenance_team_members": [
|
||||
{"team_member": "marcus@abc.com", "full_name": "marcus@abc.com", "maintenance_role": "Technician"},
|
||||
{"team_member": "thalia@abc.com", "full_name": "thalia@abc.com", "maintenance_role": "Technician"},
|
||||
{"team_member": "mathias@abc.com", "full_name": "mathias@abc.com", "maintenance_role": "Technician"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"doctype": "Item",
|
||||
"item_code": "Photocopier",
|
||||
"item_name": "Photocopier",
|
||||
"item_group": "All Item Groups",
|
||||
"company": "_Test Company",
|
||||
"is_fixed_asset": 1,
|
||||
"is_stock_item": 0,
|
||||
"asset_category": "Equipment",
|
||||
"auto_create_assets": 1,
|
||||
"asset_naming_series": "ABC.###"
|
||||
}
|
||||
]
|
@ -52,7 +52,7 @@ frappe.query_reports["Fixed Asset Register"] = {
|
||||
},
|
||||
{
|
||||
"fieldname": "include_default_book_assets",
|
||||
"label": __("Include Default Book Assets"),
|
||||
"label": __("Include Default FB Assets"),
|
||||
"fieldtype": "Check",
|
||||
"default": 1
|
||||
},
|
||||
|
@ -223,7 +223,7 @@ def get_assets_linked_to_fb(filters):
|
||||
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||
|
||||
if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb):
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default Book Assets'"))
|
||||
frappe.throw(_("To use a different finance book, please uncheck 'Include Default FB Assets'"))
|
||||
|
||||
query = query.where(
|
||||
(afb.finance_book.isin([cstr(filters.finance_book), cstr(company_fb), ""]))
|
||||
|
@ -470,6 +470,7 @@
|
||||
"fieldname": "material_request",
|
||||
"fieldtype": "Link",
|
||||
"label": "Material Request",
|
||||
"mandatory_depends_on": "eval: doc.material_request_item",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "prevdoc_docname",
|
||||
"oldfieldtype": "Link",
|
||||
@ -485,6 +486,7 @@
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Material Request Item",
|
||||
"mandatory_depends_on": "eval: doc.material_request",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "prevdoc_detail_docname",
|
||||
"oldfieldtype": "Data",
|
||||
@ -914,7 +916,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-27 15:50:42.655573",
|
||||
"modified": "2023-11-06 11:00:53.596417",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Purchase Order Item",
|
||||
|
@ -9,6 +9,8 @@
|
||||
"field_order": [
|
||||
"naming_series",
|
||||
"company",
|
||||
"billing_address",
|
||||
"billing_address_display",
|
||||
"vendor",
|
||||
"column_break1",
|
||||
"transaction_date",
|
||||
@ -292,13 +294,25 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "Send Document Print",
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "billing_address",
|
||||
"fieldtype": "Link",
|
||||
"label": "Company Billing Address",
|
||||
"options": "Address"
|
||||
},
|
||||
{
|
||||
"fieldname": "billing_address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Billing Address Details",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-shopping-cart",
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-08-09 12:20:26.850623",
|
||||
"modified": "2023-11-06 12:45:28.898706",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation",
|
||||
|
@ -174,7 +174,7 @@
|
||||
"fieldname": "supplier_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "Supplier Type",
|
||||
"options": "Company\nIndividual",
|
||||
"options": "Company\nIndividual\nProprietorship\nPartnership",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@ -485,7 +485,7 @@
|
||||
"link_fieldname": "party"
|
||||
}
|
||||
],
|
||||
"modified": "2023-09-25 12:48:21.869563",
|
||||
"modified": "2023-10-19 16:55:15.148325",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Supplier",
|
||||
|
@ -79,6 +79,7 @@
|
||||
"pricing_rule_details",
|
||||
"pricing_rules",
|
||||
"address_and_contact_tab",
|
||||
"supplier_address_section",
|
||||
"supplier_address",
|
||||
"address_display",
|
||||
"column_break_72",
|
||||
@ -86,6 +87,14 @@
|
||||
"contact_display",
|
||||
"contact_mobile",
|
||||
"contact_email",
|
||||
"shipping_address_section",
|
||||
"shipping_address",
|
||||
"column_break_zjaq",
|
||||
"shipping_address_display",
|
||||
"company_billing_address_section",
|
||||
"billing_address",
|
||||
"column_break_gcth",
|
||||
"billing_address_display",
|
||||
"terms_tab",
|
||||
"tc_name",
|
||||
"terms",
|
||||
@ -838,6 +847,55 @@
|
||||
"fieldname": "named_place",
|
||||
"fieldtype": "Data",
|
||||
"label": "Named Place"
|
||||
},
|
||||
{
|
||||
"fieldname": "shipping_address",
|
||||
"fieldtype": "Link",
|
||||
"label": "Shipping Address",
|
||||
"options": "Address",
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_zjaq",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "shipping_address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Shipping Address Details",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "shipping_address_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Shipping Address"
|
||||
},
|
||||
{
|
||||
"fieldname": "supplier_address_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Supplier Address"
|
||||
},
|
||||
{
|
||||
"fieldname": "company_billing_address_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Company Billing Address"
|
||||
},
|
||||
{
|
||||
"fieldname": "billing_address",
|
||||
"fieldtype": "Link",
|
||||
"label": "Company Billing Address",
|
||||
"options": "Address"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_gcth",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "billing_address_display",
|
||||
"fieldtype": "Small Text",
|
||||
"label": "Billing Address Details",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-shopping-cart",
|
||||
@ -845,7 +903,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-06-03 16:20:15.880114",
|
||||
"modified": "2023-11-03 13:21:40.172508",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Supplier Quotation",
|
||||
|
@ -2275,6 +2275,7 @@ class AccountsController(TransactionBase):
|
||||
repost_ledger = frappe.new_doc("Repost Accounting Ledger")
|
||||
repost_ledger.company = self.company
|
||||
repost_ledger.append("vouchers", {"voucher_type": self.doctype, "voucher_no": self.name})
|
||||
repost_ledger.flags.ignore_permissions = True
|
||||
repost_ledger.insert()
|
||||
repost_ledger.submit()
|
||||
self.db_set("repost_required", 0)
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import ValidationError, _, msgprint
|
||||
from frappe.contacts.doctype.address.address import get_address_display
|
||||
from frappe.contacts.doctype.address.address import render_address
|
||||
from frappe.utils import cint, flt, getdate
|
||||
from frappe.utils.data import nowtime
|
||||
|
||||
@ -105,26 +105,26 @@ class BuyingController(SubcontractingController):
|
||||
def set_rate_for_standalone_debit_note(self):
|
||||
if self.get("is_return") and self.get("update_stock") and not self.return_against:
|
||||
for row in self.items:
|
||||
if row.rate <= 0:
|
||||
# override the rate with valuation rate
|
||||
row.rate = get_incoming_rate(
|
||||
{
|
||||
"item_code": row.item_code,
|
||||
"warehouse": row.warehouse,
|
||||
"posting_date": self.get("posting_date"),
|
||||
"posting_time": self.get("posting_time"),
|
||||
"qty": row.qty,
|
||||
"serial_and_batch_bundle": row.get("serial_and_batch_bundle"),
|
||||
"company": self.company,
|
||||
"voucher_type": self.doctype,
|
||||
"voucher_no": self.name,
|
||||
},
|
||||
raise_error_if_no_rate=False,
|
||||
)
|
||||
|
||||
# override the rate with valuation rate
|
||||
row.rate = get_incoming_rate(
|
||||
{
|
||||
"item_code": row.item_code,
|
||||
"warehouse": row.warehouse,
|
||||
"posting_date": self.get("posting_date"),
|
||||
"posting_time": self.get("posting_time"),
|
||||
"qty": row.qty,
|
||||
"serial_and_batch_bundle": row.get("serial_and_batch_bundle"),
|
||||
"company": self.company,
|
||||
"voucher_type": self.doctype,
|
||||
"voucher_no": self.name,
|
||||
},
|
||||
raise_error_if_no_rate=False,
|
||||
)
|
||||
|
||||
row.discount_percentage = 0.0
|
||||
row.discount_amount = 0.0
|
||||
row.margin_rate_or_amount = 0.0
|
||||
row.discount_percentage = 0.0
|
||||
row.discount_amount = 0.0
|
||||
row.margin_rate_or_amount = 0.0
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
super(BuyingController, self).set_missing_values(for_validate)
|
||||
@ -246,7 +246,9 @@ class BuyingController(SubcontractingController):
|
||||
|
||||
for address_field, address_display_field in address_dict.items():
|
||||
if self.get(address_field):
|
||||
self.set(address_display_field, get_address_display(self.get(address_field)))
|
||||
self.set(
|
||||
address_display_field, render_address(self.get(address_field), check_permissions=False)
|
||||
)
|
||||
|
||||
def set_total_in_words(self):
|
||||
from frappe.utils import money_in_words
|
||||
|
@ -611,6 +611,8 @@ def get_income_account(doctype, txt, searchfield, start, page_len, filters):
|
||||
if filters.get("company"):
|
||||
condition += "and tabAccount.company = %(company)s"
|
||||
|
||||
condition += f"and tabAccount.disabled = {filters.get('disabled', 0)}"
|
||||
|
||||
return frappe.db.sql(
|
||||
"""select tabAccount.name from `tabAccount`
|
||||
where (tabAccount.report_type = "Profit and Loss"
|
||||
|
@ -47,11 +47,11 @@ status_map = {
|
||||
],
|
||||
[
|
||||
"To Bill",
|
||||
"eval:(self.per_delivered == 100 or self.skip_delivery_note) and self.per_billed < 100 and self.docstatus == 1",
|
||||
"eval:(self.per_delivered >= 100 or self.skip_delivery_note) and self.per_billed < 100 and self.docstatus == 1",
|
||||
],
|
||||
[
|
||||
"To Deliver",
|
||||
"eval:self.per_delivered < 100 and self.per_billed == 100 and self.docstatus == 1 and not self.skip_delivery_note",
|
||||
"eval:self.per_delivered < 100 and self.per_billed >= 100 and self.docstatus == 1 and not self.skip_delivery_note",
|
||||
],
|
||||
[
|
||||
"To Pay",
|
||||
@ -59,7 +59,7 @@ status_map = {
|
||||
],
|
||||
[
|
||||
"Completed",
|
||||
"eval:(self.per_delivered == 100 or self.skip_delivery_note) and self.per_billed == 100 and self.docstatus == 1",
|
||||
"eval:(self.per_delivered >= 100 or self.skip_delivery_note) and self.per_billed >= 100 and self.docstatus == 1",
|
||||
],
|
||||
["Cancelled", "eval:self.docstatus==2"],
|
||||
["Closed", "eval:self.status=='Closed' and self.docstatus != 2"],
|
||||
|
@ -1210,8 +1210,6 @@ def create_item_wise_repost_entries(voucher_type, voucher_no, allow_zero_rate=Fa
|
||||
|
||||
repost_entry = frappe.new_doc("Repost Item Valuation")
|
||||
repost_entry.based_on = "Item and Warehouse"
|
||||
repost_entry.voucher_type = voucher_type
|
||||
repost_entry.voucher_no = voucher_no
|
||||
|
||||
repost_entry.item_code = sle.item_code
|
||||
repost_entry.warehouse = sle.warehouse
|
||||
|
@ -7,6 +7,8 @@ from frappe.contacts.address_and_contact import (
|
||||
delete_contact_and_address,
|
||||
load_address_and_contact,
|
||||
)
|
||||
from frappe.contacts.doctype.address.address import get_default_address
|
||||
from frappe.contacts.doctype.contact.contact import get_default_contact
|
||||
from frappe.email.inbox import link_communication_to_document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.utils import comma_and, get_link_to_form, has_gravatar, validate_email_address
|
||||
@ -251,6 +253,13 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False):
|
||||
|
||||
target.customer_group = frappe.db.get_default("Customer Group")
|
||||
|
||||
address = get_default_address("Lead", source.name)
|
||||
contact = get_default_contact("Lead", source.name)
|
||||
if address:
|
||||
target.customer_primary_address = address
|
||||
if contact:
|
||||
target.customer_primary_contact = contact
|
||||
|
||||
doclist = get_mapped_doc(
|
||||
"Lead",
|
||||
source_name,
|
||||
|
@ -192,26 +192,6 @@
|
||||
"onboard": 0,
|
||||
"type": "Card Break"
|
||||
},
|
||||
{
|
||||
"hidden": 0,
|
||||
"is_query_report": 0,
|
||||
"label": "GoCardless Settings",
|
||||
"link_count": 0,
|
||||
"link_to": "GoCardless Settings",
|
||||
"link_type": "DocType",
|
||||
"onboard": 0,
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"hidden": 0,
|
||||
"is_query_report": 0,
|
||||
"label": "Mpesa Settings",
|
||||
"link_count": 0,
|
||||
"link_to": "Mpesa Settings",
|
||||
"link_type": "DocType",
|
||||
"onboard": 0,
|
||||
"type": "Link"
|
||||
},
|
||||
{
|
||||
"hidden": 0,
|
||||
"is_query_report": 0,
|
||||
@ -223,7 +203,7 @@
|
||||
"type": "Link"
|
||||
}
|
||||
],
|
||||
"modified": "2023-08-29 15:48:59.010704",
|
||||
"modified": "2023-10-31 19:57:32.748726",
|
||||
"modified_by": "Administrator",
|
||||
"module": "ERPNext Integrations",
|
||||
"name": "ERPNext Integrations",
|
||||
|
@ -89,10 +89,6 @@ frappe.ui.form.on('Production Plan', {
|
||||
frm.trigger("show_progress");
|
||||
|
||||
if (frm.doc.status !== "Completed") {
|
||||
frm.add_custom_button(__("Work Order Tree"), ()=> {
|
||||
frappe.set_route('Tree', 'Work Order', {production_plan: frm.doc.name});
|
||||
}, __('View'));
|
||||
|
||||
frm.add_custom_button(__("Production Plan Summary"), ()=> {
|
||||
frappe.set_route('query-report', 'Production Plan Summary', {production_plan: frm.doc.name});
|
||||
}, __('View'));
|
||||
|
@ -36,6 +36,7 @@
|
||||
"prod_plan_references",
|
||||
"section_break_24",
|
||||
"combine_sub_items",
|
||||
"sub_assembly_warehouse",
|
||||
"section_break_ucc4",
|
||||
"skip_available_sub_assembly_item",
|
||||
"column_break_igxl",
|
||||
@ -416,13 +417,19 @@
|
||||
{
|
||||
"fieldname": "column_break_igxl",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "sub_assembly_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"label": "Sub Assembly Warehouse",
|
||||
"options": "Warehouse"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-calendar",
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-29 11:41:03.246059",
|
||||
"modified": "2023-11-03 14:08:11.928027",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Production Plan",
|
||||
|
@ -490,6 +490,12 @@ class ProductionPlan(Document):
|
||||
bin = frappe.get_doc("Bin", bin_name, for_update=True)
|
||||
bin.update_reserved_qty_for_production_plan()
|
||||
|
||||
for d in self.sub_assembly_items:
|
||||
if d.fg_warehouse and d.type_of_manufacturing == "In House":
|
||||
bin_name = get_or_make_bin(d.production_item, d.fg_warehouse)
|
||||
bin = frappe.get_doc("Bin", bin_name, for_update=True)
|
||||
bin.update_reserved_qty_for_for_sub_assembly()
|
||||
|
||||
def delete_draft_work_order(self):
|
||||
for d in frappe.get_all(
|
||||
"Work Order", fields=["name"], filters={"docstatus": 0, "production_plan": ("=", self.name)}
|
||||
@ -809,7 +815,11 @@ class ProductionPlan(Document):
|
||||
|
||||
bom_data = []
|
||||
|
||||
warehouse = row.warehouse if self.skip_available_sub_assembly_item else None
|
||||
warehouse = (
|
||||
(self.sub_assembly_warehouse or row.warehouse)
|
||||
if self.skip_available_sub_assembly_item
|
||||
else None
|
||||
)
|
||||
get_sub_assembly_items(row.bom_no, bom_data, row.planned_qty, self.company, warehouse=warehouse)
|
||||
self.set_sub_assembly_items_based_on_level(row, bom_data, manufacturing_type)
|
||||
sub_assembly_items_store.extend(bom_data)
|
||||
@ -818,8 +828,6 @@ class ProductionPlan(Document):
|
||||
# Combine subassembly items
|
||||
sub_assembly_items_store = self.combine_subassembly_items(sub_assembly_items_store)
|
||||
|
||||
sub_assembly_items_store.sort(key=lambda d: d.bom_level, reverse=True) # sort by bom level
|
||||
|
||||
for idx, row in enumerate(sub_assembly_items_store):
|
||||
row.idx = idx + 1
|
||||
self.append("sub_assembly_items", row)
|
||||
@ -831,7 +839,7 @@ class ProductionPlan(Document):
|
||||
for data in bom_data:
|
||||
data.qty = data.stock_qty
|
||||
data.production_plan_item = row.name
|
||||
data.fg_warehouse = row.warehouse
|
||||
data.fg_warehouse = self.sub_assembly_warehouse or row.warehouse
|
||||
data.schedule_date = row.planned_start_date
|
||||
data.type_of_manufacturing = manufacturing_type or (
|
||||
"Subcontract" if data.is_sub_contracted_item else "In House"
|
||||
@ -1637,8 +1645,8 @@ def get_reserved_qty_for_production_plan(item_code, warehouse):
|
||||
|
||||
query = query.run()
|
||||
|
||||
if not query:
|
||||
return 0.0
|
||||
if not query or query[0][0] is None:
|
||||
return None
|
||||
|
||||
reserved_qty_for_production_plan = flt(query[0][0])
|
||||
|
||||
@ -1735,7 +1743,10 @@ def get_raw_materials_of_sub_assembly_items(
|
||||
if not item.conversion_factor and item.purchase_uom:
|
||||
item.conversion_factor = get_uom_conversion_factor(item.item_code, item.purchase_uom)
|
||||
|
||||
item_details.setdefault(item.get("item_code"), item)
|
||||
if details := item_details.get(item.get("item_code")):
|
||||
details.qty += item.get("qty")
|
||||
else:
|
||||
item_details.setdefault(item.get("item_code"), item)
|
||||
|
||||
return item_details
|
||||
|
||||
@ -1777,3 +1788,29 @@ def sales_order_query(
|
||||
query = query.offset(start)
|
||||
|
||||
return query.run()
|
||||
|
||||
|
||||
def get_reserved_qty_for_sub_assembly(item_code, warehouse):
|
||||
table = frappe.qb.DocType("Production Plan")
|
||||
child = frappe.qb.DocType("Production Plan Sub Assembly Item")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(table)
|
||||
.inner_join(child)
|
||||
.on(table.name == child.parent)
|
||||
.select(Sum(child.qty - IfNull(child.wo_produced_qty, 0)))
|
||||
.where(
|
||||
(table.docstatus == 1)
|
||||
& (child.production_item == item_code)
|
||||
& (child.fg_warehouse == warehouse)
|
||||
& (table.status.notin(["Completed", "Closed"]))
|
||||
)
|
||||
)
|
||||
|
||||
query = query.run()
|
||||
|
||||
if not query or query[0][0] is None:
|
||||
return None
|
||||
|
||||
qty = flt(query[0][0])
|
||||
return qty if qty > 0 else 0.0
|
||||
|
@ -664,49 +664,6 @@ class TestProductionPlan(FrappeTestCase):
|
||||
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_subassmebly_sorting(self):
|
||||
"Test subassembly sorting in case of multiple items with nested BOMs."
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
|
||||
prefix = "_TestLevel_"
|
||||
boms = {
|
||||
"Assembly": {
|
||||
"SubAssembly1": {
|
||||
"ChildPart1": {},
|
||||
"ChildPart2": {},
|
||||
},
|
||||
"ChildPart6": {},
|
||||
"SubAssembly4": {"SubSubAssy2": {"ChildPart7": {}}},
|
||||
},
|
||||
"MegaDeepAssy": {
|
||||
"SecretSubassy": {
|
||||
"SecretPart": {"VerySecret": {"SuperSecret": {"Classified": {}}}},
|
||||
},
|
||||
# ^ assert that this is
|
||||
# first item in subassy table
|
||||
},
|
||||
}
|
||||
create_nested_bom(boms, prefix=prefix)
|
||||
|
||||
items = [prefix + item_code for item_code in boms.keys()]
|
||||
plan = create_production_plan(item_code=items[0], do_not_save=True)
|
||||
plan.append(
|
||||
"po_items",
|
||||
{
|
||||
"use_multi_level_bom": 1,
|
||||
"item_code": items[1],
|
||||
"bom_no": frappe.db.get_value("Item", items[1], "default_bom"),
|
||||
"planned_qty": 1,
|
||||
"planned_start_date": now_datetime(),
|
||||
},
|
||||
)
|
||||
plan.get_sub_assembly_items()
|
||||
|
||||
bom_level_order = [d.bom_level for d in plan.sub_assembly_items]
|
||||
self.assertEqual(bom_level_order, sorted(bom_level_order, reverse=True))
|
||||
# lowest most level of subassembly should be first
|
||||
self.assertIn("SuperSecret", plan.sub_assembly_items[0].production_item)
|
||||
|
||||
def test_multiple_work_order_for_production_plan_item(self):
|
||||
"Test producing Prod Plan (making WO) in parts."
|
||||
|
||||
@ -1042,13 +999,14 @@ class TestProductionPlan(FrappeTestCase):
|
||||
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
|
||||
|
||||
self.assertEqual(after_qty - before_qty, 1)
|
||||
|
||||
pln = frappe.get_doc("Production Plan", pln.name)
|
||||
pln.cancel()
|
||||
|
||||
bin_name = get_or_make_bin("Raw Material Item 1", "_Test Warehouse - _TC")
|
||||
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
|
||||
|
||||
pln.reload()
|
||||
self.assertEqual(pln.docstatus, 2)
|
||||
self.assertEqual(after_qty, before_qty)
|
||||
|
||||
def test_resered_qty_for_production_plan_for_work_order(self):
|
||||
@ -1332,6 +1290,120 @@ class TestProductionPlan(FrappeTestCase):
|
||||
self.assertTrue(row.warehouse == mrp_warhouse)
|
||||
self.assertEqual(row.quantity, 12)
|
||||
|
||||
def test_mr_qty_for_same_rm_with_different_sub_assemblies(self):
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
|
||||
bom_tree = {
|
||||
"Fininshed Goods2 For SUB Test": {
|
||||
"SubAssembly2 For SUB Test": {"ChildPart2 For SUB Test": {}},
|
||||
"SubAssembly3 For SUB Test": {"ChildPart2 For SUB Test": {}},
|
||||
}
|
||||
}
|
||||
|
||||
parent_bom = create_nested_bom(bom_tree, prefix="")
|
||||
plan = create_production_plan(
|
||||
item_code=parent_bom.item,
|
||||
planned_qty=1,
|
||||
ignore_existing_ordered_qty=1,
|
||||
do_not_submit=1,
|
||||
skip_available_sub_assembly_item=1,
|
||||
warehouse="_Test Warehouse - _TC",
|
||||
)
|
||||
|
||||
plan.get_sub_assembly_items()
|
||||
plan.make_material_request()
|
||||
|
||||
for row in plan.mr_items:
|
||||
if row.item_code == "ChildPart2 For SUB Test":
|
||||
self.assertEqual(row.quantity, 2)
|
||||
|
||||
def test_reserve_sub_assembly_items(self):
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
|
||||
bom_tree = {
|
||||
"Fininshed Goods Bicycle": {
|
||||
"Frame Assembly": {"Frame": {}},
|
||||
"Chain Assembly": {"Chain": {}},
|
||||
}
|
||||
}
|
||||
parent_bom = create_nested_bom(bom_tree, prefix="")
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
company = "_Test Company"
|
||||
|
||||
sub_assembly_warehouse = create_warehouse("SUB ASSEMBLY WH", company=company)
|
||||
|
||||
for item_code in ["Frame", "Chain"]:
|
||||
make_stock_entry(item_code=item_code, target=warehouse, qty=2, basic_rate=100)
|
||||
|
||||
before_qty = flt(
|
||||
frappe.db.get_value(
|
||||
"Bin",
|
||||
{"item_code": "Frame Assembly", "warehouse": sub_assembly_warehouse},
|
||||
"reserved_qty_for_production_plan",
|
||||
)
|
||||
)
|
||||
|
||||
plan = create_production_plan(
|
||||
item_code=parent_bom.item,
|
||||
planned_qty=2,
|
||||
ignore_existing_ordered_qty=1,
|
||||
do_not_submit=1,
|
||||
skip_available_sub_assembly_item=1,
|
||||
warehouse=warehouse,
|
||||
sub_assembly_warehouse=sub_assembly_warehouse,
|
||||
)
|
||||
|
||||
plan.get_sub_assembly_items()
|
||||
plan.submit()
|
||||
|
||||
after_qty = flt(
|
||||
frappe.db.get_value(
|
||||
"Bin",
|
||||
{"item_code": "Frame Assembly", "warehouse": sub_assembly_warehouse},
|
||||
"reserved_qty_for_production_plan",
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(after_qty, before_qty + 2)
|
||||
|
||||
plan.make_work_order()
|
||||
work_orders = frappe.get_all(
|
||||
"Work Order",
|
||||
fields=["name", "production_item"],
|
||||
filters={"production_plan": plan.name},
|
||||
order_by="creation desc",
|
||||
)
|
||||
|
||||
for d in work_orders:
|
||||
wo_doc = frappe.get_doc("Work Order", d.name)
|
||||
wo_doc.skip_transfer = 1
|
||||
wo_doc.from_wip_warehouse = 1
|
||||
|
||||
wo_doc.wip_warehouse = (
|
||||
warehouse
|
||||
if d.production_item in ["Frame Assembly", "Chain Assembly"]
|
||||
else sub_assembly_warehouse
|
||||
)
|
||||
|
||||
wo_doc.submit()
|
||||
|
||||
if d.production_item == "Frame Assembly":
|
||||
self.assertEqual(wo_doc.fg_warehouse, sub_assembly_warehouse)
|
||||
se_doc = frappe.get_doc(make_se_from_wo(wo_doc.name, "Manufacture", 2))
|
||||
se_doc.submit()
|
||||
|
||||
after_qty = flt(
|
||||
frappe.db.get_value(
|
||||
"Bin",
|
||||
{"item_code": "Frame Assembly", "warehouse": sub_assembly_warehouse},
|
||||
"reserved_qty_for_production_plan",
|
||||
)
|
||||
)
|
||||
|
||||
self.assertEqual(after_qty, before_qty)
|
||||
|
||||
|
||||
def create_production_plan(**args):
|
||||
"""
|
||||
@ -1352,6 +1424,7 @@ def create_production_plan(**args):
|
||||
"ignore_existing_ordered_qty": args.ignore_existing_ordered_qty or 0,
|
||||
"get_items_from": "Sales Order",
|
||||
"skip_available_sub_assembly_item": args.skip_available_sub_assembly_item or 0,
|
||||
"sub_assembly_warehouse": args.sub_assembly_warehouse,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -17,11 +17,10 @@
|
||||
"type_of_manufacturing",
|
||||
"supplier",
|
||||
"work_order_details_section",
|
||||
"work_order",
|
||||
"wo_produced_qty",
|
||||
"purchase_order",
|
||||
"production_plan_item",
|
||||
"column_break_7",
|
||||
"produced_qty",
|
||||
"received_qty",
|
||||
"indent",
|
||||
"section_break_19",
|
||||
@ -52,13 +51,6 @@
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Reference"
|
||||
},
|
||||
{
|
||||
"fieldname": "work_order",
|
||||
"fieldtype": "Link",
|
||||
"label": "Work Order",
|
||||
"options": "Work Order",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_7",
|
||||
"fieldtype": "Column Break"
|
||||
@ -81,7 +73,8 @@
|
||||
{
|
||||
"fieldname": "received_qty",
|
||||
"fieldtype": "Float",
|
||||
"label": "Received Qty"
|
||||
"label": "Received Qty",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "bom_no",
|
||||
@ -161,12 +154,6 @@
|
||||
"label": "Target Warehouse",
|
||||
"options": "Warehouse"
|
||||
},
|
||||
{
|
||||
"fieldname": "produced_qty",
|
||||
"fieldtype": "Data",
|
||||
"label": "Produced Quantity",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "In House",
|
||||
"fieldname": "type_of_manufacturing",
|
||||
@ -209,12 +196,18 @@
|
||||
"label": "Projected Qty",
|
||||
"no_copy": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "wo_produced_qty",
|
||||
"fieldtype": "Float",
|
||||
"label": "Produced Qty",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-05-22 17:52:34.708879",
|
||||
"modified": "2023-11-03 13:33:42.959387",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Production Plan Sub Assembly Item",
|
||||
|
@ -494,6 +494,7 @@ class TestWorkOrder(FrappeTestCase):
|
||||
"from_time": row.from_time,
|
||||
"to_time": row.to_time,
|
||||
"time_in_mins": row.time_in_mins,
|
||||
"completed_qty": 0,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -710,7 +710,7 @@ erpnext.work_order = {
|
||||
return new Promise((resolve, reject) => {
|
||||
frappe.prompt({
|
||||
fieldtype: 'Float',
|
||||
label: __('Qty for {0}', [purpose]),
|
||||
label: __('Qty for {0}', [__(purpose)]),
|
||||
fieldname: 'qty',
|
||||
description: __('Max: {0}', [max]),
|
||||
default: max
|
||||
|
@ -293,6 +293,7 @@ class WorkOrder(Document):
|
||||
update_produced_qty_in_so_item(self.sales_order, self.sales_order_item)
|
||||
|
||||
if self.production_plan:
|
||||
self.set_produced_qty_for_sub_assembly_item()
|
||||
self.update_production_plan_status()
|
||||
|
||||
def get_transferred_or_manufactured_qty(self, purpose):
|
||||
@ -569,16 +570,49 @@ class WorkOrder(Document):
|
||||
)
|
||||
|
||||
def update_planned_qty(self):
|
||||
from erpnext.manufacturing.doctype.production_plan.production_plan import (
|
||||
get_reserved_qty_for_sub_assembly,
|
||||
)
|
||||
|
||||
qty_dict = {"planned_qty": get_planned_qty(self.production_item, self.fg_warehouse)}
|
||||
|
||||
if self.production_plan_sub_assembly_item and self.production_plan:
|
||||
qty_dict["reserved_qty_for_production_plan"] = get_reserved_qty_for_sub_assembly(
|
||||
self.production_item, self.fg_warehouse
|
||||
)
|
||||
|
||||
update_bin_qty(
|
||||
self.production_item,
|
||||
self.fg_warehouse,
|
||||
{"planned_qty": get_planned_qty(self.production_item, self.fg_warehouse)},
|
||||
qty_dict,
|
||||
)
|
||||
|
||||
if self.material_request:
|
||||
mr_obj = frappe.get_doc("Material Request", self.material_request)
|
||||
mr_obj.update_requested_qty([self.material_request_item])
|
||||
|
||||
def set_produced_qty_for_sub_assembly_item(self):
|
||||
table = frappe.qb.DocType("Work Order")
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(table)
|
||||
.select(Sum(table.produced_qty))
|
||||
.where(
|
||||
(table.production_plan == self.production_plan)
|
||||
& (table.production_plan_sub_assembly_item == self.production_plan_sub_assembly_item)
|
||||
& (table.docstatus == 1)
|
||||
)
|
||||
).run()
|
||||
|
||||
produced_qty = flt(query[0][0]) if query else 0
|
||||
|
||||
frappe.db.set_value(
|
||||
"Production Plan Sub Assembly Item",
|
||||
self.production_plan_sub_assembly_item,
|
||||
"wo_produced_qty",
|
||||
produced_qty,
|
||||
)
|
||||
|
||||
def update_ordered_qty(self):
|
||||
if (
|
||||
self.production_plan
|
||||
|
@ -22,9 +22,9 @@ frappe.query_reports["Production Plan Summary"] = {
|
||||
"formatter": function(value, row, column, data, default_formatter) {
|
||||
value = default_formatter(value, row, column, data);
|
||||
|
||||
if (column.fieldname == "document_name") {
|
||||
if (column.fieldname == "item_code") {
|
||||
var color = data.pending_qty > 0 ? 'red': 'green';
|
||||
value = `<a style='color:${color}' href="#Form/${data['document_type']}/${data['document_name']}" data-doctype="${data['document_type']}">${data['document_name']}</a>`;
|
||||
value = `<a style='color:${color}' href="/app/item/${data['item_code']}" data-doctype="Item">${data['item_code']}</a>`;
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -44,6 +44,7 @@ def get_production_plan_item_details(filters, data, order_details):
|
||||
{
|
||||
"indent": 0,
|
||||
"item_code": row.item_code,
|
||||
"sales_order": row.get("sales_order"),
|
||||
"item_name": frappe.get_cached_value("Item", row.item_code, "item_name"),
|
||||
"qty": row.planned_qty,
|
||||
"document_type": "Work Order",
|
||||
@ -80,7 +81,7 @@ def get_production_plan_sub_assembly_item_details(
|
||||
|
||||
data.append(
|
||||
{
|
||||
"indent": 1,
|
||||
"indent": 1 + item.indent,
|
||||
"item_code": item.production_item,
|
||||
"item_name": item.item_name,
|
||||
"qty": item.qty,
|
||||
@ -98,7 +99,7 @@ def get_work_order_details(filters, order_details):
|
||||
for row in frappe.get_all(
|
||||
"Work Order",
|
||||
filters={"production_plan": filters.get("production_plan")},
|
||||
fields=["name", "produced_qty", "production_plan", "production_item"],
|
||||
fields=["name", "produced_qty", "production_plan", "production_item", "sales_order"],
|
||||
):
|
||||
order_details.setdefault((row.name, row.production_item), row)
|
||||
|
||||
@ -118,10 +119,17 @@ def get_column(filters):
|
||||
"label": _("Finished Good"),
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "item_code",
|
||||
"width": 300,
|
||||
"width": 240,
|
||||
"options": "Item",
|
||||
},
|
||||
{"label": _("Item Name"), "fieldtype": "data", "fieldname": "item_name", "width": 100},
|
||||
{"label": _("Item Name"), "fieldtype": "data", "fieldname": "item_name", "width": 150},
|
||||
{
|
||||
"label": _("Sales Order"),
|
||||
"options": "Sales Order",
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "sales_order",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Document Type"),
|
||||
"fieldtype": "Link",
|
||||
@ -133,10 +141,16 @@ def get_column(filters):
|
||||
"label": _("Document Name"),
|
||||
"fieldtype": "Dynamic Link",
|
||||
"fieldname": "document_name",
|
||||
"width": 150,
|
||||
"options": "document_type",
|
||||
"width": 180,
|
||||
},
|
||||
{"label": _("BOM Level"), "fieldtype": "Int", "fieldname": "bom_level", "width": 100},
|
||||
{"label": _("Order Qty"), "fieldtype": "Float", "fieldname": "qty", "width": 120},
|
||||
{"label": _("Received Qty"), "fieldtype": "Float", "fieldname": "produced_qty", "width": 160},
|
||||
{
|
||||
"label": _("Produced / Received Qty"),
|
||||
"fieldtype": "Float",
|
||||
"fieldname": "produced_qty",
|
||||
"width": 200,
|
||||
},
|
||||
{"label": _("Pending Qty"), "fieldtype": "Float", "fieldname": "pending_qty", "width": 110},
|
||||
]
|
||||
|
@ -338,11 +338,18 @@ erpnext.patches.v15_0.delete_woocommerce_settings_doctype
|
||||
erpnext.patches.v14_0.migrate_deferred_accounts_to_item_defaults
|
||||
erpnext.patches.v14_0.update_invoicing_period_in_subscription
|
||||
execute:frappe.delete_doc("Page", "welcome-to-erpnext")
|
||||
erpnext.patches.v15_0.migrate_payment_request_status
|
||||
erpnext.patches.v15_0.delete_payment_gateway_doctypes
|
||||
erpnext.patches.v14_0.create_accounting_dimensions_in_sales_order_item
|
||||
erpnext.patches.v15_0.update_sre_from_voucher_details
|
||||
erpnext.patches.v14_0.rename_over_order_allowance_field
|
||||
erpnext.patches.v14_0.migrate_delivery_stop_lock_field
|
||||
execute:frappe.db.set_single_value("Payment Reconciliation", "invoice_limit", 50)
|
||||
execute:frappe.db.set_single_value("Payment Reconciliation", "payment_limit", 50)
|
||||
erpnext.patches.v14_0.add_default_for_repost_settings
|
||||
erpnext.patches.v15_0.rename_daily_depreciation_to_depreciation_amount_based_on_num_days_in_month
|
||||
erpnext.patches.v15_0.rename_depreciation_amount_based_on_num_days_in_month_to_daily_prorata_based
|
||||
erpnext.patches.v15_0.set_reserved_stock_in_bin
|
||||
erpnext.patches.v15_0.create_advance_payment_status
|
||||
# below migration patch should always run last
|
||||
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
|
||||
|
12
erpnext/patches/v14_0/add_default_for_repost_settings.py
Normal file
12
erpnext/patches/v14_0/add_default_for_repost_settings.py
Normal file
@ -0,0 +1,12 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""
|
||||
Update Repost Accounting Ledger Settings with default values
|
||||
"""
|
||||
allowed_types = ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]
|
||||
repost_settings = frappe.get_doc("Repost Accounting Ledger Settings")
|
||||
for x in allowed_types:
|
||||
repost_settings.append("allowed_types", {"document_type": x, "allowed": True})
|
||||
repost_settings.save()
|
13
erpnext/patches/v15_0/migrate_payment_request_status.py
Normal file
13
erpnext/patches/v15_0/migrate_payment_request_status.py
Normal file
@ -0,0 +1,13 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
"""
|
||||
Description:
|
||||
Change Inward Payment Requests from statut 'Initiated' to correct status 'Requested'.
|
||||
Status 'Initiated' is reserved for Outward Payment Requests and was a semantic error in previour versions.
|
||||
"""
|
||||
so = frappe.qb.DocType("Payment Request")
|
||||
frappe.qb.update(so).set(so.status, "Requested").where(so.payment_request_type == "Inward").where(
|
||||
so.status == "Initiated"
|
||||
).run()
|
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
from frappe.model.utils.rename_field import rename_field
|
||||
|
||||
|
||||
def execute():
|
||||
try:
|
||||
rename_field(
|
||||
"Asset Finance Book", "daily_depreciation", "depreciation_amount_based_on_num_days_in_month"
|
||||
)
|
||||
rename_field(
|
||||
"Asset Depreciation Schedule",
|
||||
"daily_depreciation",
|
||||
"depreciation_amount_based_on_num_days_in_month",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
if e.args[0] != 1054:
|
||||
raise
|
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
from frappe.model.utils.rename_field import rename_field
|
||||
|
||||
|
||||
def execute():
|
||||
try:
|
||||
rename_field(
|
||||
"Asset Finance Book", "depreciation_amount_based_on_num_days_in_month", "daily_prorata_based"
|
||||
)
|
||||
rename_field(
|
||||
"Asset Depreciation Schedule",
|
||||
"depreciation_amount_based_on_num_days_in_month",
|
||||
"daily_prorata_based",
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
if e.args[0] != 1054:
|
||||
raise
|
24
erpnext/patches/v15_0/set_reserved_stock_in_bin.py
Normal file
24
erpnext/patches/v15_0/set_reserved_stock_in_bin.py
Normal file
@ -0,0 +1,24 @@
|
||||
import frappe
|
||||
from frappe.query_builder.functions import Sum
|
||||
|
||||
|
||||
def execute():
|
||||
sre = frappe.qb.DocType("Stock Reservation Entry")
|
||||
query = (
|
||||
frappe.qb.from_(sre)
|
||||
.select(
|
||||
sre.item_code,
|
||||
sre.warehouse,
|
||||
Sum(sre.reserved_qty - sre.delivered_qty).as_("reserved_stock"),
|
||||
)
|
||||
.where((sre.docstatus == 1) & (sre.status.notin(["Delivered", "Cancelled"])))
|
||||
.groupby(sre.item_code, sre.warehouse)
|
||||
)
|
||||
|
||||
for d in query.run(as_dict=True):
|
||||
frappe.db.set_value(
|
||||
"Bin",
|
||||
{"item_code": d.item_code, "warehouse": d.warehouse},
|
||||
"reserved_stock",
|
||||
d.reserved_stock,
|
||||
)
|
@ -1,155 +0,0 @@
|
||||
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt, time_diff_in_hours
|
||||
|
||||
|
||||
def get_columns():
|
||||
return [
|
||||
{
|
||||
"label": _("Employee ID"),
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "employee",
|
||||
"options": "Employee",
|
||||
"width": 300,
|
||||
},
|
||||
{
|
||||
"label": _("Employee Name"),
|
||||
"fieldtype": "data",
|
||||
"fieldname": "employee_name",
|
||||
"hidden": 1,
|
||||
"width": 200,
|
||||
},
|
||||
{
|
||||
"label": _("Timesheet"),
|
||||
"fieldtype": "Link",
|
||||
"fieldname": "timesheet",
|
||||
"options": "Timesheet",
|
||||
"width": 150,
|
||||
},
|
||||
{"label": _("Working Hours"), "fieldtype": "Float", "fieldname": "total_hours", "width": 150},
|
||||
{
|
||||
"label": _("Billable Hours"),
|
||||
"fieldtype": "Float",
|
||||
"fieldname": "total_billable_hours",
|
||||
"width": 150,
|
||||
},
|
||||
{"label": _("Billing Amount"), "fieldtype": "Currency", "fieldname": "amount", "width": 150},
|
||||
]
|
||||
|
||||
|
||||
def get_data(filters):
|
||||
data = []
|
||||
if filters.from_date > filters.to_date:
|
||||
frappe.msgprint(_("From Date can not be greater than To Date"))
|
||||
return data
|
||||
|
||||
timesheets = get_timesheets(filters)
|
||||
|
||||
filters.from_date = frappe.utils.get_datetime(filters.from_date)
|
||||
filters.to_date = frappe.utils.add_to_date(
|
||||
frappe.utils.get_datetime(filters.to_date), days=1, seconds=-1
|
||||
)
|
||||
|
||||
timesheet_details = get_timesheet_details(filters, timesheets.keys())
|
||||
|
||||
for ts, ts_details in timesheet_details.items():
|
||||
total_hours = 0
|
||||
total_billing_hours = 0
|
||||
total_amount = 0
|
||||
|
||||
for row in ts_details:
|
||||
from_time, to_time = filters.from_date, filters.to_date
|
||||
|
||||
if row.to_time < from_time or row.from_time > to_time:
|
||||
continue
|
||||
|
||||
if row.from_time > from_time:
|
||||
from_time = row.from_time
|
||||
|
||||
if row.to_time < to_time:
|
||||
to_time = row.to_time
|
||||
|
||||
activity_duration, billing_duration = get_billable_and_total_duration(row, from_time, to_time)
|
||||
|
||||
total_hours += activity_duration
|
||||
total_billing_hours += billing_duration
|
||||
total_amount += billing_duration * flt(row.billing_rate)
|
||||
|
||||
if total_hours:
|
||||
data.append(
|
||||
{
|
||||
"employee": timesheets.get(ts).employee,
|
||||
"employee_name": timesheets.get(ts).employee_name,
|
||||
"timesheet": ts,
|
||||
"total_billable_hours": total_billing_hours,
|
||||
"total_hours": total_hours,
|
||||
"amount": total_amount,
|
||||
}
|
||||
)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def get_timesheets(filters):
|
||||
record_filters = [
|
||||
["start_date", "<=", filters.to_date],
|
||||
["end_date", ">=", filters.from_date],
|
||||
]
|
||||
if not filters.get("include_draft_timesheets"):
|
||||
record_filters.append(["docstatus", "=", 1])
|
||||
else:
|
||||
record_filters.append(["docstatus", "!=", 2])
|
||||
if "employee" in filters:
|
||||
record_filters.append(["employee", "=", filters.employee])
|
||||
|
||||
timesheets = frappe.get_all(
|
||||
"Timesheet", filters=record_filters, fields=["employee", "employee_name", "name"]
|
||||
)
|
||||
timesheet_map = frappe._dict()
|
||||
for d in timesheets:
|
||||
timesheet_map.setdefault(d.name, d)
|
||||
|
||||
return timesheet_map
|
||||
|
||||
|
||||
def get_timesheet_details(filters, timesheet_list):
|
||||
timesheet_details_filter = {"parent": ["in", timesheet_list]}
|
||||
|
||||
if "project" in filters:
|
||||
timesheet_details_filter["project"] = filters.project
|
||||
|
||||
timesheet_details = frappe.get_all(
|
||||
"Timesheet Detail",
|
||||
filters=timesheet_details_filter,
|
||||
fields=[
|
||||
"from_time",
|
||||
"to_time",
|
||||
"hours",
|
||||
"is_billable",
|
||||
"billing_hours",
|
||||
"billing_rate",
|
||||
"parent",
|
||||
],
|
||||
)
|
||||
|
||||
timesheet_details_map = frappe._dict()
|
||||
for d in timesheet_details:
|
||||
timesheet_details_map.setdefault(d.parent, []).append(d)
|
||||
|
||||
return timesheet_details_map
|
||||
|
||||
|
||||
def get_billable_and_total_duration(activity, start_time, end_time):
|
||||
precision = frappe.get_precision("Timesheet Detail", "hours")
|
||||
activity_duration = time_diff_in_hours(end_time, start_time)
|
||||
billing_duration = 0.0
|
||||
if activity.is_billable:
|
||||
billing_duration = activity.billing_hours
|
||||
if activity_duration != activity.billing_hours:
|
||||
billing_duration = activity_duration * activity.billing_hours / activity.hours
|
||||
|
||||
return flt(activity_duration, precision), flt(billing_duration, precision)
|
@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
|
||||
frappe.query_reports["Employee Billing Summary"] = {
|
||||
"filters": [
|
||||
{
|
||||
fieldname: "employee",
|
||||
label: __("Employee"),
|
||||
fieldtype: "Link",
|
||||
options: "Employee",
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"from_date",
|
||||
label: __("From Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_months(frappe.datetime.month_start(), -1),
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"to_date",
|
||||
label: __("To Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_days(frappe.datetime.month_start(), -1),
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"include_draft_timesheets",
|
||||
label: __("Include Timesheets in Draft Status"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
]
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"creation": "2019-03-08 15:08:19.929728",
|
||||
"disable_prepared_report": 0,
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"idx": 0,
|
||||
"is_standard": "Yes",
|
||||
"modified": "2019-06-13 15:54:49.213973",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Projects",
|
||||
"name": "Employee Billing Summary",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"ref_doctype": "Timesheet",
|
||||
"report_name": "Employee Billing Summary",
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Projects User"
|
||||
},
|
||||
{
|
||||
"role": "HR User"
|
||||
},
|
||||
{
|
||||
"role": "Manufacturing User"
|
||||
},
|
||||
{
|
||||
"role": "Employee"
|
||||
},
|
||||
{
|
||||
"role": "Accounts User"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
|
||||
from erpnext.projects.report.billing_summary import get_columns, get_data
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
filters = frappe._dict(filters or {})
|
||||
columns = get_columns()
|
||||
|
||||
data = get_data(filters)
|
||||
return columns, data
|
@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
|
||||
frappe.query_reports["Project Billing Summary"] = {
|
||||
"filters": [
|
||||
{
|
||||
fieldname: "project",
|
||||
label: __("Project"),
|
||||
fieldtype: "Link",
|
||||
options: "Project",
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"from_date",
|
||||
label: __("From Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_months(frappe.datetime.month_start(), -1),
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"to_date",
|
||||
label: __("To Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_days(frappe.datetime.month_start(),-1),
|
||||
reqd: 1
|
||||
},
|
||||
{
|
||||
fieldname:"include_draft_timesheets",
|
||||
label: __("Include Timesheets in Draft Status"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
]
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
|
||||
from erpnext.projects.report.billing_summary import get_columns, get_data
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
filters = frappe._dict(filters or {})
|
||||
columns = get_columns()
|
||||
|
||||
data = get_data(filters)
|
||||
return columns, data
|
@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.query_reports["Timesheet Billing Summary"] = {
|
||||
tree: true,
|
||||
initial_depth: 0,
|
||||
filters: [
|
||||
{
|
||||
fieldname: "employee",
|
||||
label: __("Employee"),
|
||||
fieldtype: "Link",
|
||||
options: "Employee",
|
||||
on_change: function (report) {
|
||||
unset_group_by(report, "employee");
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "project",
|
||||
label: __("Project"),
|
||||
fieldtype: "Link",
|
||||
options: "Project",
|
||||
on_change: function (report) {
|
||||
unset_group_by(report, "project");
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "from_date",
|
||||
label: __("From Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_months(
|
||||
frappe.datetime.month_start(),
|
||||
-1
|
||||
),
|
||||
},
|
||||
{
|
||||
fieldname: "to_date",
|
||||
label: __("To Date"),
|
||||
fieldtype: "Date",
|
||||
default: frappe.datetime.add_days(
|
||||
frappe.datetime.month_start(),
|
||||
-1
|
||||
),
|
||||
},
|
||||
{ // NOTE: `update_group_by_options` expects this filter to be the fifth in the list
|
||||
fieldname: "group_by",
|
||||
label: __("Group By"),
|
||||
fieldtype: "Select",
|
||||
options: [
|
||||
"",
|
||||
{ value: "employee", label: __("Employee") },
|
||||
{ value: "project", label: __("Project") },
|
||||
{ value: "date", label: __("Start Date") },
|
||||
],
|
||||
},
|
||||
{
|
||||
fieldname: "include_draft_timesheets",
|
||||
label: __("Include Timesheets in Draft Status"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
function unset_group_by(report, fieldname) {
|
||||
if (report.get_filter_value(fieldname) && report.get_filter_value("group_by") == fieldname) {
|
||||
report.set_filter_value("group_by", "");
|
||||
}
|
||||
}
|
@ -1,36 +1,42 @@
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"creation": "2019-03-11 16:22:39.460524",
|
||||
"disable_prepared_report": 0,
|
||||
"columns": [],
|
||||
"creation": "2023-10-10 23:53:43.692067",
|
||||
"disabled": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "Report",
|
||||
"filters": [],
|
||||
"idx": 0,
|
||||
"is_standard": "Yes",
|
||||
"modified": "2019-06-13 15:54:55.255947",
|
||||
"letter_head": "ALYF GmbH",
|
||||
"letterhead": null,
|
||||
"modified": "2023-10-11 00:58:30.639078",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Projects",
|
||||
"name": "Project Billing Summary",
|
||||
"name": "Timesheet Billing Summary",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"ref_doctype": "Timesheet",
|
||||
"report_name": "Project Billing Summary",
|
||||
"report_name": "Timesheet Billing Summary",
|
||||
"report_type": "Script Report",
|
||||
"roles": [
|
||||
{
|
||||
"role": "Projects User"
|
||||
},
|
||||
{
|
||||
"role": "HR User"
|
||||
"role": "Employee"
|
||||
},
|
||||
{
|
||||
"role": "Accounts User"
|
||||
},
|
||||
{
|
||||
"role": "Manufacturing User"
|
||||
},
|
||||
{
|
||||
"role": "Employee"
|
||||
"role": "HR User"
|
||||
},
|
||||
{
|
||||
"role": "Accounts User"
|
||||
"role": "Employee Self Service"
|
||||
}
|
||||
]
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user