mirror of
https://github.com/frappe/erpnext.git
synced 2026-07-28 23:18:19 +00:00
Compare commits
165 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fd68f7204 | ||
|
|
760af497ca | ||
|
|
2e6f1378f1 | ||
|
|
2d0e1830a9 | ||
|
|
1cc887a997 | ||
|
|
ee7474ba20 | ||
|
|
a2a8558677 | ||
|
|
cc07213faa | ||
|
|
f4e3f0d656 | ||
|
|
0379ea5086 | ||
|
|
65005d8630 | ||
|
|
3f3fc8214d | ||
|
|
b529883897 | ||
|
|
3d621d47a6 | ||
|
|
8fe346aef8 | ||
|
|
952cee3d6a | ||
|
|
41e384326e | ||
|
|
f42e93bf6c | ||
|
|
a3146c39dd | ||
|
|
a15ad804d0 | ||
|
|
8c496fbf2b | ||
|
|
36ba33c500 | ||
|
|
c2eeeecac8 | ||
|
|
c9d4c41db3 | ||
|
|
71f9b7f675 | ||
|
|
0ebd133eda | ||
|
|
d0e1162c96 | ||
|
|
7b4b630b2c | ||
|
|
5e517cfc77 | ||
|
|
2ea2146b34 | ||
|
|
856926d664 | ||
|
|
0f6477a253 | ||
|
|
580e9f6e10 | ||
|
|
69c460c756 | ||
|
|
06d193ad87 | ||
|
|
f6b10f3d84 | ||
|
|
f236a2c081 | ||
|
|
2866f7c441 | ||
|
|
948045ea32 | ||
|
|
080a742725 | ||
|
|
feaa16d748 | ||
|
|
6ca29a93bf | ||
|
|
20aac93731 | ||
|
|
43cc7e4a59 | ||
|
|
71ecf081c3 | ||
|
|
26ae708d6d | ||
|
|
7d64df05bc | ||
|
|
b6a36270b2 | ||
|
|
fa442ca788 | ||
|
|
558861b634 | ||
|
|
2c90ee23f9 | ||
|
|
78771cd72f | ||
|
|
bfc94cf284 | ||
|
|
cad15cdec2 | ||
|
|
96dfcd7149 | ||
|
|
c7d17d21e8 | ||
|
|
fe9acc898e | ||
|
|
b8dce3eeac | ||
|
|
1cbe1e894d | ||
|
|
81ef7b4c00 | ||
|
|
88e5c9e61b | ||
|
|
c0b598074c | ||
|
|
04fb215ff5 | ||
|
|
a2cba1bf23 | ||
|
|
29d383ad8b | ||
|
|
e4d6df39ff | ||
|
|
7ad42ec957 | ||
|
|
c74e6aaebb | ||
|
|
92d61eb19e | ||
|
|
6e479f918d | ||
|
|
8e8d0ad9aa | ||
|
|
400c78c600 | ||
|
|
f6f2712db0 | ||
|
|
1eee203f7f | ||
|
|
ec337a1c9f | ||
|
|
7577706a9d | ||
|
|
81b5e6c5f1 | ||
|
|
28f052d586 | ||
|
|
2eac618bba | ||
|
|
6f6de13813 | ||
|
|
be1a269f9f | ||
|
|
0d70be56d2 | ||
|
|
50655821c1 | ||
|
|
b254a72d41 | ||
|
|
2770ca1b65 | ||
|
|
0d7cb1a9be | ||
|
|
3abb91b2c4 | ||
|
|
a63b8df867 | ||
|
|
3b9feffc00 | ||
|
|
0c13cb829c | ||
|
|
8aba707b6a | ||
|
|
98bfcc4c75 | ||
|
|
3a668bbe96 | ||
|
|
f2f410093a | ||
|
|
8169c7de0d | ||
|
|
eefac19cc8 | ||
|
|
afc049154d | ||
|
|
4d1ccd9e27 | ||
|
|
c48c8b8ddb | ||
|
|
c2f692a4e4 | ||
|
|
d94b5a318d | ||
|
|
30cb218638 | ||
|
|
d9e0d55b88 | ||
|
|
1e9b4e2403 | ||
|
|
8657ba374a | ||
|
|
3a8b7e9b96 | ||
|
|
22b442d593 | ||
|
|
f7bfbd82dd | ||
|
|
d375164100 | ||
|
|
7fdac62393 | ||
|
|
2184e8ef58 | ||
|
|
87e8dd0d63 | ||
|
|
857843bc29 | ||
|
|
37a18299d0 | ||
|
|
e0c8ff10da | ||
|
|
61b02ec75c | ||
|
|
939b7f7cbf | ||
|
|
77da0da945 | ||
|
|
226d0e0196 | ||
|
|
4114760efd | ||
|
|
23042dfc3c | ||
|
|
9216a852d4 | ||
|
|
6478c80359 | ||
|
|
e18dc5cea3 | ||
|
|
fb5090fd3f | ||
|
|
39aa36e44b | ||
|
|
20a764a4a3 | ||
|
|
24ae45ce84 | ||
|
|
a14e7f0e84 | ||
|
|
7eee573fcb | ||
|
|
0894022695 | ||
|
|
3c717db3fd | ||
|
|
942f34a734 | ||
|
|
4821919695 | ||
|
|
34549b62bd | ||
|
|
d593f81a16 | ||
|
|
e05b23c388 | ||
|
|
d4c131b153 | ||
|
|
9836205725 | ||
|
|
98198d35ea | ||
|
|
12cd7a7083 | ||
|
|
e539152c6b | ||
|
|
6ed7c6610a | ||
|
|
d6d717c315 | ||
|
|
935e23449f | ||
|
|
ed9b38bc8d | ||
|
|
2c52f2ce13 | ||
|
|
1469ca7d0b | ||
|
|
73d525e84d | ||
|
|
f6c611d026 | ||
|
|
30b6321fd5 | ||
|
|
20a26c3dd4 | ||
|
|
d975eccaab | ||
|
|
cdef0bd503 | ||
|
|
a714114cd9 | ||
|
|
bf585de558 | ||
|
|
dda95ea892 | ||
|
|
229075048b | ||
|
|
0d49dd3648 | ||
|
|
038a30feb0 | ||
|
|
c63f873a6f | ||
|
|
df93447d30 | ||
|
|
7477ff3b5c | ||
|
|
812b301aab | ||
|
|
9dfe342838 |
@@ -5,7 +5,7 @@ fail_fast: false
|
||||
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.0.1
|
||||
rev: v4.3.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
files: "erpnext.*"
|
||||
@@ -15,6 +15,10 @@ repos:
|
||||
args: ['--branch', 'develop']
|
||||
- id: check-merge-conflict
|
||||
- id: check-ast
|
||||
- id: check-json
|
||||
- id: check-toml
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 5.0.4
|
||||
|
||||
@@ -3,7 +3,7 @@ import inspect
|
||||
|
||||
import frappe
|
||||
|
||||
__version__ = "14.54.1"
|
||||
__version__ = "14.60.0"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
@@ -53,8 +53,13 @@
|
||||
},
|
||||
"II. Forderungen und sonstige Vermögensgegenstände": {
|
||||
"is_group": 1,
|
||||
"Ford. a. Lieferungen und Leistungen": {
|
||||
"Forderungen aus Lieferungen und Leistungen mit Kontokorrent": {
|
||||
"account_number": "1400",
|
||||
"account_type": "Receivable",
|
||||
"is_group": 1
|
||||
},
|
||||
"Forderungen aus Lieferungen und Leistungen ohne Kontokorrent": {
|
||||
"account_number": "1410",
|
||||
"account_type": "Receivable"
|
||||
},
|
||||
"Durchlaufende Posten": {
|
||||
@@ -180,8 +185,13 @@
|
||||
},
|
||||
"IV. Verbindlichkeiten aus Lieferungen und Leistungen": {
|
||||
"is_group": 1,
|
||||
"Verbindlichkeiten aus Lieferungen u. Leistungen": {
|
||||
"Verbindlichkeiten aus Lieferungen und Leistungen mit Kontokorrent": {
|
||||
"account_number": "1600",
|
||||
"account_type": "Payable",
|
||||
"is_group": 1
|
||||
},
|
||||
"Verbindlichkeiten aus Lieferungen und Leistungen ohne Kontokorrent": {
|
||||
"account_number": "1610",
|
||||
"account_type": "Payable"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -407,13 +407,10 @@
|
||||
"Bewertungskorrektur zu Forderungen aus Lieferungen und Leistungen": {
|
||||
"account_number": "9960"
|
||||
},
|
||||
"Debitoren": {
|
||||
"is_group": 1,
|
||||
"account_number": "10000"
|
||||
},
|
||||
"Forderungen aus Lieferungen und Leistungen": {
|
||||
"Forderungen aus Lieferungen und Leistungen mit Kontokorrent": {
|
||||
"account_number": "1200",
|
||||
"account_type": "Receivable"
|
||||
"account_type": "Receivable",
|
||||
"is_group": 1
|
||||
},
|
||||
"Forderungen aus Lieferungen und Leistungen ohne Kontokorrent": {
|
||||
"account_number": "1210"
|
||||
@@ -1138,18 +1135,15 @@
|
||||
"Bewertungskorrektur zu Verb. aus Lieferungen und Leistungen": {
|
||||
"account_number": "9964"
|
||||
},
|
||||
"Kreditoren": {
|
||||
"account_number": "70000",
|
||||
"Verb. aus Lieferungen und Leistungen mit Kontokorrent": {
|
||||
"account_number": "3300",
|
||||
"account_type": "Payable",
|
||||
"is_group": 1,
|
||||
"Wareneingangs-Verrechnungskonto" : {
|
||||
"Wareneingangs-Verrechnungskonto" : {
|
||||
"account_number": "70001",
|
||||
"account_type": "Stock Received But Not Billed"
|
||||
}
|
||||
},
|
||||
"Verb. aus Lieferungen und Leistungen": {
|
||||
"account_number": "3300",
|
||||
"account_type": "Payable"
|
||||
},
|
||||
"Verb. aus Lieferungen und Leistungen ohne Kontokorrent": {
|
||||
"account_number": "3310"
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
{
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
"in_list_view": 1,
|
||||
"label": "Company",
|
||||
"options": "Company",
|
||||
@@ -19,7 +20,7 @@
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-05-01 12:32:34.044911",
|
||||
"modified": "2024-01-03 11:13:02.669632",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Allowed To Transact With",
|
||||
@@ -28,5 +29,6 @@
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -137,7 +137,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
||||
"erpnext.accounts.doctype.bank_reconciliation_tool.bank_reconciliation_tool.get_account_balance",
|
||||
args: {
|
||||
bank_account: frm.doc.bank_account,
|
||||
till_date: frm.doc.bank_statement_from_date,
|
||||
till_date: frappe.datetime.add_days(frm.doc.bank_statement_from_date, -1)
|
||||
},
|
||||
callback: (response) => {
|
||||
frm.set_value("account_opening_balance", response.message);
|
||||
|
||||
@@ -1,457 +1,152 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"actions": [],
|
||||
"autoname": "naming_series:",
|
||||
"beta": 0,
|
||||
"creation": "2018-06-18 16:51:49.994750",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"naming_series",
|
||||
"user",
|
||||
"date",
|
||||
"from_time",
|
||||
"time",
|
||||
"expense",
|
||||
"custody",
|
||||
"returns",
|
||||
"outstanding_amount",
|
||||
"payments",
|
||||
"net_amount",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "POS-CLO-",
|
||||
"fieldname": "naming_series",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 1,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Series",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "POS-CLO-",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "user",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "User",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "User",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "Today",
|
||||
"fieldname": "date",
|
||||
"fieldtype": "Date",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Date",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "from_time",
|
||||
"fieldtype": "Time",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "From Time",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "",
|
||||
"fieldname": "time",
|
||||
"fieldtype": "Time",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 1,
|
||||
"label": "To Time",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "0.00",
|
||||
"fieldname": "expense",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Expense",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"label": "Expense"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "0.00",
|
||||
"fieldname": "custody",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Custody",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"label": "Custody"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "0.00",
|
||||
"fieldname": "returns",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Returns",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "2",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"unique": 0
|
||||
"precision": "2"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "0.00",
|
||||
"fieldname": "outstanding_amount",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Outstanding Amount",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"default": "0.0",
|
||||
"fieldname": "payments",
|
||||
"fieldtype": "Table",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Payments",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Cashier Closing Payments",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"options": "Cashier Closing Payments"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "net_amount",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 1,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Net Amount",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "amended_from",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Amended From",
|
||||
"length": 0,
|
||||
"no_copy": 1,
|
||||
"options": "Cashier Closing",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 1,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 1,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-02-19 08:35:24.157327",
|
||||
"links": [],
|
||||
"modified": "2023-12-28 13:15:46.858427",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Cashier Closing",
|
||||
"name_case": "",
|
||||
"naming_rule": "By \"Naming Series\" field",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
}
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -138,8 +138,7 @@
|
||||
"label": "Against Voucher Type",
|
||||
"oldfieldname": "against_voucher_type",
|
||||
"oldfieldtype": "Data",
|
||||
"options": "DocType",
|
||||
"search_index": 1
|
||||
"options": "DocType"
|
||||
},
|
||||
{
|
||||
"fieldname": "against_voucher",
|
||||
@@ -158,8 +157,7 @@
|
||||
"label": "Voucher Type",
|
||||
"oldfieldname": "voucher_type",
|
||||
"oldfieldtype": "Select",
|
||||
"options": "DocType",
|
||||
"search_index": 1
|
||||
"options": "DocType"
|
||||
},
|
||||
{
|
||||
"fieldname": "voucher_no",
|
||||
@@ -291,4 +289,4 @@
|
||||
"search_fields": "voucher_no,account,posting_date,against_voucher",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
},
|
||||
{
|
||||
"account": "Sales - _TC",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"credit_in_account_currency": 400.0,
|
||||
"debit_in_account_currency": 0.0,
|
||||
"doctype": "Journal Entry Account",
|
||||
|
||||
@@ -111,8 +111,6 @@ class PaymentReconciliation(Document):
|
||||
def get_payment_entries(self):
|
||||
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
|
||||
condition = self.get_conditions(get_payments=True)
|
||||
if self.payment_name:
|
||||
condition += "name like '%%{0}%%'".format(self.payment_name)
|
||||
|
||||
payment_entries = get_advance_payment_entries_for_regional(
|
||||
self.party_type,
|
||||
@@ -122,6 +120,7 @@ class PaymentReconciliation(Document):
|
||||
against_all_orders=True,
|
||||
limit=self.payment_limit,
|
||||
condition=condition,
|
||||
payment_name=self.payment_name,
|
||||
)
|
||||
|
||||
return payment_entries
|
||||
@@ -539,6 +538,27 @@ class PaymentReconciliation(Document):
|
||||
|
||||
invoice_exchange_map.update(purchase_invoice_map)
|
||||
|
||||
journals = [
|
||||
d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Journal Entry"
|
||||
]
|
||||
journals.extend(
|
||||
[d.get("reference_name") for d in payments if d.get("reference_type") == "Journal Entry"]
|
||||
)
|
||||
if journals:
|
||||
journals = list(set(journals))
|
||||
journals_map = frappe._dict(
|
||||
frappe.db.get_all(
|
||||
"Journal Entry Account",
|
||||
filters={"parent": ("in", journals), "account": ("in", [self.receivable_payable_account])},
|
||||
fields=[
|
||||
"parent as `name`",
|
||||
"exchange_rate",
|
||||
],
|
||||
as_list=1,
|
||||
)
|
||||
)
|
||||
invoice_exchange_map.update(journals_map)
|
||||
|
||||
return invoice_exchange_map
|
||||
|
||||
def validate_allocation(self):
|
||||
|
||||
@@ -705,7 +705,7 @@ def get_pos_reserved_qty(item_code, warehouse):
|
||||
reserved_qty = (
|
||||
frappe.qb.from_(p_inv)
|
||||
.from_(p_item)
|
||||
.select(Sum(p_item.qty).as_("qty"))
|
||||
.select(Sum(p_item.stock_qty).as_("stock_qty"))
|
||||
.where(
|
||||
(p_inv.name == p_item.parent)
|
||||
& (IfNull(p_inv.consolidated_invoice, "") == "")
|
||||
@@ -716,7 +716,7 @@ def get_pos_reserved_qty(item_code, warehouse):
|
||||
)
|
||||
).run(as_dict=True)
|
||||
|
||||
return reserved_qty[0].qty or 0 if reserved_qty else 0
|
||||
return flt(reserved_qty[0].stock_qty) if reserved_qty else 0
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
@@ -521,7 +521,7 @@ def get_qty_amount_data_for_cumulative(pr_doc, doc, items=None):
|
||||
values.extend(warehouses)
|
||||
|
||||
if items:
|
||||
condition = " and `tab{child_doc}`.{apply_on} in ({items})".format(
|
||||
condition += " and `tab{child_doc}`.{apply_on} in ({items})".format(
|
||||
child_doc=child_doctype, apply_on=apply_on, items=",".join(["%s"] * len(items))
|
||||
)
|
||||
|
||||
|
||||
@@ -415,7 +415,7 @@ def reconcile(doc: None | str = None) -> None:
|
||||
# Update the parent doc about the exception
|
||||
frappe.db.rollback()
|
||||
|
||||
traceback = frappe.get_traceback()
|
||||
traceback = frappe.get_traceback(with_context=True)
|
||||
if traceback:
|
||||
message = "Traceback: <br>" + traceback
|
||||
frappe.db.set_value("Process Payment Reconciliation Log", log, "error_log", message)
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"group_by",
|
||||
"cost_center",
|
||||
"territory",
|
||||
"ignore_exchange_rate_revaluation_journals",
|
||||
"column_break_14",
|
||||
"to_date",
|
||||
"finance_book",
|
||||
@@ -374,10 +375,16 @@
|
||||
"fieldname": "pdf_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "PDF Name"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "ignore_exchange_rate_revaluation_journals",
|
||||
"fieldtype": "Check",
|
||||
"label": "Ignore Exchange Rate Revaluation Journals"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2023-08-28 12:59:53.071334",
|
||||
"modified": "2023-12-18 12:20:08.965120",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Statement Of Accounts",
|
||||
|
||||
@@ -64,6 +64,18 @@ def get_statement_dict(doc, get_statement_dict=False):
|
||||
statement_dict = {}
|
||||
ageing = ""
|
||||
|
||||
err_journals = None
|
||||
if doc.report == "General Ledger" and doc.ignore_exchange_rate_revaluation_journals:
|
||||
err_journals = frappe.db.get_all(
|
||||
"Journal Entry",
|
||||
filters={
|
||||
"company": doc.company,
|
||||
"docstatus": 1,
|
||||
"voucher_type": ("in", ["Exchange Rate Revaluation", "Exchange Gain Or Loss"]),
|
||||
},
|
||||
as_list=True,
|
||||
)
|
||||
|
||||
for entry in doc.customers:
|
||||
if doc.include_ageing:
|
||||
ageing = set_ageing(doc, entry)
|
||||
@@ -76,6 +88,8 @@ def get_statement_dict(doc, get_statement_dict=False):
|
||||
)
|
||||
|
||||
filters = get_common_filters(doc)
|
||||
if err_journals:
|
||||
filters.update({"voucher_no_not_in": [x[0] for x in err_journals]})
|
||||
|
||||
if doc.report == "General Ledger":
|
||||
filters.update(get_gl_filters(doc, entry, tax_id, presentation_currency))
|
||||
|
||||
@@ -164,6 +164,18 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying.
|
||||
}
|
||||
})
|
||||
}, __("Get Items From"));
|
||||
|
||||
if (!this.frm.doc.is_return) {
|
||||
frappe.db.get_single_value("Buying Settings", "maintain_same_rate").then((value) => {
|
||||
if (value) {
|
||||
this.frm.doc.items.forEach((item) => {
|
||||
this.frm.fields_dict.items.grid.update_docfield_property(
|
||||
"rate", "read_only", (item.purchase_receipt && item.pr_detail)
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
this.frm.toggle_reqd("supplier_warehouse", this.frm.doc.is_subcontracted);
|
||||
|
||||
|
||||
@@ -925,17 +925,6 @@ class PurchaseInvoice(BuyingController):
|
||||
item=item,
|
||||
)
|
||||
)
|
||||
|
||||
# update gross amount of asset bought through this document
|
||||
assets = frappe.db.get_all(
|
||||
"Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code}
|
||||
)
|
||||
for asset in assets:
|
||||
frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate))
|
||||
frappe.db.set_value(
|
||||
"Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate)
|
||||
)
|
||||
|
||||
if (
|
||||
self.auto_accounting_for_stock
|
||||
and self.is_opening == "No"
|
||||
@@ -975,12 +964,25 @@ class PurchaseInvoice(BuyingController):
|
||||
item.item_tax_amount, item.precision("item_tax_amount")
|
||||
)
|
||||
|
||||
if item.is_fixed_asset and item.landed_cost_voucher_amount:
|
||||
self.update_gross_purchase_amount_for_linked_assets(item)
|
||||
|
||||
def update_gross_purchase_amount_for_linked_assets(self, item):
|
||||
assets = frappe.db.get_all(
|
||||
"Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code}
|
||||
"Asset",
|
||||
filters={"purchase_invoice": self.name, "item_code": item.item_code},
|
||||
fields=["name", "asset_quantity"],
|
||||
)
|
||||
for asset in assets:
|
||||
frappe.db.set_value("Asset", asset.name, "gross_purchase_amount", flt(item.valuation_rate))
|
||||
frappe.db.set_value("Asset", asset.name, "purchase_receipt_amount", flt(item.valuation_rate))
|
||||
purchase_amount = flt(item.valuation_rate) * asset.asset_quantity
|
||||
frappe.db.set_value(
|
||||
"Asset",
|
||||
asset.name,
|
||||
{
|
||||
"gross_purchase_amount": purchase_amount,
|
||||
"purchase_receipt_amount": purchase_amount,
|
||||
},
|
||||
)
|
||||
|
||||
def make_stock_adjustment_entry(
|
||||
self, gl_entries, item, voucher_wise_stock_value, account_currency
|
||||
@@ -1660,10 +1662,6 @@ def make_inter_company_sales_invoice(source_name, target_doc=None):
|
||||
return make_inter_company_transaction("Purchase Invoice", source_name, target_doc)
|
||||
|
||||
|
||||
def on_doctype_update():
|
||||
frappe.db.add_index("Purchase Invoice", ["supplier", "is_return", "return_against"])
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_purchase_receipt(source_name, target_doc=None):
|
||||
def update_item(obj, target, source_parent):
|
||||
|
||||
@@ -286,7 +286,6 @@
|
||||
"oldfieldname": "import_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"read_only_depends_on": "eval: (!parent.is_return && doc.purchase_receipt && doc.pr_detail)",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -894,7 +893,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-30 16:26:05.629780",
|
||||
"modified": "2023-12-25 22:00:28.043555",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Item",
|
||||
|
||||
@@ -43,7 +43,7 @@ def start_payment_ledger_repost(docname=None):
|
||||
except Exception as e:
|
||||
frappe.db.rollback()
|
||||
|
||||
traceback = frappe.get_traceback()
|
||||
traceback = frappe.get_traceback(with_context=True)
|
||||
if traceback:
|
||||
message = "Traceback: <br>" + traceback
|
||||
frappe.db.set_value(repost_doc.doctype, repost_doc.name, "repost_error_log", message)
|
||||
|
||||
@@ -890,8 +890,8 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
frm.events.append_time_log(frm, timesheet, 1.0);
|
||||
}
|
||||
});
|
||||
frm.refresh_field("timesheets");
|
||||
frm.trigger("calculate_timesheet_totals");
|
||||
frm.refresh();
|
||||
},
|
||||
|
||||
async get_exchange_rate(frm, from_currency, to_currency) {
|
||||
|
||||
@@ -2195,9 +2195,18 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
|
||||
|
||||
|
||||
def get_received_items(reference_name, doctype, reference_fieldname):
|
||||
reference_field = "inter_company_invoice_reference"
|
||||
if doctype == "Purchase Order":
|
||||
reference_field = "inter_company_order_reference"
|
||||
|
||||
filters = {
|
||||
reference_field: reference_name,
|
||||
"docstatus": 1,
|
||||
}
|
||||
|
||||
target_doctypes = frappe.get_all(
|
||||
doctype,
|
||||
filters={"inter_company_invoice_reference": reference_name, "docstatus": 1},
|
||||
filters=filters,
|
||||
as_list=True,
|
||||
)
|
||||
|
||||
@@ -2379,10 +2388,6 @@ def get_loyalty_programs(customer):
|
||||
return lp_details
|
||||
|
||||
|
||||
def on_doctype_update():
|
||||
frappe.db.add_index("Sales Invoice", ["customer", "is_return", "return_against"])
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def create_invoice_discounting(source_name, target_doc=None):
|
||||
invoice = frappe.get_doc("Sales Invoice", source_name)
|
||||
|
||||
@@ -114,14 +114,12 @@ def _get_party_details(
|
||||
set_account_and_due_date(party, account, party_type, company, posting_date, bill_date, doctype)
|
||||
)
|
||||
party = party_details[party_type.lower()]
|
||||
|
||||
if not ignore_permissions and not (
|
||||
frappe.has_permission(party_type, "read", party)
|
||||
or frappe.has_permission(party_type, "select", party)
|
||||
):
|
||||
frappe.throw(_("Not permitted for {0}").format(party), frappe.PermissionError)
|
||||
|
||||
party = frappe.get_doc(party_type, party)
|
||||
|
||||
if not ignore_permissions:
|
||||
ptype = "select" if frappe.only_has_select_perm(party_type) else "read"
|
||||
frappe.has_permission(party_type, ptype, party, throw=True)
|
||||
|
||||
currency = party.get("default_currency") or currency or get_company_currency(company)
|
||||
|
||||
party_address, shipping_address = set_address_details(
|
||||
|
||||
@@ -149,11 +149,16 @@ frappe.query_reports["Accounts Payable"] = {
|
||||
"label": __("Revaluation Journals"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "in_party_currency",
|
||||
"label": __("In Party Currency"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "ignore_accounts",
|
||||
"label": __("Group by Voucher"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"in_party_currency": 1,
|
||||
}
|
||||
|
||||
data = execute(filters)
|
||||
|
||||
@@ -181,13 +181,17 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
"label": __("Revaluation Journals"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "in_party_currency",
|
||||
"label": __("In Party Currency"),
|
||||
"fieldtype": "Check",
|
||||
},
|
||||
{
|
||||
"fieldname": "ignore_accounts",
|
||||
"label": __("Group by Voucher"),
|
||||
"fieldtype": "Check",
|
||||
}
|
||||
|
||||
|
||||
],
|
||||
|
||||
"formatter": function(value, row, column, data, default_formatter) {
|
||||
|
||||
30
erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Executable file → Normal file
30
erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Executable file → Normal file
@@ -28,8 +28,8 @@ from erpnext.accounts.utils import get_currency_precision
|
||||
# 6. Configurable Ageing Groups (0-30, 30-60 etc) can be set via filters
|
||||
# 7. For overpayment against an invoice with payment terms, there will be an additional row
|
||||
# 8. Invoice details like Sales Persons, Delivery Notes are also fetched comma separated
|
||||
# 9. Report amounts are in "Party Currency" if party is selected, or company currency for multi-party
|
||||
# 10. This reports is based on all GL Entries that are made against account_type "Receivable" or "Payable"
|
||||
# 9. Report amounts are in party currency if in_party_currency is selected, otherwise company currency
|
||||
# 10. This report is based on Payment Ledger Entries
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -84,6 +84,9 @@ class ReceivablePayableReport(object):
|
||||
self.total_row_map = {}
|
||||
self.skip_total_row = 1
|
||||
|
||||
if self.filters.get("in_party_currency"):
|
||||
self.skip_total_row = 1
|
||||
|
||||
def get_data(self):
|
||||
self.get_ple_entries()
|
||||
self.get_sales_invoices_or_customers_based_on_sales_person()
|
||||
@@ -145,7 +148,7 @@ class ReceivablePayableReport(object):
|
||||
if self.filters.get("group_by_party"):
|
||||
self.init_subtotal_row(ple.party)
|
||||
|
||||
if self.filters.get("group_by_party"):
|
||||
if self.filters.get("group_by_party") and not self.filters.get("in_party_currency"):
|
||||
self.init_subtotal_row("Total")
|
||||
|
||||
def get_invoices(self, ple):
|
||||
@@ -224,8 +227,7 @@ class ReceivablePayableReport(object):
|
||||
if not row:
|
||||
return
|
||||
|
||||
# amount in "Party Currency", if its supplied. If not, amount in company currency
|
||||
if self.filters.get("party_type") and self.filters.get("party"):
|
||||
if self.filters.get("in_party_currency") or self.filters.get("party_account"):
|
||||
amount = ple.amount_in_account_currency
|
||||
else:
|
||||
amount = ple.amount
|
||||
@@ -244,8 +246,12 @@ class ReceivablePayableReport(object):
|
||||
row.invoiced_in_account_currency += amount_in_account_currency
|
||||
else:
|
||||
if self.is_invoice(ple):
|
||||
row.credit_note -= amount
|
||||
row.credit_note_in_account_currency -= amount_in_account_currency
|
||||
if row.voucher_no == ple.voucher_no == ple.against_voucher_no:
|
||||
row.paid -= amount
|
||||
row.paid_in_account_currency -= amount_in_account_currency
|
||||
else:
|
||||
row.credit_note -= amount
|
||||
row.credit_note_in_account_currency -= amount_in_account_currency
|
||||
else:
|
||||
row.paid -= amount
|
||||
row.paid_in_account_currency -= amount_in_account_currency
|
||||
@@ -256,8 +262,10 @@ class ReceivablePayableReport(object):
|
||||
def update_sub_total_row(self, row, party):
|
||||
total_row = self.total_row_map.get(party)
|
||||
|
||||
for field in self.get_currency_fields():
|
||||
total_row[field] += row.get(field, 0.0)
|
||||
if total_row:
|
||||
for field in self.get_currency_fields():
|
||||
total_row[field] += row.get(field, 0.0)
|
||||
total_row["currency"] = row.get("currency", "")
|
||||
|
||||
def append_subtotal_row(self, party):
|
||||
sub_total_row = self.total_row_map.get(party)
|
||||
@@ -318,7 +326,7 @@ class ReceivablePayableReport(object):
|
||||
if self.filters.get("group_by_party"):
|
||||
self.append_subtotal_row(self.previous_party)
|
||||
if self.data:
|
||||
self.data.append(self.total_row_map.get("Total"))
|
||||
self.data.append(self.total_row_map.get("Total", {}))
|
||||
|
||||
def append_row(self, row):
|
||||
self.allocate_future_payments(row)
|
||||
@@ -449,7 +457,7 @@ class ReceivablePayableReport(object):
|
||||
party_details = self.get_party_details(row.party) or {}
|
||||
row.update(party_details)
|
||||
|
||||
if self.filters.get("party_type") and self.filters.get("party"):
|
||||
if self.filters.get("in_party_currency") or self.filters.get("party_account"):
|
||||
row.currency = row.account_currency
|
||||
else:
|
||||
row.currency = self.company_currency
|
||||
|
||||
@@ -76,6 +76,41 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
|
||||
return credit_note
|
||||
|
||||
def test_pos_receivable(self):
|
||||
filters = {
|
||||
"company": self.company,
|
||||
"party_type": "Customer",
|
||||
"party": [self.customer],
|
||||
"report_date": add_days(today(), 2),
|
||||
"based_on_payment_terms": 0,
|
||||
"range1": 30,
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"show_remarks": False,
|
||||
}
|
||||
|
||||
pos_inv = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
|
||||
pos_inv.posting_date = add_days(today(), 2)
|
||||
pos_inv.is_pos = 1
|
||||
pos_inv.append(
|
||||
"payments",
|
||||
frappe._dict(
|
||||
mode_of_payment="Cash",
|
||||
amount=flt(pos_inv.grand_total / 2),
|
||||
),
|
||||
)
|
||||
pos_inv.disable_rounded_total = 1
|
||||
pos_inv.save()
|
||||
pos_inv.submit()
|
||||
|
||||
report = execute(filters)
|
||||
expected_data = [[pos_inv.grand_total, pos_inv.paid_amount, 0]]
|
||||
|
||||
row = report[1][-1]
|
||||
self.assertEqual(expected_data[0], [row.invoiced, row.paid, row.credit_note])
|
||||
pos_inv.cancel()
|
||||
|
||||
def test_accounts_receivable(self):
|
||||
filters = {
|
||||
"company": self.company,
|
||||
@@ -544,7 +579,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
filters.update({"party_account": self.debtors_usd})
|
||||
report = execute(filters)[1]
|
||||
self.assertEqual(len(report), 1)
|
||||
expected_data = [8000.0, 8000.0, self.debtors_usd, si2.currency]
|
||||
expected_data = [100.0, 100.0, self.debtors_usd, si2.currency]
|
||||
row = report[0]
|
||||
self.assertEqual(
|
||||
expected_data, [row.invoiced, row.outstanding, row.party_account, row.account_currency]
|
||||
@@ -581,6 +616,7 @@ class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase):
|
||||
"range2": 60,
|
||||
"range3": 90,
|
||||
"range4": 120,
|
||||
"in_party_currency": 1,
|
||||
}
|
||||
|
||||
si = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True)
|
||||
|
||||
@@ -2,7 +2,44 @@
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.query_reports["Budget Variance Report"] = {
|
||||
"filters": [
|
||||
"filters": get_filters(),
|
||||
"formatter": function (value, row, column, data, default_formatter) {
|
||||
value = default_formatter(value, row, column, data);
|
||||
|
||||
if (column.fieldname.includes(__("variance"))) {
|
||||
|
||||
if (data[column.fieldname] < 0) {
|
||||
value = "<span style='color:red'>" + value + "</span>";
|
||||
}
|
||||
else if (data[column.fieldname] > 0) {
|
||||
value = "<span style='color:green'>" + value + "</span>";
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
function get_filters() {
|
||||
function get_dimensions() {
|
||||
let result = [];
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.accounting_dimension.accounting_dimension.get_dimensions",
|
||||
args: {
|
||||
'with_cost_center_and_project': true
|
||||
},
|
||||
async: false,
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
result = r.message[0].map(elem => elem.document_type);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
let budget_against_options = get_dimensions();
|
||||
|
||||
let filters = [
|
||||
{
|
||||
fieldname: "from_fiscal_year",
|
||||
label: __("From Fiscal Year"),
|
||||
@@ -44,9 +81,13 @@ frappe.query_reports["Budget Variance Report"] = {
|
||||
fieldname: "budget_against",
|
||||
label: __("Budget Against"),
|
||||
fieldtype: "Select",
|
||||
options: ["Cost Center", "Project"],
|
||||
options: budget_against_options,
|
||||
default: "Cost Center",
|
||||
reqd: 1,
|
||||
get_data: function() {
|
||||
console.log(this.options);
|
||||
return ["Emacs", "Rocks"];
|
||||
},
|
||||
on_change: function() {
|
||||
frappe.query_report.set_filter_value("budget_against_filter", []);
|
||||
frappe.query_report.refresh();
|
||||
@@ -71,24 +112,8 @@ frappe.query_reports["Budget Variance Report"] = {
|
||||
fieldtype: "Check",
|
||||
default: 0,
|
||||
},
|
||||
],
|
||||
"formatter": function (value, row, column, data, default_formatter) {
|
||||
value = default_formatter(value, row, column, data);
|
||||
]
|
||||
|
||||
if (column.fieldname.includes(__("variance"))) {
|
||||
|
||||
if (data[column.fieldname] < 0) {
|
||||
value = "<span style='color:red'>" + value + "</span>";
|
||||
}
|
||||
else if (data[column.fieldname] > 0) {
|
||||
value = "<span style='color:green'>" + value + "</span>";
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
erpnext.dimension_filters.forEach((dimension) => {
|
||||
frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]);
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _, scrub
|
||||
from frappe import _, qb, scrub
|
||||
from frappe.utils import getdate, nowdate
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ class PartyLedgerSummaryReport(object):
|
||||
"""
|
||||
Additional Columns for 'User Permission' based access control
|
||||
"""
|
||||
from frappe import qb
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
self.territories = frappe._dict({})
|
||||
@@ -365,13 +364,29 @@ class PartyLedgerSummaryReport(object):
|
||||
|
||||
def get_party_adjustment_amounts(self):
|
||||
conditions = self.prepare_conditions()
|
||||
income_or_expense = (
|
||||
"Expense Account" if self.filters.party_type == "Customer" else "Income Account"
|
||||
account_type = "Expense Account" if self.filters.party_type == "Customer" else "Income Account"
|
||||
income_or_expense_accounts = frappe.db.get_all(
|
||||
"Account", filters={"account_type": account_type, "company": self.filters.company}, pluck="name"
|
||||
)
|
||||
invoice_dr_or_cr = "debit" if self.filters.party_type == "Customer" else "credit"
|
||||
reverse_dr_or_cr = "credit" if self.filters.party_type == "Customer" else "debit"
|
||||
round_off_account = frappe.get_cached_value("Company", self.filters.company, "round_off_account")
|
||||
|
||||
gl = qb.DocType("GL Entry")
|
||||
if not income_or_expense_accounts:
|
||||
# prevent empty 'in' condition
|
||||
income_or_expense_accounts.append("")
|
||||
|
||||
accounts_query = (
|
||||
qb.from_(gl)
|
||||
.select(gl.voucher_type, gl.voucher_no)
|
||||
.where(
|
||||
(gl.account.isin(income_or_expense_accounts))
|
||||
& (gl.posting_date.gte(self.filters.from_date))
|
||||
& (gl.posting_date.lte(self.filters.to_date))
|
||||
)
|
||||
)
|
||||
|
||||
gl_entries = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
@@ -381,16 +396,15 @@ class PartyLedgerSummaryReport(object):
|
||||
where
|
||||
docstatus < 2 and is_cancelled = 0
|
||||
and (voucher_type, voucher_no) in (
|
||||
select voucher_type, voucher_no from `tabGL Entry` gle, `tabAccount` acc
|
||||
where acc.name = gle.account and acc.account_type = '{income_or_expense}'
|
||||
and gle.posting_date between %(from_date)s and %(to_date)s and gle.docstatus < 2
|
||||
{accounts_query}
|
||||
) and (voucher_type, voucher_no) in (
|
||||
select voucher_type, voucher_no from `tabGL Entry` gle
|
||||
where gle.party_type=%(party_type)s and ifnull(party, '') != ''
|
||||
and gle.posting_date between %(from_date)s and %(to_date)s and gle.docstatus < 2 {conditions}
|
||||
)
|
||||
""".format(
|
||||
conditions=conditions, income_or_expense=income_or_expense
|
||||
""".format(
|
||||
accounts_query=accounts_query,
|
||||
conditions=conditions,
|
||||
),
|
||||
self.filters,
|
||||
as_dict=True,
|
||||
@@ -414,7 +428,7 @@ class PartyLedgerSummaryReport(object):
|
||||
elif gle.party:
|
||||
parties.setdefault(gle.party, 0)
|
||||
parties[gle.party] += gle.get(reverse_dr_or_cr) - gle.get(invoice_dr_or_cr)
|
||||
elif frappe.get_cached_value("Account", gle.account, "account_type") == income_or_expense:
|
||||
elif frappe.get_cached_value("Account", gle.account, "account_type") == account_type:
|
||||
accounts.setdefault(gle.account, 0)
|
||||
accounts[gle.account] += gle.get(invoice_dr_or_cr) - gle.get(reverse_dr_or_cr)
|
||||
else:
|
||||
|
||||
@@ -231,6 +231,9 @@ def get_conditions(filters):
|
||||
if filters.get("voucher_no"):
|
||||
conditions.append("voucher_no=%(voucher_no)s")
|
||||
|
||||
if filters.get("voucher_no_not_in"):
|
||||
conditions.append("voucher_no not in %(voucher_no_not_in)s")
|
||||
|
||||
if filters.get("group_by") == "Group by Party" and not filters.get("party_type"):
|
||||
conditions.append("party_type in ('Customer', 'Supplier')")
|
||||
|
||||
|
||||
@@ -309,7 +309,8 @@ def get_conditions(filters):
|
||||
|
||||
def get_items(filters, additional_query_columns):
|
||||
conditions = get_conditions(filters)
|
||||
|
||||
if additional_query_columns:
|
||||
additional_query_columns = "," + ",".join(additional_query_columns)
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
|
||||
@@ -381,7 +381,8 @@ def get_group_by_conditions(filters, doctype):
|
||||
|
||||
def get_items(filters, additional_query_columns, additional_conditions=None):
|
||||
conditions = get_conditions(filters, additional_conditions)
|
||||
|
||||
if additional_query_columns:
|
||||
additional_query_columns = "," + ",".join(additional_query_columns)
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
|
||||
@@ -119,8 +119,4 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
||||
"initial_depth": 3
|
||||
}
|
||||
|
||||
erpnext.dimension_filters.forEach((dimension) => {
|
||||
frappe.query_reports["Profitability Analysis"].filters[1].options.push(dimension["document_type"]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -52,6 +52,12 @@ frappe.query_reports["Purchase Register"] = {
|
||||
"label": __("Item Group"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Item Group"
|
||||
},
|
||||
{
|
||||
"fieldname": "include_payments",
|
||||
"label": __("Show Ledger View"),
|
||||
"fieldtype": "Check",
|
||||
"default": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -4,13 +4,22 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _, msgprint
|
||||
from frappe.utils import flt
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.utils import flt, getdate
|
||||
from pypika import Order
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_dimension_with_children,
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.report.utils import (
|
||||
apply_common_conditions,
|
||||
get_advance_taxes_and_charges,
|
||||
get_journal_entries,
|
||||
get_opening_row,
|
||||
get_party_details,
|
||||
get_payment_entries,
|
||||
get_query_columns,
|
||||
get_taxes_query,
|
||||
get_values_for_columns,
|
||||
)
|
||||
from erpnext.accounts.report.utils import get_query_columns, get_values_for_columns
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -21,9 +30,15 @@ def _execute(filters=None, additional_table_columns=None):
|
||||
if not filters:
|
||||
filters = {}
|
||||
|
||||
include_payments = filters.get("include_payments")
|
||||
if filters.get("include_payments") and not filters.get("supplier"):
|
||||
frappe.throw(_("Please select a supplier for fetching payments."))
|
||||
invoice_list = get_invoices(filters, get_query_columns(additional_table_columns))
|
||||
if filters.get("include_payments"):
|
||||
invoice_list += get_payments(filters)
|
||||
|
||||
columns, expense_accounts, tax_accounts, unrealized_profit_loss_accounts = get_columns(
|
||||
invoice_list, additional_table_columns
|
||||
invoice_list, additional_table_columns, include_payments
|
||||
)
|
||||
|
||||
if not invoice_list:
|
||||
@@ -33,14 +48,28 @@ def _execute(filters=None, additional_table_columns=None):
|
||||
invoice_expense_map = get_invoice_expense_map(invoice_list)
|
||||
internal_invoice_map = get_internal_invoice_map(invoice_list)
|
||||
invoice_expense_map, invoice_tax_map = get_invoice_tax_map(
|
||||
invoice_list, invoice_expense_map, expense_accounts
|
||||
invoice_list, invoice_expense_map, expense_accounts, include_payments
|
||||
)
|
||||
invoice_po_pr_map = get_invoice_po_pr_map(invoice_list)
|
||||
suppliers = list(set(d.supplier for d in invoice_list))
|
||||
supplier_details = get_supplier_details(suppliers)
|
||||
supplier_details = get_party_details("Supplier", suppliers)
|
||||
|
||||
company_currency = frappe.get_cached_value("Company", filters.company, "default_currency")
|
||||
|
||||
res = []
|
||||
if include_payments:
|
||||
opening_row = get_opening_row(
|
||||
"Supplier", filters.supplier, getdate(filters.from_date), filters.company
|
||||
)[0]
|
||||
res.append(
|
||||
{
|
||||
"payable_account": opening_row.account,
|
||||
"debit": flt(opening_row.debit),
|
||||
"credit": flt(opening_row.credit),
|
||||
"balance": flt(opening_row.balance),
|
||||
}
|
||||
)
|
||||
|
||||
data = []
|
||||
for inv in invoice_list:
|
||||
# invoice details
|
||||
@@ -48,24 +77,23 @@ def _execute(filters=None, additional_table_columns=None):
|
||||
purchase_receipt = list(set(invoice_po_pr_map.get(inv.name, {}).get("purchase_receipt", [])))
|
||||
project = list(set(invoice_po_pr_map.get(inv.name, {}).get("project", [])))
|
||||
|
||||
row = [
|
||||
inv.name,
|
||||
inv.posting_date,
|
||||
inv.supplier,
|
||||
inv.supplier_name,
|
||||
*get_values_for_columns(additional_table_columns, inv).values(),
|
||||
supplier_details.get(inv.supplier), # supplier_group
|
||||
inv.tax_id,
|
||||
inv.credit_to,
|
||||
inv.mode_of_payment,
|
||||
", ".join(project),
|
||||
inv.bill_no,
|
||||
inv.bill_date,
|
||||
inv.remarks,
|
||||
", ".join(purchase_order),
|
||||
", ".join(purchase_receipt),
|
||||
company_currency,
|
||||
]
|
||||
row = {
|
||||
"voucher_type": inv.doctype,
|
||||
"voucher_no": inv.name,
|
||||
"posting_date": inv.posting_date,
|
||||
"supplier_id": inv.supplier,
|
||||
"supplier_name": inv.supplier_name,
|
||||
**get_values_for_columns(additional_table_columns, inv),
|
||||
"supplier_group": supplier_details.get(inv.supplier).get("supplier_group"), # supplier_group
|
||||
"tax_id": supplier_details.get(inv.supplier).get("tax_id"),
|
||||
"payable_account": inv.credit_to,
|
||||
"mode_of_payment": inv.mode_of_payment,
|
||||
"project": ", ".join(project) if inv.doctype == "Purchase Invoice" else inv.project,
|
||||
"remarks": inv.remarks,
|
||||
"purchase_order": ", ".join(purchase_order),
|
||||
"purchase_receipt": ", ".join(purchase_receipt),
|
||||
"currency": company_currency,
|
||||
}
|
||||
|
||||
# map expense values
|
||||
base_net_total = 0
|
||||
@@ -75,14 +103,16 @@ def _execute(filters=None, additional_table_columns=None):
|
||||
else:
|
||||
expense_amount = flt(invoice_expense_map.get(inv.name, {}).get(expense_acc))
|
||||
base_net_total += expense_amount
|
||||
row.append(expense_amount)
|
||||
row.update({frappe.scrub(expense_acc): expense_amount})
|
||||
|
||||
# Add amount in unrealized account
|
||||
for account in unrealized_profit_loss_accounts:
|
||||
row.append(flt(internal_invoice_map.get((inv.name, account))))
|
||||
row.update(
|
||||
{frappe.scrub(account + "_unrealized"): flt(internal_invoice_map.get((inv.name, account)))}
|
||||
)
|
||||
|
||||
# net total
|
||||
row.append(base_net_total or inv.base_net_total)
|
||||
row.update({"net_total": base_net_total or inv.base_net_total})
|
||||
|
||||
# tax account
|
||||
total_tax = 0
|
||||
@@ -90,45 +120,190 @@ def _execute(filters=None, additional_table_columns=None):
|
||||
if tax_acc not in expense_accounts:
|
||||
tax_amount = flt(invoice_tax_map.get(inv.name, {}).get(tax_acc))
|
||||
total_tax += tax_amount
|
||||
row.append(tax_amount)
|
||||
row.update({frappe.scrub(tax_acc): tax_amount})
|
||||
|
||||
# total tax, grand total, rounded total & outstanding amount
|
||||
row += [total_tax, inv.base_grand_total, flt(inv.base_grand_total, 0), inv.outstanding_amount]
|
||||
row.update(
|
||||
{
|
||||
"total_tax": total_tax,
|
||||
"grand_total": inv.base_grand_total,
|
||||
"rounded_total": inv.base_rounded_total,
|
||||
"outstanding_amount": inv.outstanding_amount,
|
||||
}
|
||||
)
|
||||
|
||||
if inv.doctype == "Purchase Invoice":
|
||||
row.update({"debit": inv.base_grand_total, "credit": 0.0})
|
||||
else:
|
||||
row.update({"debit": 0.0, "credit": inv.base_grand_total})
|
||||
data.append(row)
|
||||
|
||||
return columns, data
|
||||
res += sorted(data, key=lambda x: x["posting_date"])
|
||||
|
||||
if include_payments:
|
||||
running_balance = flt(opening_row.balance)
|
||||
for row in range(1, len(res)):
|
||||
running_balance += res[row]["debit"] - res[row]["credit"]
|
||||
res[row].update({"balance": running_balance})
|
||||
|
||||
return columns, res, None, None, None, include_payments
|
||||
|
||||
|
||||
def get_columns(invoice_list, additional_table_columns):
|
||||
def get_columns(invoice_list, additional_table_columns, include_payments=False):
|
||||
"""return columns based on filters"""
|
||||
columns = [
|
||||
_("Invoice") + ":Link/Purchase Invoice:120",
|
||||
_("Posting Date") + ":Date:80",
|
||||
_("Supplier Id") + "::120",
|
||||
_("Supplier Name") + "::120",
|
||||
{
|
||||
"label": _("Voucher Type"),
|
||||
"fieldname": "voucher_type",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Voucher"),
|
||||
"fieldname": "voucher_no",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"options": "voucher_type",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 80},
|
||||
{
|
||||
"label": _("Supplier"),
|
||||
"fieldname": "supplier_id",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Supplier Name"), "fieldname": "supplier_name", "fieldtype": "Data", "width": 120},
|
||||
]
|
||||
|
||||
if additional_table_columns:
|
||||
if additional_table_columns and not include_payments:
|
||||
columns += additional_table_columns
|
||||
|
||||
columns += [
|
||||
_("Supplier Group") + ":Link/Supplier Group:120",
|
||||
_("Tax Id") + "::80",
|
||||
_("Payable Account") + ":Link/Account:120",
|
||||
_("Mode of Payment") + ":Link/Mode of Payment:80",
|
||||
_("Project") + ":Link/Project:80",
|
||||
_("Bill No") + "::120",
|
||||
_("Bill Date") + ":Date:80",
|
||||
_("Remarks") + "::150",
|
||||
_("Purchase Order") + ":Link/Purchase Order:100",
|
||||
_("Purchase Receipt") + ":Link/Purchase Receipt:100",
|
||||
{"fieldname": "currency", "label": _("Currency"), "fieldtype": "Data", "width": 80},
|
||||
]
|
||||
if not include_payments:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Supplier Group"),
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier Group",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Tax Id"), "fieldname": "tax_id", "fieldtype": "Data", "width": 80},
|
||||
{
|
||||
"label": _("Payable Account"),
|
||||
"fieldname": "payable_account",
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Mode Of Payment"),
|
||||
"fieldname": "mode_of_payment",
|
||||
"fieldtype": "Data",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Project"),
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"options": "Project",
|
||||
"width": 80,
|
||||
},
|
||||
{"label": _("Bill No"), "fieldname": "bill_no", "fieldtype": "Data", "width": 120},
|
||||
{"label": _("Bill Date"), "fieldname": "bill_date", "fieldtype": "Date", "width": 80},
|
||||
{
|
||||
"label": _("Purchase Order"),
|
||||
"fieldname": "purchase_order",
|
||||
"fieldtype": "Link",
|
||||
"options": "Purchase Order",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Purchase Receipt"),
|
||||
"fieldname": "purchase_receipt",
|
||||
"fieldtype": "Link",
|
||||
"options": "Purchase Receipt",
|
||||
"width": 100,
|
||||
},
|
||||
{"fieldname": "currency", "label": _("Currency"), "fieldtype": "Data", "width": 80},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"fieldname": "payable_account",
|
||||
"label": _("Payable Account"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 120,
|
||||
},
|
||||
{"fieldname": "debit", "label": _("Debit"), "fieldtype": "Currency", "width": 120},
|
||||
{"fieldname": "credit", "label": _("Credit"), "fieldtype": "Currency", "width": 120},
|
||||
{"fieldname": "balance", "label": _("Balance"), "fieldtype": "Currency", "width": 120},
|
||||
]
|
||||
|
||||
account_columns, accounts = get_account_columns(invoice_list, include_payments)
|
||||
|
||||
columns = (
|
||||
columns
|
||||
+ account_columns[0]
|
||||
+ account_columns[1]
|
||||
+ [
|
||||
{
|
||||
"label": _("Net Total"),
|
||||
"fieldname": "net_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
]
|
||||
+ account_columns[2]
|
||||
+ [
|
||||
{
|
||||
"label": _("Total Tax"),
|
||||
"fieldname": "total_tax",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
if not include_payments:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Grand Total"),
|
||||
"fieldname": "grand_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Rounded Total"),
|
||||
"fieldname": "rounded_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Outstanding Amount"),
|
||||
"fieldname": "outstanding_amount",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
]
|
||||
columns += [{"label": _("Remarks"), "fieldname": "remarks", "fieldtype": "Data", "width": 120}]
|
||||
return columns, accounts[0], accounts[2], accounts[1]
|
||||
|
||||
|
||||
def get_account_columns(invoice_list, include_payments):
|
||||
expense_accounts = []
|
||||
tax_accounts = []
|
||||
unrealized_profit_loss_accounts = []
|
||||
|
||||
expense_columns = []
|
||||
tax_columns = []
|
||||
unrealized_profit_loss_account_columns = []
|
||||
|
||||
if invoice_list:
|
||||
expense_accounts = frappe.db.sql_list(
|
||||
"""select distinct expense_account
|
||||
@@ -139,15 +314,18 @@ def get_columns(invoice_list, additional_table_columns):
|
||||
tuple([inv.name for inv in invoice_list]),
|
||||
)
|
||||
|
||||
tax_accounts = frappe.db.sql_list(
|
||||
"""select distinct account_head
|
||||
from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
|
||||
and docstatus = 1 and (account_head is not null and account_head != '')
|
||||
and category in ('Total', 'Valuation and Total')
|
||||
and parent in (%s) order by account_head"""
|
||||
% ", ".join(["%s"] * len(invoice_list)),
|
||||
tuple(inv.name for inv in invoice_list),
|
||||
purchase_taxes_query = get_taxes_query(
|
||||
invoice_list, "Purchase Taxes and Charges", "Purchase Invoice"
|
||||
)
|
||||
purchase_tax_accounts = purchase_taxes_query.run(as_dict=True, pluck="account_head")
|
||||
tax_accounts = purchase_tax_accounts
|
||||
|
||||
if include_payments:
|
||||
advance_taxes_query = get_taxes_query(
|
||||
invoice_list, "Advance Taxes and Charges", "Payment Entry"
|
||||
)
|
||||
advance_tax_accounts = advance_taxes_query.run(as_dict=True, pluck="account_head")
|
||||
tax_accounts = set(tax_accounts + advance_tax_accounts)
|
||||
|
||||
unrealized_profit_loss_accounts = frappe.db.sql_list(
|
||||
"""SELECT distinct unrealized_profit_loss_account
|
||||
@@ -158,108 +336,109 @@ def get_columns(invoice_list, additional_table_columns):
|
||||
tuple(inv.name for inv in invoice_list),
|
||||
)
|
||||
|
||||
expense_columns = [(account + ":Currency/currency:120") for account in expense_accounts]
|
||||
unrealized_profit_loss_account_columns = [
|
||||
(account + ":Currency/currency:120") for account in unrealized_profit_loss_accounts
|
||||
]
|
||||
tax_columns = [
|
||||
(account + ":Currency/currency:120")
|
||||
for account in tax_accounts
|
||||
if account not in expense_accounts
|
||||
]
|
||||
for account in expense_accounts:
|
||||
expense_columns.append(
|
||||
{
|
||||
"label": account,
|
||||
"fieldname": frappe.scrub(account),
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
)
|
||||
|
||||
columns = (
|
||||
columns
|
||||
+ expense_columns
|
||||
+ unrealized_profit_loss_account_columns
|
||||
+ [_("Net Total") + ":Currency/currency:120"]
|
||||
+ tax_columns
|
||||
+ [
|
||||
_("Total Tax") + ":Currency/currency:120",
|
||||
_("Grand Total") + ":Currency/currency:120",
|
||||
_("Rounded Total") + ":Currency/currency:120",
|
||||
_("Outstanding Amount") + ":Currency/currency:120",
|
||||
]
|
||||
)
|
||||
for account in tax_accounts:
|
||||
if account not in expense_accounts:
|
||||
tax_columns.append(
|
||||
{
|
||||
"label": account,
|
||||
"fieldname": frappe.scrub(account),
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
)
|
||||
|
||||
return columns, expense_accounts, tax_accounts, unrealized_profit_loss_accounts
|
||||
for account in unrealized_profit_loss_accounts:
|
||||
unrealized_profit_loss_account_columns.append(
|
||||
{
|
||||
"label": account,
|
||||
"fieldname": frappe.scrub(account),
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
)
|
||||
|
||||
columns = [expense_columns, unrealized_profit_loss_account_columns, tax_columns]
|
||||
accounts = [expense_accounts, unrealized_profit_loss_accounts, tax_accounts]
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = ""
|
||||
|
||||
if filters.get("company"):
|
||||
conditions += " and company=%(company)s"
|
||||
if filters.get("supplier"):
|
||||
conditions += " and supplier = %(supplier)s"
|
||||
|
||||
if filters.get("from_date"):
|
||||
conditions += " and posting_date>=%(from_date)s"
|
||||
if filters.get("to_date"):
|
||||
conditions += " and posting_date<=%(to_date)s"
|
||||
|
||||
if filters.get("mode_of_payment"):
|
||||
conditions += " and ifnull(mode_of_payment, '') = %(mode_of_payment)s"
|
||||
|
||||
if filters.get("cost_center"):
|
||||
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||
where parent=`tabPurchase Invoice`.name
|
||||
and ifnull(`tabPurchase Invoice Item`.cost_center, '') = %(cost_center)s)"""
|
||||
|
||||
if filters.get("warehouse"):
|
||||
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||
where parent=`tabPurchase Invoice`.name
|
||||
and ifnull(`tabPurchase Invoice Item`.warehouse, '') = %(warehouse)s)"""
|
||||
|
||||
if filters.get("item_group"):
|
||||
conditions += """ and exists(select name from `tabPurchase Invoice Item`
|
||||
where parent=`tabPurchase Invoice`.name
|
||||
and ifnull(`tabPurchase Invoice Item`.item_group, '') = %(item_group)s)"""
|
||||
|
||||
accounting_dimensions = get_accounting_dimensions(as_list=False)
|
||||
|
||||
if accounting_dimensions:
|
||||
common_condition = """
|
||||
and exists(select name from `tabPurchase Invoice Item`
|
||||
where parent=`tabPurchase Invoice`.name
|
||||
"""
|
||||
for dimension in accounting_dimensions:
|
||||
if filters.get(dimension.fieldname):
|
||||
if frappe.get_cached_value("DocType", dimension.document_type, "is_tree"):
|
||||
filters[dimension.fieldname] = get_dimension_with_children(
|
||||
dimension.document_type, filters.get(dimension.fieldname)
|
||||
)
|
||||
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabPurchase Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
else:
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabPurchase Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
|
||||
return conditions
|
||||
return columns, accounts
|
||||
|
||||
|
||||
def get_invoices(filters, additional_query_columns):
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
name, posting_date, credit_to, supplier, supplier_name, tax_id, bill_no, bill_date,
|
||||
remarks, base_net_total, base_grand_total, outstanding_amount,
|
||||
mode_of_payment {0}
|
||||
from `tabPurchase Invoice`
|
||||
where docstatus = 1 {1}
|
||||
order by posting_date desc, name desc""".format(
|
||||
additional_query_columns, conditions
|
||||
),
|
||||
filters,
|
||||
as_dict=1,
|
||||
pi = frappe.qb.DocType("Purchase Invoice")
|
||||
query = (
|
||||
frappe.qb.from_(pi)
|
||||
.select(
|
||||
ConstantColumn("Purchase Invoice").as_("doctype"),
|
||||
pi.name,
|
||||
pi.posting_date,
|
||||
pi.credit_to,
|
||||
pi.supplier,
|
||||
pi.supplier_name,
|
||||
pi.tax_id,
|
||||
pi.bill_no,
|
||||
pi.bill_date,
|
||||
pi.remarks,
|
||||
pi.base_net_total,
|
||||
pi.base_grand_total,
|
||||
pi.base_rounded_total,
|
||||
pi.outstanding_amount,
|
||||
pi.mode_of_payment,
|
||||
)
|
||||
.where((pi.docstatus == 1))
|
||||
.orderby(pi.posting_date, pi.name, order=Order.desc)
|
||||
)
|
||||
|
||||
if additional_query_columns:
|
||||
for col in additional_query_columns:
|
||||
query = query.select(col)
|
||||
|
||||
if filters.get("supplier"):
|
||||
query = query.where(pi.supplier == filters.supplier)
|
||||
|
||||
query = get_conditions(filters, query, "Purchase Invoice")
|
||||
|
||||
query = apply_common_conditions(
|
||||
filters, query, doctype="Purchase Invoice", child_doctype="Purchase Invoice Item"
|
||||
)
|
||||
|
||||
invoices = query.run(as_dict=True)
|
||||
return invoices
|
||||
|
||||
|
||||
def get_conditions(filters, query, doctype):
|
||||
parent_doc = frappe.qb.DocType(doctype)
|
||||
|
||||
if filters.get("mode_of_payment"):
|
||||
query = query.where(parent_doc.mode_of_payment == filters.mode_of_payment)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def get_payments(filters):
|
||||
args = frappe._dict(
|
||||
account="credit_to",
|
||||
account_fieldname="paid_to",
|
||||
party="supplier",
|
||||
party_name="supplier_name",
|
||||
party_account=get_party_account("Supplier", filters.supplier, filters.company),
|
||||
)
|
||||
payment_entries = get_payment_entries(filters, args)
|
||||
journal_entries = get_journal_entries(filters, args)
|
||||
return payment_entries + journal_entries
|
||||
|
||||
|
||||
def get_invoice_expense_map(invoice_list):
|
||||
expense_details = frappe.db.sql(
|
||||
@@ -300,7 +479,9 @@ def get_internal_invoice_map(invoice_list):
|
||||
return internal_invoice_map
|
||||
|
||||
|
||||
def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
|
||||
def get_invoice_tax_map(
|
||||
invoice_list, invoice_expense_map, expense_accounts, include_payments=False
|
||||
):
|
||||
tax_details = frappe.db.sql(
|
||||
"""
|
||||
select parent, account_head, case add_deduct_tax when "Add" then sum(base_tax_amount_after_discount_amount)
|
||||
@@ -315,6 +496,9 @@ def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if include_payments:
|
||||
tax_details += get_advance_taxes_and_charges(invoice_list)
|
||||
|
||||
invoice_tax_map = {}
|
||||
for d in tax_details:
|
||||
if d.account_head in expense_accounts:
|
||||
@@ -382,17 +566,3 @@ def get_account_details(invoice_list):
|
||||
account_map[acc.name] = acc.parent_account
|
||||
|
||||
return account_map
|
||||
|
||||
|
||||
def get_supplier_details(suppliers):
|
||||
supplier_details = {}
|
||||
for supp in frappe.db.sql(
|
||||
"""select name, supplier_group from `tabSupplier`
|
||||
where name in (%s)"""
|
||||
% ", ".join(["%s"] * len(suppliers)),
|
||||
tuple(suppliers),
|
||||
as_dict=1,
|
||||
):
|
||||
supplier_details.setdefault(supp.name, supp.supplier_group)
|
||||
|
||||
return supplier_details
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_months, getdate, today
|
||||
|
||||
from erpnext.accounts.report.purchase_register.purchase_register import execute
|
||||
|
||||
|
||||
class TestPurchaseRegister(FrappeTestCase):
|
||||
def test_purchase_register(self):
|
||||
frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company 6'")
|
||||
frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 6'")
|
||||
|
||||
filters = frappe._dict(
|
||||
company="_Test Company 6", from_date=add_months(today(), -1), to_date=today()
|
||||
)
|
||||
|
||||
pi = make_purchase_invoice()
|
||||
|
||||
report_results = execute(filters)
|
||||
first_row = frappe._dict(report_results[1][0])
|
||||
self.assertEqual(first_row.voucher_type, "Purchase Invoice")
|
||||
self.assertEqual(first_row.voucher_no, pi.name)
|
||||
self.assertEqual(first_row.payable_account, "Creditors - _TC6")
|
||||
self.assertEqual(first_row.net_total, 1000)
|
||||
self.assertEqual(first_row.total_tax, 100)
|
||||
self.assertEqual(first_row.grand_total, 1100)
|
||||
|
||||
def test_purchase_register_ledger_view(self):
|
||||
frappe.db.sql("delete from `tabPurchase Invoice` where company='_Test Company 6'")
|
||||
frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 6'")
|
||||
|
||||
filters = frappe._dict(
|
||||
company="_Test Company 6",
|
||||
from_date=add_months(today(), -1),
|
||||
to_date=today(),
|
||||
include_payments=True,
|
||||
supplier="_Test Supplier",
|
||||
)
|
||||
|
||||
pi = make_purchase_invoice()
|
||||
pe = make_payment_entry()
|
||||
|
||||
report_results = execute(filters)
|
||||
first_row = frappe._dict(report_results[1][2])
|
||||
self.assertEqual(first_row.voucher_type, "Payment Entry")
|
||||
self.assertEqual(first_row.voucher_no, pe.name)
|
||||
self.assertEqual(first_row.payable_account, "Creditors - _TC6")
|
||||
self.assertEqual(first_row.debit, 0)
|
||||
self.assertEqual(first_row.credit, 600)
|
||||
self.assertEqual(first_row.balance, 500)
|
||||
|
||||
|
||||
def make_purchase_invoice():
|
||||
from erpnext.accounts.doctype.account.test_account import create_account
|
||||
from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
|
||||
gst_acc = create_account(
|
||||
account_name="GST",
|
||||
account_type="Tax",
|
||||
parent_account="Duties and Taxes - _TC6",
|
||||
company="_Test Company 6",
|
||||
account_currency="INR",
|
||||
)
|
||||
create_warehouse(warehouse_name="_Test Warehouse - _TC6", company="_Test Company 6")
|
||||
create_cost_center(cost_center_name="_Test Cost Center", company="_Test Company 6")
|
||||
pi = create_purchase_invoice_with_taxes()
|
||||
pi.submit()
|
||||
return pi
|
||||
|
||||
|
||||
def create_purchase_invoice_with_taxes():
|
||||
return frappe.get_doc(
|
||||
{
|
||||
"doctype": "Purchase Invoice",
|
||||
"posting_date": today(),
|
||||
"supplier": "_Test Supplier",
|
||||
"company": "_Test Company 6",
|
||||
"cost_center": "_Test Cost Center - _TC6",
|
||||
"taxes_and_charges": "",
|
||||
"currency": "INR",
|
||||
"credit_to": "Creditors - _TC6",
|
||||
"items": [
|
||||
{
|
||||
"doctype": "Purchase Invoice Item",
|
||||
"cost_center": "_Test Cost Center - _TC6",
|
||||
"item_code": "_Test Item",
|
||||
"qty": 1,
|
||||
"rate": 1000,
|
||||
"expense_account": "Stock Received But Not Billed - _TC6",
|
||||
}
|
||||
],
|
||||
"taxes": [
|
||||
{
|
||||
"account_head": "GST - _TC6",
|
||||
"cost_center": "_Test Cost Center - _TC6",
|
||||
"add_deduct_tax": "Add",
|
||||
"category": "Valuation and Total",
|
||||
"charge_type": "Actual",
|
||||
"description": "Shipping Charges",
|
||||
"doctype": "Purchase Taxes and Charges",
|
||||
"parentfield": "taxes",
|
||||
"rate": 100,
|
||||
"tax_amount": 100.0,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def make_payment_entry():
|
||||
frappe.set_user("Administrator")
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_entry
|
||||
|
||||
return create_payment_entry(
|
||||
company="_Test Company 6",
|
||||
party_type="Supplier",
|
||||
party="_Test Supplier",
|
||||
payment_type="Pay",
|
||||
paid_from="Cash - _TC6",
|
||||
paid_to="Creditors - _TC6",
|
||||
paid_amount=600,
|
||||
save=1,
|
||||
submit=1,
|
||||
)
|
||||
@@ -64,6 +64,12 @@ frappe.query_reports["Sales Register"] = {
|
||||
"label": __("Item Group"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Item Group"
|
||||
},
|
||||
{
|
||||
"fieldname": "include_payments",
|
||||
"label": __("Show Ledger View"),
|
||||
"fieldtype": "Check",
|
||||
"default": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -5,13 +5,22 @@
|
||||
import frappe
|
||||
from frappe import _, msgprint
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.utils import flt
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.utils import flt, getdate
|
||||
from pypika import Order
|
||||
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_dimension_with_children,
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.accounts.report.utils import (
|
||||
apply_common_conditions,
|
||||
get_advance_taxes_and_charges,
|
||||
get_journal_entries,
|
||||
get_opening_row,
|
||||
get_party_details,
|
||||
get_payment_entries,
|
||||
get_query_columns,
|
||||
get_taxes_query,
|
||||
get_values_for_columns,
|
||||
)
|
||||
from erpnext.accounts.report.utils import get_query_columns, get_values_for_columns
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -22,9 +31,15 @@ def _execute(filters, additional_table_columns=None):
|
||||
if not filters:
|
||||
filters = frappe._dict({})
|
||||
|
||||
include_payments = filters.get("include_payments")
|
||||
if filters.get("include_payments") and not filters.get("customer"):
|
||||
frappe.throw(_("Please select a customer for fetching payments."))
|
||||
invoice_list = get_invoices(filters, get_query_columns(additional_table_columns))
|
||||
columns, income_accounts, tax_accounts, unrealized_profit_loss_accounts = get_columns(
|
||||
invoice_list, additional_table_columns
|
||||
if filters.get("include_payments"):
|
||||
invoice_list += get_payments(filters)
|
||||
|
||||
columns, income_accounts, unrealized_profit_loss_accounts, tax_accounts = get_columns(
|
||||
invoice_list, additional_table_columns, include_payments
|
||||
)
|
||||
|
||||
if not invoice_list:
|
||||
@@ -34,13 +49,29 @@ def _execute(filters, additional_table_columns=None):
|
||||
invoice_income_map = get_invoice_income_map(invoice_list)
|
||||
internal_invoice_map = get_internal_invoice_map(invoice_list)
|
||||
invoice_income_map, invoice_tax_map = get_invoice_tax_map(
|
||||
invoice_list, invoice_income_map, income_accounts
|
||||
invoice_list, invoice_income_map, income_accounts, include_payments
|
||||
)
|
||||
# Cost Center & Warehouse Map
|
||||
invoice_cc_wh_map = get_invoice_cc_wh_map(invoice_list)
|
||||
invoice_so_dn_map = get_invoice_so_dn_map(invoice_list)
|
||||
company_currency = frappe.get_cached_value("Company", filters.get("company"), "default_currency")
|
||||
mode_of_payments = get_mode_of_payments([inv.name for inv in invoice_list])
|
||||
customers = list(set(d.customer for d in invoice_list))
|
||||
customer_details = get_party_details("Customer", customers)
|
||||
|
||||
res = []
|
||||
if include_payments:
|
||||
opening_row = get_opening_row(
|
||||
"Customer", filters.customer, getdate(filters.from_date), filters.company
|
||||
)[0]
|
||||
res.append(
|
||||
{
|
||||
"receivable_account": opening_row.account,
|
||||
"debit": flt(opening_row.debit),
|
||||
"credit": flt(opening_row.credit),
|
||||
"balance": flt(opening_row.balance),
|
||||
}
|
||||
)
|
||||
|
||||
data = []
|
||||
for inv in invoice_list:
|
||||
@@ -51,14 +82,15 @@ def _execute(filters, additional_table_columns=None):
|
||||
warehouse = list(set(invoice_cc_wh_map.get(inv.name, {}).get("warehouse", [])))
|
||||
|
||||
row = {
|
||||
"invoice": inv.name,
|
||||
"voucher_type": inv.doctype,
|
||||
"voucher_no": inv.name,
|
||||
"posting_date": inv.posting_date,
|
||||
"customer": inv.customer,
|
||||
"customer_name": inv.customer_name,
|
||||
**get_values_for_columns(additional_table_columns, inv),
|
||||
"customer_group": inv.get("customer_group"),
|
||||
"territory": inv.get("territory"),
|
||||
"tax_id": inv.get("tax_id"),
|
||||
"customer_group": customer_details.get(inv.customer).get("customer_group"),
|
||||
"territory": customer_details.get(inv.customer).get("territory"),
|
||||
"tax_id": customer_details.get(inv.customer).get("tax_id"),
|
||||
"receivable_account": inv.debit_to,
|
||||
"mode_of_payment": ", ".join(mode_of_payments.get(inv.name, [])),
|
||||
"project": inv.project,
|
||||
@@ -66,7 +98,7 @@ def _execute(filters, additional_table_columns=None):
|
||||
"remarks": inv.remarks,
|
||||
"sales_order": ", ".join(sales_order),
|
||||
"delivery_note": ", ".join(delivery_note),
|
||||
"cost_center": ", ".join(cost_center),
|
||||
"cost_center": ", ".join(cost_center) if inv.doctype == "Sales Invoice" else inv.cost_center,
|
||||
"warehouse": ", ".join(warehouse),
|
||||
"currency": company_currency,
|
||||
}
|
||||
@@ -116,19 +148,36 @@ def _execute(filters, additional_table_columns=None):
|
||||
}
|
||||
)
|
||||
|
||||
if inv.doctype == "Sales Invoice":
|
||||
row.update({"debit": inv.base_grand_total, "credit": 0.0})
|
||||
else:
|
||||
row.update({"debit": 0.0, "credit": inv.base_grand_total})
|
||||
data.append(row)
|
||||
|
||||
return columns, data
|
||||
res += sorted(data, key=lambda x: x["posting_date"])
|
||||
|
||||
if include_payments:
|
||||
running_balance = flt(opening_row.balance)
|
||||
for row in range(1, len(res)):
|
||||
running_balance += res[row]["debit"] - res[row]["credit"]
|
||||
res[row].update({"balance": running_balance})
|
||||
|
||||
return columns, res, None, None, None, include_payments
|
||||
|
||||
|
||||
def get_columns(invoice_list, additional_table_columns):
|
||||
def get_columns(invoice_list, additional_table_columns, include_payments=False):
|
||||
"""return columns based on filters"""
|
||||
columns = [
|
||||
{
|
||||
"label": _("Invoice"),
|
||||
"fieldname": "invoice",
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Invoice",
|
||||
"label": _("Voucher Type"),
|
||||
"fieldname": "voucher_type",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Voucher"),
|
||||
"fieldname": "voucher_no",
|
||||
"fieldtype": "Dynamic Link",
|
||||
"options": "voucher_type",
|
||||
"width": 120,
|
||||
},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 80},
|
||||
@@ -142,83 +191,156 @@ def get_columns(invoice_list, additional_table_columns):
|
||||
{"label": _("Customer Name"), "fieldname": "customer_name", "fieldtype": "Data", "width": 120},
|
||||
]
|
||||
|
||||
if additional_table_columns:
|
||||
if additional_table_columns and not include_payments:
|
||||
columns += additional_table_columns
|
||||
|
||||
columns += [
|
||||
if not include_payments:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
"width": 80,
|
||||
},
|
||||
{"label": _("Tax Id"), "fieldname": "tax_id", "fieldtype": "Data", "width": 80},
|
||||
{
|
||||
"label": _("Receivable Account"),
|
||||
"fieldname": "receivable_account",
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Mode Of Payment"),
|
||||
"fieldname": "mode_of_payment",
|
||||
"fieldtype": "Data",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Project"),
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"options": "Project",
|
||||
"width": 80,
|
||||
},
|
||||
{"label": _("Owner"), "fieldname": "owner", "fieldtype": "Data", "width": 100},
|
||||
{
|
||||
"label": _("Sales Order"),
|
||||
"fieldname": "sales_order",
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Order",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Delivery Note"),
|
||||
"fieldname": "delivery_note",
|
||||
"fieldtype": "Link",
|
||||
"options": "Delivery Note",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Cost Center"),
|
||||
"fieldname": "cost_center",
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Warehouse"),
|
||||
"fieldname": "warehouse",
|
||||
"fieldtype": "Link",
|
||||
"options": "Warehouse",
|
||||
"width": 100,
|
||||
},
|
||||
{"fieldname": "currency", "label": _("Currency"), "fieldtype": "Data", "width": 80},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"fieldname": "receivable_account",
|
||||
"label": _("Receivable Account"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 120,
|
||||
},
|
||||
{"fieldname": "debit", "label": _("Debit"), "fieldtype": "Currency", "width": 120},
|
||||
{"fieldname": "credit", "label": _("Credit"), "fieldtype": "Currency", "width": 120},
|
||||
{"fieldname": "balance", "label": _("Balance"), "fieldtype": "Currency", "width": 120},
|
||||
]
|
||||
|
||||
account_columns, accounts = get_account_columns(invoice_list, include_payments)
|
||||
|
||||
net_total_column = [
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
"label": _("Net Total"),
|
||||
"fieldname": "net_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
"width": 80,
|
||||
},
|
||||
{"label": _("Tax Id"), "fieldname": "tax_id", "fieldtype": "Data", "width": 120},
|
||||
{
|
||||
"label": _("Receivable Account"),
|
||||
"fieldname": "receivable_account",
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 80,
|
||||
},
|
||||
{
|
||||
"label": _("Mode Of Payment"),
|
||||
"fieldname": "mode_of_payment",
|
||||
"fieldtype": "Data",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Project"),
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"options": "Project",
|
||||
"width": 80,
|
||||
},
|
||||
{"label": _("Owner"), "fieldname": "owner", "fieldtype": "Data", "width": 150},
|
||||
{"label": _("Remarks"), "fieldname": "remarks", "fieldtype": "Data", "width": 150},
|
||||
{
|
||||
"label": _("Sales Order"),
|
||||
"fieldname": "sales_order",
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Order",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Delivery Note"),
|
||||
"fieldname": "delivery_note",
|
||||
"fieldtype": "Link",
|
||||
"options": "Delivery Note",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Cost Center"),
|
||||
"fieldname": "cost_center",
|
||||
"fieldtype": "Link",
|
||||
"options": "Cost Center",
|
||||
"width": 100,
|
||||
},
|
||||
{
|
||||
"label": _("Warehouse"),
|
||||
"fieldname": "warehouse",
|
||||
"fieldtype": "Link",
|
||||
"options": "Warehouse",
|
||||
"width": 100,
|
||||
},
|
||||
{"fieldname": "currency", "label": _("Currency"), "fieldtype": "Data", "width": 80},
|
||||
}
|
||||
]
|
||||
|
||||
total_columns = [
|
||||
{
|
||||
"label": _("Tax Total"),
|
||||
"fieldname": "tax_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
]
|
||||
if not include_payments:
|
||||
total_columns += [
|
||||
{
|
||||
"label": _("Grand Total"),
|
||||
"fieldname": "grand_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Rounded Total"),
|
||||
"fieldname": "rounded_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Outstanding Amount"),
|
||||
"fieldname": "outstanding_amount",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
]
|
||||
|
||||
columns = (
|
||||
columns
|
||||
+ account_columns[0]
|
||||
+ account_columns[2]
|
||||
+ net_total_column
|
||||
+ account_columns[1]
|
||||
+ total_columns
|
||||
)
|
||||
columns += [{"label": _("Remarks"), "fieldname": "remarks", "fieldtype": "Data", "width": 150}]
|
||||
return columns, accounts[0], accounts[1], accounts[2]
|
||||
|
||||
|
||||
def get_account_columns(invoice_list, include_payments):
|
||||
income_accounts = []
|
||||
tax_accounts = []
|
||||
unrealized_profit_loss_accounts = []
|
||||
|
||||
income_columns = []
|
||||
tax_columns = []
|
||||
unrealized_profit_loss_accounts = []
|
||||
unrealized_profit_loss_account_columns = []
|
||||
|
||||
if invoice_list:
|
||||
@@ -230,14 +352,16 @@ def get_columns(invoice_list, additional_table_columns):
|
||||
tuple(inv.name for inv in invoice_list),
|
||||
)
|
||||
|
||||
tax_accounts = frappe.db.sql_list(
|
||||
"""select distinct account_head
|
||||
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
|
||||
and docstatus = 1 and base_tax_amount_after_discount_amount != 0
|
||||
and parent in (%s) order by account_head"""
|
||||
% ", ".join(["%s"] * len(invoice_list)),
|
||||
tuple(inv.name for inv in invoice_list),
|
||||
)
|
||||
sales_taxes_query = get_taxes_query(invoice_list, "Sales Taxes and Charges", "Sales Invoice")
|
||||
sales_tax_accounts = sales_taxes_query.run(as_dict=True, pluck="account_head")
|
||||
tax_accounts = sales_tax_accounts
|
||||
|
||||
if include_payments:
|
||||
advance_taxes_query = get_taxes_query(
|
||||
invoice_list, "Advance Taxes and Charges", "Payment Entry"
|
||||
)
|
||||
advance_tax_accounts = advance_taxes_query.run(as_dict=True, pluck="account_head")
|
||||
tax_accounts = set(tax_accounts + advance_tax_accounts)
|
||||
|
||||
unrealized_profit_loss_accounts = frappe.db.sql_list(
|
||||
"""SELECT distinct unrealized_profit_loss_account
|
||||
@@ -283,134 +407,82 @@ def get_columns(invoice_list, additional_table_columns):
|
||||
}
|
||||
)
|
||||
|
||||
net_total_column = [
|
||||
{
|
||||
"label": _("Net Total"),
|
||||
"fieldname": "net_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
}
|
||||
]
|
||||
columns = [income_columns, unrealized_profit_loss_account_columns, tax_columns]
|
||||
accounts = [income_accounts, unrealized_profit_loss_accounts, tax_accounts]
|
||||
|
||||
total_columns = [
|
||||
{
|
||||
"label": _("Tax Total"),
|
||||
"fieldname": "tax_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Grand Total"),
|
||||
"fieldname": "grand_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Rounded Total"),
|
||||
"fieldname": "rounded_total",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
{
|
||||
"label": _("Outstanding Amount"),
|
||||
"fieldname": "outstanding_amount",
|
||||
"fieldtype": "Currency",
|
||||
"options": "currency",
|
||||
"width": 120,
|
||||
},
|
||||
]
|
||||
|
||||
columns = (
|
||||
columns
|
||||
+ income_columns
|
||||
+ unrealized_profit_loss_account_columns
|
||||
+ net_total_column
|
||||
+ tax_columns
|
||||
+ total_columns
|
||||
)
|
||||
|
||||
return columns, income_accounts, tax_accounts, unrealized_profit_loss_accounts
|
||||
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = ""
|
||||
|
||||
accounting_dimensions = get_accounting_dimensions(as_list=False) or []
|
||||
accounting_dimensions_list = [d.fieldname for d in accounting_dimensions]
|
||||
|
||||
if filters.get("company"):
|
||||
conditions += " and company=%(company)s"
|
||||
|
||||
if filters.get("customer") and "customer" not in accounting_dimensions_list:
|
||||
conditions += " and customer = %(customer)s"
|
||||
|
||||
if filters.get("from_date"):
|
||||
conditions += " and posting_date >= %(from_date)s"
|
||||
if filters.get("to_date"):
|
||||
conditions += " and posting_date <= %(to_date)s"
|
||||
|
||||
if filters.get("owner"):
|
||||
conditions += " and owner = %(owner)s"
|
||||
|
||||
def get_sales_invoice_item_field_condition(field, table="Sales Invoice Item") -> str:
|
||||
if not filters.get(field) or field in accounting_dimensions_list:
|
||||
return ""
|
||||
return f""" and exists(select name from `tab{table}`
|
||||
where parent=`tabSales Invoice`.name
|
||||
and ifnull(`tab{table}`.{field}, '') = %({field})s)"""
|
||||
|
||||
conditions += get_sales_invoice_item_field_condition("mode_of_payment", "Sales Invoice Payment")
|
||||
conditions += get_sales_invoice_item_field_condition("cost_center")
|
||||
conditions += get_sales_invoice_item_field_condition("warehouse")
|
||||
conditions += get_sales_invoice_item_field_condition("brand")
|
||||
conditions += get_sales_invoice_item_field_condition("item_group")
|
||||
|
||||
if accounting_dimensions:
|
||||
common_condition = """
|
||||
and exists(select name from `tabSales Invoice Item`
|
||||
where parent=`tabSales Invoice`.name
|
||||
"""
|
||||
for dimension in accounting_dimensions:
|
||||
if filters.get(dimension.fieldname):
|
||||
if frappe.get_cached_value("DocType", dimension.document_type, "is_tree"):
|
||||
filters[dimension.fieldname] = get_dimension_with_children(
|
||||
dimension.document_type, filters.get(dimension.fieldname)
|
||||
)
|
||||
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabSales Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
else:
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabSales Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
|
||||
return conditions
|
||||
return columns, accounts
|
||||
|
||||
|
||||
def get_invoices(filters, additional_query_columns):
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select name, posting_date, debit_to, project, customer,
|
||||
customer_name, owner, remarks, territory, tax_id, customer_group,
|
||||
base_net_total, base_grand_total, base_rounded_total, outstanding_amount,
|
||||
is_internal_customer, represents_company, company {0}
|
||||
from `tabSales Invoice`
|
||||
where docstatus = 1 {1}
|
||||
order by posting_date desc, name desc""".format(
|
||||
additional_query_columns, conditions
|
||||
),
|
||||
filters,
|
||||
as_dict=1,
|
||||
si = frappe.qb.DocType("Sales Invoice")
|
||||
query = (
|
||||
frappe.qb.from_(si)
|
||||
.select(
|
||||
ConstantColumn("Sales Invoice").as_("doctype"),
|
||||
si.name,
|
||||
si.posting_date,
|
||||
si.debit_to,
|
||||
si.project,
|
||||
si.customer,
|
||||
si.customer_name,
|
||||
si.owner,
|
||||
si.remarks,
|
||||
si.territory,
|
||||
si.tax_id,
|
||||
si.customer_group,
|
||||
si.base_net_total,
|
||||
si.base_grand_total,
|
||||
si.base_rounded_total,
|
||||
si.outstanding_amount,
|
||||
si.is_internal_customer,
|
||||
si.represents_company,
|
||||
si.company,
|
||||
)
|
||||
.where((si.docstatus == 1))
|
||||
.orderby(si.posting_date, si.name, order=Order.desc)
|
||||
)
|
||||
|
||||
if additional_query_columns:
|
||||
for col in additional_query_columns:
|
||||
query = query.select(col)
|
||||
|
||||
if filters.get("customer"):
|
||||
query = query.where(si.customer == filters.customer)
|
||||
|
||||
query = get_conditions(filters, query, "Sales Invoice")
|
||||
query = apply_common_conditions(
|
||||
filters, query, doctype="Sales Invoice", child_doctype="Sales Invoice Item"
|
||||
)
|
||||
|
||||
invoices = query.run(as_dict=True)
|
||||
return invoices
|
||||
|
||||
|
||||
def get_conditions(filters, query, doctype):
|
||||
parent_doc = frappe.qb.DocType(doctype)
|
||||
if filters.get("owner"):
|
||||
query = query.where(parent_doc.owner == filters.owner)
|
||||
|
||||
if filters.get("mode_of_payment"):
|
||||
payment_doc = frappe.qb.DocType("Sales Invoice Payment")
|
||||
query = query.inner_join(payment_doc).on(parent_doc.name == payment_doc.parent)
|
||||
query = query.where(payment_doc.mode_of_payment == filters.mode_of_payment).distinct()
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def get_payments(filters):
|
||||
args = frappe._dict(
|
||||
account="debit_to",
|
||||
account_fieldname="paid_from",
|
||||
party="customer",
|
||||
party_name="customer_name",
|
||||
party_account=get_party_account("Customer", filters.customer, filters.company),
|
||||
)
|
||||
payment_entries = get_payment_entries(filters, args)
|
||||
journal_entries = get_journal_entries(filters, args)
|
||||
return payment_entries + journal_entries
|
||||
|
||||
|
||||
def get_invoice_income_map(invoice_list):
|
||||
income_details = frappe.db.sql(
|
||||
@@ -447,7 +519,7 @@ def get_internal_invoice_map(invoice_list):
|
||||
return internal_invoice_map
|
||||
|
||||
|
||||
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
||||
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts, include_payments=False):
|
||||
tax_details = frappe.db.sql(
|
||||
"""select parent, account_head,
|
||||
sum(base_tax_amount_after_discount_amount) as tax_amount
|
||||
@@ -457,6 +529,9 @@ def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if include_payments:
|
||||
tax_details += get_advance_taxes_and_charges(invoice_list)
|
||||
|
||||
invoice_tax_map = {}
|
||||
for d in tax_details:
|
||||
if d.account_head in income_accounts:
|
||||
|
||||
@@ -345,21 +345,16 @@ def get_tds_docs_query(filters, bank_accounts, tds_accounts):
|
||||
|
||||
if filters.get("party"):
|
||||
party = [filters.get("party")]
|
||||
query = query.where(
|
||||
((gle.account.isin(tds_accounts) & gle.against.isin(party)))
|
||||
| ((gle.voucher_type == "Journal Entry") & (gle.party == filters.get("party")))
|
||||
| gle.party.isin(party)
|
||||
jv_condition = gle.against.isin(party) | (
|
||||
(gle.voucher_type == "Journal Entry") & (gle.party == filters.get("party"))
|
||||
)
|
||||
else:
|
||||
party = frappe.get_all(filters.get("party_type"), pluck="name")
|
||||
query = query.where(
|
||||
((gle.account.isin(tds_accounts) & gle.against.isin(party)))
|
||||
| (
|
||||
(gle.voucher_type == "Journal Entry")
|
||||
& ((gle.party_type == filters.get("party_type")) | (gle.party_type == ""))
|
||||
)
|
||||
| gle.party.isin(party)
|
||||
jv_condition = gle.against.isin(party) | (
|
||||
(gle.voucher_type == "Journal Entry")
|
||||
& ((gle.party_type == filters.get("party_type")) | (gle.party_type == ""))
|
||||
)
|
||||
query = query.where((gle.account.isin(tds_accounts) & jv_condition) | gle.party.isin(party))
|
||||
return query
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
import frappe
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.utils import flt, formatdate, get_datetime_str, get_table_name
|
||||
from pypika import Order
|
||||
|
||||
from erpnext import get_company_currency, get_default_company
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_dimension_with_children,
|
||||
)
|
||||
from erpnext.accounts.doctype.fiscal_year.fiscal_year import get_from_and_to_date
|
||||
from erpnext.accounts.party import get_party_account
|
||||
from erpnext.setup.utils import get_exchange_rate
|
||||
|
||||
__exchange_rates = {}
|
||||
@@ -165,7 +173,7 @@ def get_query_columns(report_columns):
|
||||
else:
|
||||
columns.append(fieldname)
|
||||
|
||||
return ", " + ", ".join(columns)
|
||||
return columns
|
||||
|
||||
|
||||
def get_values_for_columns(report_columns, report_row):
|
||||
@@ -179,3 +187,203 @@ def get_values_for_columns(report_columns, report_row):
|
||||
values[fieldname] = report_row.get(fieldname)
|
||||
|
||||
return values
|
||||
|
||||
|
||||
def get_party_details(party_type, party_list):
|
||||
party_details = {}
|
||||
party = frappe.qb.DocType(party_type)
|
||||
query = frappe.qb.from_(party).select(party.name, party.tax_id).where(party.name.isin(party_list))
|
||||
if party_type == "Supplier":
|
||||
query = query.select(party.supplier_group)
|
||||
else:
|
||||
query = query.select(party.customer_group, party.territory)
|
||||
|
||||
party_detail_list = query.run(as_dict=True)
|
||||
for party_dict in party_detail_list:
|
||||
party_details[party_dict.name] = party_dict
|
||||
return party_details
|
||||
|
||||
|
||||
def get_taxes_query(invoice_list, doctype, parenttype):
|
||||
taxes = frappe.qb.DocType(doctype)
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(taxes)
|
||||
.select(taxes.account_head)
|
||||
.distinct()
|
||||
.where(
|
||||
(taxes.parenttype == parenttype)
|
||||
& (taxes.docstatus == 1)
|
||||
& (taxes.account_head.isnotnull())
|
||||
& (taxes.parent.isin([inv.name for inv in invoice_list]))
|
||||
)
|
||||
.orderby(taxes.account_head)
|
||||
)
|
||||
|
||||
if doctype == "Purchase Taxes and Charges":
|
||||
return query.where(taxes.category.isin(["Total", "Valuation and Total"]))
|
||||
elif doctype == "Sales Taxes and Charges":
|
||||
return query
|
||||
return query.where(taxes.charge_type.isin(["On Paid Amount", "Actual"]))
|
||||
|
||||
|
||||
def get_journal_entries(filters, args):
|
||||
je = frappe.qb.DocType("Journal Entry")
|
||||
journal_account = frappe.qb.DocType("Journal Entry Account")
|
||||
query = (
|
||||
frappe.qb.from_(je)
|
||||
.inner_join(journal_account)
|
||||
.on(je.name == journal_account.parent)
|
||||
.select(
|
||||
je.voucher_type.as_("doctype"),
|
||||
je.name,
|
||||
je.posting_date,
|
||||
journal_account.account.as_(args.account),
|
||||
journal_account.party.as_(args.party),
|
||||
journal_account.party.as_(args.party_name),
|
||||
je.bill_no,
|
||||
je.bill_date,
|
||||
je.remark.as_("remarks"),
|
||||
je.total_amount.as_("base_net_total"),
|
||||
je.total_amount.as_("base_grand_total"),
|
||||
je.mode_of_payment,
|
||||
journal_account.project,
|
||||
)
|
||||
.where(
|
||||
(je.voucher_type == "Journal Entry")
|
||||
& (journal_account.party == filters.get(args.party))
|
||||
& (journal_account.account == args.party_account)
|
||||
)
|
||||
.orderby(je.posting_date, je.name, order=Order.desc)
|
||||
)
|
||||
query = apply_common_conditions(filters, query, doctype="Journal Entry", payments=True)
|
||||
|
||||
journal_entries = query.run(as_dict=True)
|
||||
return journal_entries
|
||||
|
||||
|
||||
def get_payment_entries(filters, args):
|
||||
pe = frappe.qb.DocType("Payment Entry")
|
||||
query = (
|
||||
frappe.qb.from_(pe)
|
||||
.select(
|
||||
ConstantColumn("Payment Entry").as_("doctype"),
|
||||
pe.name,
|
||||
pe.posting_date,
|
||||
pe[args.account_fieldname].as_(args.account),
|
||||
pe.party.as_(args.party),
|
||||
pe.party_name.as_(args.party_name),
|
||||
pe.remarks,
|
||||
pe.paid_amount.as_("base_net_total"),
|
||||
pe.paid_amount_after_tax.as_("base_grand_total"),
|
||||
pe.mode_of_payment,
|
||||
pe.project,
|
||||
pe.cost_center,
|
||||
)
|
||||
.where(
|
||||
(pe.party == filters.get(args.party)) & (pe[args.account_fieldname] == args.party_account)
|
||||
)
|
||||
.orderby(pe.posting_date, pe.name, order=Order.desc)
|
||||
)
|
||||
query = apply_common_conditions(filters, query, doctype="Payment Entry", payments=True)
|
||||
payment_entries = query.run(as_dict=True)
|
||||
return payment_entries
|
||||
|
||||
|
||||
def apply_common_conditions(filters, query, doctype, child_doctype=None, payments=False):
|
||||
parent_doc = frappe.qb.DocType(doctype)
|
||||
if child_doctype:
|
||||
child_doc = frappe.qb.DocType(child_doctype)
|
||||
|
||||
join_required = False
|
||||
|
||||
if filters.get("company"):
|
||||
query = query.where(parent_doc.company == filters.company)
|
||||
if filters.get("from_date"):
|
||||
query = query.where(parent_doc.posting_date >= filters.from_date)
|
||||
if filters.get("to_date"):
|
||||
query = query.where(parent_doc.posting_date <= filters.to_date)
|
||||
|
||||
if payments:
|
||||
if filters.get("cost_center"):
|
||||
query = query.where(parent_doc.cost_center == filters.cost_center)
|
||||
else:
|
||||
if filters.get("cost_center"):
|
||||
query = query.where(child_doc.cost_center == filters.cost_center)
|
||||
join_required = True
|
||||
if filters.get("warehouse"):
|
||||
query = query.where(child_doc.warehouse == filters.warehouse)
|
||||
join_required = True
|
||||
if filters.get("item_group"):
|
||||
query = query.where(child_doc.item_group == filters.item_group)
|
||||
join_required = True
|
||||
|
||||
if not payments:
|
||||
if filters.get("brand"):
|
||||
query = query.where(child_doc.brand == filters.brand)
|
||||
join_required = True
|
||||
|
||||
if join_required:
|
||||
query = query.inner_join(child_doc).on(parent_doc.name == child_doc.parent)
|
||||
query = query.distinct()
|
||||
|
||||
if parent_doc.get_table_name() != "tabJournal Entry":
|
||||
query = filter_invoices_based_on_dimensions(filters, query, parent_doc)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def get_advance_taxes_and_charges(invoice_list):
|
||||
adv_taxes = frappe.qb.DocType("Advance Taxes and Charges")
|
||||
return (
|
||||
frappe.qb.from_(adv_taxes)
|
||||
.select(
|
||||
adv_taxes.parent,
|
||||
adv_taxes.account_head,
|
||||
(
|
||||
frappe.qb.terms.Case()
|
||||
.when(adv_taxes.add_deduct_tax == "Add", Sum(adv_taxes.base_tax_amount))
|
||||
.else_(Sum(adv_taxes.base_tax_amount) * -1)
|
||||
).as_("tax_amount"),
|
||||
)
|
||||
.where(
|
||||
(adv_taxes.parent.isin([inv.name for inv in invoice_list]))
|
||||
& (adv_taxes.charge_type.isin(["On Paid Amount", "Actual"]))
|
||||
& (adv_taxes.base_tax_amount != 0)
|
||||
)
|
||||
.groupby(adv_taxes.parent, adv_taxes.account_head, adv_taxes.add_deduct_tax)
|
||||
).run(as_dict=True)
|
||||
|
||||
|
||||
def filter_invoices_based_on_dimensions(filters, query, parent_doc):
|
||||
accounting_dimensions = get_accounting_dimensions(as_list=False)
|
||||
if accounting_dimensions:
|
||||
for dimension in accounting_dimensions:
|
||||
if filters.get(dimension.fieldname):
|
||||
if frappe.get_cached_value("DocType", dimension.document_type, "is_tree"):
|
||||
filters[dimension.fieldname] = get_dimension_with_children(
|
||||
dimension.document_type, filters.get(dimension.fieldname)
|
||||
)
|
||||
fieldname = dimension.fieldname
|
||||
query = query.where(parent_doc[fieldname] == filters.fieldname)
|
||||
return query
|
||||
|
||||
|
||||
def get_opening_row(party_type, party, from_date, company):
|
||||
party_account = get_party_account(party_type, party, company)
|
||||
gle = frappe.qb.DocType("GL Entry")
|
||||
return (
|
||||
frappe.qb.from_(gle)
|
||||
.select(
|
||||
ConstantColumn("Opening").as_("account"),
|
||||
Sum(gle.debit).as_("debit"),
|
||||
Sum(gle.credit).as_("credit"),
|
||||
(Sum(gle.debit) - Sum(gle.credit)).as_("balance"),
|
||||
)
|
||||
.where(
|
||||
(gle.account == party_account)
|
||||
& (gle.party == party)
|
||||
& (gle.posting_date < from_date)
|
||||
& (gle.is_cancelled == 0)
|
||||
)
|
||||
).run(as_dict=True)
|
||||
|
||||
@@ -626,8 +626,10 @@ def update_reference_in_payment_entry(
|
||||
"total_amount": d.grand_total,
|
||||
"outstanding_amount": d.outstanding_amount,
|
||||
"allocated_amount": d.allocated_amount,
|
||||
"exchange_rate": d.exchange_rate if d.exchange_gain_loss else payment_entry.get_exchange_rate(),
|
||||
"exchange_gain_loss": d.exchange_gain_loss,
|
||||
"exchange_rate": d.exchange_rate
|
||||
if d.difference_amount is not None
|
||||
else payment_entry.get_exchange_rate(),
|
||||
"exchange_gain_loss": d.difference_amount,
|
||||
}
|
||||
|
||||
if d.voucher_detail_no:
|
||||
|
||||
@@ -519,10 +519,16 @@ frappe.ui.form.on('Asset', {
|
||||
indicator: 'red'
|
||||
});
|
||||
}
|
||||
frm.set_value('gross_purchase_amount', item.base_net_rate + item.item_tax_amount);
|
||||
frm.set_value('purchase_receipt_amount', item.base_net_rate + item.item_tax_amount);
|
||||
item.asset_location && frm.set_value('location', item.asset_location);
|
||||
var is_grouped_asset = frappe.db.get_value('Item', item.item_code, 'is_grouped_asset');
|
||||
var asset_quantity = is_grouped_asset ? item.qty : 1;
|
||||
var purchase_amount = flt(item.valuation_rate * asset_quantity, precision('gross_purchase_amount'));
|
||||
|
||||
frm.set_value('gross_purchase_amount', purchase_amount);
|
||||
frm.set_value('purchase_receipt_amount', purchase_amount);
|
||||
frm.set_value('asset_quantity', asset_quantity);
|
||||
frm.set_value('cost_center', item.cost_center || purchase_doc.cost_center);
|
||||
if(item.asset_location) { frm.set_value('location', item.asset_location); }
|
||||
|
||||
},
|
||||
|
||||
set_depreciation_rate: function(frm, row) {
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
"purchase_receipt",
|
||||
"purchase_invoice",
|
||||
"available_for_use_date",
|
||||
"total_asset_cost",
|
||||
"additional_asset_cost",
|
||||
"column_break_23",
|
||||
"gross_purchase_amount",
|
||||
"asset_quantity",
|
||||
@@ -200,9 +202,9 @@
|
||||
"fieldname": "purchase_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Purchase Date",
|
||||
"mandatory_depends_on": "eval:!doc.is_existing_asset",
|
||||
"read_only": 1,
|
||||
"read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset",
|
||||
"reqd": 1
|
||||
"read_only_depends_on": "eval:!doc.is_existing_asset && !doc.is_composite_asset"
|
||||
},
|
||||
{
|
||||
"fieldname": "disposal_date",
|
||||
@@ -225,15 +227,15 @@
|
||||
"fieldname": "gross_purchase_amount",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Gross Purchase Amount",
|
||||
"mandatory_depends_on": "eval:(!doc.is_composite_asset || doc.docstatus==1)",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only_depends_on": "eval:!doc.is_existing_asset",
|
||||
"reqd": 1
|
||||
"read_only_depends_on": "eval:!doc.is_existing_asset"
|
||||
},
|
||||
{
|
||||
"fieldname": "available_for_use_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Available-for-use Date",
|
||||
"reqd": 1
|
||||
"mandatory_depends_on": "eval:(!doc.is_composite_asset || doc.docstatus==1)"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@@ -532,6 +534,22 @@
|
||||
"label": "Capitalized In",
|
||||
"options": "Asset Capitalization",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.docstatus > 0",
|
||||
"fieldname": "total_asset_cost",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Asset Cost",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.docstatus > 0",
|
||||
"fieldname": "additional_asset_cost",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Additional Asset Cost",
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"idx": 72,
|
||||
@@ -565,7 +583,7 @@
|
||||
"link_fieldname": "target_asset"
|
||||
}
|
||||
],
|
||||
"modified": "2023-11-20 21:05:45.216899",
|
||||
"modified": "2024-01-05 17:36:53.131512",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset",
|
||||
@@ -609,4 +627,4 @@
|
||||
"states": [],
|
||||
"title_field": "asset_name",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class Asset(AccountsController):
|
||||
if self.get("schedules"):
|
||||
self.validate_expected_value_after_useful_life()
|
||||
|
||||
self.total_asset_cost = self.gross_purchase_amount
|
||||
self.status = self.get_status()
|
||||
|
||||
def on_submit(self):
|
||||
@@ -246,7 +247,12 @@ class Asset(AccountsController):
|
||||
frappe.throw(_("Gross Purchase Amount is mandatory"), frappe.MandatoryError)
|
||||
|
||||
if is_cwip_accounting_enabled(self.asset_category):
|
||||
if not self.is_existing_asset and not (self.purchase_receipt or self.purchase_invoice):
|
||||
if (
|
||||
not self.is_existing_asset
|
||||
and not self.is_composite_asset
|
||||
and not self.purchase_receipt
|
||||
and not self.purchase_invoice
|
||||
):
|
||||
frappe.throw(
|
||||
_("Please create purchase receipt or purchase invoice for the item {0}").format(
|
||||
self.item_code
|
||||
@@ -259,7 +265,7 @@ class Asset(AccountsController):
|
||||
and not frappe.db.get_value("Purchase Invoice", self.purchase_invoice, "update_stock")
|
||||
):
|
||||
frappe.throw(
|
||||
_("Update stock must be enable for the purchase invoice {0}").format(self.purchase_invoice)
|
||||
_("Update stock must be enabled for the purchase invoice {0}").format(self.purchase_invoice)
|
||||
)
|
||||
|
||||
if not self.calculate_depreciation:
|
||||
@@ -427,10 +433,7 @@ class Asset(AccountsController):
|
||||
n == 0
|
||||
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
|
||||
and not self.opening_accumulated_depreciation
|
||||
and get_updated_rate_of_depreciation_for_wdv_and_dd(
|
||||
self, value_after_depreciation, finance_book, False
|
||||
)
|
||||
== finance_book.rate_of_depreciation
|
||||
and not self.flags.wdv_it_act_applied
|
||||
):
|
||||
from_date = add_days(
|
||||
self.available_for_use_date, -1
|
||||
@@ -1377,26 +1380,16 @@ def get_depreciation_amount(
|
||||
asset, fb_row, schedule_idx, number_of_pending_depreciations
|
||||
)
|
||||
else:
|
||||
rate_of_depreciation = get_updated_rate_of_depreciation_for_wdv_and_dd(
|
||||
asset, depreciable_value, fb_row
|
||||
)
|
||||
return get_wdv_or_dd_depr_amount(
|
||||
asset,
|
||||
fb_row,
|
||||
depreciable_value,
|
||||
rate_of_depreciation,
|
||||
fb_row.frequency_of_depreciation,
|
||||
schedule_idx,
|
||||
prev_depreciation_amount,
|
||||
has_wdv_or_dd_non_yearly_pro_rata,
|
||||
)
|
||||
|
||||
|
||||
@erpnext.allow_regional
|
||||
def get_updated_rate_of_depreciation_for_wdv_and_dd(
|
||||
asset, depreciable_value, fb_row, show_msg=True
|
||||
):
|
||||
return fb_row.rate_of_depreciation
|
||||
|
||||
|
||||
def get_straight_line_or_manual_depr_amount(
|
||||
asset, row, schedule_idx, number_of_pending_depreciations
|
||||
):
|
||||
@@ -1531,30 +1524,53 @@ def get_asset_shift_factors_map():
|
||||
return dict(frappe.db.get_all("Asset Shift Factor", ["shift_name", "shift_factor"], as_list=True))
|
||||
|
||||
|
||||
@erpnext.allow_regional
|
||||
def get_wdv_or_dd_depr_amount(
|
||||
asset,
|
||||
fb_row,
|
||||
depreciable_value,
|
||||
rate_of_depreciation,
|
||||
frequency_of_depreciation,
|
||||
schedule_idx,
|
||||
prev_depreciation_amount,
|
||||
has_wdv_or_dd_non_yearly_pro_rata,
|
||||
):
|
||||
if cint(frequency_of_depreciation) == 12:
|
||||
return flt(depreciable_value) * (flt(rate_of_depreciation) / 100)
|
||||
return get_default_wdv_or_dd_depr_amount(
|
||||
asset,
|
||||
fb_row,
|
||||
depreciable_value,
|
||||
schedule_idx,
|
||||
prev_depreciation_amount,
|
||||
has_wdv_or_dd_non_yearly_pro_rata,
|
||||
)
|
||||
|
||||
|
||||
def get_default_wdv_or_dd_depr_amount(
|
||||
asset,
|
||||
fb_row,
|
||||
depreciable_value,
|
||||
schedule_idx,
|
||||
prev_depreciation_amount,
|
||||
has_wdv_or_dd_non_yearly_pro_rata,
|
||||
):
|
||||
if cint(fb_row.frequency_of_depreciation) == 12:
|
||||
return flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100)
|
||||
else:
|
||||
if has_wdv_or_dd_non_yearly_pro_rata:
|
||||
if schedule_idx == 0:
|
||||
return flt(depreciable_value) * (flt(rate_of_depreciation) / 100)
|
||||
elif schedule_idx % (12 / cint(frequency_of_depreciation)) == 1:
|
||||
return flt(depreciable_value) * (flt(fb_row.rate_of_depreciation) / 100)
|
||||
elif schedule_idx % (12 / cint(fb_row.frequency_of_depreciation)) == 1:
|
||||
return (
|
||||
flt(depreciable_value) * flt(frequency_of_depreciation) * (flt(rate_of_depreciation) / 1200)
|
||||
flt(depreciable_value)
|
||||
* flt(fb_row.frequency_of_depreciation)
|
||||
* (flt(fb_row.rate_of_depreciation) / 1200)
|
||||
)
|
||||
else:
|
||||
return prev_depreciation_amount
|
||||
else:
|
||||
if schedule_idx % (12 / cint(frequency_of_depreciation)) == 0:
|
||||
if schedule_idx % (12 / cint(fb_row.frequency_of_depreciation)) == 0:
|
||||
return (
|
||||
flt(depreciable_value) * flt(frequency_of_depreciation) * (flt(rate_of_depreciation) / 1200)
|
||||
flt(depreciable_value)
|
||||
* flt(fb_row.frequency_of_depreciation)
|
||||
* (flt(fb_row.rate_of_depreciation) / 1200)
|
||||
)
|
||||
else:
|
||||
return prev_depreciation_amount
|
||||
|
||||
@@ -19,6 +19,7 @@ from frappe.utils import (
|
||||
from frappe.utils.data import get_link_to_form
|
||||
from frappe.utils.user import get_users_with_role
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_checks_for_pl_and_bs_accounts,
|
||||
)
|
||||
@@ -473,6 +474,13 @@ def depreciate_asset(asset, date):
|
||||
|
||||
make_depreciation_entry(asset.name, date)
|
||||
|
||||
cancel_depreciation_entries(asset, date)
|
||||
|
||||
|
||||
@erpnext.allow_regional
|
||||
def cancel_depreciation_entries(asset, date):
|
||||
pass
|
||||
|
||||
|
||||
def reset_depreciation_schedule(asset, date):
|
||||
if not asset.calculate_depreciation:
|
||||
|
||||
@@ -67,12 +67,12 @@ class AssetCategory(Document):
|
||||
if selected_key_type not in expected_key_types:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Row #{}: {} of {} should be {}. Please modify the account or select a different account."
|
||||
"Row #{0}: {1} of {2} should be {3}. Please update the {1} or select a different account."
|
||||
).format(
|
||||
d.idx,
|
||||
frappe.unscrub(key_to_match),
|
||||
frappe.bold(selected_account),
|
||||
frappe.bold(expected_key_types),
|
||||
frappe.bold(" or ".join(expected_key_types)),
|
||||
),
|
||||
title=_("Invalid Account"),
|
||||
)
|
||||
|
||||
@@ -90,7 +90,6 @@
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"depends_on": "eval:doc.depreciation_method == \"Straight Line\" || doc.depreciation_method == \"Manual\"",
|
||||
"fieldname": "daily_prorata_based",
|
||||
"fieldtype": "Check",
|
||||
"label": "Depreciate based on daily pro-rata"
|
||||
@@ -106,7 +105,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-29 03:53:03.591098",
|
||||
"modified": "2023-12-29 08:49:39.876439",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Finance Book",
|
||||
|
||||
@@ -46,6 +46,10 @@ class AssetRepair(AccountsController):
|
||||
|
||||
self.increase_asset_value()
|
||||
|
||||
if self.capitalize_repair_cost:
|
||||
self.asset_doc.total_asset_cost += self.repair_cost
|
||||
self.asset_doc.additional_asset_cost += self.repair_cost
|
||||
|
||||
if self.get("stock_consumption"):
|
||||
self.check_for_stock_items_and_warehouse()
|
||||
self.decrease_stock_quantity()
|
||||
@@ -68,6 +72,10 @@ class AssetRepair(AccountsController):
|
||||
|
||||
self.decrease_asset_value()
|
||||
|
||||
if self.capitalize_repair_cost:
|
||||
self.asset_doc.total_asset_cost -= self.repair_cost
|
||||
self.asset_doc.additional_asset_cost -= self.repair_cost
|
||||
|
||||
if self.get("stock_consumption"):
|
||||
self.increase_stock_quantity()
|
||||
if self.get("capitalize_repair_cost"):
|
||||
|
||||
@@ -188,7 +188,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-24 10:55:51.287327",
|
||||
"modified": "2024-01-05 15:26:02.320942",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Buying Settings",
|
||||
@@ -212,10 +212,45 @@
|
||||
"role": "Purchase Manager",
|
||||
"share": 1,
|
||||
"write": 1
|
||||
},
|
||||
{
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Accounts User",
|
||||
"share": 1
|
||||
},
|
||||
{
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Accounts Manager",
|
||||
"share": 1
|
||||
},
|
||||
{
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Stock Manager",
|
||||
"share": 1
|
||||
},
|
||||
{
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Stock User",
|
||||
"share": 1
|
||||
},
|
||||
{
|
||||
"email": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"role": "Purchase User",
|
||||
"share": 1
|
||||
}
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,7 @@
|
||||
"oldfieldname": "item_code",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Item",
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "supplier_part_no",
|
||||
|
||||
@@ -80,6 +80,15 @@ class RequestforQuotation(BuyingController):
|
||||
supplier.quote_status = "Pending"
|
||||
self.send_to_supplier()
|
||||
|
||||
def before_print(self, settings=None):
|
||||
"""Use the first suppliers data to render the print preview."""
|
||||
if self.vendor or not self.suppliers:
|
||||
# If a specific supplier is already set, via Tools > Download PDF,
|
||||
# we don't want to override it.
|
||||
return
|
||||
|
||||
self.update_supplier_part_no(self.suppliers[0].supplier)
|
||||
|
||||
def on_cancel(self):
|
||||
self.db_set("status", "Cancelled")
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ class AccountsController(TransactionBase):
|
||||
self.disable_pricing_rule_on_internal_transfer()
|
||||
self.disable_tax_included_prices_for_internal_transfer()
|
||||
self.set_incoming_rate()
|
||||
self.init_internal_values()
|
||||
|
||||
if self.meta.get_field("currency"):
|
||||
self.calculate_taxes_and_totals()
|
||||
@@ -224,6 +225,16 @@ class AccountsController(TransactionBase):
|
||||
|
||||
self.set_total_in_words()
|
||||
|
||||
def init_internal_values(self):
|
||||
# init all the internal values as 0 on sa
|
||||
if self.docstatus.is_draft():
|
||||
# TODO: Add all such pending values here
|
||||
fields = ["billed_amt", "delivered_qty"]
|
||||
for item in self.get("items"):
|
||||
for field in fields:
|
||||
if hasattr(item, field):
|
||||
item.set(field, 0)
|
||||
|
||||
def before_cancel(self):
|
||||
validate_einvoice_fields(self)
|
||||
|
||||
@@ -629,6 +640,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
args["doctype"] = self.doctype
|
||||
args["name"] = self.name
|
||||
args["child_doctype"] = item.doctype
|
||||
args["child_docname"] = item.name
|
||||
args["ignore_pricing_rule"] = (
|
||||
self.ignore_pricing_rule if hasattr(self, "ignore_pricing_rule") else 0
|
||||
@@ -2353,6 +2365,7 @@ def validate_taxes_and_charges(tax):
|
||||
|
||||
def validate_account_head(idx, account, company, context=""):
|
||||
account_company = frappe.get_cached_value("Account", account, "company")
|
||||
is_group = frappe.get_cached_value("Account", account, "is_group")
|
||||
|
||||
if account_company != company:
|
||||
frappe.throw(
|
||||
@@ -2362,6 +2375,12 @@ def validate_account_head(idx, account, company, context=""):
|
||||
title=_("Invalid Account"),
|
||||
)
|
||||
|
||||
if is_group:
|
||||
frappe.throw(
|
||||
_("Row {0}: Account {1} is a Group Account").format(idx, frappe.bold(account)),
|
||||
title=_("Invalid Account"),
|
||||
)
|
||||
|
||||
|
||||
def validate_cost_center(tax, doc):
|
||||
if not tax.cost_center:
|
||||
@@ -2504,6 +2523,7 @@ def get_advance_payment_entries(
|
||||
against_all_orders=False,
|
||||
limit=None,
|
||||
condition=None,
|
||||
payment_name=None,
|
||||
):
|
||||
party_account_field = "paid_from" if party_type == "Customer" else "paid_to"
|
||||
currency_field = (
|
||||
@@ -2526,6 +2546,10 @@ def get_advance_payment_entries(
|
||||
reference_condition = ""
|
||||
order_list = []
|
||||
|
||||
payment_name_filter = ""
|
||||
if payment_name:
|
||||
payment_name_filter = " and t1.name like '%%{0}%%'".format(payment_name)
|
||||
|
||||
if not condition:
|
||||
condition = ""
|
||||
|
||||
@@ -2540,7 +2564,7 @@ def get_advance_payment_entries(
|
||||
where
|
||||
t1.name = t2.parent and t1.{1} = %s and t1.payment_type = %s
|
||||
and t1.party_type = %s and t1.party = %s and t1.docstatus = 1
|
||||
and t2.reference_doctype = %s {2} {3}
|
||||
and t2.reference_doctype = %s {2} {3} {6}
|
||||
order by t1.posting_date {4}
|
||||
""".format(
|
||||
currency_field,
|
||||
@@ -2549,12 +2573,17 @@ def get_advance_payment_entries(
|
||||
condition,
|
||||
limit_cond,
|
||||
exchange_rate_field,
|
||||
payment_name_filter,
|
||||
),
|
||||
[party_account, payment_type, party_type, party, order_doctype] + order_list,
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if include_unallocated:
|
||||
payment_name_filter = ""
|
||||
if payment_name:
|
||||
payment_name_filter = " and name like '%%{0}%%'".format(payment_name)
|
||||
|
||||
unallocated_payment_entries = frappe.db.sql(
|
||||
"""
|
||||
select 'Payment Entry' as reference_type, name as reference_name, posting_date,
|
||||
@@ -2562,10 +2591,15 @@ def get_advance_payment_entries(
|
||||
from `tabPayment Entry`
|
||||
where
|
||||
{0} = %s and party_type = %s and party = %s and payment_type = %s
|
||||
and docstatus = 1 and unallocated_amount > 0 {condition}
|
||||
and docstatus = 1 and unallocated_amount > 0 {condition} {4}
|
||||
order by posting_date {1}
|
||||
""".format(
|
||||
party_account_field, limit_cond, exchange_rate_field, currency_field, condition=condition or ""
|
||||
party_account_field,
|
||||
limit_cond,
|
||||
exchange_rate_field,
|
||||
currency_field,
|
||||
payment_name_filter,
|
||||
condition=condition or "",
|
||||
),
|
||||
(party_account, party_type, party, payment_type),
|
||||
as_dict=1,
|
||||
|
||||
@@ -354,7 +354,11 @@ class BuyingController(SubcontractingController):
|
||||
|
||||
rate = flt(outgoing_rate * (d.conversion_factor or 1), d.precision("rate"))
|
||||
else:
|
||||
field = "incoming_rate" if self.get("is_internal_supplier") else "rate"
|
||||
field = (
|
||||
"incoming_rate"
|
||||
if self.get("is_internal_supplier") and not self.doctype == "Purchase Order"
|
||||
else "rate"
|
||||
)
|
||||
rate = flt(
|
||||
frappe.db.get_value(ref_doctype, d.get(frappe.scrub(ref_doctype)), field)
|
||||
* (d.conversion_factor or 1),
|
||||
@@ -726,11 +730,8 @@ class BuyingController(SubcontractingController):
|
||||
item_data = frappe.db.get_value(
|
||||
"Item", row.item_code, ["asset_naming_series", "asset_category"], as_dict=1
|
||||
)
|
||||
|
||||
if is_grouped_asset:
|
||||
purchase_amount = flt(row.base_amount + row.item_tax_amount)
|
||||
else:
|
||||
purchase_amount = flt(row.base_rate + row.item_tax_amount)
|
||||
asset_quantity = row.qty if is_grouped_asset else 1
|
||||
purchase_amount = flt(row.valuation_rate) * asset_quantity
|
||||
|
||||
asset = frappe.get_doc(
|
||||
{
|
||||
@@ -746,7 +747,7 @@ class BuyingController(SubcontractingController):
|
||||
"calculate_depreciation": 1,
|
||||
"purchase_receipt_amount": purchase_amount,
|
||||
"gross_purchase_amount": purchase_amount,
|
||||
"asset_quantity": row.qty if is_grouped_asset else 1,
|
||||
"asset_quantity": asset_quantity,
|
||||
"purchase_receipt": self.name if self.doctype == "Purchase Receipt" else None,
|
||||
"purchase_invoice": self.name if self.doctype == "Purchase Invoice" else None,
|
||||
"cost_center": row.cost_center,
|
||||
|
||||
@@ -52,10 +52,24 @@ def make_variant_based_on_manufacturer(template, manufacturer, manufacturer_part
|
||||
|
||||
copy_attributes_to_variant(template, variant)
|
||||
|
||||
variant.manufacturer = manufacturer
|
||||
variant.manufacturer_part_no = manufacturer_part_no
|
||||
|
||||
variant.item_code = append_number_if_name_exists("Item", template.name)
|
||||
variant.flags.ignore_mandatory = True
|
||||
variant.save()
|
||||
|
||||
if not frappe.db.exists(
|
||||
"Item Manufacturer", {"item_code": variant.name, "manufacturer": manufacturer}
|
||||
):
|
||||
manufacturer_doc = frappe.new_doc("Item Manufacturer")
|
||||
manufacturer_doc.update(
|
||||
{
|
||||
"item_code": variant.name,
|
||||
"manufacturer": manufacturer,
|
||||
"manufacturer_part_no": manufacturer_part_no,
|
||||
}
|
||||
)
|
||||
|
||||
manufacturer_doc.flags.ignore_mandatory = True
|
||||
manufacturer_doc.save(ignore_permissions=True)
|
||||
|
||||
return variant
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from frappe.model.meta import get_field_precision
|
||||
from frappe.utils import flt, format_datetime, get_datetime
|
||||
|
||||
import erpnext
|
||||
from erpnext.stock.utils import get_incoming_rate
|
||||
from erpnext.stock.utils import get_incoming_rate, get_valuation_method
|
||||
|
||||
|
||||
class StockOverReturnError(frappe.ValidationError):
|
||||
@@ -116,7 +116,12 @@ def validate_returned_items(doc):
|
||||
ref = valid_items.get(d.item_code, frappe._dict())
|
||||
validate_quantity(doc, d, ref, valid_items, already_returned_items)
|
||||
|
||||
if ref.rate and doc.doctype in ("Delivery Note", "Sales Invoice") and flt(d.rate) > ref.rate:
|
||||
if (
|
||||
ref.rate
|
||||
and flt(d.rate) > ref.rate
|
||||
and doc.doctype in ("Delivery Note", "Sales Invoice")
|
||||
and get_valuation_method(ref.item_code) != "Moving Average"
|
||||
):
|
||||
frappe.throw(
|
||||
_("Row # {0}: Rate cannot be greater than the rate used in {1} {2}").format(
|
||||
d.idx, doc.doctype, doc.return_against
|
||||
|
||||
@@ -12,7 +12,7 @@ from erpnext.controllers.sales_and_purchase_return import get_rate_for_return
|
||||
from erpnext.controllers.stock_controller import StockController
|
||||
from erpnext.stock.doctype.item.item import set_item_default
|
||||
from erpnext.stock.get_item_details import get_bin_details, get_conversion_factor
|
||||
from erpnext.stock.utils import get_incoming_rate
|
||||
from erpnext.stock.utils import get_incoming_rate, get_valuation_method
|
||||
|
||||
|
||||
class SellingController(StockController):
|
||||
@@ -422,11 +422,18 @@ class SellingController(StockController):
|
||||
|
||||
items = self.get("items") + (self.get("packed_items") or [])
|
||||
for d in items:
|
||||
if not self.get("return_against"):
|
||||
if not frappe.get_cached_value("Item", d.item_code, "is_stock_item"):
|
||||
continue
|
||||
|
||||
if not self.get("return_against") or (
|
||||
get_valuation_method(d.item_code) == "Moving Average" and self.get("is_return")
|
||||
):
|
||||
# Get incoming rate based on original item cost based on valuation method
|
||||
qty = flt(d.get("stock_qty") or d.get("actual_qty"))
|
||||
|
||||
if not (self.get("is_return") and d.incoming_rate):
|
||||
if not d.incoming_rate or (
|
||||
get_valuation_method(d.item_code) == "Moving Average" and self.get("is_return")
|
||||
):
|
||||
d.incoming_rate = get_incoming_rate(
|
||||
{
|
||||
"item_code": d.item_code,
|
||||
|
||||
@@ -433,8 +433,11 @@ class SubcontractingController(StockController):
|
||||
self.__set_batch_no_as_per_qty(item_row, new_rm_obj, batch_no, batch_qty)
|
||||
self.available_materials[key]["batch_no"][batch_no] = 0
|
||||
|
||||
if abs(qty) > 0 and not new_rm_obj:
|
||||
if new_rm_obj:
|
||||
self.remove(rm_obj)
|
||||
elif abs(qty) > 0:
|
||||
self.__set_consumed_qty(rm_obj, qty)
|
||||
|
||||
else:
|
||||
self.__set_consumed_qty(rm_obj, qty, bom_item.required_qty or qty)
|
||||
self.__set_serial_nos(item_row, rm_obj)
|
||||
@@ -525,6 +528,10 @@ class SubcontractingController(StockController):
|
||||
(row.item_code, row.get(self.subcontract_data.order_field))
|
||||
] -= row.qty
|
||||
|
||||
def __reset_idx(self):
|
||||
for idx, item in enumerate(self.get(self.raw_material_table)):
|
||||
item.idx = idx + 1
|
||||
|
||||
def __prepare_supplied_items(self):
|
||||
self.initialized_fields()
|
||||
self.__get_subcontract_orders()
|
||||
@@ -532,6 +539,7 @@ class SubcontractingController(StockController):
|
||||
self.get_available_materials()
|
||||
self.__remove_changed_rows()
|
||||
self.__set_supplied_items()
|
||||
self.__reset_idx()
|
||||
|
||||
def __validate_batch_no(self, row, key):
|
||||
if row.get("batch_no") and row.get("batch_no") not in self.__transferred_items.get(key).get(
|
||||
|
||||
@@ -514,7 +514,7 @@
|
||||
"idx": 5,
|
||||
"image_field": "image",
|
||||
"links": [],
|
||||
"modified": "2022-10-13 12:42:04.277879",
|
||||
"modified": "2023-12-01 18:46:49.468526",
|
||||
"modified_by": "Administrator",
|
||||
"module": "CRM",
|
||||
"name": "Lead",
|
||||
@@ -576,10 +576,11 @@
|
||||
],
|
||||
"search_fields": "lead_name,lead_owner,status",
|
||||
"sender_field": "email_id",
|
||||
"sender_name_field": "lead_name",
|
||||
"show_name_in_global_search": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"subject_field": "title",
|
||||
"title_field": "title"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ from frappe.utils import comma_and, get_link_to_form, has_gravatar, validate_ema
|
||||
from erpnext.accounts.party import set_taxes
|
||||
from erpnext.controllers.selling_controller import SellingController
|
||||
from erpnext.crm.utils import CRMNote, copy_comments, link_communications, link_open_events
|
||||
from erpnext.selling.doctype.customer.customer import parse_full_name
|
||||
|
||||
|
||||
class Lead(SellingController, CRMNote):
|
||||
@@ -48,6 +49,10 @@ class Lead(SellingController, CRMNote):
|
||||
return
|
||||
self.contact_doc = self.create_contact()
|
||||
|
||||
# leads created by email inbox only have the full name set
|
||||
if self.lead_name and not any([self.first_name, self.middle_name, self.last_name]):
|
||||
self.first_name, self.middle_name, self.last_name = parse_full_name(self.lead_name)
|
||||
|
||||
def after_insert(self):
|
||||
self.link_to_contact()
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"column_break_21",
|
||||
"default_customer_group",
|
||||
"quotation_series",
|
||||
"show_actual_qty",
|
||||
"checkout_settings_section",
|
||||
"enable_checkout",
|
||||
"show_price_in_quotation",
|
||||
@@ -366,12 +367,19 @@
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable Redisearch",
|
||||
"read_only_depends_on": "eval:!doc.is_redisearch_loaded"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"description": "If enabled Actual Qty will be shown as <b>In Stock</b> on the product page instead of Projected Qty.",
|
||||
"fieldname": "show_actual_qty",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Actual Qty"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2022-04-01 18:35:56.106756",
|
||||
"modified": "2024-01-10 21:06:45.386977",
|
||||
"modified_by": "Administrator",
|
||||
"module": "E-commerce",
|
||||
"name": "E Commerce Settings",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from frappe import _
|
||||
|
||||
app_name = "erpnext"
|
||||
app_title = "ERPNext"
|
||||
app_publisher = "Frappe Technologies Pvt. Ltd."
|
||||
@@ -92,7 +90,7 @@ website_route_rules = [
|
||||
{
|
||||
"from_route": "/orders/<path:name>",
|
||||
"to_route": "order",
|
||||
"defaults": {"doctype": "Sales Order", "parents": [{"label": _("Orders"), "route": "orders"}]},
|
||||
"defaults": {"doctype": "Sales Order", "parents": [{"label": "Orders", "route": "orders"}]},
|
||||
},
|
||||
{"from_route": "/invoices", "to_route": "Sales Invoice"},
|
||||
{
|
||||
@@ -100,7 +98,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Sales Invoice",
|
||||
"parents": [{"label": _("Invoices"), "route": "invoices"}],
|
||||
"parents": [{"label": "Invoices", "route": "invoices"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/supplier-quotations", "to_route": "Supplier Quotation"},
|
||||
@@ -109,7 +107,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Supplier Quotation",
|
||||
"parents": [{"label": _("Supplier Quotation"), "route": "supplier-quotations"}],
|
||||
"parents": [{"label": "Supplier Quotation", "route": "supplier-quotations"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/purchase-orders", "to_route": "Purchase Order"},
|
||||
@@ -118,7 +116,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Purchase Order",
|
||||
"parents": [{"label": _("Purchase Order"), "route": "purchase-orders"}],
|
||||
"parents": [{"label": "Purchase Order", "route": "purchase-orders"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/purchase-invoices", "to_route": "Purchase Invoice"},
|
||||
@@ -127,7 +125,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Purchase Invoice",
|
||||
"parents": [{"label": _("Purchase Invoice"), "route": "purchase-invoices"}],
|
||||
"parents": [{"label": "Purchase Invoice", "route": "purchase-invoices"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/quotations", "to_route": "Quotation"},
|
||||
@@ -136,7 +134,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Quotation",
|
||||
"parents": [{"label": _("Quotations"), "route": "quotations"}],
|
||||
"parents": [{"label": "Quotations", "route": "quotations"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/shipments", "to_route": "Delivery Note"},
|
||||
@@ -145,7 +143,7 @@ website_route_rules = [
|
||||
"to_route": "order",
|
||||
"defaults": {
|
||||
"doctype": "Delivery Note",
|
||||
"parents": [{"label": _("Shipments"), "route": "shipments"}],
|
||||
"parents": [{"label": "Shipments", "route": "shipments"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/rfq", "to_route": "Request for Quotation"},
|
||||
@@ -154,14 +152,14 @@ website_route_rules = [
|
||||
"to_route": "rfq",
|
||||
"defaults": {
|
||||
"doctype": "Request for Quotation",
|
||||
"parents": [{"label": _("Request for Quotation"), "route": "rfq"}],
|
||||
"parents": [{"label": "Request for Quotation", "route": "rfq"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/addresses", "to_route": "Address"},
|
||||
{
|
||||
"from_route": "/addresses/<path:name>",
|
||||
"to_route": "addresses",
|
||||
"defaults": {"doctype": "Address", "parents": [{"label": _("Addresses"), "route": "addresses"}]},
|
||||
"defaults": {"doctype": "Address", "parents": [{"label": "Addresses", "route": "addresses"}]},
|
||||
},
|
||||
{"from_route": "/boms", "to_route": "BOM"},
|
||||
{"from_route": "/timesheets", "to_route": "Timesheet"},
|
||||
@@ -171,78 +169,78 @@ website_route_rules = [
|
||||
"to_route": "material_request_info",
|
||||
"defaults": {
|
||||
"doctype": "Material Request",
|
||||
"parents": [{"label": _("Material Request"), "route": "material-requests"}],
|
||||
"parents": [{"label": "Material Request", "route": "material-requests"}],
|
||||
},
|
||||
},
|
||||
{"from_route": "/project", "to_route": "Project"},
|
||||
]
|
||||
|
||||
standard_portal_menu_items = [
|
||||
{"title": _("Projects"), "route": "/project", "reference_doctype": "Project"},
|
||||
{"title": "Projects", "route": "/project", "reference_doctype": "Project"},
|
||||
{
|
||||
"title": _("Request for Quotations"),
|
||||
"title": "Request for Quotations",
|
||||
"route": "/rfq",
|
||||
"reference_doctype": "Request for Quotation",
|
||||
"role": "Supplier",
|
||||
},
|
||||
{
|
||||
"title": _("Supplier Quotation"),
|
||||
"title": "Supplier Quotation",
|
||||
"route": "/supplier-quotations",
|
||||
"reference_doctype": "Supplier Quotation",
|
||||
"role": "Supplier",
|
||||
},
|
||||
{
|
||||
"title": _("Purchase Orders"),
|
||||
"title": "Purchase Orders",
|
||||
"route": "/purchase-orders",
|
||||
"reference_doctype": "Purchase Order",
|
||||
"role": "Supplier",
|
||||
},
|
||||
{
|
||||
"title": _("Purchase Invoices"),
|
||||
"title": "Purchase Invoices",
|
||||
"route": "/purchase-invoices",
|
||||
"reference_doctype": "Purchase Invoice",
|
||||
"role": "Supplier",
|
||||
},
|
||||
{
|
||||
"title": _("Quotations"),
|
||||
"title": "Quotations",
|
||||
"route": "/quotations",
|
||||
"reference_doctype": "Quotation",
|
||||
"role": "Customer",
|
||||
},
|
||||
{
|
||||
"title": _("Orders"),
|
||||
"title": "Orders",
|
||||
"route": "/orders",
|
||||
"reference_doctype": "Sales Order",
|
||||
"role": "Customer",
|
||||
},
|
||||
{
|
||||
"title": _("Invoices"),
|
||||
"title": "Invoices",
|
||||
"route": "/invoices",
|
||||
"reference_doctype": "Sales Invoice",
|
||||
"role": "Customer",
|
||||
},
|
||||
{
|
||||
"title": _("Shipments"),
|
||||
"title": "Shipments",
|
||||
"route": "/shipments",
|
||||
"reference_doctype": "Delivery Note",
|
||||
"role": "Customer",
|
||||
},
|
||||
{"title": _("Issues"), "route": "/issues", "reference_doctype": "Issue", "role": "Customer"},
|
||||
{"title": _("Addresses"), "route": "/addresses", "reference_doctype": "Address"},
|
||||
{"title": "Issues", "route": "/issues", "reference_doctype": "Issue", "role": "Customer"},
|
||||
{"title": "Addresses", "route": "/addresses", "reference_doctype": "Address"},
|
||||
{
|
||||
"title": _("Timesheets"),
|
||||
"title": "Timesheets",
|
||||
"route": "/timesheets",
|
||||
"reference_doctype": "Timesheet",
|
||||
"role": "Customer",
|
||||
},
|
||||
{"title": _("Newsletter"), "route": "/newsletters", "reference_doctype": "Newsletter"},
|
||||
{"title": "Newsletter", "route": "/newsletters", "reference_doctype": "Newsletter"},
|
||||
{
|
||||
"title": _("Material Request"),
|
||||
"title": "Material Request",
|
||||
"route": "/material-requests",
|
||||
"reference_doctype": "Material Request",
|
||||
"role": "Customer",
|
||||
},
|
||||
{"title": _("Appointment Booking"), "route": "/book_appointment"},
|
||||
{"title": "Appointment Booking", "route": "/book_appointment"},
|
||||
]
|
||||
|
||||
default_roles = [
|
||||
|
||||
@@ -80,7 +80,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
self.update_amc_date(serial_nos, d.end_date)
|
||||
|
||||
no_email_sp = []
|
||||
if d.sales_person not in email_map:
|
||||
if d.sales_person and d.sales_person not in email_map:
|
||||
sp = frappe.get_doc("Sales Person", d.sales_person)
|
||||
try:
|
||||
email_map[d.sales_person] = sp.get_email_id()
|
||||
@@ -94,12 +94,11 @@ class MaintenanceSchedule(TransactionBase):
|
||||
).format(self.owner, "<br>" + "<br>".join(no_email_sp))
|
||||
)
|
||||
|
||||
scheduled_date = frappe.db.sql(
|
||||
"""select scheduled_date from
|
||||
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
||||
parent=%s""",
|
||||
(d.sales_person, d.item_code, self.name),
|
||||
as_dict=1,
|
||||
scheduled_date = frappe.db.get_all(
|
||||
"Maintenance Schedule Detail",
|
||||
{"parent": self.name, "item_code": d.item_code},
|
||||
["scheduled_date"],
|
||||
as_list=False,
|
||||
)
|
||||
|
||||
for key in scheduled_date:
|
||||
@@ -195,8 +194,6 @@ class MaintenanceSchedule(TransactionBase):
|
||||
throw(_("Please select Start Date and End Date for Item {0}").format(d.item_code))
|
||||
elif not d.no_of_visits:
|
||||
throw(_("Please mention no of visits required"))
|
||||
elif not d.sales_person:
|
||||
throw(_("Please select a Sales Person for item: {0}").format(d.item_name))
|
||||
|
||||
if getdate(d.start_date) >= getdate(d.end_date):
|
||||
throw(_("Start date should be less than end date for Item {0}").format(d.item_code))
|
||||
@@ -392,16 +389,28 @@ def get_serial_nos_from_schedule(item_code, schedule=None):
|
||||
def make_maintenance_visit(source_name, target_doc=None, item_name=None, s_id=None):
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
def condition(doc):
|
||||
if s_id:
|
||||
return doc.name == s_id
|
||||
elif item_name:
|
||||
return doc.item_name == item_name
|
||||
|
||||
return True
|
||||
|
||||
def update_status_and_detail(source, target, parent):
|
||||
target.maintenance_type = "Scheduled"
|
||||
target.maintenance_schedule_detail = s_id
|
||||
|
||||
def update_serial(source, target, parent):
|
||||
serial_nos = get_serial_nos(target.serial_no)
|
||||
if len(serial_nos) == 1:
|
||||
target.serial_no = serial_nos[0]
|
||||
else:
|
||||
target.serial_no = ""
|
||||
if source.item_reference:
|
||||
if serial_nos := frappe.db.get_value(
|
||||
"Maintenance Schedule Item", source.item_reference, "serial_no"
|
||||
):
|
||||
serial_nos = serial_nos.split("\n")
|
||||
|
||||
if len(serial_nos) == 1:
|
||||
target.serial_no = serial_nos[0]
|
||||
else:
|
||||
target.serial_no = ""
|
||||
|
||||
doclist = get_mapped_doc(
|
||||
"Maintenance Schedule",
|
||||
@@ -413,10 +422,13 @@ def make_maintenance_visit(source_name, target_doc=None, item_name=None, s_id=No
|
||||
"validation": {"docstatus": ["=", 1]},
|
||||
"postprocess": update_status_and_detail,
|
||||
},
|
||||
"Maintenance Schedule Item": {
|
||||
"Maintenance Schedule Detail": {
|
||||
"doctype": "Maintenance Visit Purpose",
|
||||
"condition": lambda doc: doc.item_name == item_name if item_name else True,
|
||||
"field_map": {"sales_person": "service_person"},
|
||||
"condition": condition,
|
||||
"field_map": {
|
||||
"sales_person": "service_person",
|
||||
"name": "maintenance_schedule_detail",
|
||||
},
|
||||
"postprocess": update_serial,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -23,20 +23,39 @@ class MaintenanceVisit(TransactionBase):
|
||||
frappe.throw(_("Add Items in the Purpose Table"), title=_("Purposes Required"))
|
||||
|
||||
def validate_maintenance_date(self):
|
||||
if self.maintenance_type == "Scheduled" and self.maintenance_schedule_detail:
|
||||
item_ref = frappe.db.get_value(
|
||||
"Maintenance Schedule Detail", self.maintenance_schedule_detail, "item_reference"
|
||||
)
|
||||
if item_ref:
|
||||
start_date, end_date = frappe.db.get_value(
|
||||
"Maintenance Schedule Item", item_ref, ["start_date", "end_date"]
|
||||
if self.maintenance_type == "Scheduled":
|
||||
if self.maintenance_schedule_detail:
|
||||
item_ref = frappe.db.get_value(
|
||||
"Maintenance Schedule Detail", self.maintenance_schedule_detail, "item_reference"
|
||||
)
|
||||
if get_datetime(self.mntc_date) < get_datetime(start_date) or get_datetime(
|
||||
self.mntc_date
|
||||
) > get_datetime(end_date):
|
||||
frappe.throw(
|
||||
_("Date must be between {0} and {1}").format(format_date(start_date), format_date(end_date))
|
||||
if item_ref:
|
||||
start_date, end_date = frappe.db.get_value(
|
||||
"Maintenance Schedule Item", item_ref, ["start_date", "end_date"]
|
||||
)
|
||||
if get_datetime(self.mntc_date) < get_datetime(start_date) or get_datetime(
|
||||
self.mntc_date
|
||||
) > get_datetime(end_date):
|
||||
frappe.throw(
|
||||
_("Date must be between {0} and {1}").format(format_date(start_date), format_date(end_date))
|
||||
)
|
||||
else:
|
||||
for purpose in self.purposes:
|
||||
if purpose.maintenance_schedule_detail:
|
||||
item_ref = frappe.db.get_value(
|
||||
"Maintenance Schedule Detail", purpose.maintenance_schedule_detail, "item_reference"
|
||||
)
|
||||
if item_ref:
|
||||
start_date, end_date = frappe.db.get_value(
|
||||
"Maintenance Schedule Item", item_ref, ["start_date", "end_date"]
|
||||
)
|
||||
if get_datetime(self.mntc_date) < get_datetime(start_date) or get_datetime(
|
||||
self.mntc_date
|
||||
) > get_datetime(end_date):
|
||||
frappe.throw(
|
||||
_("Date must be between {0} and {1}").format(
|
||||
format_date(start_date), format_date(end_date)
|
||||
)
|
||||
)
|
||||
|
||||
def validate(self):
|
||||
self.validate_serial_no()
|
||||
@@ -49,6 +68,7 @@ class MaintenanceVisit(TransactionBase):
|
||||
if not cancel:
|
||||
status = self.completion_status
|
||||
actual_date = self.mntc_date
|
||||
|
||||
if self.maintenance_schedule_detail:
|
||||
frappe.db.set_value(
|
||||
"Maintenance Schedule Detail", self.maintenance_schedule_detail, "completion_status", status
|
||||
@@ -56,6 +76,21 @@ class MaintenanceVisit(TransactionBase):
|
||||
frappe.db.set_value(
|
||||
"Maintenance Schedule Detail", self.maintenance_schedule_detail, "actual_date", actual_date
|
||||
)
|
||||
else:
|
||||
for purpose in self.purposes:
|
||||
if purpose.maintenance_schedule_detail:
|
||||
frappe.db.set_value(
|
||||
"Maintenance Schedule Detail",
|
||||
purpose.maintenance_schedule_detail,
|
||||
"completion_status",
|
||||
status,
|
||||
)
|
||||
frappe.db.set_value(
|
||||
"Maintenance Schedule Detail",
|
||||
purpose.maintenance_schedule_detail,
|
||||
"actual_date",
|
||||
actual_date,
|
||||
)
|
||||
|
||||
def update_customer_issue(self, flag):
|
||||
if not self.maintenance_schedule:
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
"work_details",
|
||||
"work_done",
|
||||
"prevdoc_doctype",
|
||||
"prevdoc_docname"
|
||||
"prevdoc_docname",
|
||||
"maintenance_schedule_detail"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@@ -49,6 +50,8 @@
|
||||
"options": "Serial No"
|
||||
},
|
||||
{
|
||||
"fetch_from": "item_code.description",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "description",
|
||||
"fieldtype": "Text Editor",
|
||||
"in_list_view": 1,
|
||||
@@ -56,7 +59,6 @@
|
||||
"oldfieldname": "description",
|
||||
"oldfieldtype": "Small Text",
|
||||
"print_width": "300px",
|
||||
"reqd": 1,
|
||||
"width": "300px"
|
||||
},
|
||||
{
|
||||
@@ -103,12 +105,19 @@
|
||||
{
|
||||
"fieldname": "section_break_6",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "maintenance_schedule_detail",
|
||||
"fieldtype": "Data",
|
||||
"hidden": 1,
|
||||
"label": "Maintenance Schedule Detail",
|
||||
"options": "Maintenance Schedule Detail"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-02-27 11:09:33.114458",
|
||||
"modified": "2024-01-05 21:46:53.239830",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Maintenance",
|
||||
"name": "Maintenance Visit Purpose",
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
"is_public": 1,
|
||||
"is_standard": 1,
|
||||
"last_synced_on": "2020-07-21 16:57:09.767009",
|
||||
"modified": "2020-07-21 16:57:55.719802",
|
||||
"modified": "2024-01-10 12:21:25.134075",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Completed Operation",
|
||||
"number_of_groups": 0,
|
||||
"owner": "Administrator",
|
||||
"parent_document_type": "Work Order",
|
||||
"time_interval": "Quarterly",
|
||||
"timeseries": 1,
|
||||
"timespan": "Last Year",
|
||||
|
||||
@@ -214,6 +214,7 @@
|
||||
"options": "\nWork Order\nJob Card"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "conversion_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Conversion Rate",
|
||||
@@ -606,7 +607,7 @@
|
||||
"image_field": "image",
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-04-06 12:47:58.514795",
|
||||
"modified": "2023-12-26 19:34:08.159312",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "BOM",
|
||||
@@ -645,4 +646,4 @@
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,6 +661,9 @@ class BOM(WebsiteGenerator):
|
||||
base_total_rm_cost = 0
|
||||
|
||||
for d in self.get("items"):
|
||||
if not d.is_stock_item and self.rm_cost_as_per == "Valuation Rate":
|
||||
continue
|
||||
|
||||
old_rate = d.rate
|
||||
d.rate = self.get_rm_rate(
|
||||
{
|
||||
@@ -1392,3 +1395,47 @@ def make_variant_bom(source_name, bom_no, item, variant_items, target_doc=None):
|
||||
)
|
||||
|
||||
return doc
|
||||
|
||||
|
||||
def get_op_cost_from_sub_assemblies(bom_no, op_cost=0):
|
||||
# Get operating cost from sub-assemblies
|
||||
|
||||
bom_items = frappe.get_all(
|
||||
"BOM Item", filters={"parent": bom_no, "docstatus": 1}, fields=["bom_no"], order_by="idx asc"
|
||||
)
|
||||
|
||||
for row in bom_items:
|
||||
if not row.bom_no:
|
||||
continue
|
||||
|
||||
if cost := frappe.get_cached_value("BOM", row.bom_no, "operating_cost_per_bom_quantity"):
|
||||
op_cost += flt(cost)
|
||||
get_op_cost_from_sub_assemblies(row.bom_no, op_cost)
|
||||
|
||||
return op_cost
|
||||
|
||||
|
||||
def get_scrap_items_from_sub_assemblies(bom_no, company, qty, scrap_items=None):
|
||||
if not scrap_items:
|
||||
scrap_items = {}
|
||||
|
||||
bom_items = frappe.get_all(
|
||||
"BOM Item",
|
||||
filters={"parent": bom_no, "docstatus": 1},
|
||||
fields=["bom_no", "qty"],
|
||||
order_by="idx asc",
|
||||
)
|
||||
|
||||
for row in bom_items:
|
||||
if not row.bom_no:
|
||||
continue
|
||||
|
||||
qty = flt(row.qty) * flt(qty)
|
||||
items = get_bom_items_as_dict(
|
||||
row.bom_no, company, qty=qty, fetch_exploded=0, fetch_scrap_items=1
|
||||
)
|
||||
scrap_items.update(items)
|
||||
|
||||
get_scrap_items_from_sub_assemblies(row.bom_no, company, qty, scrap_items)
|
||||
|
||||
return scrap_items
|
||||
|
||||
@@ -698,6 +698,35 @@ class TestBOM(FrappeTestCase):
|
||||
bom.update_cost()
|
||||
self.assertFalse(bom.flags.cost_updated)
|
||||
|
||||
def test_bom_with_service_item_cost(self):
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
|
||||
rm_item = make_item(properties={"is_stock_item": 1, "valuation_rate": 1000.0}).name
|
||||
|
||||
service_item = make_item(properties={"is_stock_item": 0}).name
|
||||
|
||||
fg_item = make_item(properties={"is_stock_item": 1}).name
|
||||
|
||||
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
|
||||
|
||||
bom = make_bom(item=fg_item, raw_materials=[rm_item, service_item], do_not_save=True)
|
||||
bom.rm_cost_as_per = "Valuation Rate"
|
||||
|
||||
for row in bom.items:
|
||||
if row.item_code == service_item:
|
||||
row.rate = 566.00
|
||||
else:
|
||||
row.rate = 800.00
|
||||
|
||||
bom.save()
|
||||
|
||||
for row in bom.items:
|
||||
if row.item_code == service_item:
|
||||
self.assertEqual(row.is_stock_item, 0)
|
||||
self.assertEqual(row.rate, 566.00)
|
||||
else:
|
||||
self.assertEqual(row.is_stock_item, 1)
|
||||
|
||||
def test_do_not_include_manufacturing_and_fixed_items(self):
|
||||
from erpnext.manufacturing.doctype.bom.bom import item_query
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
"oldfieldname": "item_code",
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Item",
|
||||
"read_only": 1
|
||||
"read_only": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "item_name",
|
||||
@@ -170,7 +171,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-14 18:35:40.856895",
|
||||
"modified": "2024-01-02 13:49:36.211586",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "BOM Explosion Item",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"bom_no",
|
||||
"source_warehouse",
|
||||
"allow_alternative_item",
|
||||
"is_stock_item",
|
||||
"section_break_5",
|
||||
"description",
|
||||
"col_break1",
|
||||
@@ -185,7 +186,7 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Rate",
|
||||
"options": "currency",
|
||||
"read_only": 1,
|
||||
"read_only_depends_on": "eval:doc.is_stock_item == 1",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
@@ -284,13 +285,21 @@
|
||||
"fieldname": "do_not_explode",
|
||||
"fieldtype": "Check",
|
||||
"label": "Do Not Explode"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fetch_from": "item_code.is_stock_item",
|
||||
"fieldname": "is_stock_item",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Stock Item",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-14 18:35:51.378513",
|
||||
"modified": "2023-12-20 16:21:55.477883",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "BOM Item",
|
||||
|
||||
@@ -86,10 +86,12 @@ def get_ancestor_boms(new_bom: str, bom_list: Optional[List] = None) -> List:
|
||||
if new_bom == d.parent:
|
||||
frappe.throw(_("BOM recursion: {0} cannot be child of {1}").format(new_bom, d.parent))
|
||||
|
||||
bom_list.append(d.parent)
|
||||
if d.parent not in tuple(bom_list):
|
||||
bom_list.append(d.parent)
|
||||
|
||||
get_ancestor_boms(d.parent, bom_list)
|
||||
|
||||
return list(set(bom_list))
|
||||
return bom_list
|
||||
|
||||
|
||||
def update_new_bom_in_bom_items(unit_cost: float, current_bom: str, new_bom: str) -> None:
|
||||
|
||||
@@ -57,6 +57,68 @@ class TestBOMUpdateLog(FrappeTestCase):
|
||||
log.reload()
|
||||
self.assertEqual(log.status, "Completed")
|
||||
|
||||
def test_bom_replace_for_root_bom(self):
|
||||
"""
|
||||
- B-Item A (Root Item)
|
||||
- B-Item B
|
||||
- B-Item C
|
||||
- B-Item D
|
||||
- B-Item E
|
||||
- B-Item F
|
||||
|
||||
Create New BOM for B-Item E with B-Item G and replace it in the above BOM.
|
||||
"""
|
||||
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
items = ["B-Item A", "B-Item B", "B-Item C", "B-Item D", "B-Item E", "B-Item F", "B-Item G"]
|
||||
|
||||
for item_code in items:
|
||||
if not frappe.db.exists("Item", item_code):
|
||||
make_item(item_code)
|
||||
|
||||
for item_code in items:
|
||||
remove_bom(item_code)
|
||||
|
||||
bom_tree = {
|
||||
"B-Item A": {"B-Item B": {"B-Item C": {}}, "B-Item D": {"B-Item E": {"B-Item F": {}}}}
|
||||
}
|
||||
|
||||
root_bom = create_nested_bom(bom_tree, prefix="")
|
||||
|
||||
exploded_items = frappe.get_all(
|
||||
"BOM Explosion Item", filters={"parent": root_bom.name}, fields=["item_code"]
|
||||
)
|
||||
|
||||
exploded_items = [item.item_code for item in exploded_items]
|
||||
expected_exploded_items = ["B-Item C", "B-Item F"]
|
||||
self.assertEqual(sorted(exploded_items), sorted(expected_exploded_items))
|
||||
|
||||
old_bom = frappe.db.get_value("BOM", {"item": "B-Item E"}, "name")
|
||||
bom_tree = {"B-Item E": {"B-Item G": {}}}
|
||||
|
||||
new_bom = create_nested_bom(bom_tree, prefix="")
|
||||
enqueue_replace_bom(boms=frappe._dict(current_bom=old_bom, new_bom=new_bom.name))
|
||||
|
||||
exploded_items = frappe.get_all(
|
||||
"BOM Explosion Item", filters={"parent": root_bom.name}, fields=["item_code"]
|
||||
)
|
||||
|
||||
exploded_items = [item.item_code for item in exploded_items]
|
||||
expected_exploded_items = ["B-Item C", "B-Item G"]
|
||||
self.assertEqual(sorted(exploded_items), sorted(expected_exploded_items))
|
||||
|
||||
|
||||
def remove_bom(item_code):
|
||||
boms = frappe.get_all("BOM", fields=["docstatus", "name"], filters={"item": item_code})
|
||||
|
||||
for row in boms:
|
||||
if row.docstatus == 1:
|
||||
frappe.get_doc("BOM", row.name).cancel()
|
||||
|
||||
frappe.delete_doc("BOM", row.name)
|
||||
|
||||
|
||||
def update_cost_in_all_boms_in_test():
|
||||
"""
|
||||
|
||||
@@ -227,35 +227,39 @@ class JobCard(Document):
|
||||
|
||||
def has_overlap(self, production_capacity, time_logs):
|
||||
overlap = False
|
||||
if production_capacity == 1 and len(time_logs) > 0:
|
||||
if production_capacity == 1 and len(time_logs) >= 1:
|
||||
return True
|
||||
if not len(time_logs):
|
||||
return False
|
||||
|
||||
# Check overlap exists or not between the overlapping time logs with the current Job Card
|
||||
for row in time_logs:
|
||||
count = 1
|
||||
for next_row in time_logs:
|
||||
if row.name == next_row.name:
|
||||
continue
|
||||
|
||||
if (
|
||||
(
|
||||
get_datetime(next_row.from_time) >= get_datetime(row.from_time)
|
||||
and get_datetime(next_row.from_time) <= get_datetime(row.to_time)
|
||||
)
|
||||
or (
|
||||
get_datetime(next_row.to_time) >= get_datetime(row.from_time)
|
||||
and get_datetime(next_row.to_time) <= get_datetime(row.to_time)
|
||||
)
|
||||
or (
|
||||
get_datetime(next_row.from_time) <= get_datetime(row.from_time)
|
||||
and get_datetime(next_row.to_time) >= get_datetime(row.to_time)
|
||||
)
|
||||
):
|
||||
count += 1
|
||||
|
||||
if count > production_capacity:
|
||||
return True
|
||||
|
||||
# sorting overlapping job cards as per from_time
|
||||
time_logs = sorted(time_logs, key=lambda x: x.get("from_time"))
|
||||
# alloted_capacity has key number starting from 1. Key number will increment by 1 if non sequential job card found
|
||||
# if key number reaches/crosses to production_capacity means capacity is full and overlap error generated
|
||||
# this will store last to_time of sequential job cards
|
||||
alloted_capacity = {1: time_logs[0]["to_time"]}
|
||||
# flag for sequential Job card found
|
||||
sequential_job_card_found = False
|
||||
for i in range(1, len(time_logs)):
|
||||
# scanning for all Existing keys
|
||||
for key in alloted_capacity.keys():
|
||||
# if current Job Card from time is greater than last to_time in that key means these job card are sequential
|
||||
if alloted_capacity[key] <= time_logs[i]["from_time"]:
|
||||
# So update key's value with last to_time
|
||||
alloted_capacity[key] = time_logs[i]["to_time"]
|
||||
# flag is true as we get sequential Job Card for that key
|
||||
sequential_job_card_found = True
|
||||
# Immediately break so that job card to time is not added with any other key except this
|
||||
break
|
||||
# if sequential job card not found above means it is overlapping so increment key number to alloted_capacity
|
||||
if not sequential_job_card_found:
|
||||
# increment key number
|
||||
key = key + 1
|
||||
# for that key last to time is assigned.
|
||||
alloted_capacity[key] = time_logs[i]["to_time"]
|
||||
if len(alloted_capacity) >= production_capacity:
|
||||
# if number of keys greater or equal to production caoacity means full capacity is utilized and we should throw overlap error
|
||||
return True
|
||||
return overlap
|
||||
|
||||
def get_workstation_based_on_available_slot(self, existing) -> Optional[str]:
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
"job_card_excess_transfer",
|
||||
"other_settings_section",
|
||||
"update_bom_costs_automatically",
|
||||
"set_op_cost_and_scrape_from_sub_assemblies",
|
||||
"column_break_23",
|
||||
"make_serial_no_batch_from_work_order"
|
||||
],
|
||||
@@ -194,13 +195,20 @@
|
||||
"fieldname": "job_card_excess_transfer",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow Excess Material Transfer"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"description": "In the case of 'Use Multi-Level BOM' in a work order, if the user wishes to add sub-assembly costs to Finished Goods items without using a job card as well the scrap items, then this option needs to be enable.",
|
||||
"fieldname": "set_op_cost_and_scrape_from_sub_assemblies",
|
||||
"fieldtype": "Check",
|
||||
"label": "Set Operating Cost / Scrape Items From Sub-assemblies"
|
||||
}
|
||||
],
|
||||
"icon": "icon-wrench",
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-13 22:09:09.401559",
|
||||
"modified": "2023-12-28 16:37:44.874096",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Manufacturing Settings",
|
||||
@@ -216,5 +224,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -305,6 +305,8 @@ frappe.ui.form.on('Production Plan', {
|
||||
frappe.throw(__("Select the Warehouse"));
|
||||
}
|
||||
|
||||
frm.set_value("consider_minimum_order_qty", 0);
|
||||
|
||||
if (frm.doc.ignore_existing_ordered_qty) {
|
||||
frm.events.get_items_for_material_requests(frm);
|
||||
} else {
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
"material_request_planning",
|
||||
"include_non_stock_items",
|
||||
"include_subcontracted_items",
|
||||
"consider_minimum_order_qty",
|
||||
"include_safety_stock",
|
||||
"ignore_existing_ordered_qty",
|
||||
"column_break_25",
|
||||
@@ -423,13 +424,19 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Sub Assembly Warehouse",
|
||||
"options": "Warehouse"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "consider_minimum_order_qty",
|
||||
"fieldtype": "Check",
|
||||
"label": "Consider Minimum Order Qty"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-calendar",
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-11-03 14:08:11.928027",
|
||||
"modified": "2023-12-26 16:31:13.740777",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Manufacturing",
|
||||
"name": "Production Plan",
|
||||
|
||||
@@ -508,6 +508,7 @@ class ProductionPlan(Document):
|
||||
|
||||
if close:
|
||||
self.db_set("status", "Closed")
|
||||
self.update_bin_qty()
|
||||
return
|
||||
|
||||
if self.total_produced_qty > 0:
|
||||
@@ -522,6 +523,9 @@ class ProductionPlan(Document):
|
||||
if close is not None:
|
||||
self.db_set("status", self.status)
|
||||
|
||||
if self.docstatus == 1 and self.status != "Completed":
|
||||
self.update_bin_qty()
|
||||
|
||||
def update_ordered_status(self):
|
||||
update_status = False
|
||||
for d in self.po_items:
|
||||
@@ -566,6 +570,10 @@ class ProductionPlan(Document):
|
||||
"project": self.project,
|
||||
}
|
||||
|
||||
key = (d.item_code, d.sales_order, d.warehouse)
|
||||
if not d.sales_order:
|
||||
key = (d.name, d.item_code, d.warehouse)
|
||||
|
||||
if not item_details["project"] and d.sales_order:
|
||||
item_details["project"] = frappe.get_cached_value("Sales Order", d.sales_order, "project")
|
||||
|
||||
@@ -574,12 +582,9 @@ class ProductionPlan(Document):
|
||||
item_dict[(d.item_code, d.material_request_item, d.warehouse)] = item_details
|
||||
else:
|
||||
item_details.update(
|
||||
{
|
||||
"qty": flt(item_dict.get((d.item_code, d.sales_order, d.warehouse), {}).get("qty"))
|
||||
+ (flt(d.planned_qty) - flt(d.ordered_qty))
|
||||
}
|
||||
{"qty": flt(item_dict.get(key, {}).get("qty")) + (flt(d.planned_qty) - flt(d.ordered_qty))}
|
||||
)
|
||||
item_dict[(d.item_code, d.sales_order, d.warehouse)] = item_details
|
||||
item_dict[key] = item_details
|
||||
|
||||
return item_dict
|
||||
|
||||
@@ -1131,7 +1136,14 @@ def get_subitems(
|
||||
|
||||
|
||||
def get_material_request_items(
|
||||
row, sales_order, company, ignore_existing_ordered_qty, include_safety_stock, warehouse, bin_dict
|
||||
doc,
|
||||
row,
|
||||
sales_order,
|
||||
company,
|
||||
ignore_existing_ordered_qty,
|
||||
include_safety_stock,
|
||||
warehouse,
|
||||
bin_dict,
|
||||
):
|
||||
total_qty = row["qty"]
|
||||
|
||||
@@ -1140,8 +1152,14 @@ def get_material_request_items(
|
||||
required_qty = total_qty
|
||||
elif total_qty > bin_dict.get("projected_qty", 0):
|
||||
required_qty = total_qty - bin_dict.get("projected_qty", 0)
|
||||
if required_qty > 0 and required_qty < row["min_order_qty"]:
|
||||
|
||||
if (
|
||||
doc.get("consider_minimum_order_qty")
|
||||
and required_qty > 0
|
||||
and required_qty < row["min_order_qty"]
|
||||
):
|
||||
required_qty = row["min_order_qty"]
|
||||
|
||||
item_group_defaults = get_item_group_defaults(row.item_code, company)
|
||||
|
||||
if not row["purchase_uom"]:
|
||||
@@ -1479,6 +1497,7 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
|
||||
|
||||
if details.qty > 0:
|
||||
items = get_material_request_items(
|
||||
doc,
|
||||
details,
|
||||
sales_order,
|
||||
company,
|
||||
|
||||
@@ -661,7 +661,7 @@ class TestProductionPlan(FrappeTestCase):
|
||||
items_data = pln.get_production_items()
|
||||
|
||||
# Update qty
|
||||
items_data[(item, None, None)]["qty"] = qty
|
||||
items_data[(pln.po_items[0].name, item, None)]["qty"] = qty
|
||||
|
||||
# Create and Submit Work Order for each item in items_data
|
||||
for key, item in items_data.items():
|
||||
@@ -1447,6 +1447,109 @@ class TestProductionPlan(FrappeTestCase):
|
||||
self.assertEqual(row.get("uom"), "Nos")
|
||||
self.assertEqual(row.get("conversion_factor"), 10.0)
|
||||
|
||||
def test_unreserve_qty_on_closing_of_pp(self):
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
from erpnext.stock.utils import get_or_make_bin
|
||||
|
||||
fg_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name
|
||||
rm_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name
|
||||
|
||||
store_warehouse = create_warehouse("Store Warehouse", company="_Test Company")
|
||||
rm_warehouse = create_warehouse("RM Warehouse", company="_Test Company")
|
||||
|
||||
make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")
|
||||
|
||||
pln = create_production_plan(
|
||||
item_code=fg_item, planned_qty=10, stock_uom="_Test UOM 1", do_not_submit=1
|
||||
)
|
||||
|
||||
pln.for_warehouse = rm_warehouse
|
||||
mr_items = get_items_for_material_requests(pln.as_dict())
|
||||
for d in mr_items:
|
||||
pln.append("mr_items", d)
|
||||
|
||||
pln.save()
|
||||
pln.submit()
|
||||
|
||||
bin_name = get_or_make_bin(rm_item, rm_warehouse)
|
||||
before_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
|
||||
|
||||
pln.reload()
|
||||
pln.set_status(close=True)
|
||||
|
||||
bin_name = get_or_make_bin(rm_item, rm_warehouse)
|
||||
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
|
||||
self.assertAlmostEqual(after_qty, before_qty - 10)
|
||||
|
||||
pln.reload()
|
||||
pln.set_status(close=False)
|
||||
|
||||
bin_name = get_or_make_bin(rm_item, rm_warehouse)
|
||||
after_qty = flt(frappe.db.get_value("Bin", bin_name, "reserved_qty_for_production_plan"))
|
||||
self.assertAlmostEqual(after_qty, before_qty)
|
||||
|
||||
def test_min_order_qty_in_pp(self):
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
from erpnext.stock.utils import get_or_make_bin
|
||||
|
||||
fg_item = make_item(properties={"is_stock_item": 1}).name
|
||||
rm_item = make_item(properties={"is_stock_item": 1, "min_order_qty": 1000}).name
|
||||
|
||||
rm_warehouse = create_warehouse("RM Warehouse", company="_Test Company")
|
||||
|
||||
make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")
|
||||
|
||||
pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1)
|
||||
|
||||
pln.for_warehouse = rm_warehouse
|
||||
mr_items = get_items_for_material_requests(pln.as_dict())
|
||||
for d in mr_items:
|
||||
self.assertEqual(d.get("quantity"), 10.0)
|
||||
|
||||
pln.consider_minimum_order_qty = 1
|
||||
mr_items = get_items_for_material_requests(pln.as_dict())
|
||||
for d in mr_items:
|
||||
self.assertEqual(d.get("quantity"), 1000.0)
|
||||
|
||||
def test_fg_item_quantity(self):
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
from erpnext.stock.utils import get_or_make_bin
|
||||
|
||||
fg_item = make_item(properties={"is_stock_item": 1}).name
|
||||
rm_item = make_item(properties={"is_stock_item": 1}).name
|
||||
|
||||
make_bom(item=fg_item, raw_materials=[rm_item], source_warehouse="_Test Warehouse - _TC")
|
||||
|
||||
pln = create_production_plan(item_code=fg_item, planned_qty=10, do_not_submit=1)
|
||||
|
||||
pln.append(
|
||||
"po_items",
|
||||
{
|
||||
"item_code": rm_item,
|
||||
"planned_qty": 20,
|
||||
"bom_no": pln.po_items[0].bom_no,
|
||||
"warehouse": pln.po_items[0].warehouse,
|
||||
"planned_start_date": add_to_date(nowdate(), days=1),
|
||||
},
|
||||
)
|
||||
pln.submit()
|
||||
wo_qty = {}
|
||||
|
||||
for row in pln.po_items:
|
||||
wo_qty[row.name] = row.planned_qty
|
||||
|
||||
pln.make_work_order()
|
||||
|
||||
work_orders = frappe.get_all(
|
||||
"Work Order",
|
||||
fields=["qty", "production_plan_item as name"],
|
||||
filters={"production_plan": pln.name},
|
||||
)
|
||||
self.assertEqual(len(work_orders), 2)
|
||||
|
||||
for row in work_orders:
|
||||
self.assertEqual(row.qty, wo_qty[row.name])
|
||||
|
||||
|
||||
def create_production_plan(**args):
|
||||
"""
|
||||
@@ -1527,6 +1630,10 @@ def make_bom(**args):
|
||||
}
|
||||
)
|
||||
|
||||
if args.operating_cost_per_bom_quantity:
|
||||
bom.fg_based_operating_cost = 1
|
||||
bom.operating_cost_per_bom_quantity = args.operating_cost_per_bom_quantity
|
||||
|
||||
for item in args.raw_materials:
|
||||
item_doc = frappe.get_doc("Item", item)
|
||||
bom.append(
|
||||
|
||||
@@ -1726,6 +1726,93 @@ class TestWorkOrder(FrappeTestCase):
|
||||
|
||||
frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 0)
|
||||
|
||||
def test_op_cost_and_scrap_based_on_sub_assemblies(self):
|
||||
# Make Sub Assembly BOM 1
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Manufacturing Settings", "set_op_cost_and_scrape_from_sub_assemblies", 1
|
||||
)
|
||||
|
||||
items = {
|
||||
"Test Final FG Item": 0,
|
||||
"Test Final SF Item 1": 0,
|
||||
"Test Final SF Item 2": 0,
|
||||
"Test Final RM Item 1": 100,
|
||||
"Test Final RM Item 2": 200,
|
||||
"Test Final Scrap Item 1": 50,
|
||||
"Test Final Scrap Item 2": 60,
|
||||
}
|
||||
|
||||
for item in items:
|
||||
if not frappe.db.exists("Item", item):
|
||||
item_properties = {"is_stock_item": 1, "valuation_rate": items[item]}
|
||||
|
||||
make_item(item_code=item, properties=item_properties),
|
||||
|
||||
prepare_boms_for_sub_assembly_test()
|
||||
|
||||
wo_order = make_wo_order_test_record(
|
||||
production_item="Test Final FG Item",
|
||||
qty=10,
|
||||
use_multi_level_bom=1,
|
||||
skip_transfer=1,
|
||||
from_wip_warehouse=1,
|
||||
)
|
||||
|
||||
se_doc = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 10))
|
||||
se_doc.save()
|
||||
|
||||
self.assertTrue(se_doc.additional_costs)
|
||||
scrap_items = []
|
||||
for item in se_doc.items:
|
||||
if item.is_scrap_item:
|
||||
scrap_items.append(item.item_code)
|
||||
|
||||
self.assertEqual(
|
||||
sorted(scrap_items), sorted(["Test Final Scrap Item 1", "Test Final Scrap Item 2"])
|
||||
)
|
||||
for row in se_doc.additional_costs:
|
||||
self.assertEqual(row.amount, 3000)
|
||||
|
||||
frappe.db.set_single_value(
|
||||
"Manufacturing Settings", "set_op_cost_and_scrape_from_sub_assemblies", 0
|
||||
)
|
||||
|
||||
|
||||
def prepare_boms_for_sub_assembly_test():
|
||||
if not frappe.db.exists("BOM", {"item": "Test Final SF Item 1"}):
|
||||
bom = make_bom(
|
||||
item="Test Final SF Item 1",
|
||||
source_warehouse="Stores - _TC",
|
||||
raw_materials=["Test Final RM Item 1"],
|
||||
operating_cost_per_bom_quantity=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
|
||||
bom.append("scrap_items", {"item_code": "Test Final Scrap Item 1", "qty": 1})
|
||||
|
||||
bom.submit()
|
||||
|
||||
if not frappe.db.exists("BOM", {"item": "Test Final SF Item 2"}):
|
||||
bom = make_bom(
|
||||
item="Test Final SF Item 2",
|
||||
source_warehouse="Stores - _TC",
|
||||
raw_materials=["Test Final RM Item 2"],
|
||||
operating_cost_per_bom_quantity=200,
|
||||
do_not_submit=True,
|
||||
)
|
||||
|
||||
bom.append("scrap_items", {"item_code": "Test Final Scrap Item 2", "qty": 1})
|
||||
|
||||
bom.submit()
|
||||
|
||||
if not frappe.db.exists("BOM", {"item": "Test Final FG Item"}):
|
||||
bom = make_bom(
|
||||
item="Test Final FG Item",
|
||||
source_warehouse="Stores - _TC",
|
||||
raw_materials=["Test Final SF Item 1", "Test Final SF Item 2"],
|
||||
)
|
||||
|
||||
|
||||
def prepare_data_for_workstation_type_check():
|
||||
from erpnext.manufacturing.doctype.operation.test_operation import make_operation
|
||||
@@ -1955,7 +2042,7 @@ def make_wo_order_test_record(**args):
|
||||
wo_order.sales_order = args.sales_order or None
|
||||
wo_order.planned_start_date = args.planned_start_date or now()
|
||||
wo_order.transfer_material_against = args.transfer_material_against or "Work Order"
|
||||
wo_order.from_wip_warehouse = args.from_wip_warehouse or None
|
||||
wo_order.from_wip_warehouse = args.from_wip_warehouse or 0
|
||||
|
||||
if args.source_warehouse:
|
||||
for item in wo_order.get("required_items"):
|
||||
|
||||
@@ -352,5 +352,9 @@ erpnext.patches.v14_0.create_accounting_dimensions_in_supplier_quotation
|
||||
erpnext.patches.v14_0.update_zero_asset_quantity_field
|
||||
execute:frappe.db.set_single_value("Buying Settings", "project_update_frequency", "Each Transaction")
|
||||
erpnext.patches.v14_0.clear_reconciliation_values_from_singles
|
||||
erpnext.patches.v14_0.update_total_asset_cost_field
|
||||
# below migration patch should always run last
|
||||
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
|
||||
erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20
|
||||
erpnext.patches.v14_0.set_maintain_stock_for_bom_item
|
||||
execute:frappe.db.set_single_value('E Commerce Settings', 'show_actual_qty', 1)
|
||||
|
||||
19
erpnext/patches/v14_0/set_maintain_stock_for_bom_item.py
Normal file
19
erpnext/patches/v14_0/set_maintain_stock_for_bom_item.py
Normal file
@@ -0,0 +1,19 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
if not frappe.db.exists("BOM", {"docstatus": 1}):
|
||||
return
|
||||
|
||||
# Added is_stock_item to handle Read Only based on condition for the rate field
|
||||
frappe.db.sql(
|
||||
"""
|
||||
UPDATE
|
||||
`tabBOM Item` boi,
|
||||
`tabItem` i
|
||||
SET
|
||||
boi.is_stock_item = i.is_stock_item
|
||||
WHERE
|
||||
boi.item_code = i.name
|
||||
"""
|
||||
)
|
||||
17
erpnext/patches/v14_0/update_total_asset_cost_field.py
Normal file
17
erpnext/patches/v14_0/update_total_asset_cost_field.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
asset = frappe.qb.DocType("Asset")
|
||||
frappe.qb.update(asset).set(asset.total_asset_cost, asset.gross_purchase_amount).run()
|
||||
|
||||
asset_repair_list = frappe.db.get_all(
|
||||
"Asset Repair",
|
||||
filters={"docstatus": 1, "repair_status": "Completed", "capitalize_repair_cost": 1},
|
||||
fields=["asset", "repair_cost"],
|
||||
)
|
||||
|
||||
for asset_repair in asset_repair_list:
|
||||
frappe.qb.update(asset).set(
|
||||
asset.total_asset_cost, asset.total_asset_cost + asset_repair.repair_cost
|
||||
).where(asset.name == asset_repair.asset).run()
|
||||
@@ -389,6 +389,9 @@ def make_sales_invoice(source_name, item_code=None, customer=None, currency=None
|
||||
"timesheets",
|
||||
{
|
||||
"time_sheet": timesheet.name,
|
||||
"project_name": time_log.project_name,
|
||||
"from_time": time_log.from_time,
|
||||
"to_time": time_log.to_time,
|
||||
"billing_hours": time_log.billing_hours,
|
||||
"billing_amount": time_log.billing_amount,
|
||||
"timesheet_detail": time_log.name,
|
||||
|
||||
@@ -482,6 +482,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
cost_center: item.cost_center,
|
||||
tax_category: me.frm.doc.tax_category,
|
||||
item_tax_template: item.item_tax_template,
|
||||
child_doctype: item.doctype,
|
||||
child_docname: item.name,
|
||||
is_old_subcontracting_flow: me.frm.doc.is_old_subcontracting_flow,
|
||||
}
|
||||
@@ -738,7 +739,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
if (me.frm.doc.price_list_currency == company_currency) {
|
||||
me.frm.set_value('plc_conversion_rate', 1.0);
|
||||
}
|
||||
if (company_doc.default_letter_head) {
|
||||
if (company_doc && company_doc.default_letter_head) {
|
||||
if(me.frm.fields_dict.letter_head) {
|
||||
me.frm.set_value("letter_head", company_doc.default_letter_head);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ erpnext.HierarchyChart = class {
|
||||
|
||||
show() {
|
||||
this.setup_actions();
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
if (this.page.main.find('[data-fieldname="company"]').length) return;
|
||||
let me = this;
|
||||
|
||||
let company = this.page.add_field({
|
||||
@@ -80,7 +80,7 @@ erpnext.HierarchyChart = class {
|
||||
only_select: true,
|
||||
reqd: 1,
|
||||
change: () => {
|
||||
me.company = undefined;
|
||||
me.company = '';
|
||||
$('#hierarchy-chart-wrapper').remove();
|
||||
|
||||
if (company.get_value()) {
|
||||
@@ -219,8 +219,8 @@ erpnext.HierarchyChart = class {
|
||||
}
|
||||
}).then(r => {
|
||||
if (r.message.length) {
|
||||
let expand_node = undefined;
|
||||
let node = undefined;
|
||||
let expand_node;
|
||||
let node;
|
||||
|
||||
$.each(r.message, (_i, data) => {
|
||||
if ($(`[id="${data.id}"]`).length)
|
||||
@@ -229,7 +229,7 @@ erpnext.HierarchyChart = class {
|
||||
node = new me.Node({
|
||||
id: data.id,
|
||||
parent: $('<li class="child-node"></li>').appendTo(me.$hierarchy.find('.node-children')),
|
||||
parent_id: undefined,
|
||||
parent_id: '',
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
@@ -286,6 +286,10 @@ erpnext.HierarchyChart = class {
|
||||
}
|
||||
|
||||
load_children(node, deep=false) {
|
||||
if (!this.company) {
|
||||
frappe.throw(__('Please select a company first.'));
|
||||
}
|
||||
|
||||
if (!deep) {
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node.id),
|
||||
@@ -367,8 +371,8 @@ erpnext.HierarchyChart = class {
|
||||
}
|
||||
|
||||
render_children_of_all_nodes(data_list) {
|
||||
let entry = undefined;
|
||||
let node = undefined;
|
||||
let entry;
|
||||
let node;
|
||||
|
||||
while (data_list.length) {
|
||||
// to avoid overlapping connectors
|
||||
@@ -423,7 +427,7 @@ erpnext.HierarchyChart = class {
|
||||
title: data.title,
|
||||
expandable: data.expandable,
|
||||
connections: data.connections,
|
||||
children: undefined
|
||||
children: null,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -519,7 +523,7 @@ erpnext.HierarchyChart = class {
|
||||
collapse_previous_level_nodes(node) {
|
||||
let node_parent = $(`[id="${node.parent_id}"]`);
|
||||
let previous_level_nodes = node_parent.parent().parent().children('li');
|
||||
let node_card = undefined;
|
||||
let node_card;
|
||||
|
||||
previous_level_nodes.each(function() {
|
||||
node_card = $(this).find('.node-card');
|
||||
@@ -582,12 +586,12 @@ erpnext.HierarchyChart = class {
|
||||
level.nextAll('li').remove();
|
||||
|
||||
let nodes = level.find('.node-card');
|
||||
let node_object = undefined;
|
||||
let node_object;
|
||||
|
||||
$.each(nodes, (_i, element) => {
|
||||
node_object = this.nodes[element.id];
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
node_object.$children = null;
|
||||
});
|
||||
|
||||
nodes.removeClass('collapsed active-path');
|
||||
|
||||
@@ -59,8 +59,8 @@ erpnext.HierarchyChartMobile = class {
|
||||
}
|
||||
|
||||
show() {
|
||||
if (this.page.main.find('[data-fieldname="company"]').length) return;
|
||||
let me = this;
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
|
||||
let company = this.page.add_field({
|
||||
fieldtype: 'Link',
|
||||
@@ -71,7 +71,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
only_select: true,
|
||||
reqd: 1,
|
||||
change: () => {
|
||||
me.company = undefined;
|
||||
me.company = '';
|
||||
|
||||
if (company.get_value() && me.company != company.get_value()) {
|
||||
me.company = company.get_value();
|
||||
@@ -154,7 +154,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
return new me.Node({
|
||||
id: data.id,
|
||||
parent: root_level,
|
||||
parent_id: undefined,
|
||||
parent_id: '',
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
@@ -174,7 +174,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
|
||||
if (this.$sibling_group) {
|
||||
const sibling_parent = this.$sibling_group.find('.node-group').attr('data-parent');
|
||||
if (node.parent_id !== undefined && node.parent_id != sibling_parent)
|
||||
if (node.parent_id != '' && node.parent_id != sibling_parent)
|
||||
this.$sibling_group.empty();
|
||||
}
|
||||
|
||||
@@ -225,6 +225,10 @@ erpnext.HierarchyChartMobile = class {
|
||||
}
|
||||
|
||||
load_children(node) {
|
||||
if (!this.company) {
|
||||
frappe.throw(__('Please select a company first'));
|
||||
}
|
||||
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node.id),
|
||||
(child_nodes) => this.render_child_nodes(node, child_nodes)
|
||||
@@ -281,7 +285,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
title: data.title,
|
||||
expandable: data.expandable,
|
||||
connections: data.connections,
|
||||
children: undefined
|
||||
children: null
|
||||
});
|
||||
}
|
||||
|
||||
@@ -291,7 +295,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
|
||||
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
||||
|
||||
let connector = undefined;
|
||||
let connector = null;
|
||||
|
||||
if ($(`[id="${parent_id}"]`).hasClass('active')) {
|
||||
connector = this.get_connector_for_active_node(parent_node, child_node);
|
||||
@@ -377,7 +381,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
let node_element = $(`[id="${node.id}"]`);
|
||||
|
||||
node_element.click(function() {
|
||||
let el = undefined;
|
||||
let el = null;
|
||||
|
||||
if (node.is_root) {
|
||||
el = $(this).detach();
|
||||
@@ -411,7 +415,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
|
||||
$('.node-group').on('click', function() {
|
||||
let parent = $(this).attr('data-parent');
|
||||
if (parent === 'undefined') {
|
||||
if (parent == '') {
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
} else {
|
||||
@@ -427,7 +431,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
|
||||
let node_object = this.nodes[node.id];
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
node_object.$children = null;
|
||||
this.nodes[node.id] = node_object;
|
||||
}
|
||||
|
||||
@@ -484,7 +488,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
|
||||
node.removeClass('active-child active-path');
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
node_object.$children = null;
|
||||
this.nodes[node.id] = node_object;
|
||||
|
||||
// show parent's siblings and expand parent node
|
||||
@@ -523,7 +527,7 @@ erpnext.HierarchyChartMobile = class {
|
||||
current_node.removeClass('active-child active-path');
|
||||
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
node_object.$children = null;
|
||||
|
||||
level.empty().append(current_node);
|
||||
}
|
||||
|
||||
@@ -737,7 +737,7 @@ erpnext.utils.map_current_doc = function(opts) {
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
var doc = frappe.model.sync(r.message);
|
||||
frappe.model.sync(r.message);
|
||||
cur_frm.dirty();
|
||||
cur_frm.refresh();
|
||||
}
|
||||
@@ -759,11 +759,20 @@ erpnext.utils.map_current_doc = function(opts) {
|
||||
}
|
||||
|
||||
if (opts.source_doctype) {
|
||||
let data_fields = [];
|
||||
if(opts.source_doctype == "Purchase Receipt") {
|
||||
data_fields.push({
|
||||
fieldname: 'merge_taxes',
|
||||
fieldtype: 'Check',
|
||||
label: __('Merge taxes from multiple documents'),
|
||||
});
|
||||
}
|
||||
const d = new frappe.ui.form.MultiSelectDialog({
|
||||
doctype: opts.source_doctype,
|
||||
target: opts.target,
|
||||
date_field: opts.date_field || undefined,
|
||||
setters: opts.setters,
|
||||
data_fields: data_fields,
|
||||
get_query: opts.get_query,
|
||||
add_filters_group: 1,
|
||||
allow_child_item_selection: opts.allow_child_item_selection,
|
||||
@@ -777,7 +786,7 @@ erpnext.utils.map_current_doc = function(opts) {
|
||||
return;
|
||||
}
|
||||
opts.source_name = values;
|
||||
if (opts.allow_child_item_selection) {
|
||||
if (opts.allow_child_item_selection || opts.source_doctype == "Purchase Receipt") {
|
||||
// args contains filtered child docnames
|
||||
opts.args = args;
|
||||
}
|
||||
@@ -971,7 +980,7 @@ function set_time_to_resolve_and_response(frm, apply_sla_for_resolution) {
|
||||
}
|
||||
|
||||
function get_time_left(timestamp, agreement_status) {
|
||||
const diff = moment(timestamp).diff(moment());
|
||||
const diff = moment(timestamp).diff(frappe.datetime.system_datetime(true));
|
||||
const diff_display = diff >= 44500 ? moment.duration(diff).humanize() : 'Failed';
|
||||
let indicator = (diff_display == 'Failed' && agreement_status != 'Fulfilled') ? 'red' : 'green';
|
||||
return {'diff_display': diff_display, 'indicator': indicator};
|
||||
|
||||
@@ -1,431 +0,0 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext.selling");
|
||||
|
||||
erpnext.sales_common = {
|
||||
setup_selling_controller:function() {
|
||||
erpnext.selling.SellingController = class SellingController extends erpnext.TransactionController {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.toggle_enable_for_stock_uom("allow_to_edit_stock_uom_qty_for_sales");
|
||||
this.frm.email_field = "contact_email";
|
||||
}
|
||||
|
||||
onload() {
|
||||
super.onload();
|
||||
this.setup_queries();
|
||||
this.frm.set_query('shipping_rule', function() {
|
||||
return {
|
||||
filters: {
|
||||
"shipping_rule_type": "Selling"
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
setup_queries() {
|
||||
var me = this;
|
||||
|
||||
$.each([["customer", "customer"],
|
||||
["lead", "lead"]],
|
||||
function(i, opts) {
|
||||
if(me.frm.fields_dict[opts[0]])
|
||||
me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
|
||||
});
|
||||
|
||||
me.frm.set_query('contact_person', erpnext.queries.contact_query);
|
||||
me.frm.set_query('customer_address', erpnext.queries.address_query);
|
||||
me.frm.set_query('shipping_address_name', erpnext.queries.address_query);
|
||||
me.frm.set_query('dispatch_address_name', erpnext.queries.dispatch_address_query);
|
||||
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype);
|
||||
|
||||
if(this.frm.fields_dict.selling_price_list) {
|
||||
this.frm.set_query("selling_price_list", function() {
|
||||
return { filters: { selling: 1 } };
|
||||
});
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict.tc_name) {
|
||||
this.frm.set_query("tc_name", function() {
|
||||
return { filters: { selling: 1 } };
|
||||
});
|
||||
}
|
||||
|
||||
if(!this.frm.fields_dict["items"]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
|
||||
this.frm.set_query("item_code", "items", function() {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.item_query",
|
||||
filters: {'is_sales_item': 1, 'customer': me.frm.doc.customer, 'has_variants': 0}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict["packed_items"] &&
|
||||
this.frm.fields_dict["packed_items"].grid.get_field('batch_no')) {
|
||||
this.frm.set_query("batch_no", "packed_items", function(doc, cdt, cdn) {
|
||||
return me.set_query_for_batch(doc, cdt, cdn)
|
||||
});
|
||||
}
|
||||
|
||||
if(this.frm.fields_dict["items"].grid.get_field('item_code')) {
|
||||
this.frm.set_query("item_tax_template", "items", function(doc, cdt, cdn) {
|
||||
return me.set_query_for_item_tax_template(doc, cdt, cdn)
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
refresh() {
|
||||
super.refresh();
|
||||
|
||||
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||
|
||||
this.frm.toggle_display("customer_name",
|
||||
(this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
|
||||
|
||||
this.toggle_editable_price_list_rate();
|
||||
}
|
||||
|
||||
customer() {
|
||||
var me = this;
|
||||
erpnext.utils.get_party_details(this.frm, null, null, function() {
|
||||
me.apply_price_list();
|
||||
});
|
||||
}
|
||||
|
||||
customer_address() {
|
||||
erpnext.utils.get_address_display(this.frm, "customer_address");
|
||||
erpnext.utils.set_taxes_from_address(this.frm, "customer_address", "customer_address", "shipping_address_name");
|
||||
}
|
||||
|
||||
shipping_address_name() {
|
||||
erpnext.utils.get_address_display(this.frm, "shipping_address_name", "shipping_address");
|
||||
erpnext.utils.set_taxes_from_address(this.frm, "shipping_address_name", "customer_address", "shipping_address_name");
|
||||
}
|
||||
|
||||
dispatch_address_name() {
|
||||
erpnext.utils.get_address_display(this.frm, "dispatch_address_name", "dispatch_address");
|
||||
}
|
||||
|
||||
sales_partner() {
|
||||
this.apply_pricing_rule();
|
||||
}
|
||||
|
||||
campaign() {
|
||||
this.apply_pricing_rule();
|
||||
}
|
||||
|
||||
selling_price_list() {
|
||||
this.apply_price_list();
|
||||
this.set_dynamic_labels();
|
||||
}
|
||||
|
||||
discount_percentage(doc, cdt, cdn) {
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
item.discount_amount = 0.0;
|
||||
this.apply_discount_on_item(doc, cdt, cdn, 'discount_percentage');
|
||||
}
|
||||
|
||||
discount_amount(doc, cdt, cdn) {
|
||||
|
||||
if(doc.name === cdn) {
|
||||
return;
|
||||
}
|
||||
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
item.discount_percentage = 0.0;
|
||||
this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount');
|
||||
}
|
||||
|
||||
commission_rate() {
|
||||
this.calculate_commission();
|
||||
}
|
||||
|
||||
total_commission() {
|
||||
frappe.model.round_floats_in(this.frm.doc, ["amount_eligible_for_commission", "total_commission"]);
|
||||
|
||||
const { amount_eligible_for_commission } = this.frm.doc;
|
||||
if(!amount_eligible_for_commission) return;
|
||||
|
||||
this.frm.set_value(
|
||||
"commission_rate", flt(
|
||||
this.frm.doc.total_commission * 100.0 / amount_eligible_for_commission
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
allocated_percentage(doc, cdt, cdn) {
|
||||
var sales_person = frappe.get_doc(cdt, cdn);
|
||||
if(sales_person.allocated_percentage) {
|
||||
|
||||
sales_person.allocated_percentage = flt(sales_person.allocated_percentage,
|
||||
precision("allocated_percentage", sales_person));
|
||||
|
||||
sales_person.allocated_amount = flt(this.frm.doc.amount_eligible_for_commission *
|
||||
sales_person.allocated_percentage / 100.0,
|
||||
precision("allocated_amount", sales_person));
|
||||
refresh_field(["allocated_amount"], sales_person);
|
||||
|
||||
this.calculate_incentive(sales_person);
|
||||
refresh_field(["allocated_percentage", "allocated_amount", "commission_rate","incentives"], sales_person.name,
|
||||
sales_person.parentfield);
|
||||
}
|
||||
}
|
||||
|
||||
sales_person(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
this.calculate_incentive(row);
|
||||
refresh_field("incentives",row.name,row.parentfield);
|
||||
}
|
||||
|
||||
toggle_editable_price_list_rate() {
|
||||
var df = frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "price_list_rate", this.frm.doc.name);
|
||||
var editable_price_list_rate = cint(frappe.defaults.get_default("editable_price_list_rate"));
|
||||
|
||||
if(df && editable_price_list_rate) {
|
||||
const parent_field = frappe.meta.get_parentfield(this.frm.doc.doctype, this.frm.doc.doctype + " Item");
|
||||
if (!this.frm.fields_dict[parent_field]) return;
|
||||
|
||||
this.frm.fields_dict[parent_field].grid.update_docfield_property(
|
||||
'price_list_rate', 'read_only', 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
calculate_commission() {
|
||||
if(!this.frm.fields_dict.commission_rate || this.frm.doc.docstatus === 1) return;
|
||||
|
||||
if(this.frm.doc.commission_rate > 100) {
|
||||
this.frm.set_value("commission_rate", 100);
|
||||
frappe.throw(`${__(frappe.meta.get_label(
|
||||
this.frm.doc.doctype, "commission_rate", this.frm.doc.name
|
||||
))} ${__("cannot be greater than 100")}`);
|
||||
}
|
||||
|
||||
this.frm.doc.amount_eligible_for_commission = this.frm.doc.items.reduce(
|
||||
(sum, item) => item.grant_commission ? sum + item.base_net_amount : sum, 0
|
||||
)
|
||||
|
||||
this.frm.doc.total_commission = flt(
|
||||
this.frm.doc.amount_eligible_for_commission * this.frm.doc.commission_rate / 100.0,
|
||||
precision("total_commission")
|
||||
);
|
||||
|
||||
refresh_field(["amount_eligible_for_commission", "total_commission"]);
|
||||
}
|
||||
|
||||
calculate_contribution() {
|
||||
var me = this;
|
||||
$.each(this.frm.doc.doctype.sales_team || [], function(i, sales_person) {
|
||||
frappe.model.round_floats_in(sales_person);
|
||||
if (!sales_person.allocated_percentage) return;
|
||||
|
||||
sales_person.allocated_amount = flt(
|
||||
me.frm.doc.amount_eligible_for_commission
|
||||
* sales_person.allocated_percentage
|
||||
/ 100.0,
|
||||
precision("allocated_amount", sales_person)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
calculate_incentive(row) {
|
||||
if(row.allocated_amount)
|
||||
{
|
||||
row.incentives = flt(
|
||||
row.allocated_amount * row.commission_rate / 100.0,
|
||||
precision("incentives", row));
|
||||
}
|
||||
}
|
||||
|
||||
set_dynamic_labels() {
|
||||
super.set_dynamic_labels();
|
||||
this.set_product_bundle_help(this.frm.doc);
|
||||
}
|
||||
|
||||
set_product_bundle_help(doc) {
|
||||
if(!this.frm.fields_dict.packing_list) return;
|
||||
if ((doc.packed_items || []).length) {
|
||||
$(this.frm.fields_dict.packing_list.row.wrapper).toggle(true);
|
||||
|
||||
if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
|
||||
var help_msg = "<div class='alert alert-warning'>" +
|
||||
__("For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table.")+
|
||||
"</div>";
|
||||
frappe.meta.get_docfield(doc.doctype, 'product_bundle_help', doc.name).options = help_msg;
|
||||
}
|
||||
} else {
|
||||
$(this.frm.fields_dict.packing_list.row.wrapper).toggle(false);
|
||||
if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
|
||||
frappe.meta.get_docfield(doc.doctype, 'product_bundle_help', doc.name).options = '';
|
||||
}
|
||||
}
|
||||
refresh_field('product_bundle_help');
|
||||
}
|
||||
|
||||
company_address() {
|
||||
var me = this;
|
||||
if(this.frm.doc.company_address) {
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.address.address.get_address_display",
|
||||
args: {"address_dict": this.frm.doc.company_address },
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
me.frm.set_value("company_address_display", r.message)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.frm.set_value("company_address_display", "");
|
||||
}
|
||||
}
|
||||
|
||||
conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate) {
|
||||
super.conversion_factor(doc, cdt, cdn, dont_fetch_price_list_rate);
|
||||
}
|
||||
|
||||
qty(doc, cdt, cdn) {
|
||||
super.qty(doc, cdt, cdn);
|
||||
}
|
||||
|
||||
pick_serial_and_batch(doc, cdt, cdn) {
|
||||
let item = locals[cdt][cdn];
|
||||
let me = this;
|
||||
let path = "assets/erpnext/js/utils/serial_no_batch_selector.js";
|
||||
|
||||
frappe.db.get_value("Item", item.item_code, ["has_batch_no", "has_serial_no"])
|
||||
.then((r) => {
|
||||
if (r.message && (r.message.has_batch_no || r.message.has_serial_no)) {
|
||||
item.has_serial_no = r.message.has_serial_no;
|
||||
item.has_batch_no = r.message.has_batch_no;
|
||||
item.type_of_transaction = item.qty > 0 ? "Outward":"Inward";
|
||||
|
||||
item.title = item.has_serial_no ?
|
||||
__("Select Serial No") : __("Select Batch No");
|
||||
|
||||
if (item.has_serial_no && item.has_batch_no) {
|
||||
item.title = __("Select Serial and Batch");
|
||||
}
|
||||
|
||||
frappe.require(path, function() {
|
||||
new erpnext.SerialBatchPackageSelector(
|
||||
me.frm, item, (r) => {
|
||||
if (r) {
|
||||
frappe.model.set_value(item.doctype, item.name, {
|
||||
"serial_and_batch_bundle": r.name,
|
||||
"qty": Math.abs(r.total_qty)
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
update_auto_repeat_reference(doc) {
|
||||
if (doc.auto_repeat) {
|
||||
frappe.call({
|
||||
method:"frappe.automation.doctype.auto_repeat.auto_repeat.update_reference",
|
||||
args:{
|
||||
docname: doc.auto_repeat,
|
||||
reference:doc.name
|
||||
},
|
||||
callback: function(r){
|
||||
if (r.message=="success") {
|
||||
frappe.show_alert({message:__("Auto repeat document updated"), indicator:'green'});
|
||||
} else {
|
||||
frappe.show_alert({message:__("An error occurred during the update process"), indicator:'red'});
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
project() {
|
||||
let me = this;
|
||||
if(in_list(["Delivery Note", "Sales Invoice", "Sales Order"], this.frm.doc.doctype)) {
|
||||
if(this.frm.doc.project) {
|
||||
frappe.call({
|
||||
method:'erpnext.projects.doctype.project.project.get_cost_center_name' ,
|
||||
args: {project: this.frm.doc.project},
|
||||
callback: function(r, rt) {
|
||||
if(!r.exc) {
|
||||
$.each(me.frm.doc["items"] || [], function(i, row) {
|
||||
if(r.message) {
|
||||
frappe.model.set_value(row.doctype, row.name, "cost_center", r.message);
|
||||
frappe.msgprint(__("Cost Center For Item with Item Code {0} has been Changed to {1}", [row.item_name, r.message]));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
coupon_code() {
|
||||
this.frm.set_value("discount_amount", 0);
|
||||
this.frm.set_value("additional_discount_percentage", 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
erpnext.pre_sales = {
|
||||
set_as_lost: function(doctype) {
|
||||
frappe.ui.form.on(doctype, {
|
||||
set_as_lost_dialog: function(frm) {
|
||||
var dialog = new frappe.ui.Dialog({
|
||||
title: __("Set as Lost"),
|
||||
fields: [
|
||||
{
|
||||
"fieldtype": "Table MultiSelect",
|
||||
"label": __("Lost Reasons"),
|
||||
"fieldname": "lost_reason",
|
||||
"options": frm.doctype === 'Opportunity' ? 'Opportunity Lost Reason Detail': 'Quotation Lost Reason Detail',
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldtype": "Table MultiSelect",
|
||||
"label": __("Competitors"),
|
||||
"fieldname": "competitors",
|
||||
"options": "Competitor Detail"
|
||||
},
|
||||
{
|
||||
"fieldtype": "Small Text",
|
||||
"label": __("Detailed Reason"),
|
||||
"fieldname": "detailed_reason"
|
||||
},
|
||||
],
|
||||
primary_action: function() {
|
||||
let values = dialog.get_values();
|
||||
|
||||
frm.call({
|
||||
doc: frm.doc,
|
||||
method: 'declare_enquiry_lost',
|
||||
args: {
|
||||
'lost_reasons_list': values.lost_reason,
|
||||
'competitors': values.competitors ? values.competitors : [],
|
||||
'detailed_reason': values.detailed_reason
|
||||
},
|
||||
callback: function(r) {
|
||||
dialog.hide();
|
||||
frm.reload_doc();
|
||||
},
|
||||
});
|
||||
},
|
||||
primary_action_label: __('Declare Lost')
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -447,7 +447,6 @@
|
||||
"report_hide": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "credit_limits",
|
||||
"fieldtype": "Table",
|
||||
"label": "Credit Limit",
|
||||
@@ -568,7 +567,7 @@
|
||||
"link_fieldname": "party"
|
||||
}
|
||||
],
|
||||
"modified": "2023-10-19 16:56:27.327035",
|
||||
"modified": "2023-12-28 13:15:36.298369",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Customer",
|
||||
|
||||
@@ -307,18 +307,19 @@ class Customer(TransactionBase):
|
||||
|
||||
def create_contact(contact, party_type, party, email):
|
||||
"""Create contact based on given contact name"""
|
||||
contact = contact.split(" ")
|
||||
|
||||
contact = frappe.get_doc(
|
||||
first, middle, last = parse_full_name(contact)
|
||||
doc = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Contact",
|
||||
"first_name": contact[0],
|
||||
"last_name": len(contact) > 1 and contact[1] or "",
|
||||
"first_name": first,
|
||||
"middle_name": middle,
|
||||
"last_name": last,
|
||||
"is_primary_contact": 1,
|
||||
}
|
||||
)
|
||||
contact.append("email_ids", dict(email_id=email, is_primary=1))
|
||||
contact.append("links", dict(link_doctype=party_type, link_name=party))
|
||||
contact.insert()
|
||||
doc.append("email_ids", dict(email_id=email, is_primary=1))
|
||||
doc.append("links", dict(link_doctype=party_type, link_name=party))
|
||||
return doc.insert()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@@ -684,24 +685,50 @@ def get_credit_limit(customer, company):
|
||||
|
||||
|
||||
def make_contact(args, is_primary_contact=1):
|
||||
contact = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Contact",
|
||||
"first_name": args.get("name"),
|
||||
"is_primary_contact": is_primary_contact,
|
||||
"links": [{"link_doctype": args.get("doctype"), "link_name": args.get("name")}],
|
||||
}
|
||||
)
|
||||
values = {
|
||||
"doctype": "Contact",
|
||||
"is_primary_contact": is_primary_contact,
|
||||
"links": [{"link_doctype": args.get("doctype"), "link_name": args.get("name")}],
|
||||
}
|
||||
|
||||
party_type = args.customer_type if args.doctype == "Customer" else args.supplier_type
|
||||
party_name_key = "customer_name" if args.doctype == "Customer" else "supplier_name"
|
||||
|
||||
if party_type == "Individual":
|
||||
first, middle, last = parse_full_name(args.get(party_name_key))
|
||||
values.update(
|
||||
{
|
||||
"first_name": first,
|
||||
"middle_name": middle,
|
||||
"last_name": last,
|
||||
}
|
||||
)
|
||||
else:
|
||||
values.update(
|
||||
{
|
||||
"first_name": args.get("customer_name")
|
||||
if args.doctype == "Customer"
|
||||
else args.get("supplier_name"),
|
||||
"company_name": args.get(party_name_key),
|
||||
}
|
||||
)
|
||||
|
||||
contact = frappe.get_doc(values)
|
||||
|
||||
if args.get("email_id"):
|
||||
contact.add_email(args.get("email_id"), is_primary=True)
|
||||
if args.get("mobile_no"):
|
||||
contact.add_phone(args.get("mobile_no"), is_primary_mobile_no=True)
|
||||
contact.insert()
|
||||
|
||||
if flags := args.get("flags"):
|
||||
contact.insert(ignore_permissions=flags.get("ignore_permissions"))
|
||||
else:
|
||||
contact.insert()
|
||||
|
||||
return contact
|
||||
|
||||
|
||||
def make_address(args, is_primary_address=1):
|
||||
def make_address(args, is_primary_address=1, is_shipping_address=1):
|
||||
reqd_fields = []
|
||||
for field in ["city", "country"]:
|
||||
if not args.get(field):
|
||||
@@ -714,19 +741,28 @@ def make_address(args, is_primary_address=1):
|
||||
title=_("Missing Values Required"),
|
||||
)
|
||||
|
||||
party_name_key = "customer_name" if args.doctype == "Customer" else "supplier_name"
|
||||
|
||||
address = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Address",
|
||||
"address_title": args.get("name"),
|
||||
"address_title": args.get(party_name_key),
|
||||
"address_line1": args.get("address_line1"),
|
||||
"address_line2": args.get("address_line2"),
|
||||
"city": args.get("city"),
|
||||
"state": args.get("state"),
|
||||
"pincode": args.get("pincode"),
|
||||
"country": args.get("country"),
|
||||
"is_primary_address": is_primary_address,
|
||||
"is_shipping_address": is_shipping_address,
|
||||
"links": [{"link_doctype": args.get("doctype"), "link_name": args.get("name")}],
|
||||
}
|
||||
).insert()
|
||||
)
|
||||
|
||||
if flags := args.get("flags"):
|
||||
address.insert(ignore_permissions=flags.get("ignore_permissions"))
|
||||
else:
|
||||
address.insert()
|
||||
|
||||
return address
|
||||
|
||||
@@ -747,3 +783,13 @@ def get_customer_primary_contact(doctype, txt, searchfield, start, page_len, fil
|
||||
.where((dlink.link_name == customer) & (con.name.like(f"%{txt}%")))
|
||||
.run()
|
||||
)
|
||||
|
||||
|
||||
def parse_full_name(full_name: str) -> tuple[str, str | None, str | None]:
|
||||
"""Parse full name into first name, middle name and last name"""
|
||||
names = full_name.split()
|
||||
first_name = names[0]
|
||||
middle_name = " ".join(names[1:-1]) if len(names) > 2 else None
|
||||
last_name = names[-1] if len(names) > 1 else None
|
||||
|
||||
return first_name, middle_name, last_name
|
||||
|
||||
@@ -10,7 +10,11 @@ from frappe.utils import flt
|
||||
|
||||
from erpnext.accounts.party import get_due_date
|
||||
from erpnext.exceptions import PartyDisabled, PartyFrozen
|
||||
from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding
|
||||
from erpnext.selling.doctype.customer.customer import (
|
||||
get_credit_limit,
|
||||
get_customer_outstanding,
|
||||
parse_full_name,
|
||||
)
|
||||
from erpnext.tests.utils import create_test_contact_and_address
|
||||
|
||||
test_ignore = ["Price List"]
|
||||
@@ -373,6 +377,22 @@ class TestCustomer(FrappeTestCase):
|
||||
|
||||
frappe.db.set_value("Selling Settings", None, "cust_master_name", "Customer Name")
|
||||
|
||||
def test_parse_full_name(self):
|
||||
first, middle, last = parse_full_name("John")
|
||||
self.assertEqual(first, "John")
|
||||
self.assertEqual(middle, None)
|
||||
self.assertEqual(last, None)
|
||||
|
||||
first, middle, last = parse_full_name("John Doe")
|
||||
self.assertEqual(first, "John")
|
||||
self.assertEqual(middle, None)
|
||||
self.assertEqual(last, "Doe")
|
||||
|
||||
first, middle, last = parse_full_name("John Michael Doe")
|
||||
self.assertEqual(first, "John")
|
||||
self.assertEqual(middle, "Michael")
|
||||
self.assertEqual(last, "Doe")
|
||||
|
||||
|
||||
def get_customer_dict(customer_name):
|
||||
return {
|
||||
|
||||
@@ -288,15 +288,16 @@ def _make_sales_order(source_name, target_doc=None, ignore_permissions=False):
|
||||
)
|
||||
|
||||
# sales team
|
||||
for d in customer.get("sales_team") or []:
|
||||
target.append(
|
||||
"sales_team",
|
||||
{
|
||||
"sales_person": d.sales_person,
|
||||
"allocated_percentage": d.allocated_percentage or None,
|
||||
"commission_rate": d.commission_rate,
|
||||
},
|
||||
)
|
||||
if not target.get("sales_team"):
|
||||
for d in customer.get("sales_team") or []:
|
||||
target.append(
|
||||
"sales_team",
|
||||
{
|
||||
"sales_person": d.sales_person,
|
||||
"allocated_percentage": d.allocated_percentage or None,
|
||||
"commission_rate": d.commission_rate,
|
||||
},
|
||||
)
|
||||
|
||||
target.flags.ignore_permissions = ignore_permissions
|
||||
target.delivery_date = nowdate()
|
||||
|
||||
@@ -432,17 +432,17 @@ class SalesOrder(SellingController):
|
||||
|
||||
def set_indicator(self):
|
||||
"""Set indicator for portal"""
|
||||
if self.per_billed < 100 and self.per_delivered < 100:
|
||||
self.indicator_color = "orange"
|
||||
self.indicator_title = _("Not Paid and Not Delivered")
|
||||
self.indicator_color = {
|
||||
"Draft": "red",
|
||||
"On Hold": "orange",
|
||||
"To Deliver and Bill": "orange",
|
||||
"To Bill": "orange",
|
||||
"To Deliver": "orange",
|
||||
"Completed": "green",
|
||||
"Cancelled": "red",
|
||||
}.get(self.status, "blue")
|
||||
|
||||
elif self.per_billed == 100 and self.per_delivered < 100:
|
||||
self.indicator_color = "orange"
|
||||
self.indicator_title = _("Paid and Not Delivered")
|
||||
|
||||
else:
|
||||
self.indicator_color = "green"
|
||||
self.indicator_title = _("Paid")
|
||||
self.indicator_title = _(self.status)
|
||||
|
||||
def on_recurring(self, reference_doc, auto_repeat_doc):
|
||||
def _get_delivery_date(ref_doc_delivery_date, red_doc_transaction_date, transaction_date):
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe import _, qb
|
||||
from frappe.query_builder import Criterion
|
||||
|
||||
from erpnext import get_default_company
|
||||
from erpnext.accounts.party import get_party_details
|
||||
from erpnext.stock.get_item_details import get_price_list_rate_for
|
||||
|
||||
|
||||
def execute(filters=None):
|
||||
@@ -50,6 +50,42 @@ def get_columns(filters=None):
|
||||
]
|
||||
|
||||
|
||||
def fetch_item_prices(
|
||||
customer: str = None, price_list: str = None, selling_price_list: str = None, items: list = None
|
||||
):
|
||||
price_list_map = frappe._dict()
|
||||
ip = qb.DocType("Item Price")
|
||||
and_conditions = []
|
||||
or_conditions = []
|
||||
if items:
|
||||
and_conditions.append(ip.item_code.isin([x.item_code for x in items]))
|
||||
and_conditions.append(ip.selling == True)
|
||||
|
||||
or_conditions.append(ip.customer == None)
|
||||
or_conditions.append(ip.price_list == None)
|
||||
|
||||
if customer:
|
||||
or_conditions.append(ip.customer == customer)
|
||||
|
||||
if price_list:
|
||||
or_conditions.append(ip.price_list == price_list)
|
||||
|
||||
if selling_price_list:
|
||||
or_conditions.append(ip.price_list == selling_price_list)
|
||||
|
||||
res = (
|
||||
qb.from_(ip)
|
||||
.select(ip.item_code, ip.price_list, ip.price_list_rate)
|
||||
.where(Criterion.all(and_conditions))
|
||||
.where(Criterion.any(or_conditions))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
for x in res:
|
||||
price_list_map.update({(x.item_code, x.price_list): x.price_list_rate})
|
||||
|
||||
return price_list_map
|
||||
|
||||
|
||||
def get_data(filters=None):
|
||||
data = []
|
||||
customer_details = get_customer_details(filters)
|
||||
@@ -59,9 +95,17 @@ def get_data(filters=None):
|
||||
"Bin", fields=["item_code", "sum(actual_qty) AS available"], group_by="item_code"
|
||||
)
|
||||
item_stock_map = {item.item_code: item.available for item in item_stock_map}
|
||||
price_list_map = fetch_item_prices(
|
||||
customer_details.customer,
|
||||
customer_details.price_list,
|
||||
customer_details.selling_price_list,
|
||||
items,
|
||||
)
|
||||
|
||||
for item in items:
|
||||
price_list_rate = get_price_list_rate_for(customer_details, item.item_code) or 0.0
|
||||
price_list_rate = price_list_map.get(
|
||||
(item.item_code, customer_details.price_list or customer_details.selling_price_list), 0.0
|
||||
)
|
||||
available_stock = item_stock_map.get(item.item_code)
|
||||
|
||||
data.append(
|
||||
|
||||
@@ -200,6 +200,10 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran
|
||||
item.serial_no = null;
|
||||
}
|
||||
|
||||
if (doc.docstatus === 0 && doc.is_return && !doc.return_against) {
|
||||
item.incoming_rate = 0.0;
|
||||
}
|
||||
|
||||
var has_batch_no;
|
||||
frappe.db.get_value('Item', {'item_code': item.item_code}, 'has_batch_no', (r) => {
|
||||
has_batch_no = r && r.has_batch_no;
|
||||
@@ -428,6 +432,11 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
coupon_code() {
|
||||
this.frm.set_value("discount_amount", 0);
|
||||
this.frm.set_value("additional_discount_percentage", 0);
|
||||
}
|
||||
};
|
||||
|
||||
frappe.ui.form.on(cur_frm.doctype,"project", function(frm) {
|
||||
|
||||
@@ -616,8 +616,8 @@
|
||||
"fieldname": "relieving_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Relieving Date",
|
||||
"no_copy": 1,
|
||||
"mandatory_depends_on": "eval:doc.status == \"Left\"",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "relieving_date",
|
||||
"oldfieldtype": "Date"
|
||||
},
|
||||
@@ -822,12 +822,14 @@
|
||||
"icon": "fa fa-user",
|
||||
"idx": 24,
|
||||
"image_field": "image",
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"modified": "2023-10-04 10:57:05.174592",
|
||||
"modified": "2024-01-03 17:36:20.984421",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Employee",
|
||||
"naming_rule": "By \"Naming Series\" field",
|
||||
"nsm_parent_field": "reports_to",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
@@ -860,7 +862,6 @@
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "HR Manager",
|
||||
"set_user_permissions": 1,
|
||||
"share": 1,
|
||||
"write": 1
|
||||
}
|
||||
@@ -871,4 +872,4 @@
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "employee_name"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import frappe
|
||||
from frappe.utils import cint
|
||||
from frappe.utils.deprecations import deprecated
|
||||
|
||||
|
||||
def get_leaderboards():
|
||||
@@ -54,12 +54,13 @@ def get_leaderboards():
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_all_customers(date_range, company, field, limit=None):
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company]]
|
||||
from_date, to_date = parse_date_range(date_range)
|
||||
if field == "outstanding_amount":
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company]]
|
||||
if date_range:
|
||||
date_range = frappe.parse_json(date_range)
|
||||
filters.append(["posting_date", ">=", "between", [date_range[0], date_range[1]]])
|
||||
return frappe.db.get_all(
|
||||
if from_date and to_date:
|
||||
filters.append(["posting_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.get_list(
|
||||
"Sales Invoice",
|
||||
fields=["customer as name", "sum(outstanding_amount) as value"],
|
||||
filters=filters,
|
||||
@@ -69,26 +70,20 @@ def get_all_customers(date_range, company, field, limit=None):
|
||||
)
|
||||
else:
|
||||
if field == "total_sales_amount":
|
||||
select_field = "sum(so_item.base_net_amount)"
|
||||
select_field = "base_net_total"
|
||||
elif field == "total_qty_sold":
|
||||
select_field = "sum(so_item.stock_qty)"
|
||||
select_field = "total_qty"
|
||||
|
||||
date_condition = get_date_condition(date_range, "so.transaction_date")
|
||||
if from_date and to_date:
|
||||
filters.append(["transaction_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select so.customer as name, {0} as value
|
||||
FROM `tabSales Order` as so JOIN `tabSales Order Item` as so_item
|
||||
ON so.name = so_item.parent
|
||||
where so.docstatus = 1 {1} and so.company = %s
|
||||
group by so.customer
|
||||
order by value DESC
|
||||
limit %s
|
||||
""".format(
|
||||
select_field, date_condition
|
||||
),
|
||||
(company, cint(limit)),
|
||||
as_dict=1,
|
||||
return frappe.get_list(
|
||||
"Sales Order",
|
||||
fields=["customer as name", f"sum({select_field}) as value"],
|
||||
filters=filters,
|
||||
group_by="customer",
|
||||
order_by="value desc",
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
@@ -96,55 +91,58 @@ def get_all_customers(date_range, company, field, limit=None):
|
||||
def get_all_items(date_range, company, field, limit=None):
|
||||
if field in ("available_stock_qty", "available_stock_value"):
|
||||
select_field = "sum(actual_qty)" if field == "available_stock_qty" else "sum(stock_value)"
|
||||
return frappe.db.get_all(
|
||||
results = frappe.db.get_all(
|
||||
"Bin",
|
||||
fields=["item_code as name", "{0} as value".format(select_field)],
|
||||
group_by="item_code",
|
||||
order_by="value desc",
|
||||
limit=limit,
|
||||
)
|
||||
readable_active_items = set(frappe.get_list("Item", filters={"disabled": 0}, pluck="name"))
|
||||
return [item for item in results if item["name"] in readable_active_items]
|
||||
else:
|
||||
if field == "total_sales_amount":
|
||||
select_field = "sum(order_item.base_net_amount)"
|
||||
select_field = "base_net_amount"
|
||||
select_doctype = "Sales Order"
|
||||
elif field == "total_purchase_amount":
|
||||
select_field = "sum(order_item.base_net_amount)"
|
||||
select_field = "base_net_amount"
|
||||
select_doctype = "Purchase Order"
|
||||
elif field == "total_qty_sold":
|
||||
select_field = "sum(order_item.stock_qty)"
|
||||
select_field = "stock_qty"
|
||||
select_doctype = "Sales Order"
|
||||
elif field == "total_qty_purchased":
|
||||
select_field = "sum(order_item.stock_qty)"
|
||||
select_field = "stock_qty"
|
||||
select_doctype = "Purchase Order"
|
||||
|
||||
date_condition = get_date_condition(date_range, "sales_order.transaction_date")
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company]]
|
||||
from_date, to_date = parse_date_range(date_range)
|
||||
if from_date and to_date:
|
||||
filters.append(["transaction_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select order_item.item_code as name, {0} as value
|
||||
from `tab{1}` sales_order join `tab{1} Item` as order_item
|
||||
on sales_order.name = order_item.parent
|
||||
where sales_order.docstatus = 1
|
||||
and sales_order.company = %s {2}
|
||||
group by order_item.item_code
|
||||
order by value desc
|
||||
limit %s
|
||||
""".format(
|
||||
select_field, select_doctype, date_condition
|
||||
),
|
||||
(company, cint(limit)),
|
||||
as_dict=1,
|
||||
) # nosec
|
||||
child_doctype = f"{select_doctype} Item"
|
||||
return frappe.get_list(
|
||||
select_doctype,
|
||||
fields=[
|
||||
f"`tab{child_doctype}`.item_code as name",
|
||||
f"sum(`tab{child_doctype}`.{select_field}) as value",
|
||||
],
|
||||
filters=filters,
|
||||
order_by="value desc",
|
||||
group_by=f"`tab{child_doctype}`.item_code",
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_all_suppliers(date_range, company, field, limit=None):
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company]]
|
||||
from_date, to_date = parse_date_range(date_range)
|
||||
|
||||
if field == "outstanding_amount":
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company]]
|
||||
if date_range:
|
||||
date_range = frappe.parse_json(date_range)
|
||||
filters.append(["posting_date", "between", [date_range[0], date_range[1]]])
|
||||
return frappe.db.get_all(
|
||||
if from_date and to_date:
|
||||
filters.append(["posting_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.get_list(
|
||||
"Purchase Invoice",
|
||||
fields=["supplier as name", "sum(outstanding_amount) as value"],
|
||||
filters=filters,
|
||||
@@ -154,48 +152,40 @@ def get_all_suppliers(date_range, company, field, limit=None):
|
||||
)
|
||||
else:
|
||||
if field == "total_purchase_amount":
|
||||
select_field = "sum(purchase_order_item.base_net_amount)"
|
||||
select_field = "base_net_total"
|
||||
elif field == "total_qty_purchased":
|
||||
select_field = "sum(purchase_order_item.stock_qty)"
|
||||
select_field = "total_qty"
|
||||
|
||||
date_condition = get_date_condition(date_range, "purchase_order.modified")
|
||||
if from_date and to_date:
|
||||
filters.append(["transaction_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select purchase_order.supplier as name, {0} as value
|
||||
FROM `tabPurchase Order` as purchase_order LEFT JOIN `tabPurchase Order Item`
|
||||
as purchase_order_item ON purchase_order.name = purchase_order_item.parent
|
||||
where
|
||||
purchase_order.docstatus = 1
|
||||
{1}
|
||||
and purchase_order.company = %s
|
||||
group by purchase_order.supplier
|
||||
order by value DESC
|
||||
limit %s""".format(
|
||||
select_field, date_condition
|
||||
),
|
||||
(company, cint(limit)),
|
||||
as_dict=1,
|
||||
) # nosec
|
||||
return frappe.get_list(
|
||||
"Purchase Order",
|
||||
fields=["supplier as name", f"sum({select_field}) as value"],
|
||||
filters=filters,
|
||||
group_by="supplier",
|
||||
order_by="value desc",
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_all_sales_partner(date_range, company, field, limit=None):
|
||||
if field == "total_sales_amount":
|
||||
select_field = "sum(`base_net_total`)"
|
||||
select_field = "base_net_total"
|
||||
elif field == "total_commission":
|
||||
select_field = "sum(`total_commission`)"
|
||||
select_field = "total_commission"
|
||||
|
||||
filters = {"sales_partner": ["!=", ""], "docstatus": 1, "company": company}
|
||||
if date_range:
|
||||
date_range = frappe.parse_json(date_range)
|
||||
filters["transaction_date"] = ["between", [date_range[0], date_range[1]]]
|
||||
filters = [["docstatus", "=", "1"], ["company", "=", company], ["sales_partner", "is", "set"]]
|
||||
from_date, to_date = parse_date_range(date_range)
|
||||
if from_date and to_date:
|
||||
filters.append(["transaction_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.get_list(
|
||||
"Sales Order",
|
||||
fields=[
|
||||
"`sales_partner` as name",
|
||||
"{} as value".format(select_field),
|
||||
"sales_partner as name",
|
||||
f"sum({select_field}) as value",
|
||||
],
|
||||
filters=filters,
|
||||
group_by="sales_partner",
|
||||
@@ -206,27 +196,29 @@ def get_all_sales_partner(date_range, company, field, limit=None):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_all_sales_person(date_range, company, field=None, limit=0):
|
||||
date_condition = get_date_condition(date_range, "sales_order.transaction_date")
|
||||
filters = [
|
||||
["docstatus", "=", "1"],
|
||||
["company", "=", company],
|
||||
["Sales Team", "sales_person", "is", "set"],
|
||||
]
|
||||
from_date, to_date = parse_date_range(date_range)
|
||||
if from_date and to_date:
|
||||
filters.append(["transaction_date", "between", [from_date, to_date]])
|
||||
|
||||
return frappe.db.sql(
|
||||
"""
|
||||
select sales_team.sales_person as name, sum(sales_order.base_net_total) as value
|
||||
from `tabSales Order` as sales_order join `tabSales Team` as sales_team
|
||||
on sales_order.name = sales_team.parent and sales_team.parenttype = 'Sales Order'
|
||||
where sales_order.docstatus = 1
|
||||
and sales_order.company = %s
|
||||
{date_condition}
|
||||
group by sales_team.sales_person
|
||||
order by value DESC
|
||||
limit %s
|
||||
""".format(
|
||||
date_condition=date_condition
|
||||
),
|
||||
(company, cint(limit)),
|
||||
as_dict=1,
|
||||
return frappe.get_list(
|
||||
"Sales Order",
|
||||
fields=[
|
||||
"`tabSales Team`.sales_person as name",
|
||||
"sum(`tabSales Team`.allocated_amount) as value",
|
||||
],
|
||||
filters=filters,
|
||||
group_by="`tabSales Team`.sales_person",
|
||||
order_by="value desc",
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
@deprecated
|
||||
def get_date_condition(date_range, field):
|
||||
date_condition = ""
|
||||
if date_range:
|
||||
@@ -236,3 +228,11 @@ def get_date_condition(date_range, field):
|
||||
field, frappe.db.escape(from_date), frappe.db.escape(to_date)
|
||||
)
|
||||
return date_condition
|
||||
|
||||
|
||||
def parse_date_range(date_range):
|
||||
if date_range:
|
||||
date_range = frappe.parse_json(date_range)
|
||||
return date_range[0], date_range[1]
|
||||
|
||||
return None, None
|
||||
|
||||
@@ -51,8 +51,7 @@
|
||||
"oldfieldtype": "Link",
|
||||
"options": "Item",
|
||||
"read_only": 1,
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0.00",
|
||||
|
||||
@@ -44,7 +44,7 @@ class ClosingStockBalance(Document):
|
||||
& (
|
||||
(table.from_date.between(self.from_date, self.to_date))
|
||||
| (table.to_date.between(self.from_date, self.to_date))
|
||||
| (table.from_date >= self.from_date and table.to_date <= self.to_date)
|
||||
| (table.from_date >= self.from_date and table.to_date >= self.to_date)
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -128,6 +128,4 @@ def prepare_closing_stock_balance(name):
|
||||
doc.db_set("status", "Completed")
|
||||
except Exception as e:
|
||||
doc.db_set("status", "Failed")
|
||||
traceback = frappe.get_traceback()
|
||||
|
||||
frappe.log_error("Closing Stock Balance Failed", traceback, doc.doctype, doc.name)
|
||||
doc.log_error(title="Closing Stock Balance Failed")
|
||||
|
||||
@@ -301,7 +301,8 @@
|
||||
"no_copy": 1,
|
||||
"options": "Delivery Note",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
"read_only": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
@@ -1400,7 +1401,7 @@
|
||||
"idx": 146,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-09-04 14:15:28.363184",
|
||||
"modified": "2023-12-18 17:19:39.368239",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Delivery Note",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user