mirror of
https://github.com/frappe/erpnext.git
synced 2026-07-26 22:18:18 +00:00
Compare commits
129 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01f9139ebd | ||
|
|
4be557bdce | ||
|
|
96d8b5242d | ||
|
|
2d09ef2509 | ||
|
|
8b5997e38f | ||
|
|
2c4610c021 | ||
|
|
e706aa692a | ||
|
|
a5fa287dad | ||
|
|
c1f14f2991 | ||
|
|
8d188dccd7 | ||
|
|
9de0d4329c | ||
|
|
40fbb1d6ff | ||
|
|
0722aa5a3f | ||
|
|
cfea2de131 | ||
|
|
fe206b0d77 | ||
|
|
4e621b09ba | ||
|
|
1f42302997 | ||
|
|
0e1884539e | ||
|
|
b17a811abf | ||
|
|
979d801de5 | ||
|
|
49d5b7c4d3 | ||
|
|
176feb20ad | ||
|
|
ec27077d9c | ||
|
|
7db135dab5 | ||
|
|
8bc76bae9c | ||
|
|
9d2cbccff2 | ||
|
|
10ecdb99fe | ||
|
|
2aa1380c81 | ||
|
|
99e004b619 | ||
|
|
b415e858e7 | ||
|
|
4cec68c7ad | ||
|
|
085a4c61ac | ||
|
|
5f08ef5cd1 | ||
|
|
e06a01fae5 | ||
|
|
998fef779b | ||
|
|
b99ca7d9e9 | ||
|
|
0fd2964032 | ||
|
|
15baa3f305 | ||
|
|
5920525369 | ||
|
|
05c92cce71 | ||
|
|
a0f01dac1a | ||
|
|
e8c174c12b | ||
|
|
927f80035d | ||
|
|
e5ae828580 | ||
|
|
f89a3dbb65 | ||
|
|
2d9142832d | ||
|
|
a7ccc9420b | ||
|
|
40459288f6 | ||
|
|
250a1c9341 | ||
|
|
63d4fddb49 | ||
|
|
7e6d6f08a2 | ||
|
|
d1c72dc27b | ||
|
|
86ae644574 | ||
|
|
f6725e2eed | ||
|
|
e90532e406 | ||
|
|
84e26e21ab | ||
|
|
34ca0c3bb6 | ||
|
|
42e4b8a68c | ||
|
|
34d159b3a2 | ||
|
|
17ad402695 | ||
|
|
953b5790ed | ||
|
|
557ef5d214 | ||
|
|
680354ac0d | ||
|
|
73d98addbc | ||
|
|
479e8573c2 | ||
|
|
6a0b15211a | ||
|
|
7aeadcbf98 | ||
|
|
82982e25c6 | ||
|
|
782c9dda1a | ||
|
|
dfe47261ae | ||
|
|
3d29007aeb | ||
|
|
52a161f076 | ||
|
|
0fe901a137 | ||
|
|
8c28cb6b25 | ||
|
|
4ba37e49d8 | ||
|
|
1e89c007ed | ||
|
|
78c68397d9 | ||
|
|
f61cec27ae | ||
|
|
78768f883c | ||
|
|
edcdfdd194 | ||
|
|
861edb438b | ||
|
|
d91013a467 | ||
|
|
310b131469 | ||
|
|
86e1818420 | ||
|
|
5fe347c909 | ||
|
|
44dde1c58d | ||
|
|
291f0a580b | ||
|
|
9c4eaa230c | ||
|
|
28f1f9355d | ||
|
|
41db9d3886 | ||
|
|
53c4c153ca | ||
|
|
bee27f314f | ||
|
|
c9b6b0d868 | ||
|
|
dea735de4d | ||
|
|
f7cedac526 | ||
|
|
c5051561e4 | ||
|
|
48158fbde0 | ||
|
|
d6a3d0d468 | ||
|
|
30e9f08f37 | ||
|
|
42494db3c7 | ||
|
|
a6a2b2daae | ||
|
|
741c18b144 | ||
|
|
7027be8fbc | ||
|
|
01f30682ee | ||
|
|
5edebb28a5 | ||
|
|
11359bd235 | ||
|
|
2ad6d637ee | ||
|
|
564ff034b7 | ||
|
|
d8d4cd23a5 | ||
|
|
984acb661d | ||
|
|
00f144ed68 | ||
|
|
f060534625 | ||
|
|
f101a1ce3b | ||
|
|
ad2d6a1625 | ||
|
|
2f56ba7f42 | ||
|
|
ef6b172616 | ||
|
|
61a42ea5d7 | ||
|
|
c1a6c56217 | ||
|
|
b7e95bfd22 | ||
|
|
7989bc23e1 | ||
|
|
055e7820c8 | ||
|
|
d618c9a481 | ||
|
|
5789de25b9 | ||
|
|
4df38d357f | ||
|
|
45ff8fa296 | ||
|
|
28607f0026 | ||
|
|
1657a83151 | ||
|
|
aab91a2307 | ||
|
|
0d9741fdd7 |
@@ -4,7 +4,7 @@ import inspect
|
||||
import frappe
|
||||
from frappe.utils.user import is_website_user
|
||||
|
||||
__version__ = "15.35.1"
|
||||
__version__ = "15.37.0"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
@@ -103,14 +103,12 @@ class Account(NestedSet):
|
||||
self.name = get_autoname_with_number(self.account_number, self.account_name, self.company)
|
||||
|
||||
def validate(self):
|
||||
from erpnext.accounts.utils import validate_field_number
|
||||
|
||||
if frappe.local.flags.allow_unverified_charts:
|
||||
return
|
||||
self.validate_parent()
|
||||
self.validate_parent_child_account_type()
|
||||
self.validate_root_details()
|
||||
validate_field_number("Account", self.name, self.account_number, self.company, "account_number")
|
||||
self.validate_account_number()
|
||||
self.validate_group_or_ledger()
|
||||
self.set_root_and_report_type()
|
||||
self.validate_mandatory()
|
||||
@@ -311,6 +309,22 @@ class Account(NestedSet):
|
||||
if frappe.db.get_value("GL Entry", {"account": self.name}):
|
||||
frappe.throw(_("Currency can not be changed after making entries using some other currency"))
|
||||
|
||||
def validate_account_number(self, account_number=None):
|
||||
if not account_number:
|
||||
account_number = self.account_number
|
||||
|
||||
if account_number:
|
||||
account_with_same_number = frappe.db.get_value(
|
||||
"Account",
|
||||
{"account_number": account_number, "company": self.company, "name": ["!=", self.name]},
|
||||
)
|
||||
if account_with_same_number:
|
||||
frappe.throw(
|
||||
_("Account Number {0} already used in account {1}").format(
|
||||
account_number, account_with_same_number
|
||||
)
|
||||
)
|
||||
|
||||
def create_account_for_child_company(self, parent_acc_name_map, descendants, parent_acc_name):
|
||||
for company in descendants:
|
||||
company_bold = frappe.bold(company)
|
||||
@@ -464,19 +478,6 @@ def get_account_autoname(account_number, account_name, company):
|
||||
return " - ".join(parts)
|
||||
|
||||
|
||||
def validate_account_number(name, account_number, company):
|
||||
if account_number:
|
||||
account_with_same_number = frappe.db.get_value(
|
||||
"Account", {"account_number": account_number, "company": company, "name": ["!=", name]}
|
||||
)
|
||||
if account_with_same_number:
|
||||
frappe.throw(
|
||||
_("Account Number {0} already used in account {1}").format(
|
||||
account_number, account_with_same_number
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def update_account_number(name, account_name, account_number=None, from_descendant=False):
|
||||
account = frappe.get_cached_doc("Account", name)
|
||||
@@ -517,7 +518,7 @@ def update_account_number(name, account_name, account_number=None, from_descenda
|
||||
|
||||
frappe.throw(message, title=_("Rename Not Allowed"))
|
||||
|
||||
validate_account_number(name, account_number, account.company)
|
||||
account.validate_account_number(account_number)
|
||||
if account_number:
|
||||
frappe.db.set_value("Account", name, "account_number", account_number.strip())
|
||||
else:
|
||||
|
||||
@@ -208,8 +208,54 @@
|
||||
"label": "Disabled"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2023-09-22 21:31:34.763977",
|
||||
"links": [
|
||||
{
|
||||
"group": "Transactions",
|
||||
"link_doctype": "Payment Request",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Transactions",
|
||||
"link_doctype": "Payment Order",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Transactions",
|
||||
"link_doctype": "Bank Guarantee",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Transactions",
|
||||
"link_doctype": "Payroll Entry",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Transactions",
|
||||
"link_doctype": "Bank Transaction",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Accounting",
|
||||
"link_doctype": "Payment Entry",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Accounting",
|
||||
"link_doctype": "Journal Entry",
|
||||
"link_fieldname": "bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Party",
|
||||
"link_doctype": "Customer",
|
||||
"link_fieldname": "default_bank_account"
|
||||
},
|
||||
{
|
||||
"group": "Party",
|
||||
"link_doctype": "Supplier",
|
||||
"link_fieldname": "default_bank_account"
|
||||
}
|
||||
],
|
||||
"modified": "2024-09-24 06:57:41.292970",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Bank Account",
|
||||
@@ -246,4 +292,4 @@
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
from frappe import _
|
||||
|
||||
|
||||
def get_data():
|
||||
return {
|
||||
"fieldname": "bank_account",
|
||||
"non_standard_fieldnames": {
|
||||
"Customer": "default_bank_account",
|
||||
"Supplier": "default_bank_account",
|
||||
},
|
||||
"transactions": [
|
||||
{
|
||||
"label": _("Payments"),
|
||||
"items": ["Payment Entry", "Payment Request", "Payment Order", "Payroll Entry"],
|
||||
},
|
||||
{"label": _("Party"), "items": ["Customer", "Supplier"]},
|
||||
{"items": ["Bank Guarantee"]},
|
||||
{"items": ["Journal Entry"]},
|
||||
],
|
||||
}
|
||||
@@ -108,8 +108,18 @@ class BankClearance(Document):
|
||||
if not d.clearance_date:
|
||||
d.clearance_date = None
|
||||
|
||||
payment_entry = frappe.get_doc(d.payment_document, d.payment_entry)
|
||||
payment_entry.db_set("clearance_date", d.clearance_date)
|
||||
if d.payment_document == "Sales Invoice":
|
||||
frappe.db.set_value(
|
||||
"Sales Invoice Payment",
|
||||
{"parent": d.payment_entry, "account": self.get("account"), "amount": [">", 0]},
|
||||
"clearance_date",
|
||||
d.clearance_date,
|
||||
)
|
||||
|
||||
else:
|
||||
frappe.db.set_value(
|
||||
d.payment_document, d.payment_entry, "clearance_date", d.clearance_date
|
||||
)
|
||||
|
||||
clearance_date_updated = True
|
||||
|
||||
|
||||
@@ -6,16 +6,29 @@ import unittest
|
||||
import frappe
|
||||
from frappe.utils import add_months, getdate
|
||||
|
||||
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
from erpnext.tests.utils import if_lending_app_installed, if_lending_app_not_installed
|
||||
|
||||
|
||||
class TestBankClearance(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
create_warehouse(
|
||||
warehouse_name="_Test Warehouse",
|
||||
properties={"parent_warehouse": "All Warehouses - _TC"},
|
||||
company="_Test Company",
|
||||
)
|
||||
create_item("_Test Item")
|
||||
create_cost_center(cost_center_name="_Test Cost Center", company="_Test Company")
|
||||
|
||||
clear_payment_entries()
|
||||
clear_loan_transactions()
|
||||
clear_pos_sales_invoices()
|
||||
make_bank_account()
|
||||
add_transactions()
|
||||
|
||||
@@ -83,11 +96,41 @@ class TestBankClearance(unittest.TestCase):
|
||||
bank_clearance.get_payment_entries()
|
||||
self.assertEqual(len(bank_clearance.payment_entries), 3)
|
||||
|
||||
def test_update_clearance_date_on_si(self):
|
||||
sales_invoice = make_pos_sales_invoice()
|
||||
|
||||
date = getdate()
|
||||
bank_clearance = frappe.get_doc("Bank Clearance")
|
||||
bank_clearance.account = "_Test Bank Clearance - _TC"
|
||||
bank_clearance.from_date = add_months(date, -1)
|
||||
bank_clearance.to_date = date
|
||||
bank_clearance.include_pos_transactions = 1
|
||||
bank_clearance.get_payment_entries()
|
||||
|
||||
self.assertNotEqual(len(bank_clearance.payment_entries), 0)
|
||||
for payment in bank_clearance.payment_entries:
|
||||
if payment.payment_entry == sales_invoice.name:
|
||||
payment.clearance_date = date
|
||||
|
||||
bank_clearance.update_clearance_date()
|
||||
|
||||
si_clearance_date = frappe.db.get_value(
|
||||
"Sales Invoice Payment",
|
||||
{"parent": sales_invoice.name, "account": bank_clearance.account},
|
||||
"clearance_date",
|
||||
)
|
||||
|
||||
self.assertEqual(si_clearance_date, date)
|
||||
|
||||
|
||||
def clear_payment_entries():
|
||||
frappe.db.delete("Payment Entry")
|
||||
|
||||
|
||||
def clear_pos_sales_invoices():
|
||||
frappe.db.delete("Sales Invoice", {"is_pos": 1})
|
||||
|
||||
|
||||
@if_lending_app_installed
|
||||
def clear_loan_transactions():
|
||||
for dt in [
|
||||
@@ -115,9 +158,45 @@ def add_transactions():
|
||||
|
||||
|
||||
def make_payment_entry():
|
||||
pi = make_purchase_invoice(supplier="_Test Supplier", qty=1, rate=690)
|
||||
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
|
||||
|
||||
supplier = create_supplier(supplier_name="_Test Supplier")
|
||||
pi = make_purchase_invoice(
|
||||
supplier=supplier,
|
||||
supplier_warehouse="_Test Warehouse - _TC",
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
uom="Nos",
|
||||
qty=1,
|
||||
rate=690,
|
||||
)
|
||||
pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank Clearance - _TC")
|
||||
pe.reference_no = "Conrad Oct 18"
|
||||
pe.reference_date = "2018-10-24"
|
||||
pe.insert()
|
||||
pe.submit()
|
||||
|
||||
|
||||
def make_pos_sales_invoice():
|
||||
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import (
|
||||
make_customer,
|
||||
)
|
||||
|
||||
mode_of_payment = frappe.get_doc({"doctype": "Mode of Payment", "name": "Cash"})
|
||||
|
||||
if not frappe.db.get_value("Mode of Payment Account", {"company": "_Test Company", "parent": "Cash"}):
|
||||
mode_of_payment.append(
|
||||
"accounts", {"company": "_Test Company", "default_account": "_Test Bank Clearance - _TC"}
|
||||
)
|
||||
mode_of_payment.save()
|
||||
|
||||
customer = make_customer(customer="_Test Customer")
|
||||
|
||||
si = create_sales_invoice(customer=customer, item="_Test Item", is_pos=1, qty=1, rate=1000, do_not_save=1)
|
||||
si.set("payments", [])
|
||||
si.append(
|
||||
"payments", {"mode_of_payment": "Cash", "account": "_Test Bank Clearance - _TC", "amount": 1000}
|
||||
)
|
||||
si.insert()
|
||||
si.submit()
|
||||
|
||||
return si
|
||||
|
||||
@@ -22,8 +22,10 @@ class TestCostCenterAllocation(unittest.TestCase):
|
||||
cost_centers = [
|
||||
"Main Cost Center 1",
|
||||
"Main Cost Center 2",
|
||||
"Main Cost Center 3",
|
||||
"Sub Cost Center 1",
|
||||
"Sub Cost Center 2",
|
||||
"Sub Cost Center 3",
|
||||
]
|
||||
for cc in cost_centers:
|
||||
create_cost_center(cost_center_name=cc, company="_Test Company")
|
||||
@@ -36,7 +38,7 @@ class TestCostCenterAllocation(unittest.TestCase):
|
||||
)
|
||||
|
||||
jv = make_journal_entry(
|
||||
"_Test Cash - _TC", "Sales - _TC", 100, cost_center="Main Cost Center 1 - _TC", submit=True
|
||||
"Cash - _TC", "Sales - _TC", 100, cost_center="Main Cost Center 1 - _TC", submit=True
|
||||
)
|
||||
|
||||
expected_values = [["Sub Cost Center 1 - _TC", 0.0, 60], ["Sub Cost Center 2 - _TC", 0.0, 40]]
|
||||
@@ -120,7 +122,7 @@ class TestCostCenterAllocation(unittest.TestCase):
|
||||
def test_valid_from_based_on_existing_gle(self):
|
||||
# GLE posted against Sub Cost Center 1 on today
|
||||
jv = make_journal_entry(
|
||||
"_Test Cash - _TC",
|
||||
"Cash - _TC",
|
||||
"Sales - _TC",
|
||||
100,
|
||||
cost_center="Main Cost Center 1 - _TC",
|
||||
@@ -141,6 +143,53 @@ class TestCostCenterAllocation(unittest.TestCase):
|
||||
|
||||
jv.cancel()
|
||||
|
||||
def test_multiple_cost_center_allocation_on_same_main_cost_center(self):
|
||||
coa1 = create_cost_center_allocation(
|
||||
"_Test Company",
|
||||
"Main Cost Center 3 - _TC",
|
||||
{"Sub Cost Center 1 - _TC": 30, "Sub Cost Center 2 - _TC": 30, "Sub Cost Center 3 - _TC": 40},
|
||||
valid_from=add_days(today(), -5),
|
||||
)
|
||||
|
||||
coa2 = create_cost_center_allocation(
|
||||
"_Test Company",
|
||||
"Main Cost Center 3 - _TC",
|
||||
{"Sub Cost Center 1 - _TC": 50, "Sub Cost Center 2 - _TC": 50},
|
||||
valid_from=add_days(today(), -1),
|
||||
)
|
||||
|
||||
jv = make_journal_entry(
|
||||
"Cash - _TC",
|
||||
"Sales - _TC",
|
||||
100,
|
||||
cost_center="Main Cost Center 3 - _TC",
|
||||
posting_date=today(),
|
||||
submit=True,
|
||||
)
|
||||
|
||||
expected_values = {"Sub Cost Center 1 - _TC": 50, "Sub Cost Center 2 - _TC": 50}
|
||||
|
||||
gle = frappe.qb.DocType("GL Entry")
|
||||
gl_entries = (
|
||||
frappe.qb.from_(gle)
|
||||
.select(gle.cost_center, gle.debit, gle.credit)
|
||||
.where(gle.voucher_type == "Journal Entry")
|
||||
.where(gle.voucher_no == jv.name)
|
||||
.where(gle.account == "Sales - _TC")
|
||||
.orderby(gle.cost_center)
|
||||
).run(as_dict=1)
|
||||
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
for gle in gl_entries:
|
||||
self.assertTrue(gle.cost_center in expected_values)
|
||||
self.assertEqual(gle.debit, 0)
|
||||
self.assertEqual(gle.credit, expected_values[gle.cost_center])
|
||||
|
||||
coa1.cancel()
|
||||
coa2.cancel()
|
||||
jv.cancel()
|
||||
|
||||
|
||||
def create_cost_center_allocation(
|
||||
company,
|
||||
|
||||
@@ -360,21 +360,23 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro
|
||||
|
||||
accounts_add(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
row.exchange_rate = 1;
|
||||
$.each(doc.accounts, function (i, d) {
|
||||
if (d.account && d.party && d.party_type) {
|
||||
row.account = d.account;
|
||||
row.party = d.party;
|
||||
row.party_type = d.party_type;
|
||||
row.exchange_rate = d.exchange_rate;
|
||||
}
|
||||
});
|
||||
|
||||
// set difference
|
||||
if (doc.difference) {
|
||||
if (doc.difference > 0) {
|
||||
row.credit_in_account_currency = doc.difference;
|
||||
row.credit_in_account_currency = doc.difference / row.exchange_rate;
|
||||
row.credit = doc.difference;
|
||||
} else {
|
||||
row.debit_in_account_currency = -doc.difference;
|
||||
row.debit_in_account_currency = -doc.difference / row.exchange_rate;
|
||||
row.debit = -doc.difference;
|
||||
}
|
||||
}
|
||||
@@ -680,6 +682,7 @@ $.extend(erpnext.journal_entry, {
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
$.extend(d, r.message);
|
||||
erpnext.journal_entry.set_amount_on_last_row(frm, dt, dn);
|
||||
erpnext.journal_entry.set_debit_credit_in_company_currency(frm, dt, dn);
|
||||
refresh_field("accounts");
|
||||
}
|
||||
@@ -687,4 +690,26 @@ $.extend(erpnext.journal_entry, {
|
||||
});
|
||||
}
|
||||
},
|
||||
set_amount_on_last_row: function (frm, dt, dn) {
|
||||
let row = locals[dt][dn];
|
||||
let length = frm.doc.accounts.length;
|
||||
if (row.idx != length) return;
|
||||
|
||||
let difference = frm.doc.accounts.reduce((total, row) => {
|
||||
if (row.idx == length) return total;
|
||||
|
||||
return total + row.debit - row.credit;
|
||||
}, 0);
|
||||
|
||||
if (difference) {
|
||||
if (difference > 0) {
|
||||
row.credit_in_account_currency = difference / row.exchange_rate;
|
||||
row.credit = difference;
|
||||
} else {
|
||||
row.debit_in_account_currency = -difference / row.exchange_rate;
|
||||
row.debit = -difference;
|
||||
}
|
||||
}
|
||||
refresh_field("accounts");
|
||||
},
|
||||
});
|
||||
|
||||
@@ -195,6 +195,11 @@ class JournalEntry(AccountsController):
|
||||
self.update_booked_depreciation()
|
||||
|
||||
def on_update_after_submit(self):
|
||||
# Flag will be set on Reconciliation
|
||||
# Reconciliation tool will anyways repost ledger entries. So, no need to check and do implicit repost.
|
||||
if self.flags.get("ignore_reposting_on_reconciliation"):
|
||||
return
|
||||
|
||||
self.needs_repost = self.check_if_fields_updated(fields_to_check=[], child_tables={"accounts": []})
|
||||
if self.needs_repost:
|
||||
self.validate_for_repost()
|
||||
|
||||
@@ -515,6 +515,23 @@ class TestJournalEntry(unittest.TestCase):
|
||||
self.assertEqual(row.debit_in_account_currency, 100)
|
||||
self.assertEqual(row.credit_in_account_currency, 100)
|
||||
|
||||
def test_transaction_exchange_rate_on_journals(self):
|
||||
jv = make_journal_entry("_Test Bank - _TC", "_Test Receivable USD - _TC", 100, save=False)
|
||||
jv.accounts[0].update({"debit_in_account_currency": 8500, "exchange_rate": 1})
|
||||
jv.accounts[1].update({"party_type": "Customer", "party": "_Test Customer USD", "exchange_rate": 85})
|
||||
jv.submit()
|
||||
actual = frappe.db.get_all(
|
||||
"GL Entry",
|
||||
filters={"voucher_no": jv.name, "is_cancelled": 0},
|
||||
fields=["account", "transaction_exchange_rate"],
|
||||
order_by="account",
|
||||
)
|
||||
expected = [
|
||||
{"account": "_Test Bank - _TC", "transaction_exchange_rate": 1.0},
|
||||
{"account": "_Test Receivable USD - _TC", "transaction_exchange_rate": 85.0},
|
||||
]
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
|
||||
def make_journal_entry(
|
||||
account1,
|
||||
|
||||
@@ -385,7 +385,15 @@ frappe.ui.form.on("Payment Entry", {
|
||||
payment_type: function (frm) {
|
||||
if (frm.doc.payment_type == "Internal Transfer") {
|
||||
$.each(
|
||||
["party", "party_balance", "paid_from", "paid_to", "references", "total_allocated_amount"],
|
||||
[
|
||||
"party",
|
||||
"party_type",
|
||||
"party_balance",
|
||||
"paid_from",
|
||||
"paid_to",
|
||||
"references",
|
||||
"total_allocated_amount",
|
||||
],
|
||||
function (i, field) {
|
||||
frm.set_value(field, null);
|
||||
}
|
||||
|
||||
@@ -145,9 +145,21 @@ class PaymentEntry(AccountsController):
|
||||
self.is_opening = "No"
|
||||
return
|
||||
|
||||
liability_account = get_party_account(
|
||||
self.party_type, self.party, self.company, include_advance=True
|
||||
)[1]
|
||||
accounts = get_party_account(self.party_type, self.party, self.company, include_advance=True)
|
||||
|
||||
liability_account = accounts[1] if len(accounts) > 1 else None
|
||||
fieldname = (
|
||||
"default_advance_received_account"
|
||||
if self.party_type == "Customer"
|
||||
else "default_advance_paid_account"
|
||||
)
|
||||
|
||||
if not liability_account:
|
||||
throw(
|
||||
_("Please set default {0} in Company {1}").format(
|
||||
frappe.bold(frappe.get_meta("Company").get_label(fieldname)), frappe.bold(self.company)
|
||||
)
|
||||
)
|
||||
|
||||
self.set(self.party_account_field, liability_account)
|
||||
|
||||
|
||||
@@ -1791,6 +1791,79 @@ class TestPaymentEntry(FrappeTestCase):
|
||||
# 'Is Opening' should always be 'No' for normal advance payments
|
||||
self.assertEqual(gl_with_opening_set, [])
|
||||
|
||||
@change_settings("Accounts Settings", {"delete_linked_ledger_entries": 1})
|
||||
def test_delete_linked_exchange_gain_loss_journal(self):
|
||||
from erpnext.accounts.doctype.account.test_account import create_account
|
||||
from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import (
|
||||
make_customer,
|
||||
)
|
||||
|
||||
debtors = create_account(
|
||||
account_name="Debtors USD",
|
||||
parent_account="Accounts Receivable - _TC",
|
||||
company="_Test Company",
|
||||
account_currency="USD",
|
||||
account_type="Receivable",
|
||||
)
|
||||
|
||||
# create a customer
|
||||
customer = make_customer(customer="_Test Party USD")
|
||||
cust_doc = frappe.get_doc("Customer", customer)
|
||||
cust_doc.default_currency = "USD"
|
||||
test_account_details = {
|
||||
"company": "_Test Company",
|
||||
"account": debtors,
|
||||
}
|
||||
cust_doc.append("accounts", test_account_details)
|
||||
cust_doc.save()
|
||||
|
||||
# create a sales invoice
|
||||
si = create_sales_invoice(
|
||||
customer=customer,
|
||||
currency="USD",
|
||||
conversion_rate=83.970000000,
|
||||
debit_to=debtors,
|
||||
do_not_save=1,
|
||||
)
|
||||
si.party_account_currency = "USD"
|
||||
si.save()
|
||||
si.submit()
|
||||
|
||||
# create a payment entry for the invoice
|
||||
pe = get_payment_entry("Sales Invoice", si.name)
|
||||
pe.reference_no = "1"
|
||||
pe.reference_date = frappe.utils.nowdate()
|
||||
pe.paid_amount = 100
|
||||
pe.source_exchange_rate = 90
|
||||
pe.append(
|
||||
"deductions",
|
||||
{
|
||||
"account": "_Test Exchange Gain/Loss - _TC",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"amount": 2710,
|
||||
},
|
||||
)
|
||||
pe.save()
|
||||
pe.submit()
|
||||
|
||||
# check creation of journal entry
|
||||
jv = frappe.get_all(
|
||||
"Journal Entry Account",
|
||||
{"reference_type": pe.doctype, "reference_name": pe.name, "docstatus": 1},
|
||||
pluck="parent",
|
||||
)
|
||||
self.assertTrue(jv)
|
||||
|
||||
# check cancellation of payment entry and journal entry
|
||||
pe.cancel()
|
||||
self.assertTrue(pe.docstatus == 2)
|
||||
self.assertTrue(frappe.db.get_value("Journal Entry", {"name": jv[0]}, "docstatus") == 2)
|
||||
|
||||
# check deletion of payment entry and journal entry
|
||||
pe.delete()
|
||||
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, pe.doctype, pe.name)
|
||||
self.assertRaises(frappe.DoesNotExistError, frappe.get_doc, "Journal Entry", jv[0])
|
||||
|
||||
|
||||
def create_payment_entry(**args):
|
||||
payment_entry = frappe.new_doc("Payment Entry")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import frappe
|
||||
from frappe import qb
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
from frappe.utils import add_days, flt, nowdate
|
||||
from frappe.utils import add_days, add_years, flt, getdate, nowdate, today
|
||||
|
||||
from erpnext import get_default_cost_center
|
||||
from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
|
||||
@@ -13,6 +13,7 @@ from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_pay
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
|
||||
@@ -1845,6 +1846,78 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 1)
|
||||
|
||||
def test_reconciliation_on_closed_period_payment(self):
|
||||
# create backdated fiscal year
|
||||
first_fy_start_date = frappe.db.get_value("Fiscal Year", {"disabled": 0}, "min(year_start_date)")
|
||||
prev_fy_start_date = add_years(first_fy_start_date, -1)
|
||||
prev_fy_end_date = add_days(first_fy_start_date, -1)
|
||||
create_fiscal_year(
|
||||
company=self.company, year_start_date=prev_fy_start_date, year_end_date=prev_fy_end_date
|
||||
)
|
||||
|
||||
# make journal entry for previous year
|
||||
je_1 = frappe.new_doc("Journal Entry")
|
||||
je_1.posting_date = add_days(prev_fy_start_date, 20)
|
||||
je_1.company = self.company
|
||||
je_1.user_remark = "test"
|
||||
je_1.set(
|
||||
"accounts",
|
||||
[
|
||||
{
|
||||
"account": self.debit_to,
|
||||
"cost_center": self.cost_center,
|
||||
"party_type": "Customer",
|
||||
"party": self.customer,
|
||||
"debit_in_account_currency": 0,
|
||||
"credit_in_account_currency": 1000,
|
||||
},
|
||||
{
|
||||
"account": self.bank,
|
||||
"cost_center": self.sub_cc.name,
|
||||
"credit_in_account_currency": 0,
|
||||
"debit_in_account_currency": 500,
|
||||
},
|
||||
{
|
||||
"account": self.cash,
|
||||
"cost_center": self.sub_cc.name,
|
||||
"credit_in_account_currency": 0,
|
||||
"debit_in_account_currency": 500,
|
||||
},
|
||||
],
|
||||
)
|
||||
je_1.submit()
|
||||
|
||||
# make period closing voucher
|
||||
pcv = make_period_closing_voucher(
|
||||
company=self.company, cost_center=self.cost_center, posting_date=prev_fy_end_date
|
||||
)
|
||||
pcv.reload()
|
||||
# check if period closing voucher is completed
|
||||
self.assertEqual(pcv.gle_processing_status, "Completed")
|
||||
|
||||
# make journal entry for active year
|
||||
je_2 = self.create_journal_entry(
|
||||
acc1=self.debit_to, acc2=self.income_account, amount=1000, posting_date=today()
|
||||
)
|
||||
je_2.accounts[0].party_type = "Customer"
|
||||
je_2.accounts[0].party = self.customer
|
||||
je_2.submit()
|
||||
|
||||
# process reconciliation on closed period payment
|
||||
pr = self.create_payment_reconciliation(party_is_customer=True)
|
||||
pr.from_invoice_date = pr.to_invoice_date = pr.from_payment_date = pr.to_payment_date = None
|
||||
pr.get_unreconciled_entries()
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
pr.reconcile()
|
||||
je_1.reload()
|
||||
je_2.reload()
|
||||
|
||||
# check whether the payment reconciliation is done on the closed period
|
||||
self.assertEqual(pr.get("invoices"), [])
|
||||
self.assertEqual(pr.get("payments"), [])
|
||||
|
||||
|
||||
def make_customer(customer_name, currency=None):
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
@@ -1872,3 +1945,61 @@ def make_supplier(supplier_name, currency=None):
|
||||
return supplier.name
|
||||
else:
|
||||
return supplier_name
|
||||
|
||||
|
||||
def create_fiscal_year(company, year_start_date, year_end_date):
|
||||
fy_docname = frappe.db.exists(
|
||||
"Fiscal Year", {"year_start_date": year_start_date, "year_end_date": year_end_date}
|
||||
)
|
||||
if not fy_docname:
|
||||
fy_doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Fiscal Year",
|
||||
"year": f"{getdate(year_start_date).year}-{getdate(year_end_date).year}",
|
||||
"year_start_date": year_start_date,
|
||||
"year_end_date": year_end_date,
|
||||
"companies": [{"company": company}],
|
||||
}
|
||||
).save()
|
||||
return fy_doc
|
||||
else:
|
||||
fy_doc = frappe.get_doc("Fiscal Year", fy_docname)
|
||||
if not frappe.db.exists("Fiscal Year Company", {"parent": fy_docname, "company": company}):
|
||||
fy_doc.append("companies", {"company": company})
|
||||
fy_doc.save()
|
||||
return fy_doc
|
||||
|
||||
|
||||
def make_period_closing_voucher(company, cost_center, posting_date=None, submit=True):
|
||||
from erpnext.accounts.doctype.account.test_account import create_account
|
||||
|
||||
parent_account = frappe.db.get_value(
|
||||
"Account", {"company": company, "account_name": "Current Liabilities", "is_group": 1}, "name"
|
||||
)
|
||||
surplus_account = create_account(
|
||||
account_name="Reserve and Surplus",
|
||||
is_group=0,
|
||||
company=company,
|
||||
root_type="Liability",
|
||||
report_type="Balance Sheet",
|
||||
account_currency="INR",
|
||||
parent_account=parent_account,
|
||||
doctype="Account",
|
||||
)
|
||||
pcv = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Period Closing Voucher",
|
||||
"transaction_date": posting_date or today(),
|
||||
"posting_date": posting_date or today(),
|
||||
"company": company,
|
||||
"fiscal_year": get_fiscal_year(posting_date or today(), company=company)[0],
|
||||
"cost_center": cost_center,
|
||||
"closing_account_head": surplus_account,
|
||||
"remarks": "test",
|
||||
}
|
||||
)
|
||||
pcv.insert()
|
||||
if submit:
|
||||
pcv.submit()
|
||||
|
||||
return pcv
|
||||
|
||||
@@ -194,7 +194,9 @@ function refresh_payments(d, frm) {
|
||||
}
|
||||
if (payment) {
|
||||
payment.expected_amount += flt(p.amount);
|
||||
payment.closing_amount = payment.expected_amount;
|
||||
if (payment.closing_amount === 0) {
|
||||
payment.closing_amount = payment.expected_amount;
|
||||
}
|
||||
payment.difference = payment.closing_amount - payment.expected_amount;
|
||||
} else {
|
||||
frm.add_child("payment_reconciliation", {
|
||||
|
||||
@@ -40,6 +40,19 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex
|
||||
};
|
||||
});
|
||||
|
||||
this.frm.set_query("item_code", "items", function (doc) {
|
||||
return {
|
||||
query: "erpnext.accounts.doctype.pos_invoice.pos_invoice.item_query",
|
||||
filters: {
|
||||
has_variants: ["=", 0],
|
||||
is_sales_item: ["=", 1],
|
||||
disabled: ["=", 0],
|
||||
is_fixed_asset: ["=", 0],
|
||||
pos_profile: ["=", doc.pos_profile],
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import frappe
|
||||
from frappe import _, bold
|
||||
from frappe.query_builder.functions import IfNull, Sum
|
||||
from frappe.utils import cint, flt, get_link_to_form, getdate, nowdate
|
||||
from frappe.utils.nestedset import get_descendants_of
|
||||
|
||||
from erpnext.accounts.doctype.loyalty_program.loyalty_program import validate_loyalty_points
|
||||
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
|
||||
@@ -15,6 +16,7 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
||||
update_multi_mode_option,
|
||||
)
|
||||
from erpnext.accounts.party import get_due_date, get_party_account
|
||||
from erpnext.controllers.queries import item_query as _item_query
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
|
||||
|
||||
@@ -449,7 +451,7 @@ class POSInvoice(SalesInvoice):
|
||||
if self.is_return and entry.amount > 0:
|
||||
frappe.throw(_("Row #{0} (Payment Table): Amount must be negative").format(entry.idx))
|
||||
|
||||
if self.is_return:
|
||||
if self.is_return and self.docstatus != 0:
|
||||
invoice_total = self.rounded_total or self.grand_total
|
||||
total_amount_in_payments = flt(total_amount_in_payments, self.precision("grand_total"))
|
||||
if total_amount_in_payments and total_amount_in_payments < invoice_total:
|
||||
@@ -837,3 +839,29 @@ def add_return_modes(doc, pos_profile):
|
||||
]:
|
||||
payment_mode = get_mode_of_payment_info(mode_of_payment, doc.company)
|
||||
append_payment(payment_mode[0])
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=False):
|
||||
if pos_profile := filters.get("pos_profile")[1]:
|
||||
pos_profile = frappe.get_cached_doc("POS Profile", pos_profile)
|
||||
if item_groups := get_item_group(pos_profile):
|
||||
filters["item_group"] = ["in", tuple(item_groups)]
|
||||
|
||||
del filters["pos_profile"]
|
||||
|
||||
else:
|
||||
filters.pop("pos_profile", None)
|
||||
|
||||
return _item_query(doctype, txt, searchfield, start, page_len, filters, as_dict)
|
||||
|
||||
|
||||
def get_item_group(pos_profile):
|
||||
item_groups = []
|
||||
if pos_profile.get("item_groups"):
|
||||
# Get items based on the item groups defined in the POS profile
|
||||
for row in pos_profile.get("item_groups"):
|
||||
item_groups.extend(get_descendants_of("Item Group", row.item_group))
|
||||
|
||||
return list(set(item_groups))
|
||||
|
||||
@@ -419,7 +419,8 @@
|
||||
"depends_on": "eval:doc.rate_or_discount==\"Rate\"",
|
||||
"fieldname": "rate",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Rate"
|
||||
"label": "Rate",
|
||||
"options": "currency"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@@ -647,7 +648,7 @@
|
||||
"icon": "fa fa-gift",
|
||||
"idx": 1,
|
||||
"links": [],
|
||||
"modified": "2024-05-17 13:16:34.496704",
|
||||
"modified": "2024-09-16 18:14:51.314765",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Pricing Rule",
|
||||
@@ -709,4 +710,4 @@
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "title"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
@@ -14,7 +15,7 @@ from erpnext.stock.doctype.item.test_item import make_item
|
||||
from erpnext.stock.get_item_details import get_item_details
|
||||
|
||||
|
||||
class TestPricingRule(unittest.TestCase):
|
||||
class TestPricingRule(FrappeTestCase):
|
||||
def setUp(self):
|
||||
delete_existing_pricing_rules()
|
||||
setup_pricing_rule_data()
|
||||
|
||||
@@ -648,11 +648,11 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
},
|
||||
|
||||
onload: function (frm) {
|
||||
if (frm.doc.__onload && frm.is_new()) {
|
||||
if (frm.doc.supplier) {
|
||||
if (frm.doc.__onload && frm.doc.supplier) {
|
||||
if (frm.is_new()) {
|
||||
frm.doc.apply_tds = frm.doc.__onload.supplier_tds ? 1 : 0;
|
||||
}
|
||||
if (!frm.doc.__onload.enable_apply_tds) {
|
||||
if (!frm.doc.__onload.supplier_tds) {
|
||||
frm.set_df_property("apply_tds", "read_only", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1271,6 +1271,7 @@
|
||||
"fieldtype": "Select",
|
||||
"in_standard_filter": 1,
|
||||
"label": "Status",
|
||||
"no_copy": 1,
|
||||
"options": "\nDraft\nReturn\nDebit Note Issued\nSubmitted\nPaid\nPartly Paid\nUnpaid\nOverdue\nCancelled\nInternal Transfer",
|
||||
"print_hide": 1
|
||||
},
|
||||
@@ -1630,7 +1631,7 @@
|
||||
"idx": 204,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2024-07-25 19:42:36.931278",
|
||||
"modified": "2024-09-11 12:59:19.130593",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice",
|
||||
|
||||
@@ -346,22 +346,6 @@ class PurchaseInvoice(BuyingController):
|
||||
self.tax_withholding_category = tds_category
|
||||
self.set_onload("supplier_tds", tds_category)
|
||||
|
||||
# If Linked Purchase Order has TDS applied, enable 'apply_tds' checkbox
|
||||
if purchase_orders := [x.purchase_order for x in self.items if x.purchase_order]:
|
||||
po = qb.DocType("Purchase Order")
|
||||
po_with_tds = (
|
||||
qb.from_(po)
|
||||
.select(po.name)
|
||||
.where(
|
||||
po.docstatus.eq(1)
|
||||
& (po.name.isin(purchase_orders))
|
||||
& (po.apply_tds.eq(1))
|
||||
& (po.tax_withholding_category.notnull())
|
||||
)
|
||||
.run()
|
||||
)
|
||||
self.set_onload("enable_apply_tds", True if po_with_tds else False)
|
||||
|
||||
super().set_missing_values(for_validate)
|
||||
|
||||
def validate_credit_to_acc(self):
|
||||
|
||||
@@ -340,6 +340,7 @@ class SalesInvoice(SellingController):
|
||||
):
|
||||
validate_loyalty_points(self, self.loyalty_points)
|
||||
|
||||
self.allow_write_off_only_on_pos()
|
||||
self.reset_default_field_value("set_warehouse", "items", "warehouse")
|
||||
|
||||
def validate_accounts(self):
|
||||
@@ -1021,6 +1022,10 @@ class SalesInvoice(SellingController):
|
||||
raise_exception=1,
|
||||
)
|
||||
|
||||
def allow_write_off_only_on_pos(self):
|
||||
if not self.is_pos and self.write_off_account:
|
||||
self.write_off_account = None
|
||||
|
||||
def validate_write_off_account(self):
|
||||
if flt(self.write_off_amount) and not self.write_off_account:
|
||||
self.write_off_account = frappe.get_cached_value("Company", self.company, "write_off_account")
|
||||
|
||||
@@ -185,7 +185,7 @@ def get_tax_template(posting_date, args):
|
||||
conditions.append("(from_date is null) and (to_date is null)")
|
||||
|
||||
conditions.append(
|
||||
"ifnull(tax_category, '') = {}".format(frappe.db.escape(cstr(args.get("tax_category"))))
|
||||
"ifnull(tax_category, '') = {}".format(frappe.db.escape(cstr(args.get("tax_category")), False))
|
||||
)
|
||||
if "tax_category" in args.keys():
|
||||
del args["tax_category"]
|
||||
|
||||
@@ -179,50 +179,53 @@ def process_gl_map(gl_map, merge_entries=True, precision=None):
|
||||
|
||||
|
||||
def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None):
|
||||
cost_center_allocation = get_cost_center_allocation_data(gl_map[0]["company"], gl_map[0]["posting_date"])
|
||||
if not cost_center_allocation:
|
||||
return gl_map
|
||||
|
||||
new_gl_map = []
|
||||
for d in gl_map:
|
||||
cost_center = d.get("cost_center")
|
||||
|
||||
# Validate budget against main cost center
|
||||
validate_expense_against_budget(d, expense_amount=flt(d.debit, precision) - flt(d.credit, precision))
|
||||
|
||||
if cost_center and cost_center_allocation.get(cost_center):
|
||||
for sub_cost_center, percentage in cost_center_allocation.get(cost_center, {}).items():
|
||||
gle = copy.deepcopy(d)
|
||||
gle.cost_center = sub_cost_center
|
||||
for field in ("debit", "credit", "debit_in_account_currency", "credit_in_account_currency"):
|
||||
gle[field] = flt(flt(d.get(field)) * percentage / 100, precision)
|
||||
new_gl_map.append(gle)
|
||||
else:
|
||||
cost_center_allocation = get_cost_center_allocation_data(
|
||||
gl_map[0]["company"], gl_map[0]["posting_date"], cost_center
|
||||
)
|
||||
if not cost_center_allocation:
|
||||
new_gl_map.append(d)
|
||||
continue
|
||||
|
||||
for sub_cost_center, percentage in cost_center_allocation:
|
||||
gle = copy.deepcopy(d)
|
||||
gle.cost_center = sub_cost_center
|
||||
for field in ("debit", "credit", "debit_in_account_currency", "credit_in_account_currency"):
|
||||
gle[field] = flt(flt(d.get(field)) * percentage / 100, precision)
|
||||
new_gl_map.append(gle)
|
||||
|
||||
return new_gl_map
|
||||
|
||||
|
||||
def get_cost_center_allocation_data(company, posting_date):
|
||||
par = frappe.qb.DocType("Cost Center Allocation")
|
||||
child = frappe.qb.DocType("Cost Center Allocation Percentage")
|
||||
def get_cost_center_allocation_data(company, posting_date, cost_center):
|
||||
cost_center_allocation = frappe.db.get_value(
|
||||
"Cost Center Allocation",
|
||||
{
|
||||
"docstatus": 1,
|
||||
"company": company,
|
||||
"valid_from": ("<=", posting_date),
|
||||
"main_cost_center": cost_center,
|
||||
},
|
||||
pluck="name",
|
||||
order_by="valid_from desc",
|
||||
)
|
||||
|
||||
records = (
|
||||
frappe.qb.from_(par)
|
||||
.inner_join(child)
|
||||
.on(par.name == child.parent)
|
||||
.select(par.main_cost_center, child.cost_center, child.percentage)
|
||||
.where(par.docstatus == 1)
|
||||
.where(par.company == company)
|
||||
.where(par.valid_from <= posting_date)
|
||||
.orderby(par.valid_from, order=frappe.qb.desc)
|
||||
).run(as_dict=True)
|
||||
if not cost_center_allocation:
|
||||
return []
|
||||
|
||||
cc_allocation = frappe._dict()
|
||||
for d in records:
|
||||
cc_allocation.setdefault(d.main_cost_center, frappe._dict()).setdefault(d.cost_center, d.percentage)
|
||||
records = frappe.db.get_all(
|
||||
"Cost Center Allocation Percentage",
|
||||
{"parent": cost_center_allocation},
|
||||
["cost_center", "percentage"],
|
||||
as_list=True,
|
||||
)
|
||||
|
||||
return cc_allocation
|
||||
return records
|
||||
|
||||
|
||||
def merge_similar_entries(gl_map, precision=None):
|
||||
|
||||
@@ -310,8 +310,8 @@ class ReceivablePayableReport:
|
||||
|
||||
must_consider = False
|
||||
if self.filters.get("for_revaluation_journals"):
|
||||
if (abs(row.outstanding) >= 0.0 / 10**self.currency_precision) or (
|
||||
abs(row.outstanding_in_account_currency) >= 0.0 / 10**self.currency_precision
|
||||
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:
|
||||
|
||||
@@ -36,6 +36,7 @@ def get_group_by_asset_category_data(filters):
|
||||
+ flt(row.cost_of_new_purchase)
|
||||
- flt(row.cost_of_sold_asset)
|
||||
- flt(row.cost_of_scrapped_asset)
|
||||
- flt(row.cost_of_capitalized_asset)
|
||||
)
|
||||
|
||||
row.update(
|
||||
@@ -68,7 +69,7 @@ def get_group_by_asset_category_data(filters):
|
||||
def get_asset_categories_for_grouped_by_category(filters):
|
||||
condition = ""
|
||||
if filters.get("asset_category"):
|
||||
condition += " and asset_category = %(asset_category)s"
|
||||
condition += " and a.asset_category = %(asset_category)s"
|
||||
if filters.get("finance_book"):
|
||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = a.name and ads.finance_book = %(finance_book)s)"
|
||||
|
||||
@@ -111,10 +112,26 @@ def get_asset_categories_for_grouped_by_category(filters):
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_scrapped_asset
|
||||
end), 0) as cost_of_scrapped_asset,
|
||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||
and a.disposal_date >= %(from_date)s
|
||||
and a.disposal_date <= %(to_date)s then
|
||||
case when a.status = "Capitalized" then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_capitalized_asset
|
||||
from `tabAsset` a
|
||||
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {condition}
|
||||
and not exists(select name from `tabAsset Capitalization Asset Item` where asset = a.name)
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {condition}
|
||||
and not exists(
|
||||
select 1 from `tabAsset Capitalization Asset Item` acai join `tabAsset Capitalization` ac on acai.parent=ac.name
|
||||
where acai.asset = a.name
|
||||
and ac.posting_date < %(from_date)s
|
||||
and ac.docstatus=1
|
||||
)
|
||||
group by a.asset_category
|
||||
""",
|
||||
{
|
||||
@@ -131,53 +148,70 @@ def get_asset_categories_for_grouped_by_category(filters):
|
||||
def get_asset_details_for_grouped_by_category(filters):
|
||||
condition = ""
|
||||
if filters.get("asset"):
|
||||
condition += " and name = %(asset)s"
|
||||
condition += " and a.name = %(asset)s"
|
||||
if filters.get("finance_book"):
|
||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = `tabAsset`.name and ads.finance_book = %(finance_book)s)"
|
||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = a.name and ads.finance_book = %(finance_book)s)"
|
||||
|
||||
# nosemgrep
|
||||
return frappe.db.sql(
|
||||
f"""
|
||||
SELECT name,
|
||||
ifnull(sum(case when purchase_date < %(from_date)s then
|
||||
case when ifnull(disposal_date, 0) = 0 or disposal_date >= %(from_date)s then
|
||||
gross_purchase_amount
|
||||
SELECT a.name,
|
||||
ifnull(sum(case when a.purchase_date < %(from_date)s then
|
||||
case when ifnull(a.disposal_date, 0) = 0 or a.disposal_date >= %(from_date)s then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_as_on_from_date,
|
||||
ifnull(sum(case when purchase_date >= %(from_date)s then
|
||||
gross_purchase_amount
|
||||
ifnull(sum(case when a.purchase_date >= %(from_date)s then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_new_purchase,
|
||||
ifnull(sum(case when ifnull(disposal_date, 0) != 0
|
||||
and disposal_date >= %(from_date)s
|
||||
and disposal_date <= %(to_date)s then
|
||||
case when status = "Sold" then
|
||||
gross_purchase_amount
|
||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||
and a.disposal_date >= %(from_date)s
|
||||
and a.disposal_date <= %(to_date)s then
|
||||
case when a.status = "Sold" then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_sold_asset,
|
||||
ifnull(sum(case when ifnull(disposal_date, 0) != 0
|
||||
and disposal_date >= %(from_date)s
|
||||
and disposal_date <= %(to_date)s then
|
||||
case when status = "Scrapped" then
|
||||
gross_purchase_amount
|
||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||
and a.disposal_date >= %(from_date)s
|
||||
and a.disposal_date <= %(to_date)s then
|
||||
case when a.status = "Scrapped" then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_scrapped_asset
|
||||
from `tabAsset`
|
||||
where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {condition}
|
||||
group by name
|
||||
end), 0) as cost_of_scrapped_asset,
|
||||
ifnull(sum(case when ifnull(a.disposal_date, 0) != 0
|
||||
and a.disposal_date >= %(from_date)s
|
||||
and a.disposal_date <= %(to_date)s then
|
||||
case when a.status = "Capitalized" then
|
||||
a.gross_purchase_amount
|
||||
else
|
||||
0
|
||||
end
|
||||
else
|
||||
0
|
||||
end), 0) as cost_of_capitalized_asset
|
||||
from `tabAsset` a
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {condition}
|
||||
and not exists(
|
||||
select 1 from `tabAsset Capitalization Asset Item` acai join `tabAsset Capitalization` ac on acai.parent=ac.name
|
||||
where acai.asset = a.name
|
||||
and ac.posting_date < %(from_date)s
|
||||
and ac.docstatus=1
|
||||
)
|
||||
group by a.name
|
||||
""",
|
||||
{
|
||||
"to_date": filters.to_date,
|
||||
@@ -206,6 +240,7 @@ def get_group_by_asset_data(filters):
|
||||
+ flt(row.cost_of_new_purchase)
|
||||
- flt(row.cost_of_sold_asset)
|
||||
- flt(row.cost_of_scrapped_asset)
|
||||
- flt(row.cost_of_capitalized_asset)
|
||||
)
|
||||
|
||||
row.update(next(asset for asset in assets if asset["asset"] == asset_detail.get("name", "")))
|
||||
@@ -232,9 +267,15 @@ def get_group_by_asset_data(filters):
|
||||
def get_assets_for_grouped_by_category(filters):
|
||||
condition = ""
|
||||
if filters.get("asset_category"):
|
||||
condition = " and a.asset_category = '{}'".format(filters.get("asset_category"))
|
||||
condition = f" and a.asset_category = '{filters.get('asset_category')}'"
|
||||
finance_book_filter = ""
|
||||
if filters.get("finance_book"):
|
||||
finance_book_filter += " and ifnull(gle.finance_book, '')=%(finance_book)s"
|
||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = a.name and ads.finance_book = %(finance_book)s)"
|
||||
|
||||
# nosemgrep
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
f"""
|
||||
SELECT results.asset_category,
|
||||
sum(results.accumulated_depreciation_as_on_from_date) as accumulated_depreciation_as_on_from_date,
|
||||
sum(results.depreciation_eliminated_during_the_period) as depreciation_eliminated_during_the_period,
|
||||
@@ -264,7 +305,14 @@ def get_assets_for_grouped_by_category(filters):
|
||||
aca.parent = a.asset_category and aca.company_name = %(company)s
|
||||
join `tabCompany` company on
|
||||
company.name = %(company)s
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) {0}
|
||||
where
|
||||
a.docstatus=1
|
||||
and a.company=%(company)s
|
||||
and a.purchase_date <= %(to_date)s
|
||||
and gle.debit != 0
|
||||
and gle.is_cancelled = 0
|
||||
and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account)
|
||||
{condition} {finance_book_filter}
|
||||
group by a.asset_category
|
||||
union
|
||||
SELECT a.asset_category,
|
||||
@@ -280,11 +328,16 @@ def get_assets_for_grouped_by_category(filters):
|
||||
end), 0) as depreciation_eliminated_during_the_period,
|
||||
0 as depreciation_amount_during_the_period
|
||||
from `tabAsset` a
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {0}
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {condition}
|
||||
group by a.asset_category) as results
|
||||
group by results.asset_category
|
||||
""".format(condition),
|
||||
{"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company},
|
||||
""",
|
||||
{
|
||||
"to_date": filters.to_date,
|
||||
"from_date": filters.from_date,
|
||||
"company": filters.company,
|
||||
"finance_book": filters.get("finance_book", ""),
|
||||
},
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
@@ -292,9 +345,15 @@ def get_assets_for_grouped_by_category(filters):
|
||||
def get_assets_for_grouped_by_asset(filters):
|
||||
condition = ""
|
||||
if filters.get("asset"):
|
||||
condition = " and a.name = '{}'".format(filters.get("asset"))
|
||||
condition = f" and a.name = '{filters.get('asset')}'"
|
||||
finance_book_filter = ""
|
||||
if filters.get("finance_book"):
|
||||
finance_book_filter += " and ifnull(gle.finance_book, '')=%(finance_book)s"
|
||||
condition += " and exists (select 1 from `tabAsset Depreciation Schedule` ads where ads.asset = a.name and ads.finance_book = %(finance_book)s)"
|
||||
|
||||
# nosemgrep
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
f"""
|
||||
SELECT results.name as asset,
|
||||
sum(results.accumulated_depreciation_as_on_from_date) as accumulated_depreciation_as_on_from_date,
|
||||
sum(results.depreciation_eliminated_during_the_period) as depreciation_eliminated_during_the_period,
|
||||
@@ -324,7 +383,14 @@ def get_assets_for_grouped_by_asset(filters):
|
||||
aca.parent = a.asset_category and aca.company_name = %(company)s
|
||||
join `tabCompany` company on
|
||||
company.name = %(company)s
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) {0}
|
||||
where
|
||||
a.docstatus=1
|
||||
and a.company=%(company)s
|
||||
and a.purchase_date <= %(to_date)s
|
||||
and gle.debit != 0
|
||||
and gle.is_cancelled = 0
|
||||
and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account)
|
||||
{finance_book_filter} {condition}
|
||||
group by a.name
|
||||
union
|
||||
SELECT a.name as name,
|
||||
@@ -340,11 +406,16 @@ def get_assets_for_grouped_by_asset(filters):
|
||||
end), 0) as depreciation_eliminated_during_the_period,
|
||||
0 as depreciation_amount_during_the_period
|
||||
from `tabAsset` a
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {0}
|
||||
where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {condition}
|
||||
group by a.name) as results
|
||||
group by results.name
|
||||
""".format(condition),
|
||||
{"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company},
|
||||
""",
|
||||
{
|
||||
"to_date": filters.to_date,
|
||||
"from_date": filters.from_date,
|
||||
"company": filters.company,
|
||||
"finance_book": filters.get("finance_book", ""),
|
||||
},
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
@@ -398,6 +469,12 @@ def get_columns(filters):
|
||||
"fieldtype": "Currency",
|
||||
"width": 140,
|
||||
},
|
||||
{
|
||||
"label": _("Cost of New Capitalized Asset"),
|
||||
"fieldname": "cost_of_capitalized_asset",
|
||||
"fieldtype": "Currency",
|
||||
"width": 140,
|
||||
},
|
||||
{
|
||||
"label": _("Cost as on") + " " + formatdate(filters.to_date),
|
||||
"fieldname": "cost_as_on_to_date",
|
||||
|
||||
@@ -95,7 +95,7 @@ def execute(filters=None):
|
||||
filters.periodicity, period_list, filters.accumulated_values, company=filters.company
|
||||
)
|
||||
|
||||
chart = get_chart_data(filters, columns, asset, liability, equity)
|
||||
chart = get_chart_data(filters, columns, asset, liability, equity, currency)
|
||||
|
||||
report_summary, primitive_summary = get_report_summary(
|
||||
period_list, asset, liability, equity, provisional_profit_loss, currency, filters
|
||||
@@ -221,7 +221,7 @@ def get_report_summary(
|
||||
], (net_asset - net_liability + net_equity)
|
||||
|
||||
|
||||
def get_chart_data(filters, columns, asset, liability, equity):
|
||||
def get_chart_data(filters, columns, asset, liability, equity, currency):
|
||||
labels = [d.get("label") for d in columns[2:]]
|
||||
|
||||
asset_data, liability_data, equity_data = [], [], []
|
||||
@@ -249,4 +249,8 @@ def get_chart_data(filters, columns, asset, liability, equity):
|
||||
else:
|
||||
chart["type"] = "line"
|
||||
|
||||
chart["fieldtype"] = "Currency"
|
||||
chart["options"] = "currency"
|
||||
chart["currency"] = currency
|
||||
|
||||
return chart
|
||||
|
||||
@@ -111,7 +111,7 @@ def execute(filters=None):
|
||||
)
|
||||
columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)
|
||||
|
||||
chart = get_chart_data(columns, data)
|
||||
chart = get_chart_data(columns, data, company_currency)
|
||||
|
||||
report_summary = get_report_summary(summary_data, company_currency)
|
||||
|
||||
@@ -252,7 +252,7 @@ def get_report_summary(summary_data, currency):
|
||||
return report_summary
|
||||
|
||||
|
||||
def get_chart_data(columns, data):
|
||||
def get_chart_data(columns, data, currency):
|
||||
labels = [d.get("label") for d in columns[2:]]
|
||||
datasets = [
|
||||
{
|
||||
@@ -267,5 +267,7 @@ def get_chart_data(columns, data):
|
||||
chart = {"data": {"labels": labels, "datasets": datasets}, "type": "bar"}
|
||||
|
||||
chart["fieldtype"] = "Currency"
|
||||
chart["options"] = "currency"
|
||||
chart["currency"] = currency
|
||||
|
||||
return chart
|
||||
|
||||
@@ -115,7 +115,7 @@ def get_balance_sheet_data(fiscal_year, companies, columns, filters):
|
||||
True,
|
||||
)
|
||||
|
||||
chart = get_chart_data(filters, columns, asset, liability, equity)
|
||||
chart = get_chart_data(filters, columns, asset, liability, equity, company_currency)
|
||||
|
||||
return data, message, chart, report_summary
|
||||
|
||||
@@ -173,7 +173,7 @@ def get_profit_loss_data(fiscal_year, companies, columns, filters):
|
||||
if net_profit_loss:
|
||||
data.append(net_profit_loss)
|
||||
|
||||
chart = get_pl_chart_data(filters, columns, income, expense, net_profit_loss)
|
||||
chart = get_pl_chart_data(filters, columns, income, expense, net_profit_loss, company_currency)
|
||||
|
||||
report_summary, primitive_summary = get_pl_summary(
|
||||
companies, "", income, expense, net_profit_loss, company_currency, filters, True
|
||||
|
||||
@@ -199,8 +199,7 @@ class General_Payment_Ledger_Comparison:
|
||||
dict(
|
||||
label=_("Voucher Type"),
|
||||
fieldname="voucher_type",
|
||||
fieldtype="Link",
|
||||
options="DocType",
|
||||
fieldtype="Data",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
@@ -219,8 +218,7 @@ class General_Payment_Ledger_Comparison:
|
||||
dict(
|
||||
label=_("Party Type"),
|
||||
fieldname="party_type",
|
||||
fieldtype="Link",
|
||||
options="DocType",
|
||||
fieldtype="Data",
|
||||
width="100",
|
||||
)
|
||||
)
|
||||
|
||||
@@ -35,6 +35,9 @@ def execute(filters=None):
|
||||
if filters.get("party"):
|
||||
filters.party = frappe.parse_json(filters.get("party"))
|
||||
|
||||
if filters.get("voucher_no") and not filters.get("group_by"):
|
||||
filters.group_by = "Group by Voucher (Consolidated)"
|
||||
|
||||
validate_filters(filters, account_details)
|
||||
|
||||
validate_party(filters)
|
||||
|
||||
@@ -210,7 +210,7 @@ class PaymentLedger:
|
||||
)
|
||||
)
|
||||
self.columns.append(
|
||||
dict(label=_("Currency"), fieldname="currency", fieldtype="Currency", hidden=True)
|
||||
dict(label=_("Currency"), fieldname="currency", fieldtype="Link", options="Currency", hidden=True)
|
||||
)
|
||||
|
||||
def run(self):
|
||||
|
||||
@@ -59,11 +59,11 @@ def execute(filters=None):
|
||||
|
||||
columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)
|
||||
|
||||
chart = get_chart_data(filters, columns, income, expense, net_profit_loss)
|
||||
|
||||
currency = filters.presentation_currency or frappe.get_cached_value(
|
||||
"Company", filters.company, "default_currency"
|
||||
)
|
||||
chart = get_chart_data(filters, columns, income, expense, net_profit_loss, currency)
|
||||
|
||||
report_summary, primitive_summary = get_report_summary(
|
||||
period_list, filters.periodicity, income, expense, net_profit_loss, currency, filters
|
||||
)
|
||||
@@ -152,7 +152,7 @@ def get_net_profit_loss(income, expense, period_list, company, currency=None, co
|
||||
return net_profit_loss
|
||||
|
||||
|
||||
def get_chart_data(filters, columns, income, expense, net_profit_loss):
|
||||
def get_chart_data(filters, columns, income, expense, net_profit_loss, currency):
|
||||
labels = [d.get("label") for d in columns[2:]]
|
||||
|
||||
income_data, expense_data, net_profit = [], [], []
|
||||
@@ -181,5 +181,7 @@ def get_chart_data(filters, columns, income, expense, net_profit_loss):
|
||||
chart["type"] = "line"
|
||||
|
||||
chart["fieldtype"] = "Currency"
|
||||
chart["options"] = "currency"
|
||||
chart["currency"] = currency
|
||||
|
||||
return chart
|
||||
|
||||
@@ -665,6 +665,8 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
|
||||
|
||||
# will work as update after submit
|
||||
journal_entry.flags.ignore_validate_update_after_submit = True
|
||||
# Ledgers will be reposted by Reconciliation tool
|
||||
journal_entry.flags.ignore_reposting_on_reconciliation = True
|
||||
if not do_not_save:
|
||||
journal_entry.save(ignore_permissions=True)
|
||||
|
||||
@@ -745,40 +747,74 @@ def cancel_exchange_gain_loss_journal(
|
||||
Cancel Exchange Gain/Loss for Sales/Purchase Invoice, if they have any.
|
||||
"""
|
||||
if parent_doc.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
|
||||
journals = frappe.db.get_all(
|
||||
"Journal Entry Account",
|
||||
filters={
|
||||
"reference_type": parent_doc.doctype,
|
||||
"reference_name": parent_doc.name,
|
||||
"docstatus": 1,
|
||||
},
|
||||
fields=["parent"],
|
||||
as_list=1,
|
||||
gain_loss_journals = get_linked_exchange_gain_loss_journal(
|
||||
referenced_dt=parent_doc.doctype, referenced_dn=parent_doc.name, je_docstatus=1
|
||||
)
|
||||
|
||||
if journals:
|
||||
gain_loss_journals = frappe.db.get_all(
|
||||
"Journal Entry",
|
||||
filters={
|
||||
"name": ["in", [x[0] for x in journals]],
|
||||
"voucher_type": "Exchange Gain Or Loss",
|
||||
"docstatus": 1,
|
||||
},
|
||||
as_list=1,
|
||||
)
|
||||
for doc in gain_loss_journals:
|
||||
gain_loss_je = frappe.get_doc("Journal Entry", doc[0])
|
||||
if referenced_dt and referenced_dn:
|
||||
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
|
||||
if (
|
||||
len(references) == 2
|
||||
and (referenced_dt, referenced_dn) in references
|
||||
and (parent_doc.doctype, parent_doc.name) in references
|
||||
):
|
||||
# only cancel JE generated against parent_doc and referenced_dn
|
||||
gain_loss_je.cancel()
|
||||
else:
|
||||
for doc in gain_loss_journals:
|
||||
gain_loss_je = frappe.get_doc("Journal Entry", doc)
|
||||
if referenced_dt and referenced_dn:
|
||||
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
|
||||
if (
|
||||
len(references) == 2
|
||||
and (referenced_dt, referenced_dn) in references
|
||||
and (parent_doc.doctype, parent_doc.name) in references
|
||||
):
|
||||
# only cancel JE generated against parent_doc and referenced_dn
|
||||
gain_loss_je.cancel()
|
||||
else:
|
||||
gain_loss_je.cancel()
|
||||
|
||||
|
||||
def delete_exchange_gain_loss_journal(
|
||||
parent_doc: dict | object, referenced_dt: str | None = None, referenced_dn: str | None = None
|
||||
) -> None:
|
||||
"""
|
||||
Delete Exchange Gain/Loss for Sales/Purchase Invoice, if they have any.
|
||||
"""
|
||||
if parent_doc.doctype in ["Sales Invoice", "Purchase Invoice", "Payment Entry", "Journal Entry"]:
|
||||
gain_loss_journals = get_linked_exchange_gain_loss_journal(
|
||||
referenced_dt=parent_doc.doctype, referenced_dn=parent_doc.name, je_docstatus=2
|
||||
)
|
||||
for doc in gain_loss_journals:
|
||||
gain_loss_je = frappe.get_doc("Journal Entry", doc)
|
||||
if referenced_dt and referenced_dn:
|
||||
references = [(x.reference_type, x.reference_name) for x in gain_loss_je.accounts]
|
||||
if (
|
||||
len(references) == 2
|
||||
and (referenced_dt, referenced_dn) in references
|
||||
and (parent_doc.doctype, parent_doc.name) in references
|
||||
):
|
||||
# only delete JE generated against parent_doc and referenced_dn
|
||||
gain_loss_je.delete()
|
||||
else:
|
||||
gain_loss_je.delete()
|
||||
|
||||
|
||||
def get_linked_exchange_gain_loss_journal(referenced_dt: str, referenced_dn: str, je_docstatus: int) -> list:
|
||||
"""
|
||||
Get all the linked exchange gain/loss journal entries for a given document.
|
||||
"""
|
||||
gain_loss_journals = []
|
||||
if journals := frappe.db.get_all(
|
||||
"Journal Entry Account",
|
||||
{
|
||||
"reference_type": referenced_dt,
|
||||
"reference_name": referenced_dn,
|
||||
"docstatus": je_docstatus,
|
||||
},
|
||||
pluck="parent",
|
||||
):
|
||||
gain_loss_journals = frappe.db.get_all(
|
||||
"Journal Entry",
|
||||
{
|
||||
"name": ["in", journals],
|
||||
"voucher_type": "Exchange Gain Or Loss",
|
||||
"is_system_generated": 1,
|
||||
"docstatus": je_docstatus,
|
||||
},
|
||||
pluck="name",
|
||||
)
|
||||
return gain_loss_journals
|
||||
|
||||
|
||||
def cancel_common_party_journal(self):
|
||||
|
||||
@@ -213,7 +213,7 @@ frappe.ui.form.on("Asset", {
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-6">
|
||||
<span class="indicator whitespace-nowrap red">
|
||||
<span>Failed to post depreciation entries</span>
|
||||
<span>${__("Failed to post depreciation entries")}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
@@ -623,6 +623,9 @@ class Asset(AccountsController):
|
||||
return records
|
||||
|
||||
def validate_make_gl_entry(self):
|
||||
if self.is_composite_asset:
|
||||
return True
|
||||
|
||||
purchase_document = self.get_purchase_document()
|
||||
if not purchase_document:
|
||||
return False
|
||||
|
||||
@@ -65,6 +65,31 @@ frappe.ui.form.on("Purchase Order", {
|
||||
}
|
||||
},
|
||||
|
||||
supplier: function (frm) {
|
||||
// Do not update if inter company reference is there as the details will already be updated
|
||||
if (frm.updating_party_details || frm.doc.inter_company_invoice_reference) return;
|
||||
|
||||
if (frm.doc.__onload && frm.doc.__onload.load_after_mapping) return;
|
||||
|
||||
erpnext.utils.get_party_details(
|
||||
frm,
|
||||
"erpnext.accounts.party.get_party_details",
|
||||
{
|
||||
posting_date: frm.doc.transaction_date,
|
||||
bill_date: frm.doc.bill_date,
|
||||
party: frm.doc.supplier,
|
||||
party_type: "Supplier",
|
||||
account: frm.doc.credit_to,
|
||||
price_list: frm.doc.buying_price_list,
|
||||
fetch_payment_terms_template: cint(!frm.doc.ignore_default_payment_terms_template),
|
||||
},
|
||||
function () {
|
||||
frm.set_df_property("apply_tds", "read_only", frm.supplier_tds ? 0 : 1);
|
||||
frm.set_df_property("tax_withholding_category", "hidden", frm.supplier_tds ? 0 : 1);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
get_materials_from_supplier: function (frm) {
|
||||
let po_details = [];
|
||||
|
||||
@@ -108,6 +133,15 @@ frappe.ui.form.on("Purchase Order", {
|
||||
frm.set_value("transaction_date", frappe.datetime.get_today());
|
||||
}
|
||||
|
||||
if (frm.doc.__onload && frm.doc.supplier) {
|
||||
if (frm.is_new()) {
|
||||
frm.doc.apply_tds = frm.doc.__onload.supplier_tds ? 1 : 0;
|
||||
}
|
||||
if (!frm.doc.__onload.supplier_tds) {
|
||||
frm.set_df_property("apply_tds", "read_only", 1);
|
||||
}
|
||||
}
|
||||
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function () {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
});
|
||||
|
||||
@@ -648,6 +648,13 @@ class PurchaseOrder(BuyingController):
|
||||
if sco:
|
||||
update_sco_status(sco, "Closed" if self.status == "Closed" else None)
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
tds_category = frappe.db.get_value("Supplier", self.supplier, "tax_withholding_category")
|
||||
if tds_category and not for_validate:
|
||||
self.set_onload("supplier_tds", tds_category)
|
||||
|
||||
super().set_missing_values(for_validate)
|
||||
|
||||
|
||||
@frappe.request_cache
|
||||
def item_last_purchase_rate(name, conversion_rate, item_code, conversion_factor=1.0):
|
||||
@@ -760,6 +767,11 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
||||
def postprocess(source, target):
|
||||
target.flags.ignore_permissions = ignore_permissions
|
||||
set_missing_values(source, target)
|
||||
|
||||
# set tax_withholding_category from Purchase Order
|
||||
if source.apply_tds and source.tax_withholding_category and target.apply_tds:
|
||||
target.tax_withholding_category = source.tax_withholding_category
|
||||
|
||||
# Get the advance paid Journal Entries in Purchase Invoice Advance
|
||||
if target.get("allocate_advances_automatically"):
|
||||
target.set_advances()
|
||||
|
||||
@@ -346,12 +346,17 @@ class AccountsController(TransactionBase):
|
||||
repost_doc.save(ignore_permissions=True)
|
||||
|
||||
def on_trash(self):
|
||||
from erpnext.accounts.utils import delete_exchange_gain_loss_journal
|
||||
|
||||
self._remove_references_in_repost_doctypes()
|
||||
self._remove_references_in_unreconcile()
|
||||
self.remove_serial_and_batch_bundle()
|
||||
|
||||
# delete sl and gl entries on deletion of transaction
|
||||
if frappe.db.get_single_value("Accounts Settings", "delete_linked_ledger_entries"):
|
||||
# delete linked exchange gain/loss journal
|
||||
delete_exchange_gain_loss_journal(self)
|
||||
|
||||
ple = frappe.qb.DocType("Payment Ledger Entry")
|
||||
frappe.qb.from_(ple).delete().where(
|
||||
(ple.voucher_type == self.doctype) & (ple.voucher_no == self.name)
|
||||
@@ -1031,7 +1036,9 @@ class AccountsController(TransactionBase):
|
||||
gl_dict.update(
|
||||
{
|
||||
"transaction_currency": self.get("currency") or self.company_currency,
|
||||
"transaction_exchange_rate": self.get("conversion_rate", 1),
|
||||
"transaction_exchange_rate": item.get("exchange_rate", 1)
|
||||
if self.doctype == "Journal Entry" and item
|
||||
else self.get("conversion_rate", 1),
|
||||
"debit_in_transaction_currency": self.get_value_in_transaction_currency(
|
||||
account_currency, gl_dict, "debit"
|
||||
),
|
||||
|
||||
@@ -640,7 +640,7 @@ class SellingController(StockController):
|
||||
if self.doctype in ["Sales Order", "Quotation"]:
|
||||
for item in self.items:
|
||||
item.gross_profit = flt(
|
||||
((item.base_rate - flt(item.valuation_rate)) * item.stock_qty),
|
||||
((flt(item.stock_uom_rate) - flt(item.valuation_rate)) * item.stock_qty),
|
||||
self.precision("amount", item),
|
||||
)
|
||||
|
||||
|
||||
173
erpnext/crm/frappe_crm_api.py
Normal file
173
erpnext/crm/frappe_crm_api.py
Normal file
@@ -0,0 +1,173 @@
|
||||
import json
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_custom_fields_for_frappe_crm():
|
||||
frappe.only_for("System Manager")
|
||||
custom_fields = {
|
||||
"Quotation": [
|
||||
{
|
||||
"fieldname": "crm_deal",
|
||||
"fieldtype": "Data",
|
||||
"label": "Frappe CRM Deal",
|
||||
"insert_after": "party_name",
|
||||
}
|
||||
],
|
||||
"Customer": [
|
||||
{
|
||||
"fieldname": "crm_deal",
|
||||
"fieldtype": "Data",
|
||||
"label": "Frappe CRM Deal",
|
||||
"insert_after": "prospect_name",
|
||||
}
|
||||
],
|
||||
}
|
||||
create_custom_fields(custom_fields, ignore_validate=True)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_prospect_against_crm_deal():
|
||||
frappe.only_for("System Manager")
|
||||
doc = frappe.form_dict
|
||||
prospect = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Prospect",
|
||||
"company_name": doc.organization or doc.lead_name,
|
||||
"no_of_employees": doc.no_of_employees,
|
||||
"prospect_owner": doc.deal_owner,
|
||||
"company": doc.erpnext_company,
|
||||
"crm_deal": doc.crm_deal,
|
||||
"territory": doc.territory,
|
||||
"industry": doc.industry,
|
||||
"website": doc.website,
|
||||
"annual_revenue": doc.annual_revenue,
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
prospect_name = frappe.db.get_value("Prospect", {"company_name": prospect.company_name})
|
||||
if not prospect_name:
|
||||
prospect.insert()
|
||||
prospect_name = prospect.name
|
||||
except Exception:
|
||||
frappe.log_error(
|
||||
frappe.get_traceback(),
|
||||
f"Error while creating prospect against CRM Deal: {frappe.form_dict.get('crm_deal_id')}",
|
||||
)
|
||||
pass
|
||||
|
||||
create_contacts(json.loads(doc.contacts), prospect.company_name, "Prospect", prospect_name)
|
||||
create_address("Prospect", prospect_name, doc.address)
|
||||
frappe.response["message"] = prospect_name
|
||||
|
||||
|
||||
def create_contacts(contacts, organization=None, link_doctype=None, link_docname=None):
|
||||
for c in contacts:
|
||||
c = frappe._dict(c)
|
||||
existing_contact = contact_exists(c.email, c.mobile_no)
|
||||
if existing_contact:
|
||||
contact = frappe.get_doc("Contact", existing_contact)
|
||||
else:
|
||||
contact = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Contact",
|
||||
"first_name": c.get("full_name"),
|
||||
"gender": c.get("gender"),
|
||||
"company_name": organization,
|
||||
}
|
||||
)
|
||||
|
||||
if c.get("email"):
|
||||
contact.append("email_ids", {"email_id": c.get("email"), "is_primary": 1})
|
||||
|
||||
if c.get("mobile_no"):
|
||||
contact.append("phone_nos", {"phone": c.get("mobile_no"), "is_primary_mobile_no": 1})
|
||||
|
||||
link_doc(contact, link_doctype, link_docname)
|
||||
|
||||
contact.save(ignore_permissions=True)
|
||||
|
||||
|
||||
def create_address(doctype, docname, address):
|
||||
if not address:
|
||||
return
|
||||
if isinstance(address, str):
|
||||
address = json.loads(address)
|
||||
try:
|
||||
_address = frappe.db.exists("Address", address.get("name"))
|
||||
if not _address:
|
||||
new_address_doc = frappe.new_doc("Address")
|
||||
for field in [
|
||||
"address_title",
|
||||
"address_type",
|
||||
"address_line1",
|
||||
"address_line2",
|
||||
"city",
|
||||
"county",
|
||||
"state",
|
||||
"pincode",
|
||||
"country",
|
||||
]:
|
||||
if address.get(field):
|
||||
new_address_doc.set(field, address.get(field))
|
||||
|
||||
new_address_doc.append("links", {"link_doctype": doctype, "link_name": docname})
|
||||
new_address_doc.insert(ignore_mandatory=True)
|
||||
return new_address_doc.name
|
||||
else:
|
||||
address = frappe.get_doc("Address", _address)
|
||||
link_doc(address, doctype, docname)
|
||||
address.save(ignore_permissions=True)
|
||||
return address.name
|
||||
except Exception:
|
||||
frappe.log_error(frappe.get_traceback(), f"Error while creating address for {docname}")
|
||||
|
||||
|
||||
def link_doc(doc, link_doctype, link_docname):
|
||||
already_linked = any(
|
||||
[(link.link_doctype == link_doctype and link.link_name == link_docname) for link in doc.links]
|
||||
)
|
||||
if not already_linked:
|
||||
doc.append(
|
||||
"links", {"link_doctype": link_doctype, "link_name": link_docname, "link_title": link_docname}
|
||||
)
|
||||
|
||||
|
||||
def contact_exists(email, mobile_no):
|
||||
email_exist = frappe.db.exists("Contact Email", {"email_id": email})
|
||||
mobile_exist = frappe.db.exists("Contact Phone", {"phone": mobile_no})
|
||||
|
||||
doctype = "Contact Email" if email_exist else "Contact Phone"
|
||||
name = email_exist or mobile_exist
|
||||
|
||||
if name:
|
||||
return frappe.db.get_value(doctype, name, "parent")
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_customer(customer_data=None):
|
||||
frappe.only_for("System Manager")
|
||||
if not customer_data:
|
||||
customer_data = frappe.form_dict
|
||||
|
||||
try:
|
||||
customer_name = frappe.db.exists("Customer", {"customer_name": customer_data.get("customer_name")})
|
||||
if not customer_name:
|
||||
customer = frappe.get_doc({"doctype": "Customer", **customer_data}).insert(
|
||||
ignore_permissions=True
|
||||
)
|
||||
customer_name = customer.name
|
||||
|
||||
contacts = json.loads(customer_data.get("contacts"))
|
||||
create_contacts(contacts, customer_name, "Customer", customer_name)
|
||||
create_address("Customer", customer_name, customer_data.get("address"))
|
||||
return customer_name
|
||||
except Exception:
|
||||
frappe.log_error(frappe.get_traceback(), "Error while creating customer against Frappe CRM Deal")
|
||||
pass
|
||||
@@ -280,6 +280,7 @@
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
"icon": "fa fa-sitemap",
|
||||
"is_submittable": 1,
|
||||
"links": [
|
||||
@@ -288,7 +289,7 @@
|
||||
"link_fieldname": "bom_creator"
|
||||
}
|
||||
],
|
||||
"modified": "2024-04-02 16:30:59.779190",
|
||||
"modified": "2024-09-21 09:05:52.945112",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "BOM Creator",
|
||||
|
||||
@@ -6,6 +6,22 @@ frappe.ui.form.on("Plant Floor", {
|
||||
frm.trigger("setup_queries");
|
||||
},
|
||||
|
||||
add_workstation(frm) {
|
||||
frm.add_custom_button(__("Create Workstation"), () => {
|
||||
var doc = frappe.model.get_new_doc("Workstation");
|
||||
doc.plant_floor = frm.doc.name;
|
||||
doc.status = "Off";
|
||||
frappe.ui.form.make_quick_entry(
|
||||
"Workstation",
|
||||
() => {
|
||||
frm.trigger("prepare_workstation_dashboard");
|
||||
},
|
||||
null,
|
||||
doc
|
||||
);
|
||||
}).addClass("btn-primary");
|
||||
},
|
||||
|
||||
setup_queries(frm) {
|
||||
frm.set_query("warehouse", (doc) => {
|
||||
if (!doc.company) {
|
||||
@@ -24,6 +40,11 @@ frappe.ui.form.on("Plant Floor", {
|
||||
refresh(frm) {
|
||||
frm.trigger("prepare_stock_dashboard");
|
||||
frm.trigger("prepare_workstation_dashboard");
|
||||
|
||||
if (!frm.is_new()) {
|
||||
frm.trigger("add_workstation");
|
||||
frm.disable_save();
|
||||
}
|
||||
},
|
||||
|
||||
prepare_workstation_dashboard(frm) {
|
||||
|
||||
@@ -69,9 +69,10 @@
|
||||
"options": "Company"
|
||||
}
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"modified": "2024-01-30 11:59:07.508535",
|
||||
"modified": "2024-09-19 19:06:36.481625",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Plant Floor",
|
||||
@@ -94,4 +95,4 @@
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ frappe.ui.form.on("Work Order", {
|
||||
frm.doc.produced_qty > 0
|
||||
) {
|
||||
frm.add_custom_button(
|
||||
__("Disassembly Order"),
|
||||
__("Disassemble Order"),
|
||||
() => {
|
||||
frm.trigger("make_disassembly_order");
|
||||
},
|
||||
|
||||
@@ -30,6 +30,9 @@ def update_report_json(report):
|
||||
report_json = json.loads(report.json)
|
||||
report_filter = report_json.get("filters")
|
||||
|
||||
if not report_filter:
|
||||
return
|
||||
|
||||
keys_to_pop = [key for key in report_filter if key.startswith("range")]
|
||||
report_filter["range"] = ", ".join(str(report_filter.pop(key)) for key in keys_to_pop)
|
||||
|
||||
|
||||
@@ -213,6 +213,13 @@ class Project(Document):
|
||||
frappe.db.set_value("Sales Order", {"project": self.name}, "project", "")
|
||||
|
||||
def update_percent_complete(self):
|
||||
if self.status == "Completed":
|
||||
if (
|
||||
len(frappe.get_all("Task", dict(project=self.name))) == 0
|
||||
): # A project without tasks should be able to complete
|
||||
self.percent_complete_method = "Manual"
|
||||
self.percent_complete = 100
|
||||
|
||||
if self.percent_complete_method == "Manual":
|
||||
if self.status == "Completed":
|
||||
self.percent_complete = 100
|
||||
|
||||
@@ -199,6 +199,34 @@ class TestProject(FrappeTestCase):
|
||||
if not pt.is_group:
|
||||
self.assertIsNotNone(pt.parent_task)
|
||||
|
||||
def test_project_having_no_tasks_complete(self):
|
||||
project_name = "Test Project - No Tasks Completion"
|
||||
frappe.db.sql(""" delete from tabTask where project = %s """, project_name)
|
||||
frappe.delete_doc("Project", project_name)
|
||||
|
||||
project = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Project",
|
||||
"project_name": project_name,
|
||||
"status": "Open",
|
||||
"expected_start_date": nowdate(),
|
||||
"company": "_Test Company",
|
||||
}
|
||||
).insert()
|
||||
|
||||
tasks = frappe.get_all(
|
||||
"Task",
|
||||
["subject", "exp_end_date", "depends_on_tasks", "name", "parent_task"],
|
||||
dict(project=project.name),
|
||||
order_by="creation asc",
|
||||
)
|
||||
|
||||
self.assertEqual(project.status, "Open")
|
||||
self.assertEqual(len(tasks), 0)
|
||||
project.status = "Completed"
|
||||
project.save()
|
||||
self.assertEqual(project.status, "Completed")
|
||||
|
||||
|
||||
def get_project(name, template):
|
||||
project = frappe.get_doc(
|
||||
|
||||
@@ -25,6 +25,9 @@ class BOMConfigurator {
|
||||
};
|
||||
|
||||
frappe.views.trees["BOM Configurator"] = new frappe.views.TreeView(options);
|
||||
let node = frappe.views.trees["BOM Configurator"].tree.root_node;
|
||||
frappe.views.trees["BOM Configurator"].tree.show_toolbar(node);
|
||||
frappe.views.trees["BOM Configurator"].tree.load_children(node, true);
|
||||
this.tree_view = frappe.views.trees["BOM Configurator"];
|
||||
}
|
||||
|
||||
@@ -137,7 +140,7 @@ class BOMConfigurator {
|
||||
btnClass: "hidden-xs",
|
||||
},
|
||||
{
|
||||
label: __("Expand All"),
|
||||
label: __("Collapse All"),
|
||||
click: function (node) {
|
||||
let view = frappe.views.trees["BOM Configurator"];
|
||||
|
||||
@@ -283,6 +286,13 @@ class BOMConfigurator {
|
||||
fieldtype: "Float",
|
||||
reqd: 1,
|
||||
read_only: read_only,
|
||||
change() {
|
||||
this.layout.fields_dict.items.grid.data.forEach((row) => {
|
||||
row.qty = flt(this.value);
|
||||
});
|
||||
|
||||
this.layout.fields_dict.items.grid.refresh();
|
||||
},
|
||||
},
|
||||
{ fieldtype: "Section Break" },
|
||||
{
|
||||
|
||||
@@ -1258,6 +1258,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
"Purchase Receipt": ["purchase_order_item", "purchase_invoice_item", "purchase_receipt_item"],
|
||||
"Purchase Invoice": ["purchase_order_item", "pr_detail", "po_detail"],
|
||||
"Sales Order": ["prevdoc_docname", "quotation_item"],
|
||||
"Purchase Order": ["supplier_quotation_item"],
|
||||
};
|
||||
const mappped_fields = mapped_item_field_map[this.frm.doc.doctype] || [];
|
||||
|
||||
@@ -1501,6 +1502,31 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
}
|
||||
}
|
||||
|
||||
batch_no(frm, cdt, cdn) {
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.use_serial_batch_fields && row.batch_no) {
|
||||
var params = this._get_args(row);
|
||||
params.batch_no = row.batch_no;
|
||||
params.uom = row.uom;
|
||||
|
||||
frappe.call({
|
||||
method: "erpnext.stock.get_item_details.get_batch_based_item_price",
|
||||
args: {
|
||||
params: params,
|
||||
item_code: row.item_code,
|
||||
},
|
||||
callback: function(r) {
|
||||
if (!r.exc && r.message) {
|
||||
row.price_list_rate = r.message;
|
||||
row.rate = r.message;
|
||||
refresh_field("rate", row.name, row.parentfield);
|
||||
refresh_field("price_list_rate", row.name, row.parentfield);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
toggle_item_grid_columns(company_currency) {
|
||||
const me = this;
|
||||
// toggle columns
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
{% $.each(workstations, (idx, row) => { %}
|
||||
<div class="workstation-wrapper">
|
||||
<div class="workstation-status text-right">
|
||||
{% if(row.status == "Production") { %}
|
||||
<div class="ring-container">
|
||||
<div class="ringring"></div>
|
||||
<div class="circle"></div>
|
||||
</div>
|
||||
{% } %}
|
||||
<span class="indicator-pill no-indicator-dot whitespace-nowrap {{row.color}}" style="margin: 3px 4px 0px 0px;">
|
||||
<span style="font-size:13px">{{row.status}}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="workstation-image">
|
||||
<div class="flex items-center justify-center h-32 border-b-grey text-6xl text-grey-100">
|
||||
<a class="workstation-image-link" href="{{row.workstation_link}}">
|
||||
@@ -11,9 +22,10 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="workstation-card text-center">
|
||||
<p style="background-color:{{row.background_color}};color:#fff">{{row.status}}</p>
|
||||
<div>{{row.workstation_name}}</div>
|
||||
<div class="workstation-card" style="display: grid;">
|
||||
<span class="ellipsis" title="{{row.name}}">
|
||||
{{row.workstation_name}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% }); %}
|
||||
{% }); %}
|
||||
|
||||
@@ -15,10 +15,11 @@ erpnext.sales_common = {
|
||||
onload() {
|
||||
super.onload();
|
||||
this.setup_queries();
|
||||
this.frm.set_query("shipping_rule", function () {
|
||||
this.frm.set_query("shipping_rule", function (doc) {
|
||||
return {
|
||||
filters: {
|
||||
shipping_rule_type: "Selling",
|
||||
company: doc.company,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@@ -507,6 +507,47 @@ body[data-route="pos"] {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.ring-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.circle {
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
background-color: #278f5e;
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
left: 9px;
|
||||
top: 8px;
|
||||
}
|
||||
|
||||
@keyframes pulsate {
|
||||
0% {
|
||||
-webkit-transform: scale(0.1, 0.1);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: scale(1.2, 1.2);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.ringring {
|
||||
border: 2px solid #62bd19;
|
||||
-webkit-border-radius: 40px;
|
||||
height: 15px;
|
||||
width: 15px;
|
||||
position: absolute;
|
||||
left: 6px;
|
||||
top: 5px;
|
||||
-webkit-animation: pulsate 3s ease-out;
|
||||
-webkit-animation-iteration-count: infinite;
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.plant-floor {
|
||||
padding-bottom: 25px;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ frappe.ui.form.on("Quotation", {
|
||||
frm.trigger("set_label");
|
||||
frm.trigger("toggle_reqd_lead_customer");
|
||||
frm.trigger("set_dynamic_field_label");
|
||||
frm.set_value("party_name", "");
|
||||
// frm.set_value("party_name", ""); // removed to set party_name from url for crm integration
|
||||
frm.set_value("customer_name", "");
|
||||
},
|
||||
|
||||
|
||||
@@ -220,6 +220,10 @@ class Quotation(SellingController):
|
||||
"Lead", self.party_name, ["lead_name", "company_name"]
|
||||
)
|
||||
self.customer_name = company_name or lead_name
|
||||
elif self.party_name and self.quotation_to == "Prospect":
|
||||
self.customer_name = self.party_name
|
||||
elif self.party_name and self.quotation_to == "CRM Deal":
|
||||
self.customer_name = frappe.db.get_value("CRM Deal", self.party_name, "organization")
|
||||
|
||||
def update_opportunity(self, status):
|
||||
for opportunity in set(d.prevdoc_docname for d in self.get("items")):
|
||||
|
||||
@@ -1251,7 +1251,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex
|
||||
],
|
||||
},
|
||||
],
|
||||
primary_action_label: "Create Purchase Order",
|
||||
primary_action_label: __("Create Purchase Order"),
|
||||
primary_action(args) {
|
||||
if (!args) return;
|
||||
|
||||
|
||||
@@ -389,28 +389,14 @@ erpnext.PointOfSale.ItemCart = class {
|
||||
placeholder: discount ? discount + "%" : __("Enter discount percentage."),
|
||||
input_class: "input-xs",
|
||||
onchange: function () {
|
||||
if (flt(this.value) != 0) {
|
||||
frappe.model.set_value(
|
||||
frm.doc.doctype,
|
||||
frm.doc.name,
|
||||
"additional_discount_percentage",
|
||||
flt(this.value)
|
||||
);
|
||||
me.hide_discount_control(this.value);
|
||||
} else {
|
||||
frappe.model.set_value(
|
||||
frm.doc.doctype,
|
||||
frm.doc.name,
|
||||
"additional_discount_percentage",
|
||||
0
|
||||
);
|
||||
me.$add_discount_elem.css({
|
||||
border: "1px dashed var(--gray-500)",
|
||||
padding: "var(--padding-sm) var(--padding-md)",
|
||||
});
|
||||
me.$add_discount_elem.html(`${me.get_discount_icon()} ${__("Add Discount")}`);
|
||||
me.discount_field = undefined;
|
||||
}
|
||||
this.value = flt(this.value);
|
||||
frappe.model.set_value(
|
||||
frm.doc.doctype,
|
||||
frm.doc.name,
|
||||
"additional_discount_percentage",
|
||||
flt(this.value)
|
||||
);
|
||||
me.hide_discount_control(this.value);
|
||||
},
|
||||
},
|
||||
parent: this.$add_discount_elem.find(".add-discount-field"),
|
||||
@@ -421,9 +407,13 @@ erpnext.PointOfSale.ItemCart = class {
|
||||
}
|
||||
|
||||
hide_discount_control(discount) {
|
||||
if (!discount) {
|
||||
this.$add_discount_elem.css({ padding: "0px", border: "none" });
|
||||
this.$add_discount_elem.html(`<div class="add-discount-field"></div>`);
|
||||
if (!flt(discount)) {
|
||||
this.$add_discount_elem.css({
|
||||
border: "1px dashed var(--gray-500)",
|
||||
padding: "var(--padding-sm) var(--padding-md)",
|
||||
});
|
||||
this.$add_discount_elem.html(`${this.get_discount_icon()} ${__("Add Discount")}`);
|
||||
this.discount_field = undefined;
|
||||
} else {
|
||||
this.$add_discount_elem.css({
|
||||
border: "1px dashed var(--dark-green-500)",
|
||||
@@ -1051,6 +1041,7 @@ erpnext.PointOfSale.ItemCart = class {
|
||||
this.highlight_checkout_btn(false);
|
||||
}
|
||||
|
||||
this.hide_discount_control(frm.doc.additional_discount_percentage);
|
||||
this.update_totals_section(frm);
|
||||
|
||||
if (frm.doc.docstatus === 1) {
|
||||
|
||||
@@ -149,7 +149,11 @@ class HolidayList(Document):
|
||||
unique_dates = []
|
||||
for row in self.holidays:
|
||||
if row.holiday_date in unique_dates:
|
||||
frappe.throw(_("Holiday Date {0} added multiple times").format(frappe.bold(row.holiday_date)))
|
||||
frappe.throw(
|
||||
_("Holiday Date {0} added multiple times").format(
|
||||
frappe.bold(formatdate(row.holiday_date))
|
||||
)
|
||||
)
|
||||
|
||||
unique_dates.append(row.holiday_date)
|
||||
|
||||
|
||||
@@ -485,8 +485,14 @@ def is_deletion_doc_running(company: str | None = None, err_msg: str | None = No
|
||||
|
||||
def check_for_running_deletion_job(doc, method=None):
|
||||
# Check if DocType has 'company' field
|
||||
df = qb.DocType("DocField")
|
||||
if qb.from_(df).select(df.parent).where((df.fieldname == "company") & (df.parent == doc.doctype)).run():
|
||||
is_deletion_doc_running(
|
||||
doc.company, _("Cannot make any transactions until the deletion job is completed")
|
||||
)
|
||||
if doc.doctype not in ("GL Entry", "Payment Ledger Entry", "Stock Ledger Entry"):
|
||||
df = qb.DocType("DocField")
|
||||
if (
|
||||
qb.from_(df)
|
||||
.select(df.parent)
|
||||
.where((df.fieldname == "company") & (df.parent == doc.doctype))
|
||||
.run()
|
||||
):
|
||||
is_deletion_doc_running(
|
||||
doc.company, _("Cannot make any transactions until the deletion job is completed")
|
||||
)
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
{
|
||||
"chart_name": "Oldest Items",
|
||||
"chart_type": "Report",
|
||||
"creation": "2020-07-20 21:01:04.336845",
|
||||
"creation": "2022-03-30 00:58:02.041721",
|
||||
"custom_options": "{\"colors\": [\"#5e64ff\"]}",
|
||||
"docstatus": 0,
|
||||
"doctype": "Dashboard Chart",
|
||||
"dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"to_date\":\"frappe.datetime.nowdate()\"}",
|
||||
"filters_json": "{\"range1\":30,\"range2\":60,\"range3\":90,\"show_warehouse_wise_stock\":0}",
|
||||
"dynamic_filters_json": "{\"company\":\"frappe.defaults.get_user_default(\\\"Company\\\")\",\"to_date\":\"frappe.datetime.nowdate()\",\"range1\":\"30\",\"range2\":\"60\",\"range3\":\"90\"}",
|
||||
"filters_json": "{\"range\":\"30, 60, 90\",\"show_warehouse_wise_stock\":0}",
|
||||
"idx": 0,
|
||||
"is_public": 1,
|
||||
"is_standard": 1,
|
||||
"modified": "2020-07-29 14:50:26.846482",
|
||||
"modified": "2024-09-23 22:37:51.392999",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Oldest Items",
|
||||
"number_of_groups": 0,
|
||||
"owner": "Administrator",
|
||||
"owner": "rohitw1991@gmail.com",
|
||||
"report_name": "Stock Ageing",
|
||||
"roles": [],
|
||||
"timeseries": 0,
|
||||
"type": "Bar",
|
||||
"use_report_chart": 1,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div>
|
||||
<a href={{ route }}>{{ title }}</a>
|
||||
<a href={{ route }}>{{ title or name }}</a>
|
||||
</div>
|
||||
<!-- this is a sample default list template -->
|
||||
|
||||
@@ -60,7 +60,7 @@ frappe.ui.form.on("Quality Inspection", {
|
||||
|
||||
refresh: function (frm) {
|
||||
// Ignore cancellation of reference doctype on cancel all.
|
||||
frm.ignore_doctypes_on_cancel_all = [frm.doc.reference_type];
|
||||
frm.ignore_doctypes_on_cancel_all = [frm.doc.reference_type, "Serial and Batch Bundle"];
|
||||
},
|
||||
|
||||
item_code: function (frm) {
|
||||
|
||||
@@ -109,6 +109,8 @@ class QualityInspection(Document):
|
||||
self.update_qc_reference()
|
||||
|
||||
def on_cancel(self):
|
||||
self.ignore_linked_doctypes = "Serial and Batch Bundle"
|
||||
|
||||
self.update_qc_reference()
|
||||
|
||||
def on_trash(self):
|
||||
|
||||
@@ -3148,11 +3148,13 @@ def get_available_materials(work_order) -> dict:
|
||||
|
||||
if row.serial_no:
|
||||
for serial_no in get_serial_nos(row.serial_no):
|
||||
item_data.serial_nos.remove(serial_no)
|
||||
if serial_no in item_data.serial_nos:
|
||||
item_data.serial_nos.remove(serial_no)
|
||||
|
||||
elif row.serial_nos:
|
||||
for serial_no in get_serial_nos(row.serial_nos):
|
||||
item_data.serial_nos.remove(serial_no)
|
||||
if serial_no in item_data.serial_nos:
|
||||
item_data.serial_nos.remove(serial_no)
|
||||
|
||||
return available_materials
|
||||
|
||||
@@ -3270,6 +3272,9 @@ def create_serial_and_batch_bundle(parent_doc, row, child, type_of_transaction=N
|
||||
for batch_no, qty in row.batches_to_be_consume.items():
|
||||
doc.append("entries", {"batch_no": batch_no, "warehouse": row.warehouse, "qty": qty * -1})
|
||||
|
||||
if not doc.entries:
|
||||
return None
|
||||
|
||||
return doc.insert(ignore_permissions=True).name
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from frappe.model import child_table_fields, default_fields
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.model.utils import get_fetch_values
|
||||
from frappe.query_builder.functions import IfNull, Sum
|
||||
from frappe.utils import add_days, add_months, cint, cstr, flt, getdate
|
||||
from frappe.utils import add_days, add_months, cint, cstr, flt, getdate, parse_json
|
||||
|
||||
from erpnext import get_company_currency
|
||||
from erpnext.accounts.doctype.pricing_rule.pricing_rule import (
|
||||
@@ -889,7 +889,7 @@ def insert_item_price(args):
|
||||
)
|
||||
|
||||
|
||||
def get_item_price(args, item_code, ignore_party=False):
|
||||
def get_item_price(args, item_code, ignore_party=False, force_batch_no=False) -> list[dict]:
|
||||
"""
|
||||
Get name, price_list_rate from Item Price based on conditions
|
||||
Check if the desired qty is within the increment of the packing list.
|
||||
@@ -906,13 +906,17 @@ def get_item_price(args, item_code, ignore_party=False):
|
||||
(ip.item_code == item_code)
|
||||
& (ip.price_list == args.get("price_list"))
|
||||
& (IfNull(ip.uom, "").isin(["", args.get("uom")]))
|
||||
& (IfNull(ip.batch_no, "").isin(["", args.get("batch_no")]))
|
||||
)
|
||||
.orderby(ip.valid_from, order=frappe.qb.desc)
|
||||
.orderby(IfNull(ip.batch_no, ""), order=frappe.qb.desc)
|
||||
.orderby(ip.uom, order=frappe.qb.desc)
|
||||
)
|
||||
|
||||
if force_batch_no:
|
||||
query = query.where(ip.batch_no == args.get("batch_no"))
|
||||
else:
|
||||
query = query.where(IfNull(ip.batch_no, "").isin(["", args.get("batch_no")]))
|
||||
|
||||
if not ignore_party:
|
||||
if args.get("customer"):
|
||||
query = query.where(ip.customer == args.get("customer"))
|
||||
@@ -930,6 +934,21 @@ def get_item_price(args, item_code, ignore_party=False):
|
||||
return query.run()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_batch_based_item_price(params, item_code) -> float:
|
||||
if isinstance(params, str):
|
||||
params = parse_json(params)
|
||||
|
||||
item_price = get_item_price(params, item_code, force_batch_no=True)
|
||||
if not item_price:
|
||||
item_price = get_item_price(params, item_code, ignore_party=True, force_batch_no=True)
|
||||
|
||||
if item_price and item_price[0].uom == params.get("uom"):
|
||||
return item_price[0].price_list_rate
|
||||
|
||||
return 0.0
|
||||
|
||||
|
||||
def get_price_list_rate_for(args, item_code):
|
||||
"""
|
||||
:param customer: link to Customer DocType
|
||||
|
||||
@@ -107,6 +107,12 @@ frappe.query_reports["Stock Balance"] = {
|
||||
fieldtype: "Check",
|
||||
default: 0,
|
||||
},
|
||||
{
|
||||
fieldname: "show_dimension_wise_stock",
|
||||
label: __("Show Dimension Wise Stock"),
|
||||
fieldtype: "Check",
|
||||
default: 0,
|
||||
},
|
||||
],
|
||||
|
||||
formatter: function (value, row, column, data, default_formatter) {
|
||||
|
||||
@@ -252,7 +252,10 @@ class StockBalanceReport:
|
||||
group_by_key = [row.company, row.item_code, row.warehouse]
|
||||
|
||||
for fieldname in self.inventory_dimensions:
|
||||
if self.filters.get(fieldname):
|
||||
if not row.get(fieldname):
|
||||
continue
|
||||
|
||||
if self.filters.get(fieldname) or self.filters.get("show_dimension_wise_stock"):
|
||||
group_by_key.append(row.get(fieldname))
|
||||
|
||||
return tuple(group_by_key)
|
||||
|
||||
@@ -4480,10 +4480,23 @@ Payment Reconciliation,Zahlungsabgleich,
|
||||
Receivable / Payable Account,Forderungen-/Verbindlichkeiten-Konto,
|
||||
Bank / Cash Account,Bank / Geldkonto,
|
||||
From Invoice Date,Ab Rechnungsdatum,
|
||||
To Invoice Date,Um Datum Rechnung,
|
||||
Minimum Invoice Amount,Mindestabrechnung,
|
||||
To Invoice Date,Bis Rechnungsdatum,
|
||||
Invoice Limit,Max. Anzahl Rechnungen,
|
||||
From Payment Date,Ab Zahlungsdatum,
|
||||
To Payment Date,Bis Zahlungsdatum,
|
||||
Payment Limit,Max. Anzahl Zahlungen,
|
||||
Minimum Invoice Amount,Minimaler Rechnungsbetrag,
|
||||
Maximum Invoice Amount,Maximaler Rechnungsbetrag,
|
||||
System will fetch all the entries if limit value is zero.,"Das System ruft alle Einträge ab, wenn der Grenzwert Null ist.",
|
||||
Minimum Payment Amount,Minimaler Zahlungsbetrag,
|
||||
Maximum Payment Amount,Maximaler Zahlungsbetrag,
|
||||
Filter on Invoice,Filter auf Rechnungsnr.,
|
||||
Filter on Payment,Filter auf Zahlungsnr.,
|
||||
"If you need to reconcile particular transactions against each other, then please select accordingly. If not, all the transactions will be allocated in FIFO order.","Wenn Sie bestimmte Transaktionen gegeneinander abgleichen müssen, wählen Sie diese bitte entsprechend aus. Andernfalls werden alle Transaktionen in FIFO-Reihenfolge zugewiesen.",
|
||||
System will fetch all the entries if limit value is zero.,"Das System ruft alle Einträge ab, wenn die max. Anzahl Null ist.",
|
||||
This filter will be applied to Journal Entry.,Dieser Filter wird auf Buchungssätze angewendet.,
|
||||
Unreconciled Entries,Nicht zugeordnete Buchungen,
|
||||
Allocated Entries,Zugewiesene Buchungen,
|
||||
Accounting Dimensions Filter,Filetr nach Buchhaltungsdimensionen,
|
||||
Get Unreconciled Entries,Nicht zugeordnete Buchungen aufrufen,
|
||||
Unreconciled Payment Details,Nicht abgeglichene Zahlungen,
|
||||
Invoice/Journal Entry Details,Einzelheiten zu Rechnungs-/Journalbuchungen,
|
||||
|
||||
|
Can't render this file because it is too large.
|
Reference in New Issue
Block a user