mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-24 19:39:50 +00:00
Compare commits
265 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d97e673874 | ||
|
|
b16bfa541d | ||
|
|
e01ff0df40 | ||
|
|
8d99763bea | ||
|
|
b4589d8b8f | ||
|
|
37ae2dfe7f | ||
|
|
cbda28d739 | ||
|
|
35c71f5923 | ||
|
|
52d4e2acf8 | ||
|
|
3691eec66c | ||
|
|
e93af962a1 | ||
|
|
9692eeeb15 | ||
|
|
7825c564eb | ||
|
|
e5fd95bb21 | ||
|
|
684a45f234 | ||
|
|
7ef0c6bb01 | ||
|
|
4587bb3767 | ||
|
|
2a18067aad | ||
|
|
b573d9739f | ||
|
|
4dbce87660 | ||
|
|
b82154cb9e | ||
|
|
2105193594 | ||
|
|
ef74c6689b | ||
|
|
799d7b254e | ||
|
|
086e74791b | ||
|
|
c3fca3cfcb | ||
|
|
1634448864 | ||
|
|
a6241fc813 | ||
|
|
896bac10bc | ||
|
|
0992ca40b0 | ||
|
|
10ac8d6e67 | ||
|
|
c8a2f9f857 | ||
|
|
b13ee4fc8c | ||
|
|
ab2f250960 | ||
|
|
e5b3748b49 | ||
|
|
eddb7b429e | ||
|
|
b3a9c1eb2a | ||
|
|
e44646054c | ||
|
|
12f11a6976 | ||
|
|
50b2898a2c | ||
|
|
23830266f2 | ||
|
|
b17ac522f5 | ||
|
|
1b22f53fde | ||
|
|
988a327b58 | ||
|
|
45f79ef644 | ||
|
|
bce3506e90 | ||
|
|
2880469706 | ||
|
|
104967881d | ||
|
|
b2ef5f7cd2 | ||
|
|
cd5b8aeb64 | ||
|
|
0003e0cb5b | ||
|
|
b3ccad8cf4 | ||
|
|
84ef814f45 | ||
|
|
ac432ea52f | ||
|
|
635d80dc2f | ||
|
|
0c4de03baa | ||
|
|
a716f780a8 | ||
|
|
6f6598878e | ||
|
|
4ad9aa29ee | ||
|
|
e54b23d71b | ||
|
|
ba9220f9d2 | ||
|
|
354f258543 | ||
|
|
f7d3f136c5 | ||
|
|
ff594831b0 | ||
|
|
b08d36cb7b | ||
|
|
cdb6a4e3f7 | ||
|
|
99188afa16 | ||
|
|
64fda0d4b7 | ||
|
|
0c6a7cef95 | ||
|
|
c930d64e8d | ||
|
|
78e64fa486 | ||
|
|
2a0d7acc2b | ||
|
|
24a3da55e6 | ||
|
|
c3289c265a | ||
|
|
b39f367dbd | ||
|
|
d76e291927 | ||
|
|
ce5419888b | ||
|
|
ffef0cb771 | ||
|
|
2de239c73b | ||
|
|
11978fca4e | ||
|
|
d38a2895b0 | ||
|
|
4492ee4771 | ||
|
|
eca2d96419 | ||
|
|
b66976bd36 | ||
|
|
776c8c6d6a | ||
|
|
452db7ed15 | ||
|
|
10cfcb5e8a | ||
|
|
b91860ddf2 | ||
|
|
eda89a467c | ||
|
|
2121714856 | ||
|
|
8b46da39ea | ||
|
|
6da7b38f6e | ||
|
|
7688239fc0 | ||
|
|
07c25ace5c | ||
|
|
6ae21c92de | ||
|
|
7af45972ae | ||
|
|
f106b9e884 | ||
|
|
b839c53572 | ||
|
|
30b42b22ab | ||
|
|
4834b78ed2 | ||
|
|
72f9308df6 | ||
|
|
dc9b81d216 | ||
|
|
61b20c81c2 | ||
|
|
58f3f2b6d9 | ||
|
|
e3435369a0 | ||
|
|
726c3d32be | ||
|
|
ecdd8493ea | ||
|
|
431a94b961 | ||
|
|
00f990e3f4 | ||
|
|
0070b5ef9a | ||
|
|
ab31eb4ee7 | ||
|
|
357ae939d1 | ||
|
|
b8aa63b5e2 | ||
|
|
9191c54b90 | ||
|
|
30b5d1c400 | ||
|
|
9d5c4ffadf | ||
|
|
85d8540379 | ||
|
|
4ad3e28147 | ||
|
|
ec6a01de4c | ||
|
|
7831744064 | ||
|
|
3aba14f71a | ||
|
|
f3f6d35a84 | ||
|
|
1cf5b23d9c | ||
|
|
de3453e477 | ||
|
|
ee015273c9 | ||
|
|
db3f8d2768 | ||
|
|
e1ecc9a819 | ||
|
|
9e340a8307 | ||
|
|
cbc8b2da0a | ||
|
|
b7ff5fb426 | ||
|
|
2b2a4f66ad | ||
|
|
78ca078474 | ||
|
|
65c9941aa4 | ||
|
|
5e46567a0b | ||
|
|
079cf6899e | ||
|
|
ad648f313c | ||
|
|
9c9c6607f8 | ||
|
|
d6901e51ad | ||
|
|
8733ce5ca9 | ||
|
|
1ee5c2ff87 | ||
|
|
09ef8eeaea | ||
|
|
40bb2cba93 | ||
|
|
95f81d3563 | ||
|
|
88ce59a1ca | ||
|
|
e93ac3c9a8 | ||
|
|
079fc2dc34 | ||
|
|
bd2242b285 | ||
|
|
79d508f4ff | ||
|
|
a0cab4c5e7 | ||
|
|
a19031cf9a | ||
|
|
e9e5ded36b | ||
|
|
fcb6ee22ba | ||
|
|
f09e4273d9 | ||
|
|
4a177113c6 | ||
|
|
972893d00e | ||
|
|
1ed0b6e89b | ||
|
|
dafb575500 | ||
|
|
9cf5e9e61e | ||
|
|
af8b99a5e0 | ||
|
|
a16347f325 | ||
|
|
19b9875ba8 | ||
|
|
43aa670e90 | ||
|
|
4f76ed1c68 | ||
|
|
b93d13feef | ||
|
|
e1a32cc620 | ||
|
|
550f5f280c | ||
|
|
fbbfeb8563 | ||
|
|
418c131331 | ||
|
|
a8bf17e560 | ||
|
|
9961037f71 | ||
|
|
84ee1b86af | ||
|
|
afe86d83aa | ||
|
|
76e4bb44f1 | ||
|
|
c1bc1040b8 | ||
|
|
1d23c9a9fd | ||
|
|
5a211813d3 | ||
|
|
601b1e3821 | ||
|
|
6d1ae68d70 | ||
|
|
19ebebdc47 | ||
|
|
a91483899b | ||
|
|
2f6d55d8d2 | ||
|
|
4a10454d89 | ||
|
|
12b15347bc | ||
|
|
9b63a1a2e9 | ||
|
|
8888957952 | ||
|
|
a9660bf026 | ||
|
|
b877b0d3a2 | ||
|
|
e4082093b8 | ||
|
|
9dc0edfb8a | ||
|
|
e13f05ce19 | ||
|
|
310e7c522c | ||
|
|
e32e0bc8fa | ||
|
|
0c24ba0118 | ||
|
|
60fa87751a | ||
|
|
50bc7785f7 | ||
|
|
d2aea0cd2e | ||
|
|
e9006582fb | ||
|
|
3483e0e2a5 | ||
|
|
65b047c94c | ||
|
|
ada3ce21c0 | ||
|
|
cb89dba5ab | ||
|
|
d73237e896 | ||
|
|
8e0d393cd4 | ||
|
|
292ff1bd6b | ||
|
|
804cf40f69 | ||
|
|
1d31ab1ab7 | ||
|
|
dd493fb46f | ||
|
|
85f48dd6bd | ||
|
|
fa0a137a38 | ||
|
|
5fc8d20e96 | ||
|
|
7ddcfc00fc | ||
|
|
3f02059085 | ||
|
|
71b21086b1 | ||
|
|
c2817bed0b | ||
|
|
dc972718d5 | ||
|
|
7afb19f965 | ||
|
|
0ca137808b | ||
|
|
99e0106193 | ||
|
|
447485ae90 | ||
|
|
98bcb7255d | ||
|
|
2df24ec459 | ||
|
|
3a2f08fbda | ||
|
|
7c9b535514 | ||
|
|
4f0c2909ab | ||
|
|
1741501ea8 | ||
|
|
ea032893d3 | ||
|
|
7601a016b8 | ||
|
|
b5376ce5cb | ||
|
|
7ba029b140 | ||
|
|
cf74d24400 | ||
|
|
b8d97b82b8 | ||
|
|
56c4c3186b | ||
|
|
015a221d8d | ||
|
|
eec770a4a8 | ||
|
|
44f5ccc9dc | ||
|
|
0ae2a4f1c4 | ||
|
|
5fdaddad86 | ||
|
|
03ccddc1cc | ||
|
|
e00ebcd9e5 | ||
|
|
7e7122b668 | ||
|
|
b1c70af4db | ||
|
|
1609129e1e | ||
|
|
9b02455c09 | ||
|
|
ff3bfb060a | ||
|
|
63e087d31e | ||
|
|
b62a397397 | ||
|
|
48efcc82b6 | ||
|
|
4383980bcc | ||
|
|
aa0552d788 | ||
|
|
3b5889ef85 | ||
|
|
8238b89907 | ||
|
|
6ae2f90683 | ||
|
|
cb7aef505d | ||
|
|
4a8c42d62b | ||
|
|
c67bdcf3c6 | ||
|
|
7a9e7b66ac | ||
|
|
151b9d4d7b | ||
|
|
b966f10711 | ||
|
|
0b48f13873 | ||
|
|
b531a38efe | ||
|
|
dd26ef96e0 | ||
|
|
227ce5f8a2 | ||
|
|
acd64ba7c1 | ||
|
|
6f43133c04 | ||
|
|
f72602ebf3 |
@@ -16,8 +16,8 @@ repos:
|
||||
- id: check-merge-conflict
|
||||
- id: check-ast
|
||||
|
||||
- repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.9.2
|
||||
- repo: https://github.com/PyCQA/flake8
|
||||
rev: 5.0.4
|
||||
hooks:
|
||||
- id: flake8
|
||||
additional_dependencies: [
|
||||
|
||||
@@ -4,7 +4,7 @@ import frappe
|
||||
|
||||
from erpnext.hooks import regional_overrides
|
||||
|
||||
__version__ = "13.40.0"
|
||||
__version__ = "13.42.7"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
|
||||
frappe.ui.form.on('Accounting Dimension Filter', {
|
||||
refresh: function(frm, cdt, cdn) {
|
||||
if (frm.doc.accounting_dimension) {
|
||||
frm.set_df_property('dimensions', 'label', frm.doc.accounting_dimension, cdn, 'dimension_value');
|
||||
}
|
||||
|
||||
let help_content =
|
||||
`<table class="table table-bordered" style="background-color: var(--scrollbar-track-color);">
|
||||
<tr><td>
|
||||
@@ -68,6 +64,7 @@ frappe.ui.form.on('Accounting Dimension Filter', {
|
||||
frm.clear_table("dimensions");
|
||||
let row = frm.add_child("dimensions");
|
||||
row.accounting_dimension = frm.doc.accounting_dimension;
|
||||
frm.fields_dict["dimensions"].grid.update_docfield_property("dimension_value", "label", frm.doc.accounting_dimension);
|
||||
frm.refresh_field("dimensions");
|
||||
frm.trigger('setup_filters');
|
||||
},
|
||||
|
||||
@@ -43,20 +43,13 @@ frappe.ui.form.on('Bank Guarantee', {
|
||||
|
||||
reference_docname: function(frm) {
|
||||
if (frm.doc.reference_docname && frm.doc.reference_doctype) {
|
||||
let fields_to_fetch = ["grand_total"];
|
||||
let party_field = frm.doc.reference_doctype == "Sales Order" ? "customer" : "supplier";
|
||||
|
||||
if (frm.doc.reference_doctype == "Sales Order") {
|
||||
fields_to_fetch.push("project");
|
||||
}
|
||||
|
||||
fields_to_fetch.push(party_field);
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_vouchar_detials",
|
||||
method: "erpnext.accounts.doctype.bank_guarantee.bank_guarantee.get_voucher_details",
|
||||
args: {
|
||||
"column_list": fields_to_fetch,
|
||||
"doctype": frm.doc.reference_doctype,
|
||||
"docname": frm.doc.reference_docname
|
||||
"bank_guarantee_type": frm.doc.bg_type,
|
||||
"reference_name": frm.doc.reference_docname
|
||||
},
|
||||
callback: function(r) {
|
||||
if (r.message) {
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
# For license information, please see license.txt
|
||||
|
||||
|
||||
import json
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.desk.search import sanitize_searchfield
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
@@ -25,14 +22,18 @@ class BankGuarantee(Document):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_vouchar_detials(column_list, doctype, docname):
|
||||
column_list = json.loads(column_list)
|
||||
for col in column_list:
|
||||
sanitize_searchfield(col)
|
||||
return frappe.db.sql(
|
||||
""" select {columns} from `tab{doctype}` where name=%s""".format(
|
||||
columns=", ".join(column_list), doctype=doctype
|
||||
),
|
||||
docname,
|
||||
as_dict=1,
|
||||
)[0]
|
||||
def get_voucher_details(bank_guarantee_type: str, reference_name: str):
|
||||
if not isinstance(reference_name, str):
|
||||
raise TypeError("reference_name must be a string")
|
||||
|
||||
fields_to_fetch = ["grand_total"]
|
||||
|
||||
if bank_guarantee_type == "Receiving":
|
||||
doctype = "Sales Order"
|
||||
fields_to_fetch.append("customer")
|
||||
fields_to_fetch.append("project")
|
||||
else:
|
||||
doctype = "Purchase Order"
|
||||
fields_to_fetch.append("supplier")
|
||||
|
||||
return frappe.db.get_value(doctype, reference_name, fields_to_fetch, as_dict=True)
|
||||
|
||||
@@ -169,5 +169,6 @@ def auto_create_fiscal_year():
|
||||
|
||||
|
||||
def get_from_and_to_date(fiscal_year):
|
||||
fields = ["year_start_date as from_date", "year_end_date as to_date"]
|
||||
return frappe.db.get_value("Fiscal Year", fiscal_year, fields, as_dict=1)
|
||||
fields = ["year_start_date", "year_end_date"]
|
||||
cached_results = frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)
|
||||
return dict(from_date=cached_results.year_start_date, to_date=cached_results.year_end_date)
|
||||
|
||||
@@ -45,21 +45,6 @@ frappe.ui.form.on("Journal Entry Template", {
|
||||
|
||||
frm.trigger("clear_child");
|
||||
switch(frm.doc.voucher_type){
|
||||
case "Opening Entry":
|
||||
frm.set_value("is_opening", "Yes");
|
||||
frappe.call({
|
||||
type:"GET",
|
||||
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
|
||||
args: {
|
||||
"company": frm.doc.company
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.message) {
|
||||
add_accounts(frm.doc, r.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case "Bank Entry":
|
||||
case "Cash Entry":
|
||||
frappe.call({
|
||||
|
||||
@@ -20,7 +20,6 @@ frappe.ui.form.on('Opening Invoice Creation Tool', {
|
||||
frm.dashboard.reset();
|
||||
frm.doc.import_in_progress = true;
|
||||
}
|
||||
if (data.user != frappe.session.user) return;
|
||||
if (data.count == data.total) {
|
||||
setTimeout((title) => {
|
||||
frm.doc.import_in_progress = false;
|
||||
|
||||
@@ -271,10 +271,10 @@ def publish(index, total, doctype):
|
||||
dict(
|
||||
title=_("Opening Invoice Creation In Progress"),
|
||||
message=_("Creating {} out of {} {}").format(index + 1, total, doctype),
|
||||
user=frappe.session.user,
|
||||
count=index + 1,
|
||||
total=total,
|
||||
),
|
||||
user=frappe.session.user,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ class PaymentEntry(AccountsController):
|
||||
self.set_missing_values()
|
||||
self.validate_payment_type()
|
||||
self.validate_party_details()
|
||||
self.validate_bank_accounts()
|
||||
self.set_exchange_rate()
|
||||
self.validate_mandatory()
|
||||
self.validate_reference_documents()
|
||||
@@ -250,23 +249,6 @@ class PaymentEntry(AccountsController):
|
||||
if not frappe.db.exists(self.party_type, self.party):
|
||||
frappe.throw(_("Invalid {0}: {1}").format(self.party_type, self.party))
|
||||
|
||||
if self.party_account and self.party_type in ("Customer", "Supplier"):
|
||||
self.validate_account_type(
|
||||
self.party_account, [erpnext.get_party_account_type(self.party_type)]
|
||||
)
|
||||
|
||||
def validate_bank_accounts(self):
|
||||
if self.payment_type in ("Pay", "Internal Transfer"):
|
||||
self.validate_account_type(self.paid_from, ["Bank", "Cash"])
|
||||
|
||||
if self.payment_type in ("Receive", "Internal Transfer"):
|
||||
self.validate_account_type(self.paid_to, ["Bank", "Cash"])
|
||||
|
||||
def validate_account_type(self, account, account_types):
|
||||
account_type = frappe.db.get_value("Account", account, "account_type")
|
||||
# if account_type not in account_types:
|
||||
# frappe.throw(_("Account Type for {0} must be {1}").format(account, comma_or(account_types)))
|
||||
|
||||
def set_exchange_rate(self, ref_doc=None):
|
||||
self.set_source_exchange_rate(ref_doc)
|
||||
self.set_target_exchange_rate(ref_doc)
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Type",
|
||||
"options": "DocType",
|
||||
"reqd": 1
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"columns": 2,
|
||||
@@ -35,7 +36,8 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Name",
|
||||
"options": "reference_doctype",
|
||||
"reqd": 1
|
||||
"reqd": 1,
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "due_date",
|
||||
@@ -104,7 +106,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-09-26 17:06:55.597389",
|
||||
"modified": "2022-12-12 12:31:44.919895",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry Reference",
|
||||
@@ -113,5 +115,6 @@
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -3,8 +3,10 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _, msgprint
|
||||
from frappe import _, msgprint, qb
|
||||
from frappe.model.document import Document
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import Sum
|
||||
from frappe.utils import flt, getdate, nowdate, today
|
||||
|
||||
import erpnext
|
||||
@@ -47,6 +49,10 @@ 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.get("cost_center"):
|
||||
condition += " and cost_center = '{0}' ".format(self.cost_center)
|
||||
|
||||
payment_entries = get_advance_payment_entries(
|
||||
self.party_type,
|
||||
self.party,
|
||||
@@ -61,6 +67,10 @@ class PaymentReconciliation(Document):
|
||||
|
||||
def get_jv_entries(self):
|
||||
condition = self.get_conditions()
|
||||
|
||||
if self.get("cost_center"):
|
||||
condition += " and t2.cost_center = '{0}' ".format(self.cost_center)
|
||||
|
||||
dr_or_cr = (
|
||||
"credit_in_account_currency"
|
||||
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||
@@ -112,54 +122,79 @@ class PaymentReconciliation(Document):
|
||||
return list(journal_entries)
|
||||
|
||||
def get_dr_or_cr_notes(self):
|
||||
condition = self.get_conditions(get_return_invoices=True)
|
||||
gl = qb.DocType("GL Entry")
|
||||
|
||||
voucher_type = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
||||
doc = qb.DocType(voucher_type)
|
||||
|
||||
# build conditions
|
||||
sub_query_conditions = []
|
||||
conditions = []
|
||||
sub_query_conditions.append(doc.company == self.company)
|
||||
|
||||
if self.get("from_payment_date"):
|
||||
sub_query_conditions.append(doc.posting_date.gte(self.from_payment_date))
|
||||
|
||||
if self.get("to_payment_date"):
|
||||
sub_query_conditions.append(doc.posting_date.lte(self.to_payment_date))
|
||||
|
||||
if self.get("cost_center"):
|
||||
sub_query_conditions.append(doc.cost_center == self.cost_center)
|
||||
|
||||
dr_or_cr = (
|
||||
"credit_in_account_currency"
|
||||
gl["credit_in_account_currency"]
|
||||
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||
else "debit_in_account_currency"
|
||||
else gl["debit_in_account_currency"]
|
||||
)
|
||||
|
||||
reconciled_dr_or_cr = (
|
||||
"debit_in_account_currency"
|
||||
if dr_or_cr == "credit_in_account_currency"
|
||||
else "credit_in_account_currency"
|
||||
gl["debit_in_account_currency"]
|
||||
if dr_or_cr.name == "credit_in_account_currency"
|
||||
else gl["credit_in_account_currency"]
|
||||
)
|
||||
|
||||
voucher_type = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
||||
having_clause = qb.Field("amount") > 0
|
||||
|
||||
return frappe.db.sql(
|
||||
""" SELECT doc.name as reference_name, %(voucher_type)s as reference_type,
|
||||
(sum(gl.{dr_or_cr}) - sum(gl.{reconciled_dr_or_cr})) as amount, doc.posting_date,
|
||||
account_currency as currency
|
||||
FROM `tab{doc}` doc, `tabGL Entry` gl
|
||||
WHERE
|
||||
(doc.name = gl.against_voucher or doc.name = gl.voucher_no)
|
||||
and doc.{party_type_field} = %(party)s
|
||||
and doc.is_return = 1 and ifnull(doc.return_against, "") = ""
|
||||
and gl.against_voucher_type = %(voucher_type)s
|
||||
and doc.docstatus = 1 and gl.party = %(party)s
|
||||
and gl.party_type = %(party_type)s and gl.account = %(account)s
|
||||
and gl.is_cancelled = 0 {condition}
|
||||
GROUP BY doc.name
|
||||
Having
|
||||
amount > 0
|
||||
ORDER BY doc.posting_date
|
||||
""".format(
|
||||
doc=voucher_type,
|
||||
dr_or_cr=dr_or_cr,
|
||||
reconciled_dr_or_cr=reconciled_dr_or_cr,
|
||||
party_type_field=frappe.scrub(self.party_type),
|
||||
condition=condition or "",
|
||||
),
|
||||
{
|
||||
"party": self.party,
|
||||
"party_type": self.party_type,
|
||||
"voucher_type": voucher_type,
|
||||
"account": self.receivable_payable_account,
|
||||
},
|
||||
as_dict=1,
|
||||
if self.minimum_payment_amount:
|
||||
having_clause = qb.Field("amount") >= self.minimum_payment_amount
|
||||
if self.maximum_payment_amount:
|
||||
having_clause = having_clause & qb.Field("amount") <= self.maximum_payment_amount
|
||||
|
||||
sub_query = (
|
||||
qb.from_(doc)
|
||||
.select(doc.name)
|
||||
.where(Criterion.all(sub_query_conditions))
|
||||
.where(
|
||||
(doc.docstatus == 1)
|
||||
& (doc.is_return == 1)
|
||||
& ((doc.return_against == "") | (doc.return_against.isnull()))
|
||||
)
|
||||
)
|
||||
|
||||
query = (
|
||||
qb.from_(gl)
|
||||
.select(
|
||||
gl.against_voucher_type.as_("reference_type"),
|
||||
gl.against_voucher.as_("reference_name"),
|
||||
(Sum(dr_or_cr) - Sum(reconciled_dr_or_cr)).as_("amount"),
|
||||
gl.posting_date,
|
||||
gl.account_currency.as_("currency"),
|
||||
)
|
||||
.where(
|
||||
(gl.against_voucher.isin(sub_query))
|
||||
& (gl.against_voucher_type == voucher_type)
|
||||
& (gl.is_cancelled == 0)
|
||||
& (gl.account == self.receivable_payable_account)
|
||||
& (gl.party_type == self.party_type)
|
||||
& (gl.party == self.party)
|
||||
)
|
||||
.where(Criterion.all(conditions))
|
||||
.groupby(gl.against_voucher)
|
||||
.having(having_clause)
|
||||
)
|
||||
dr_cr_notes = query.run(as_dict=True)
|
||||
return dr_cr_notes
|
||||
|
||||
def add_payment_entries(self, non_reconciled_payments):
|
||||
self.set("payments", [])
|
||||
|
||||
@@ -172,6 +207,9 @@ class PaymentReconciliation(Document):
|
||||
|
||||
condition = self.get_conditions(get_invoices=True)
|
||||
|
||||
if self.get("cost_center"):
|
||||
condition += " and cost_center = '{0}' ".format(self.cost_center)
|
||||
|
||||
non_reconciled_invoices = get_outstanding_invoices(
|
||||
self.party_type, self.party, self.receivable_payable_account, condition=condition
|
||||
)
|
||||
@@ -354,12 +392,9 @@ class PaymentReconciliation(Document):
|
||||
if not invoices_to_reconcile:
|
||||
frappe.throw(_("No records found in Allocation table"))
|
||||
|
||||
def get_conditions(self, get_invoices=False, get_payments=False, get_return_invoices=False):
|
||||
def get_conditions(self, get_invoices=False, get_payments=False):
|
||||
condition = " and company = '{0}' ".format(self.company)
|
||||
|
||||
if self.get("cost_center"):
|
||||
condition = " and cost_center = '{0}' ".format(self.cost_center)
|
||||
|
||||
if get_invoices:
|
||||
condition += (
|
||||
" and posting_date >= {0}".format(frappe.db.escape(self.from_invoice_date))
|
||||
@@ -385,35 +420,7 @@ class PaymentReconciliation(Document):
|
||||
condition += " and {dr_or_cr} <= {amount}".format(
|
||||
dr_or_cr=dr_or_cr, amount=flt(self.maximum_invoice_amount)
|
||||
)
|
||||
|
||||
elif get_return_invoices:
|
||||
condition = " and doc.company = '{0}' ".format(self.company)
|
||||
condition += (
|
||||
" and doc.posting_date >= {0}".format(frappe.db.escape(self.from_payment_date))
|
||||
if self.from_payment_date
|
||||
else ""
|
||||
)
|
||||
condition += (
|
||||
" and doc.posting_date <= {0}".format(frappe.db.escape(self.to_payment_date))
|
||||
if self.to_payment_date
|
||||
else ""
|
||||
)
|
||||
dr_or_cr = (
|
||||
"debit_in_account_currency"
|
||||
if erpnext.get_party_account_type(self.party_type) == "Receivable"
|
||||
else "credit_in_account_currency"
|
||||
)
|
||||
|
||||
if self.minimum_invoice_amount:
|
||||
condition += " and gl.{dr_or_cr} >= {amount}".format(
|
||||
dr_or_cr=dr_or_cr, amount=flt(self.minimum_payment_amount)
|
||||
)
|
||||
if self.maximum_invoice_amount:
|
||||
condition += " and gl.{dr_or_cr} <= {amount}".format(
|
||||
dr_or_cr=dr_or_cr, amount=flt(self.maximum_payment_amount)
|
||||
)
|
||||
|
||||
else:
|
||||
elif get_payments:
|
||||
condition += (
|
||||
" and posting_date >= {0}".format(frappe.db.escape(self.from_payment_date))
|
||||
if self.from_payment_date
|
||||
|
||||
@@ -25,7 +25,7 @@ frappe.ui.form.on('POS Closing Entry', {
|
||||
|
||||
frappe.realtime.on('closing_process_complete', async function(data) {
|
||||
await frm.reload_doc();
|
||||
if (frm.doc.status == 'Failed' && frm.doc.error_message && data.user == frappe.session.user) {
|
||||
if (frm.doc.status == 'Failed' && frm.doc.error_message) {
|
||||
frappe.msgprint({
|
||||
title: __('POS Closing Failed'),
|
||||
message: frm.doc.error_message,
|
||||
|
||||
@@ -495,6 +495,67 @@ class TestPOSInvoice(unittest.TestCase):
|
||||
|
||||
self.assertRaises(frappe.ValidationError, pos.submit)
|
||||
|
||||
def test_value_error_on_serial_no_validation(self):
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item
|
||||
|
||||
se = make_serialized_item(
|
||||
company="_Test Company",
|
||||
target_warehouse="Stores - _TC",
|
||||
cost_center="Main - _TC",
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
)
|
||||
serial_nos = se.get("items")[0].serial_no
|
||||
|
||||
# make a pos invoice
|
||||
pos = create_pos_invoice(
|
||||
company="_Test Company",
|
||||
debit_to="Debtors - _TC",
|
||||
account_for_change_amount="Cash - _TC",
|
||||
warehouse="Stores - _TC",
|
||||
income_account="Sales - _TC",
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
cost_center="Main - _TC",
|
||||
item=se.get("items")[0].item_code,
|
||||
rate=1000,
|
||||
qty=1,
|
||||
do_not_save=1,
|
||||
)
|
||||
pos.get("items")[0].has_serial_no = 1
|
||||
pos.get("items")[0].serial_no = serial_nos.split("\n")[0]
|
||||
pos.set("payments", [])
|
||||
pos.append(
|
||||
"payments", {"mode_of_payment": "Cash", "account": "Cash - _TC", "amount": 1000, "default": 1}
|
||||
)
|
||||
pos = pos.save().submit()
|
||||
|
||||
# make a return
|
||||
pos_return = make_sales_return(pos.name)
|
||||
pos_return.paid_amount = pos_return.grand_total
|
||||
pos_return.save()
|
||||
pos_return.submit()
|
||||
|
||||
# set docstatus to 2 for pos to trigger this issue
|
||||
frappe.db.set_value("POS Invoice", pos.name, "docstatus", 2)
|
||||
|
||||
pos2 = create_pos_invoice(
|
||||
company="_Test Company",
|
||||
debit_to="Debtors - _TC",
|
||||
account_for_change_amount="Cash - _TC",
|
||||
warehouse="Stores - _TC",
|
||||
income_account="Sales - _TC",
|
||||
expense_account="Cost of Goods Sold - _TC",
|
||||
cost_center="Main - _TC",
|
||||
item=se.get("items")[0].item_code,
|
||||
rate=1000,
|
||||
qty=1,
|
||||
do_not_save=1,
|
||||
)
|
||||
|
||||
pos2.get("items")[0].has_serial_no = 1
|
||||
pos2.get("items")[0].serial_no = serial_nos.split("\n")[0]
|
||||
# Value error should not be triggered on validation
|
||||
pos2.save()
|
||||
|
||||
def test_loyalty_points(self):
|
||||
from erpnext.accounts.doctype.loyalty_program.loyalty_program import (
|
||||
get_loyalty_program_details_with_points,
|
||||
|
||||
@@ -432,7 +432,7 @@ def create_merge_logs(invoice_by_customer, closing_entry=None):
|
||||
|
||||
finally:
|
||||
frappe.db.commit()
|
||||
frappe.publish_realtime("closing_process_complete", {"user": frappe.session.user})
|
||||
frappe.publish_realtime("closing_process_complete", user=frappe.session.user)
|
||||
|
||||
|
||||
def cancel_merge_logs(merge_logs, closing_entry=None):
|
||||
@@ -459,7 +459,7 @@ def cancel_merge_logs(merge_logs, closing_entry=None):
|
||||
|
||||
finally:
|
||||
frappe.db.commit()
|
||||
frappe.publish_realtime("closing_process_complete", {"user": frappe.session.user})
|
||||
frappe.publish_realtime("closing_process_complete", user=frappe.session.user)
|
||||
|
||||
|
||||
def enqueue_job(job, **kwargs):
|
||||
|
||||
@@ -269,6 +269,18 @@ def get_serial_no_for_item(args):
|
||||
return item_details
|
||||
|
||||
|
||||
def update_pricing_rule_uom(pricing_rule, args):
|
||||
child_doc = {"Item Code": "items", "Item Group": "item_groups", "Brand": "brands"}.get(
|
||||
pricing_rule.apply_on
|
||||
)
|
||||
|
||||
apply_on_field = frappe.scrub(pricing_rule.apply_on)
|
||||
|
||||
for row in pricing_rule.get(child_doc):
|
||||
if row.get(apply_on_field) == args.get(apply_on_field):
|
||||
pricing_rule.uom = row.uom
|
||||
|
||||
|
||||
def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=False):
|
||||
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||
get_applied_pricing_rules,
|
||||
@@ -325,7 +337,8 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
||||
|
||||
if isinstance(pricing_rule, string_types):
|
||||
pricing_rule = frappe.get_cached_doc("Pricing Rule", pricing_rule)
|
||||
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule)
|
||||
update_pricing_rule_uom(pricing_rule, args)
|
||||
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule) or []
|
||||
|
||||
if pricing_rule.get("suggestion"):
|
||||
continue
|
||||
@@ -439,12 +452,15 @@ def apply_price_discount_rule(pricing_rule, item_details, args):
|
||||
if pricing_rule.currency == args.currency:
|
||||
pricing_rule_rate = pricing_rule.rate
|
||||
|
||||
# TODO https://github.com/frappe/erpnext/pull/23636 solve this in some other way.
|
||||
if pricing_rule_rate:
|
||||
is_blank_uom = pricing_rule.get("uom") != args.get("uom")
|
||||
# Override already set price list rate (from item price)
|
||||
# if pricing_rule_rate > 0
|
||||
item_details.update(
|
||||
{
|
||||
"price_list_rate": pricing_rule_rate * args.get("conversion_factor", 1),
|
||||
"price_list_rate": pricing_rule_rate
|
||||
* (args.get("conversion_factor", 1) if is_blank_uom else 1),
|
||||
}
|
||||
)
|
||||
item_details.update({"discount_percentage": 0.0})
|
||||
|
||||
@@ -597,6 +597,255 @@ class TestPricingRule(unittest.TestCase):
|
||||
frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete()
|
||||
item.delete()
|
||||
|
||||
def test_item_price_with_blank_uom_pricing_rule(self):
|
||||
properties = {
|
||||
"item_code": "Item Blank UOM",
|
||||
"stock_uom": "Nos",
|
||||
"sales_uom": "Box",
|
||||
"uoms": [dict(uom="Box", conversion_factor=10)],
|
||||
}
|
||||
item = make_item(properties=properties)
|
||||
|
||||
make_item_price("Item Blank UOM", "_Test Price List", 100)
|
||||
|
||||
pricing_rule_record = {
|
||||
"doctype": "Pricing Rule",
|
||||
"title": "_Test Item Blank UOM Rule",
|
||||
"apply_on": "Item Code",
|
||||
"items": [
|
||||
{
|
||||
"item_code": "Item Blank UOM",
|
||||
}
|
||||
],
|
||||
"selling": 1,
|
||||
"currency": "INR",
|
||||
"rate_or_discount": "Rate",
|
||||
"rate": 101,
|
||||
"company": "_Test Company",
|
||||
}
|
||||
rule = frappe.get_doc(pricing_rule_record)
|
||||
rule.insert()
|
||||
|
||||
si = create_sales_invoice(
|
||||
do_not_save=True, item_code="Item Blank UOM", uom="Box", conversion_factor=10
|
||||
)
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# If UOM is blank consider it as stock UOM and apply pricing_rule on all UOM.
|
||||
# rate is 101, Selling UOM is Box that have conversion_factor of 10 so 101 * 10 = 1010
|
||||
self.assertEqual(si.items[0].price_list_rate, 1010)
|
||||
self.assertEqual(si.items[0].rate, 1010)
|
||||
|
||||
si.delete()
|
||||
|
||||
si = create_sales_invoice(do_not_save=True, item_code="Item Blank UOM", uom="Nos")
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is blank so consider it as stock UOM and apply pricing_rule on all UOM.
|
||||
# rate is 101, Selling UOM is Nos that have conversion_factor of 1 so 101 * 1 = 101
|
||||
self.assertEqual(si.items[0].price_list_rate, 101)
|
||||
self.assertEqual(si.items[0].rate, 101)
|
||||
|
||||
si.delete()
|
||||
rule.delete()
|
||||
frappe.get_doc("Item Price", {"item_code": "Item Blank UOM"}).delete()
|
||||
|
||||
item.delete()
|
||||
|
||||
def test_item_price_with_selling_uom_pricing_rule(self):
|
||||
properties = {
|
||||
"item_code": "Item UOM other than Stock",
|
||||
"stock_uom": "Nos",
|
||||
"sales_uom": "Box",
|
||||
"uoms": [dict(uom="Box", conversion_factor=10)],
|
||||
}
|
||||
item = make_item(properties=properties)
|
||||
|
||||
make_item_price("Item UOM other than Stock", "_Test Price List", 100)
|
||||
|
||||
pricing_rule_record = {
|
||||
"doctype": "Pricing Rule",
|
||||
"title": "_Test Item UOM other than Stock Rule",
|
||||
"apply_on": "Item Code",
|
||||
"items": [
|
||||
{
|
||||
"item_code": "Item UOM other than Stock",
|
||||
"uom": "Box",
|
||||
}
|
||||
],
|
||||
"selling": 1,
|
||||
"currency": "INR",
|
||||
"rate_or_discount": "Rate",
|
||||
"rate": 101,
|
||||
"company": "_Test Company",
|
||||
}
|
||||
rule = frappe.get_doc(pricing_rule_record)
|
||||
rule.insert()
|
||||
|
||||
si = create_sales_invoice(
|
||||
do_not_save=True, item_code="Item UOM other than Stock", uom="Box", conversion_factor=10
|
||||
)
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is Box so apply pricing_rule only on Box UOM.
|
||||
# Selling UOM is Box and as both UOM are same no need to multiply by conversion_factor.
|
||||
self.assertEqual(si.items[0].price_list_rate, 101)
|
||||
self.assertEqual(si.items[0].rate, 101)
|
||||
|
||||
si.delete()
|
||||
|
||||
si = create_sales_invoice(do_not_save=True, item_code="Item UOM other than Stock", uom="Nos")
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is Box so pricing_rule won't apply as selling_uom is Nos.
|
||||
# As Pricing Rule is not applied price of 100 will be fetched from Item Price List.
|
||||
self.assertEqual(si.items[0].price_list_rate, 100)
|
||||
self.assertEqual(si.items[0].rate, 100)
|
||||
|
||||
si.delete()
|
||||
rule.delete()
|
||||
frappe.get_doc("Item Price", {"item_code": "Item UOM other than Stock"}).delete()
|
||||
|
||||
item.delete()
|
||||
|
||||
def test_item_group_price_with_blank_uom_pricing_rule(self):
|
||||
group = frappe.get_doc(
|
||||
doctype="Item Group",
|
||||
item_group_name="_Test Pricing Rule Item Group",
|
||||
parent_item_group="All Item Groups",
|
||||
)
|
||||
group.save()
|
||||
properties = {
|
||||
"item_code": "Item with Group Blank UOM",
|
||||
"item_group": "_Test Pricing Rule Item Group",
|
||||
"stock_uom": "Nos",
|
||||
"sales_uom": "Box",
|
||||
"uoms": [dict(uom="Box", conversion_factor=10)],
|
||||
}
|
||||
item = make_item(properties=properties)
|
||||
|
||||
make_item_price("Item with Group Blank UOM", "_Test Price List", 100)
|
||||
|
||||
pricing_rule_record = {
|
||||
"doctype": "Pricing Rule",
|
||||
"title": "_Test Item with Group Blank UOM Rule",
|
||||
"apply_on": "Item Group",
|
||||
"item_groups": [
|
||||
{
|
||||
"item_group": "_Test Pricing Rule Item Group",
|
||||
}
|
||||
],
|
||||
"selling": 1,
|
||||
"currency": "INR",
|
||||
"rate_or_discount": "Rate",
|
||||
"rate": 101,
|
||||
"company": "_Test Company",
|
||||
}
|
||||
rule = frappe.get_doc(pricing_rule_record)
|
||||
rule.insert()
|
||||
|
||||
si = create_sales_invoice(
|
||||
do_not_save=True, item_code="Item with Group Blank UOM", uom="Box", conversion_factor=10
|
||||
)
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# If UOM is blank consider it as stock UOM and apply pricing_rule on all UOM.
|
||||
# rate is 101, Selling UOM is Box that have conversion_factor of 10 so 101 * 10 = 1010
|
||||
self.assertEqual(si.items[0].price_list_rate, 1010)
|
||||
self.assertEqual(si.items[0].rate, 1010)
|
||||
|
||||
si.delete()
|
||||
|
||||
si = create_sales_invoice(do_not_save=True, item_code="Item with Group Blank UOM", uom="Nos")
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is blank so consider it as stock UOM and apply pricing_rule on all UOM.
|
||||
# rate is 101, Selling UOM is Nos that have conversion_factor of 1 so 101 * 1 = 101
|
||||
self.assertEqual(si.items[0].price_list_rate, 101)
|
||||
self.assertEqual(si.items[0].rate, 101)
|
||||
|
||||
si.delete()
|
||||
rule.delete()
|
||||
frappe.get_doc("Item Price", {"item_code": "Item with Group Blank UOM"}).delete()
|
||||
item.delete()
|
||||
group.delete()
|
||||
|
||||
def test_item_group_price_with_selling_uom_pricing_rule(self):
|
||||
group = frappe.get_doc(
|
||||
doctype="Item Group",
|
||||
item_group_name="_Test Pricing Rule Item Group UOM",
|
||||
parent_item_group="All Item Groups",
|
||||
)
|
||||
group.save()
|
||||
properties = {
|
||||
"item_code": "Item with Group UOM other than Stock",
|
||||
"item_group": "_Test Pricing Rule Item Group UOM",
|
||||
"stock_uom": "Nos",
|
||||
"sales_uom": "Box",
|
||||
"uoms": [dict(uom="Box", conversion_factor=10)],
|
||||
}
|
||||
item = make_item(properties=properties)
|
||||
|
||||
make_item_price("Item with Group UOM other than Stock", "_Test Price List", 100)
|
||||
|
||||
pricing_rule_record = {
|
||||
"doctype": "Pricing Rule",
|
||||
"title": "_Test Item with Group UOM other than Stock Rule",
|
||||
"apply_on": "Item Group",
|
||||
"item_groups": [
|
||||
{
|
||||
"item_group": "_Test Pricing Rule Item Group UOM",
|
||||
"uom": "Box",
|
||||
}
|
||||
],
|
||||
"selling": 1,
|
||||
"currency": "INR",
|
||||
"rate_or_discount": "Rate",
|
||||
"rate": 101,
|
||||
"company": "_Test Company",
|
||||
}
|
||||
rule = frappe.get_doc(pricing_rule_record)
|
||||
rule.insert()
|
||||
|
||||
si = create_sales_invoice(
|
||||
do_not_save=True,
|
||||
item_code="Item with Group UOM other than Stock",
|
||||
uom="Box",
|
||||
conversion_factor=10,
|
||||
)
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is Box so apply pricing_rule only on Box UOM.
|
||||
# Selling UOM is Box and as both UOM are same no need to multiply by conversion_factor.
|
||||
self.assertEqual(si.items[0].price_list_rate, 101)
|
||||
self.assertEqual(si.items[0].rate, 101)
|
||||
|
||||
si.delete()
|
||||
|
||||
si = create_sales_invoice(
|
||||
do_not_save=True, item_code="Item with Group UOM other than Stock", uom="Nos"
|
||||
)
|
||||
si.selling_price_list = "_Test Price List"
|
||||
si.save()
|
||||
|
||||
# UOM is Box so pricing_rule won't apply as selling_uom is Nos.
|
||||
# As Pricing Rule is not applied price of 100 will be fetched from Item Price List.
|
||||
self.assertEqual(si.items[0].price_list_rate, 100)
|
||||
self.assertEqual(si.items[0].rate, 100)
|
||||
|
||||
si.delete()
|
||||
rule.delete()
|
||||
frappe.get_doc("Item Price", {"item_code": "Item with Group UOM other than Stock"}).delete()
|
||||
item.delete()
|
||||
group.delete()
|
||||
|
||||
def test_pricing_rule_for_different_currency(self):
|
||||
make_item("Test Sanitizer Item")
|
||||
|
||||
|
||||
@@ -111,6 +111,12 @@ def _get_pricing_rules(apply_on, args, values):
|
||||
)
|
||||
|
||||
if apply_on_field == "item_code":
|
||||
if args.get("uom", None):
|
||||
item_conditions += (
|
||||
" and ({child_doc}.uom='{item_uom}' or IFNULL({child_doc}.uom, '')='')".format(
|
||||
child_doc=child_doc, item_uom=args.get("uom")
|
||||
)
|
||||
)
|
||||
if "variant_of" not in args:
|
||||
args.variant_of = frappe.get_cached_value("Item", args.item_code, "variant_of")
|
||||
|
||||
@@ -121,7 +127,12 @@ def _get_pricing_rules(apply_on, args, values):
|
||||
values["variant_of"] = args.variant_of
|
||||
elif apply_on_field == "item_group":
|
||||
item_conditions = _get_tree_conditions(args, "Item Group", child_doc, False)
|
||||
|
||||
if args.get("uom", None):
|
||||
item_conditions += (
|
||||
" and ({child_doc}.uom='{item_uom}' or IFNULL({child_doc}.uom, '')='')".format(
|
||||
child_doc=child_doc, item_uom=args.get("uom")
|
||||
)
|
||||
)
|
||||
conditions += get_other_conditions(conditions, values, args)
|
||||
warehouse_conditions = _get_tree_conditions(args, "Warehouse", "`tabPricing Rule`")
|
||||
if warehouse_conditions:
|
||||
|
||||
@@ -8,7 +8,8 @@ frappe.ui.form.on('Process Statement Of Accounts', {
|
||||
},
|
||||
refresh: function(frm){
|
||||
if(!frm.doc.__islocal) {
|
||||
frm.add_custom_button('Send Emails',function(){
|
||||
frm.add_custom_button(__('Send Emails'), function(){
|
||||
if (frm.is_dirty()) frappe.throw(__("Please save before proceeding."))
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.send_emails",
|
||||
args: {
|
||||
@@ -24,8 +25,9 @@ frappe.ui.form.on('Process Statement Of Accounts', {
|
||||
}
|
||||
});
|
||||
});
|
||||
frm.add_custom_button('Download',function(){
|
||||
var url = frappe.urllib.get_full_url(
|
||||
frm.add_custom_button(__('Download'), function(){
|
||||
if (frm.is_dirty()) frappe.throw(__("Please save before proceeding."))
|
||||
let url = frappe.urllib.get_full_url(
|
||||
'/api/method/erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.download_statements?'
|
||||
+ 'document_name='+encodeURIComponent(frm.doc.name))
|
||||
$.ajax({
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"customers",
|
||||
"preferences",
|
||||
"orientation",
|
||||
"include_break",
|
||||
"include_ageing",
|
||||
"ageing_based_on",
|
||||
"section_break_14",
|
||||
@@ -284,10 +285,16 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Terms and Conditions",
|
||||
"options": "Terms and Conditions"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "include_break",
|
||||
"fieldtype": "Check",
|
||||
"label": "Page Break After Each SoA"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2021-09-06 21:00:45.732505",
|
||||
"modified": "2022-10-17 17:47:08.662475",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Statement Of Accounts",
|
||||
@@ -320,5 +327,6 @@
|
||||
],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import copy
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.desk.reportview import get_match_cond
|
||||
from frappe.model.document import Document
|
||||
from frappe.utils import add_days, add_months, format_date, getdate, today
|
||||
from frappe.utils.jinja import validate_template
|
||||
@@ -128,7 +129,8 @@ def get_report_pdf(doc, consolidated=True):
|
||||
if not bool(statement_dict):
|
||||
return False
|
||||
elif consolidated:
|
||||
result = "".join(list(statement_dict.values()))
|
||||
delimiter = '<div style="page-break-before: always;"></div>' if doc.include_break else ""
|
||||
result = delimiter.join(list(statement_dict.values()))
|
||||
return get_pdf(result, {"orientation": doc.orientation})
|
||||
else:
|
||||
for customer, statement_html in statement_dict.items():
|
||||
@@ -240,8 +242,6 @@ def fetch_customers(customer_collection, collection_name, primary_mandatory):
|
||||
if int(primary_mandatory):
|
||||
if primary_email == "":
|
||||
continue
|
||||
elif (billing_email == "") and (primary_email == ""):
|
||||
continue
|
||||
|
||||
customer_list.append(
|
||||
{"name": customer.name, "primary_email": primary_email, "billing_email": billing_email}
|
||||
@@ -273,8 +273,12 @@ def get_customer_emails(customer_name, primary_mandatory, billing_and_primary=Tr
|
||||
link.link_doctype='Customer'
|
||||
and link.link_name=%s
|
||||
and contact.is_billing_contact=1
|
||||
{mcond}
|
||||
ORDER BY
|
||||
contact.creation desc""",
|
||||
contact.creation desc
|
||||
""".format(
|
||||
mcond=get_match_cond("Contact")
|
||||
),
|
||||
customer_name,
|
||||
)
|
||||
|
||||
@@ -313,6 +317,8 @@ def send_emails(document_name, from_scheduler=False):
|
||||
attachments = [{"fname": customer + ".pdf", "fcontent": report_pdf}]
|
||||
|
||||
recipients, cc = get_recipients_and_cc(customer, doc)
|
||||
if not recipients:
|
||||
continue
|
||||
context = get_context(customer, doc)
|
||||
subject = frappe.render_template(doc.subject, context)
|
||||
message = frappe.render_template(doc.body, context)
|
||||
|
||||
@@ -31,7 +31,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
this._super();
|
||||
|
||||
// Ignore linked advances
|
||||
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry'];
|
||||
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry', 'Purchase Invoice'];
|
||||
|
||||
if(!this.frm.doc.__islocal) {
|
||||
// show credit_to in print format
|
||||
@@ -569,6 +569,10 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
});
|
||||
|
||||
if (frm.is_new()) {
|
||||
frm.clear_table("tax_withheld_vouchers");
|
||||
}
|
||||
},
|
||||
|
||||
is_subcontracted: function(frm) {
|
||||
|
||||
@@ -67,6 +67,9 @@ class PurchaseInvoice(BuyingController):
|
||||
supplier_tds = frappe.db.get_value("Supplier", self.supplier, "tax_withholding_category")
|
||||
self.set_onload("supplier_tds", supplier_tds)
|
||||
|
||||
if self.is_new():
|
||||
self.set("tax_withheld_vouchers", [])
|
||||
|
||||
def before_save(self):
|
||||
if not self.on_hold:
|
||||
self.release_date = ""
|
||||
@@ -695,6 +698,10 @@ class PurchaseInvoice(BuyingController):
|
||||
)
|
||||
)
|
||||
|
||||
credit_amount = item.base_net_amount
|
||||
if self.is_internal_supplier and item.valuation_rate:
|
||||
credit_amount = flt(item.valuation_rate * item.stock_qty)
|
||||
|
||||
# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
|
||||
gl_entries.append(
|
||||
self.get_gl_dict(
|
||||
@@ -704,7 +711,7 @@ class PurchaseInvoice(BuyingController):
|
||||
"cost_center": item.cost_center,
|
||||
"project": item.project or self.project,
|
||||
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
|
||||
"debit": -1 * flt(item.base_net_amount, item.precision("base_net_amount")),
|
||||
"debit": -1 * flt(credit_amount, item.precision("base_net_amount")),
|
||||
},
|
||||
warehouse_account[item.from_warehouse]["account_currency"],
|
||||
item=item,
|
||||
@@ -1364,7 +1371,14 @@ class PurchaseInvoice(BuyingController):
|
||||
frappe.db.set(self, "status", "Cancelled")
|
||||
|
||||
unlink_inter_company_doc(self.doctype, self.name, self.inter_company_invoice_reference)
|
||||
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Repost Item Valuation")
|
||||
|
||||
self.ignore_linked_doctypes = (
|
||||
"GL Entry",
|
||||
"Stock Ledger Entry",
|
||||
"Repost Item Valuation",
|
||||
"Tax Withheld Vouchers",
|
||||
)
|
||||
|
||||
self.update_advance_tax_references(cancel=1)
|
||||
|
||||
def update_project(self):
|
||||
|
||||
@@ -706,6 +706,7 @@
|
||||
"label": "Valuation Rate",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"precision": "6",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -871,7 +872,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-11-15 17:04:07.191013",
|
||||
"modified": "2022-10-12 03:37:29.032732",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Item",
|
||||
|
||||
@@ -2187,6 +2187,9 @@ def make_inter_company_transaction(doctype, source_name, target_doc=None):
|
||||
update_address(
|
||||
target_doc, "shipping_address", "shipping_address_display", source_doc.customer_address
|
||||
)
|
||||
update_address(
|
||||
target_doc, "billing_address", "billing_address_display", source_doc.customer_address
|
||||
)
|
||||
|
||||
if currency:
|
||||
target_doc.currency = currency
|
||||
|
||||
@@ -31,10 +31,20 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import (
|
||||
get_qty_after_transaction,
|
||||
make_stock_entry,
|
||||
)
|
||||
from erpnext.stock.utils import get_incoming_rate
|
||||
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import (
|
||||
create_stock_reconciliation,
|
||||
)
|
||||
from erpnext.stock.utils import get_incoming_rate, get_stock_balance
|
||||
|
||||
|
||||
class TestSalesInvoice(unittest.TestCase):
|
||||
def setUp(self):
|
||||
from erpnext.stock.doctype.stock_ledger_entry.test_stock_ledger_entry import create_items
|
||||
|
||||
create_items(["_Test Internal Transfer Item"], uoms=[{"uom": "Box", "conversion_factor": 10}])
|
||||
create_internal_parties()
|
||||
setup_accounts()
|
||||
|
||||
def make(self):
|
||||
w = frappe.copy_doc(test_records[0])
|
||||
w.is_pos = 0
|
||||
@@ -906,7 +916,8 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
pos_return.insert()
|
||||
pos_return.submit()
|
||||
|
||||
self.assertEqual(pos_return.get("payments")[0].amount, -1000)
|
||||
self.assertEqual(pos_return.get("payments")[0].amount, -500)
|
||||
self.assertEqual(pos_return.get("payments")[1].amount, -500)
|
||||
|
||||
def test_pos_change_amount(self):
|
||||
make_pos_profile(
|
||||
@@ -1687,7 +1698,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
si.save()
|
||||
self.assertEqual(si.get("items")[0].rate, flt((price_list_rate * 25) / 100 + price_list_rate))
|
||||
|
||||
def test_outstanding_amount_after_advance_jv_cancelation(self):
|
||||
def test_outstanding_amount_after_advance_jv_cancellation(self):
|
||||
from erpnext.accounts.doctype.journal_entry.test_journal_entry import (
|
||||
test_records as jv_test_records,
|
||||
)
|
||||
@@ -1731,7 +1742,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
flt(si.rounded_total + si.total_advance, si.precision("outstanding_amount")),
|
||||
)
|
||||
|
||||
def test_outstanding_amount_after_advance_payment_entry_cancelation(self):
|
||||
def test_outstanding_amount_after_advance_payment_entry_cancellation(self):
|
||||
pe = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Payment Entry",
|
||||
@@ -2369,29 +2380,6 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
acc_settings.save()
|
||||
|
||||
def test_inter_company_transaction(self):
|
||||
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||
|
||||
create_internal_customer(
|
||||
customer_name="_Test Internal Customer",
|
||||
represents_company="_Test Company 1",
|
||||
allowed_to_interact_with="Wind Power LLC",
|
||||
)
|
||||
|
||||
if not frappe.db.exists("Supplier", "_Test Internal Supplier"):
|
||||
supplier = frappe.get_doc(
|
||||
{
|
||||
"supplier_group": "_Test Supplier Group",
|
||||
"supplier_name": "_Test Internal Supplier",
|
||||
"doctype": "Supplier",
|
||||
"is_internal_supplier": 1,
|
||||
"represents_company": "Wind Power LLC",
|
||||
}
|
||||
)
|
||||
|
||||
supplier.append("companies", {"company": "_Test Company 1"})
|
||||
|
||||
supplier.insert()
|
||||
|
||||
si = create_sales_invoice(
|
||||
company="Wind Power LLC",
|
||||
customer="_Test Internal Customer",
|
||||
@@ -2451,34 +2439,9 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
se.cancel()
|
||||
|
||||
def test_internal_transfer_gl_entry(self):
|
||||
## Create internal transfer account
|
||||
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||
|
||||
account = create_account(
|
||||
account_name="Unrealized Profit",
|
||||
parent_account="Current Liabilities - TCP1",
|
||||
company="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
frappe.db.set_value(
|
||||
"Company", "_Test Company with perpetual inventory", "unrealized_profit_loss_account", account
|
||||
)
|
||||
|
||||
customer = create_internal_customer(
|
||||
"_Test Internal Customer 2",
|
||||
"_Test Company with perpetual inventory",
|
||||
"_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
create_internal_supplier(
|
||||
"_Test Internal Supplier 2",
|
||||
"_Test Company with perpetual inventory",
|
||||
"_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
si = create_sales_invoice(
|
||||
company="_Test Company with perpetual inventory",
|
||||
customer=customer,
|
||||
customer="_Test Internal Customer 2",
|
||||
debit_to="Debtors - TCP1",
|
||||
warehouse="Stores - TCP1",
|
||||
income_account="Sales - TCP1",
|
||||
@@ -2492,7 +2455,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
si.update_stock = 1
|
||||
si.items[0].target_warehouse = "Work In Progress - TCP1"
|
||||
|
||||
# Add stock to stores for succesful stock transfer
|
||||
# Add stock to stores for successful stock transfer
|
||||
make_stock_entry(
|
||||
target="Stores - TCP1", company="_Test Company with perpetual inventory", qty=1, basic_rate=100
|
||||
)
|
||||
@@ -2830,6 +2793,77 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
self.assertEqual(einvoice["ItemList"][1]["Discount"], 0)
|
||||
self.assertEqual(einvoice["ItemList"][1]["UnitPrice"], 20)
|
||||
|
||||
def test_internal_transfer_gl_precision_issues(self):
|
||||
# Make a stock queue of an item with two valuations
|
||||
|
||||
# Remove all existing stock for this
|
||||
if get_stock_balance("_Test Internal Transfer Item", "Stores - TCP1", "2022-04-10"):
|
||||
create_stock_reconciliation(
|
||||
item_code="_Test Internal Transfer Item",
|
||||
warehouse="Stores - TCP1",
|
||||
qty=0,
|
||||
rate=0,
|
||||
company="_Test Company with perpetual inventory",
|
||||
expense_account="Stock Adjustment - TCP1"
|
||||
if frappe.get_all("Stock Ledger Entry")
|
||||
else "Temporary Opening - TCP1",
|
||||
posting_date="2020-04-10",
|
||||
posting_time="14:00",
|
||||
)
|
||||
|
||||
make_stock_entry(
|
||||
item_code="_Test Internal Transfer Item",
|
||||
target="Stores - TCP1",
|
||||
qty=9000000,
|
||||
basic_rate=52.0,
|
||||
posting_date="2020-04-10",
|
||||
posting_time="14:00",
|
||||
)
|
||||
make_stock_entry(
|
||||
item_code="_Test Internal Transfer Item",
|
||||
target="Stores - TCP1",
|
||||
qty=60000000,
|
||||
basic_rate=52.349777,
|
||||
posting_date="2020-04-10",
|
||||
posting_time="14:00",
|
||||
)
|
||||
|
||||
# Make an internal transfer Sales Invoice Stock in non stock uom to check
|
||||
# for rounding errors while converting to stock uom
|
||||
si = create_sales_invoice(
|
||||
company="_Test Company with perpetual inventory",
|
||||
customer="_Test Internal Customer 2",
|
||||
item_code="_Test Internal Transfer Item",
|
||||
qty=5000000,
|
||||
uom="Box",
|
||||
debit_to="Debtors - TCP1",
|
||||
warehouse="Stores - TCP1",
|
||||
income_account="Sales - TCP1",
|
||||
expense_account="Cost of Goods Sold - TCP1",
|
||||
cost_center="Main - TCP1",
|
||||
currency="INR",
|
||||
do_not_save=1,
|
||||
)
|
||||
|
||||
# Check GL Entries with precision
|
||||
si.update_stock = 1
|
||||
si.items[0].target_warehouse = "Work In Progress - TCP1"
|
||||
si.items[0].conversion_factor = 10
|
||||
si.save()
|
||||
si.submit()
|
||||
|
||||
# Check if adjustment entry is created
|
||||
self.assertTrue(
|
||||
frappe.db.exists(
|
||||
"GL Entry",
|
||||
{
|
||||
"voucher_type": "Sales Invoice",
|
||||
"voucher_no": si.name,
|
||||
"remarks": "Rounding gain/loss Entry for Stock Transfer",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
def test_item_tax_net_range(self):
|
||||
item = create_item("T Shirt")
|
||||
|
||||
@@ -3278,7 +3312,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
[deferred_account, 2022.47, 0.0, "2019-03-15"],
|
||||
]
|
||||
|
||||
gl_entries = gl_entries = frappe.db.sql(
|
||||
gl_entries = frappe.db.sql(
|
||||
"""select account, debit, credit, posting_date
|
||||
from `tabGL Entry`
|
||||
where voucher_type='Journal Entry' and voucher_detail_no=%s and posting_date <= %s
|
||||
@@ -3683,6 +3717,7 @@ def create_sales_invoice(**args):
|
||||
"description": args.description or "_Test Item",
|
||||
"gst_hsn_code": "999800",
|
||||
"warehouse": args.warehouse or "_Test Warehouse - _TC",
|
||||
"target_warehouse": args.target_warehouse,
|
||||
"qty": args.qty or 1,
|
||||
"uom": args.uom or "Nos",
|
||||
"stock_uom": args.uom or "Nos",
|
||||
@@ -3695,7 +3730,7 @@ def create_sales_invoice(**args):
|
||||
"discount_amount": args.discount_amount or 0,
|
||||
"cost_center": args.cost_center or "_Test Cost Center - _TC",
|
||||
"serial_no": args.serial_no,
|
||||
"conversion_factor": 1,
|
||||
"conversion_factor": args.get("conversion_factor", 1),
|
||||
"incoming_rate": args.incoming_rate or 0,
|
||||
"batch_no": args.batch_no or None,
|
||||
},
|
||||
@@ -3809,6 +3844,34 @@ def get_taxes_and_charges():
|
||||
]
|
||||
|
||||
|
||||
def create_internal_parties():
|
||||
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||
|
||||
create_internal_customer(
|
||||
customer_name="_Test Internal Customer",
|
||||
represents_company="_Test Company 1",
|
||||
allowed_to_interact_with="Wind Power LLC",
|
||||
)
|
||||
|
||||
create_internal_customer(
|
||||
customer_name="_Test Internal Customer 2",
|
||||
represents_company="_Test Company with perpetual inventory",
|
||||
allowed_to_interact_with="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
create_internal_supplier(
|
||||
supplier_name="_Test Internal Supplier",
|
||||
represents_company="Wind Power LLC",
|
||||
allowed_to_interact_with="_Test Company 1",
|
||||
)
|
||||
|
||||
create_internal_supplier(
|
||||
supplier_name="_Test Internal Supplier 2",
|
||||
represents_company="_Test Company with perpetual inventory",
|
||||
allowed_to_interact_with="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
|
||||
def create_internal_supplier(supplier_name, represents_company, allowed_to_interact_with):
|
||||
if not frappe.db.exists("Supplier", supplier_name):
|
||||
supplier = frappe.get_doc(
|
||||
@@ -3831,6 +3894,19 @@ def create_internal_supplier(supplier_name, represents_company, allowed_to_inter
|
||||
return supplier_name
|
||||
|
||||
|
||||
def setup_accounts():
|
||||
## Create internal transfer account
|
||||
account = create_account(
|
||||
account_name="Unrealized Profit",
|
||||
parent_account="Current Liabilities - TCP1",
|
||||
company="_Test Company with perpetual inventory",
|
||||
)
|
||||
|
||||
frappe.db.set_value(
|
||||
"Company", "_Test Company with perpetual inventory", "unrealized_profit_loss_account", account
|
||||
)
|
||||
|
||||
|
||||
def add_taxes(doc):
|
||||
doc.append(
|
||||
"taxes",
|
||||
|
||||
@@ -812,6 +812,8 @@
|
||||
"fieldtype": "Currency",
|
||||
"label": "Incoming Rate (Costing)",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"precision": "6",
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
@@ -841,7 +843,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-08-26 12:06:31.205417",
|
||||
"modified": "2022-10-10 20:57:38.340026",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Item",
|
||||
|
||||
@@ -298,20 +298,22 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
|
||||
round_off_account, round_off_cost_center = get_round_off_account_and_cost_center(
|
||||
gl_map[0].company, gl_map[0].voucher_type, gl_map[0].voucher_no
|
||||
)
|
||||
round_off_account_exists = False
|
||||
round_off_gle = frappe._dict()
|
||||
for d in gl_map:
|
||||
if d.account == round_off_account:
|
||||
round_off_gle = d
|
||||
if d.debit:
|
||||
debit_credit_diff -= flt(d.debit)
|
||||
else:
|
||||
debit_credit_diff += flt(d.credit)
|
||||
round_off_account_exists = True
|
||||
round_off_account_exists = False
|
||||
|
||||
if round_off_account_exists and abs(debit_credit_diff) < (1.0 / (10**precision)):
|
||||
gl_map.remove(round_off_gle)
|
||||
return
|
||||
if gl_map[0].voucher_type != "Period Closing Voucher":
|
||||
for d in gl_map:
|
||||
if d.account == round_off_account:
|
||||
round_off_gle = d
|
||||
if d.debit:
|
||||
debit_credit_diff -= flt(d.debit) - flt(d.credit)
|
||||
else:
|
||||
debit_credit_diff += flt(d.credit)
|
||||
round_off_account_exists = True
|
||||
|
||||
if round_off_account_exists and abs(debit_credit_diff) < (1.0 / (10**precision)):
|
||||
gl_map.remove(round_off_gle)
|
||||
return
|
||||
|
||||
if not round_off_gle:
|
||||
for k in ["voucher_type", "voucher_no", "company", "posting_date", "remarks"]:
|
||||
@@ -334,7 +336,6 @@ def make_round_off_gle(gl_map, debit_credit_diff, precision):
|
||||
)
|
||||
|
||||
update_accounting_dimensions(round_off_gle)
|
||||
|
||||
if not round_off_account_exists:
|
||||
gl_map.append(round_off_gle)
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@
|
||||
<div class="col-xs-4"><label>Document No</label></div>
|
||||
<div class="col-xs-8 value">{{ einvoice.DocDtls.No }}</div>
|
||||
</div>
|
||||
<div class="row data-field">
|
||||
<div class="col-xs-4"><label>Document Date</label></div>
|
||||
<div class="col-xs-8 value">{{ einvoice.DocDtls.Dt }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-4 column-break">
|
||||
<img src="{{ doc.qrcode_image }}" width="175px" style="float: right;">
|
||||
|
||||
@@ -685,10 +685,10 @@ class ReceivablePayableReport(object):
|
||||
|
||||
if self.filters.get(scrub(self.party_type)):
|
||||
select_fields = "debit_in_account_currency as debit, credit_in_account_currency as credit"
|
||||
doc_currency_fields = "debit as debit_in_account_currency, credit as credit_in_account_currency"
|
||||
else:
|
||||
select_fields = "debit, credit"
|
||||
|
||||
doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"
|
||||
doc_currency_fields = "debit_in_account_currency, credit_in_account_currency"
|
||||
|
||||
remarks = ", remarks" if self.filters.get("show_remarks") else ""
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ def get_columns():
|
||||
{
|
||||
"label": _("Payment Document Type"),
|
||||
"fieldname": "payment_document_type",
|
||||
"fieldtype": "Link",
|
||||
"options": "Doctype",
|
||||
"fieldtype": "Data",
|
||||
"width": 130,
|
||||
},
|
||||
{
|
||||
@@ -33,15 +32,15 @@ def get_columns():
|
||||
"options": "payment_document_type",
|
||||
"width": 140,
|
||||
},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 100},
|
||||
{"label": _("Posting Date"), "fieldname": "posting_date", "fieldtype": "Date", "width": 120},
|
||||
{"label": _("Cheque/Reference No"), "fieldname": "cheque_no", "width": 120},
|
||||
{"label": _("Clearance Date"), "fieldname": "clearance_date", "fieldtype": "Date", "width": 100},
|
||||
{"label": _("Clearance Date"), "fieldname": "clearance_date", "fieldtype": "Date", "width": 120},
|
||||
{
|
||||
"label": _("Against Account"),
|
||||
"fieldname": "against",
|
||||
"fieldtype": "Link",
|
||||
"options": "Account",
|
||||
"width": 170,
|
||||
"width": 200,
|
||||
},
|
||||
{"label": _("Amount"), "fieldname": "amount", "fieldtype": "Currency", "width": 120},
|
||||
]
|
||||
|
||||
@@ -9,6 +9,7 @@ from six import iteritems
|
||||
|
||||
from erpnext.accounts.report.financial_statements import (
|
||||
get_columns,
|
||||
get_cost_centers_with_children,
|
||||
get_data,
|
||||
get_filtered_list_for_consolidated_report,
|
||||
get_period_list,
|
||||
@@ -161,10 +162,11 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
||||
total = 0
|
||||
for period in period_list:
|
||||
start_date = get_start_date(period, accumulated_values, company)
|
||||
filters.start_date = start_date
|
||||
filters.end_date = period["to_date"]
|
||||
filters.account_type = account_type
|
||||
|
||||
amount = get_account_type_based_gl_data(
|
||||
company, start_date, period["to_date"], account_type, filters
|
||||
)
|
||||
amount = get_account_type_based_gl_data(company, filters)
|
||||
|
||||
if amount and account_type == "Depreciation":
|
||||
amount *= -1
|
||||
@@ -176,7 +178,7 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
||||
return data
|
||||
|
||||
|
||||
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters=None):
|
||||
def get_account_type_based_gl_data(company, filters=None):
|
||||
cond = ""
|
||||
filters = frappe._dict(filters or {})
|
||||
|
||||
@@ -192,17 +194,21 @@ def get_account_type_based_gl_data(company, start_date, end_date, account_type,
|
||||
frappe.db.escape(cstr(filters.finance_book))
|
||||
)
|
||||
|
||||
if filters.get("cost_center"):
|
||||
filters.cost_center = get_cost_centers_with_children(filters.cost_center)
|
||||
cond += " and cost_center in %(cost_center)s"
|
||||
|
||||
gl_sum = frappe.db.sql_list(
|
||||
"""
|
||||
select sum(credit) - sum(debit)
|
||||
from `tabGL Entry`
|
||||
where company=%s and posting_date >= %s and posting_date <= %s
|
||||
where company=%(company)s and posting_date >= %(start_date)s and posting_date <= %(end_date)s
|
||||
and voucher_type != 'Period Closing Voucher'
|
||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %s) {cond}
|
||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %(account_type)s) {cond}
|
||||
""".format(
|
||||
cond=cond
|
||||
),
|
||||
(company, start_date, end_date, account_type),
|
||||
filters,
|
||||
)
|
||||
|
||||
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
||||
|
||||
@@ -268,10 +268,12 @@ def get_cash_flow_data(fiscal_year, companies, filters):
|
||||
def get_account_type_based_data(account_type, companies, fiscal_year, filters):
|
||||
data = {}
|
||||
total = 0
|
||||
filters.account_type = account_type
|
||||
filters.start_date = fiscal_year.year_start_date
|
||||
filters.end_date = fiscal_year.year_end_date
|
||||
|
||||
for company in companies:
|
||||
amount = get_account_type_based_gl_data(
|
||||
company, fiscal_year.year_start_date, fiscal_year.year_end_date, account_type, filters
|
||||
)
|
||||
amount = get_account_type_based_gl_data(company, filters)
|
||||
|
||||
if amount and account_type == "Depreciation":
|
||||
amount *= -1
|
||||
@@ -533,12 +535,13 @@ def get_accounts(root_type, companies):
|
||||
],
|
||||
filters={"company": company, "root_type": root_type},
|
||||
):
|
||||
if account.account_name not in added_accounts:
|
||||
if account.account_number:
|
||||
account_key = account.account_number + "-" + account.account_name
|
||||
else:
|
||||
account_key = account.account_name
|
||||
|
||||
if account_key not in added_accounts:
|
||||
accounts.append(account)
|
||||
if account.account_number:
|
||||
account_key = account.account_number + "-" + account.account_name
|
||||
else:
|
||||
account_key = account.account_name
|
||||
added_accounts.append(account_key)
|
||||
|
||||
return accounts
|
||||
|
||||
@@ -27,6 +27,7 @@ class PartyLedgerSummaryReport(object):
|
||||
)
|
||||
|
||||
self.get_gl_entries()
|
||||
self.get_additional_columns()
|
||||
self.get_return_invoices()
|
||||
self.get_party_adjustment_amounts()
|
||||
|
||||
@@ -34,6 +35,42 @@ class PartyLedgerSummaryReport(object):
|
||||
data = self.get_data()
|
||||
return columns, data
|
||||
|
||||
def get_additional_columns(self):
|
||||
"""
|
||||
Additional Columns for 'User Permission' based access control
|
||||
"""
|
||||
from frappe import qb
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
self.territories = frappe._dict({})
|
||||
self.customer_group = frappe._dict({})
|
||||
|
||||
customer = qb.DocType("Customer")
|
||||
result = (
|
||||
frappe.qb.from_(customer)
|
||||
.select(
|
||||
customer.name, customer.territory, customer.customer_group, customer.default_sales_partner
|
||||
)
|
||||
.where((customer.disabled == 0))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
for x in result:
|
||||
self.territories[x.name] = x.territory
|
||||
self.customer_group[x.name] = x.customer_group
|
||||
else:
|
||||
self.supplier_group = frappe._dict({})
|
||||
supplier = qb.DocType("Supplier")
|
||||
result = (
|
||||
frappe.qb.from_(supplier)
|
||||
.select(supplier.name, supplier.supplier_group)
|
||||
.where((supplier.disabled == 0))
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
for x in result:
|
||||
self.supplier_group[x.name] = x.supplier_group
|
||||
|
||||
def get_columns(self):
|
||||
columns = [
|
||||
{
|
||||
@@ -117,6 +154,35 @@ class PartyLedgerSummaryReport(object):
|
||||
},
|
||||
]
|
||||
|
||||
# Hidden columns for handling 'User Permissions'
|
||||
if self.filters.party_type == "Customer":
|
||||
columns += [
|
||||
{
|
||||
"label": _("Territory"),
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory",
|
||||
"hidden": 1,
|
||||
},
|
||||
{
|
||||
"label": _("Customer Group"),
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Customer Group",
|
||||
"hidden": 1,
|
||||
},
|
||||
]
|
||||
else:
|
||||
columns += [
|
||||
{
|
||||
"label": _("Supplier Group"),
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier Group",
|
||||
"hidden": 1,
|
||||
}
|
||||
]
|
||||
|
||||
return columns
|
||||
|
||||
def get_data(self):
|
||||
@@ -144,6 +210,12 @@ class PartyLedgerSummaryReport(object):
|
||||
),
|
||||
)
|
||||
|
||||
if self.filters.party_type == "Customer":
|
||||
self.party_data[gle.party].update({"territory": self.territories.get(gle.party)})
|
||||
self.party_data[gle.party].update({"customer_group": self.customer_group.get(gle.party)})
|
||||
else:
|
||||
self.party_data[gle.party].update({"supplier_group": self.supplier_group.get(gle.party)})
|
||||
|
||||
amount = gle.get(invoice_dr_or_cr) - gle.get(reverse_dr_or_cr)
|
||||
self.party_data[gle.party].closing_balance += amount
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _, scrub
|
||||
from frappe import _, qb, scrub
|
||||
from frappe.query_builder import Order
|
||||
from frappe.utils import cint, flt
|
||||
|
||||
from erpnext.controllers.queries import get_match_cond
|
||||
@@ -367,6 +368,7 @@ class GrossProfitGenerator(object):
|
||||
self.average_buying_rate = {}
|
||||
self.filters = frappe._dict(filters)
|
||||
self.load_invoice_items()
|
||||
self.get_delivery_notes()
|
||||
|
||||
if filters.group_by == "Invoice":
|
||||
self.group_items_by_invoice()
|
||||
@@ -535,6 +537,22 @@ class GrossProfitGenerator(object):
|
||||
|
||||
return flt(buying_amount, self.currency_precision)
|
||||
|
||||
def calculate_buying_amount_from_sle(self, row, my_sle, parenttype, parent, item_row, item_code):
|
||||
for i, sle in enumerate(my_sle):
|
||||
# find the stock valution rate from stock ledger entry
|
||||
if (
|
||||
sle.voucher_type == parenttype
|
||||
and parent == sle.voucher_no
|
||||
and sle.voucher_detail_no == item_row
|
||||
):
|
||||
previous_stock_value = len(my_sle) > i + 1 and flt(my_sle[i + 1].stock_value) or 0.0
|
||||
|
||||
if previous_stock_value:
|
||||
return abs(previous_stock_value - flt(sle.stock_value)) * flt(row.qty) / abs(flt(sle.qty))
|
||||
else:
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
return 0.0
|
||||
|
||||
def get_buying_amount(self, row, item_code):
|
||||
# IMP NOTE
|
||||
# stock_ledger_entries should already be filtered by item_code and warehouse and
|
||||
@@ -551,19 +569,22 @@ class GrossProfitGenerator(object):
|
||||
if row.dn_detail:
|
||||
parenttype, parent = "Delivery Note", row.delivery_note
|
||||
|
||||
for i, sle in enumerate(my_sle):
|
||||
# find the stock valution rate from stock ledger entry
|
||||
if (
|
||||
sle.voucher_type == parenttype
|
||||
and parent == sle.voucher_no
|
||||
and sle.voucher_detail_no == row.item_row
|
||||
):
|
||||
previous_stock_value = len(my_sle) > i + 1 and flt(my_sle[i + 1].stock_value) or 0.0
|
||||
|
||||
if previous_stock_value:
|
||||
return abs(previous_stock_value - flt(sle.stock_value)) * flt(row.qty) / abs(flt(sle.qty))
|
||||
else:
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
return self.calculate_buying_amount_from_sle(
|
||||
row, my_sle, parenttype, parent, row.item_row, item_code
|
||||
)
|
||||
elif self.delivery_notes.get((row.parent, row.item_code), None):
|
||||
# check if Invoice has delivery notes
|
||||
dn = self.delivery_notes.get((row.parent, row.item_code))
|
||||
parenttype, parent, item_row, warehouse = (
|
||||
"Delivery Note",
|
||||
dn["delivery_note"],
|
||||
dn["item_row"],
|
||||
dn["warehouse"],
|
||||
)
|
||||
my_sle = self.sle.get((item_code, warehouse))
|
||||
return self.calculate_buying_amount_from_sle(
|
||||
row, my_sle, parenttype, parent, item_row, item_code
|
||||
)
|
||||
else:
|
||||
return flt(row.qty) * self.get_average_buying_rate(row, item_code)
|
||||
|
||||
@@ -667,6 +688,29 @@ class GrossProfitGenerator(object):
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
def get_delivery_notes(self):
|
||||
self.delivery_notes = frappe._dict({})
|
||||
if self.si_list:
|
||||
invoices = [x.parent for x in self.si_list]
|
||||
dni = qb.DocType("Delivery Note Item")
|
||||
delivery_notes = (
|
||||
qb.from_(dni)
|
||||
.select(
|
||||
dni.against_sales_invoice.as_("sales_invoice"),
|
||||
dni.item_code,
|
||||
dni.warehouse,
|
||||
dni.parent.as_("delivery_note"),
|
||||
dni.name.as_("item_row"),
|
||||
)
|
||||
.where((dni.docstatus == 1) & (dni.against_sales_invoice.isin(invoices)))
|
||||
.groupby(dni.against_sales_invoice, dni.item_code)
|
||||
.orderby(dni.creation, order=Order.desc)
|
||||
.run(as_dict=True)
|
||||
)
|
||||
|
||||
for entry in delivery_notes:
|
||||
self.delivery_notes[(entry.sales_invoice, entry.item_code)] = entry
|
||||
|
||||
def group_items_by_invoice(self):
|
||||
"""
|
||||
Turns list of Sales Invoice Items to a tree of Sales Invoices with their Items as children.
|
||||
|
||||
303
erpnext/accounts/report/gross_profit/test_gross_profit.py
Normal file
303
erpnext/accounts/report/gross_profit/test_gross_profit.py
Normal file
@@ -0,0 +1,303 @@
|
||||
import frappe
|
||||
from frappe import qb
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
from frappe.utils import add_days, flt, nowdate
|
||||
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import make_delivery_note
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
from erpnext.accounts.report.gross_profit.gross_profit import execute
|
||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_invoice
|
||||
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||
from erpnext.stock.doctype.item.test_item import create_item
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
|
||||
|
||||
class TestGrossProfit(FrappeTestCase):
|
||||
def setUp(self):
|
||||
self.create_company()
|
||||
self.create_item()
|
||||
self.create_bundle()
|
||||
self.create_customer()
|
||||
self.create_sales_invoice()
|
||||
self.clear_old_entries()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
||||
|
||||
def create_company(self):
|
||||
company_name = "_Test Gross Profit"
|
||||
abbr = "_GP"
|
||||
if frappe.db.exists("Company", company_name):
|
||||
company = frappe.get_doc("Company", company_name)
|
||||
else:
|
||||
company = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Company",
|
||||
"company_name": company_name,
|
||||
"country": "India",
|
||||
"default_currency": "INR",
|
||||
"create_chart_of_accounts_based_on": "Standard Template",
|
||||
"chart_of_accounts": "Standard",
|
||||
}
|
||||
)
|
||||
company = company.save()
|
||||
|
||||
self.company = company.name
|
||||
self.cost_center = company.cost_center
|
||||
self.warehouse = "Stores - " + abbr
|
||||
self.finished_warehouse = "Finished Goods - " + abbr
|
||||
self.income_account = "Sales - " + abbr
|
||||
self.expense_account = "Cost of Goods Sold - " + abbr
|
||||
self.debit_to = "Debtors - " + abbr
|
||||
self.creditors = "Creditors - " + abbr
|
||||
|
||||
def create_item(self):
|
||||
item = create_item(
|
||||
item_code="_Test GP Item", is_stock_item=1, company=self.company, warehouse=self.warehouse
|
||||
)
|
||||
self.item = item if isinstance(item, str) else item.item_code
|
||||
|
||||
def create_bundle(self):
|
||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||
|
||||
item2 = create_item(
|
||||
item_code="_Test GP Item 2", is_stock_item=1, company=self.company, warehouse=self.warehouse
|
||||
)
|
||||
self.item2 = item2 if isinstance(item2, str) else item2.item_code
|
||||
|
||||
# This will be parent item
|
||||
bundle = create_item(
|
||||
item_code="_Test GP bundle", is_stock_item=0, company=self.company, warehouse=self.warehouse
|
||||
)
|
||||
self.bundle = bundle if isinstance(bundle, str) else bundle.item_code
|
||||
|
||||
# Create Product Bundle
|
||||
self.product_bundle = make_product_bundle(parent=self.bundle, items=[self.item, self.item2])
|
||||
|
||||
def create_customer(self):
|
||||
name = "_Test GP Customer"
|
||||
if frappe.db.exists("Customer", name):
|
||||
self.customer = name
|
||||
else:
|
||||
customer = frappe.new_doc("Customer")
|
||||
customer.customer_name = name
|
||||
customer.type = "Individual"
|
||||
customer.save()
|
||||
self.customer = customer.name
|
||||
|
||||
def create_sales_invoice(
|
||||
self, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False
|
||||
):
|
||||
"""
|
||||
Helper function to populate default values in sales invoice
|
||||
"""
|
||||
sinv = create_sales_invoice(
|
||||
qty=qty,
|
||||
rate=rate,
|
||||
company=self.company,
|
||||
customer=self.customer,
|
||||
item_code=self.item,
|
||||
item_name=self.item,
|
||||
cost_center=self.cost_center,
|
||||
warehouse=self.warehouse,
|
||||
debit_to=self.debit_to,
|
||||
parent_cost_center=self.cost_center,
|
||||
update_stock=0,
|
||||
currency="INR",
|
||||
is_pos=0,
|
||||
is_return=0,
|
||||
return_against=None,
|
||||
income_account=self.income_account,
|
||||
expense_account=self.expense_account,
|
||||
do_not_save=do_not_save,
|
||||
do_not_submit=do_not_submit,
|
||||
)
|
||||
return sinv
|
||||
|
||||
def create_delivery_note(
|
||||
self, item=None, qty=1, rate=100, posting_date=nowdate(), do_not_save=False, do_not_submit=False
|
||||
):
|
||||
"""
|
||||
Helper function to populate default values in Delivery Note
|
||||
"""
|
||||
dnote = create_delivery_note(
|
||||
company=self.company,
|
||||
customer=self.customer,
|
||||
currency="INR",
|
||||
item=item or self.item,
|
||||
qty=qty,
|
||||
rate=rate,
|
||||
cost_center=self.cost_center,
|
||||
warehouse=self.warehouse,
|
||||
return_against=None,
|
||||
expense_account=self.expense_account,
|
||||
do_not_save=do_not_save,
|
||||
do_not_submit=do_not_submit,
|
||||
)
|
||||
return dnote
|
||||
|
||||
def clear_old_entries(self):
|
||||
doctype_list = [
|
||||
"Sales Invoice",
|
||||
"GL Entry",
|
||||
"Stock Entry",
|
||||
"Stock Ledger Entry",
|
||||
"Delivery Note",
|
||||
]
|
||||
for doctype in doctype_list:
|
||||
qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run()
|
||||
|
||||
def test_invoice_without_only_delivery_note(self):
|
||||
"""
|
||||
Test buying amount for Invoice without `update_stock` flag set but has Delivery Note
|
||||
"""
|
||||
se = make_stock_entry(
|
||||
company=self.company,
|
||||
item_code=self.item,
|
||||
target=self.warehouse,
|
||||
qty=1,
|
||||
basic_rate=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
item = se.items[0]
|
||||
se.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": item.item_code,
|
||||
"s_warehouse": item.s_warehouse,
|
||||
"t_warehouse": item.t_warehouse,
|
||||
"qty": 1,
|
||||
"basic_rate": 200,
|
||||
"conversion_factor": item.conversion_factor or 1.0,
|
||||
"transfer_qty": flt(item.qty) * (flt(item.conversion_factor) or 1.0),
|
||||
"serial_no": item.serial_no,
|
||||
"batch_no": item.batch_no,
|
||||
"cost_center": item.cost_center,
|
||||
"expense_account": item.expense_account,
|
||||
},
|
||||
)
|
||||
se = se.save().submit()
|
||||
|
||||
sinv = create_sales_invoice(
|
||||
qty=1,
|
||||
rate=100,
|
||||
company=self.company,
|
||||
customer=self.customer,
|
||||
item_code=self.item,
|
||||
item_name=self.item,
|
||||
cost_center=self.cost_center,
|
||||
warehouse=self.warehouse,
|
||||
debit_to=self.debit_to,
|
||||
parent_cost_center=self.cost_center,
|
||||
update_stock=0,
|
||||
currency="INR",
|
||||
income_account=self.income_account,
|
||||
expense_account=self.expense_account,
|
||||
)
|
||||
|
||||
filters = frappe._dict(
|
||||
company=self.company, from_date=nowdate(), to_date=nowdate(), group_by="Invoice"
|
||||
)
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
|
||||
# Without Delivery Note, buying rate should be 150
|
||||
expected_entry_without_dn = {
|
||||
"parent_invoice": sinv.name,
|
||||
"currency": "INR",
|
||||
"sales_invoice": self.item,
|
||||
"customer": self.customer,
|
||||
"posting_date": frappe.utils.datetime.date.fromisoformat(nowdate()),
|
||||
"item_code": self.item,
|
||||
"item_name": self.item,
|
||||
"warehouse": "Stores - _GP",
|
||||
"qty": 1.0,
|
||||
"avg._selling_rate": 100.0,
|
||||
"valuation_rate": 150.0,
|
||||
"selling_amount": 100.0,
|
||||
"buying_amount": 150.0,
|
||||
"gross_profit": -50.0,
|
||||
"gross_profit_%": -50.0,
|
||||
}
|
||||
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||
self.assertDictContainsSubset(expected_entry_without_dn, gp_entry[0])
|
||||
|
||||
# make delivery note
|
||||
dn = make_delivery_note(sinv.name)
|
||||
dn.items[0].qty = 1
|
||||
dn = dn.save().submit()
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
|
||||
# Without Delivery Note, buying rate should be 100
|
||||
expected_entry_with_dn = {
|
||||
"parent_invoice": sinv.name,
|
||||
"currency": "INR",
|
||||
"sales_invoice": self.item,
|
||||
"customer": self.customer,
|
||||
"posting_date": frappe.utils.datetime.date.fromisoformat(nowdate()),
|
||||
"item_code": self.item,
|
||||
"item_name": self.item,
|
||||
"warehouse": "Stores - _GP",
|
||||
"qty": 1.0,
|
||||
"avg._selling_rate": 100.0,
|
||||
"valuation_rate": 100.0,
|
||||
"selling_amount": 100.0,
|
||||
"buying_amount": 100.0,
|
||||
"gross_profit": 0.0,
|
||||
"gross_profit_%": 0.0,
|
||||
}
|
||||
gp_entry = [x for x in data if x.parent_invoice == sinv.name]
|
||||
self.assertDictContainsSubset(expected_entry_with_dn, gp_entry[0])
|
||||
|
||||
def test_bundled_delivery_note_with_different_warehouses(self):
|
||||
"""
|
||||
Test Delivery Note with bundled item. Packed Item from the bundle having different warehouses
|
||||
"""
|
||||
se = make_stock_entry(
|
||||
company=self.company,
|
||||
item_code=self.item,
|
||||
target=self.warehouse,
|
||||
qty=1,
|
||||
basic_rate=100,
|
||||
do_not_submit=True,
|
||||
)
|
||||
item = se.items[0]
|
||||
se.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": self.item2,
|
||||
"s_warehouse": "",
|
||||
"t_warehouse": self.finished_warehouse,
|
||||
"qty": 1,
|
||||
"basic_rate": 100,
|
||||
"conversion_factor": item.conversion_factor or 1.0,
|
||||
"transfer_qty": flt(item.qty) * (flt(item.conversion_factor) or 1.0),
|
||||
"serial_no": item.serial_no,
|
||||
"batch_no": item.batch_no,
|
||||
"cost_center": item.cost_center,
|
||||
"expense_account": item.expense_account,
|
||||
},
|
||||
)
|
||||
se = se.save().submit()
|
||||
|
||||
# Make a Delivery note with Product bundle
|
||||
# Packed Items will have different warehouses
|
||||
dnote = self.create_delivery_note(item=self.bundle, qty=1, rate=200, do_not_submit=True)
|
||||
dnote.packed_items[1].warehouse = self.finished_warehouse
|
||||
dnote = dnote.submit()
|
||||
|
||||
# make Sales Invoice for above delivery note
|
||||
sinv = make_sales_invoice(dnote.name)
|
||||
sinv = sinv.save().submit()
|
||||
|
||||
filters = frappe._dict(
|
||||
company=self.company,
|
||||
from_date=nowdate(),
|
||||
to_date=nowdate(),
|
||||
group_by="Invoice",
|
||||
sales_invoice=sinv.name,
|
||||
)
|
||||
|
||||
columns, data = execute(filters=filters)
|
||||
self.assertGreater(len(data), 0)
|
||||
@@ -232,12 +232,12 @@ def get_conditions(filters):
|
||||
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabPurchase Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
+ "and ifnull(`tabPurchase Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
else:
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabPurchase Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
+ "and ifnull(`tabPurchase Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
|
||||
return conditions
|
||||
|
||||
@@ -390,12 +390,12 @@ def get_conditions(filters):
|
||||
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
+ "and ifnull(`tabSales Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
else:
|
||||
conditions += (
|
||||
common_condition
|
||||
+ "and ifnull(`tabSales Invoice Item`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
+ "and ifnull(`tabSales Invoice`.{0}, '') in %({0})s)".format(dimension.fieldname)
|
||||
)
|
||||
|
||||
return conditions
|
||||
|
||||
@@ -63,24 +63,6 @@ frappe.query_reports["Supplier Ledger Summary"] = {
|
||||
"fieldtype": "Link",
|
||||
"options": "Payment Terms Template"
|
||||
},
|
||||
{
|
||||
"fieldname":"territory",
|
||||
"label": __("Territory"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Territory"
|
||||
},
|
||||
{
|
||||
"fieldname":"sales_partner",
|
||||
"label": __("Sales Partner"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Partner"
|
||||
},
|
||||
{
|
||||
"fieldname":"sales_person",
|
||||
"label": __("Sales Person"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Sales Person"
|
||||
},
|
||||
{
|
||||
"fieldname":"tax_id",
|
||||
"label": __("Tax Id"),
|
||||
|
||||
@@ -28,7 +28,7 @@ def get_currency(filters):
|
||||
filters["presentation_currency"] if filters.get("presentation_currency") else company_currency
|
||||
)
|
||||
|
||||
report_date = filters.get("to_date")
|
||||
report_date = filters.get("to_date") or filters.get("period_end_date")
|
||||
|
||||
if not report_date:
|
||||
fiscal_year_to_date = get_from_and_to_date(filters.get("to_fiscal_year"))["to_date"]
|
||||
|
||||
@@ -835,10 +835,7 @@ def remove_return_pos_invoices(party_type, party, invoice_list):
|
||||
else:
|
||||
return invoice_list
|
||||
|
||||
# remove pos return invoices from invoice_list
|
||||
for idx, inv in enumerate(invoice_list, 0):
|
||||
if inv.voucher_no in return_pos:
|
||||
del invoice_list[idx]
|
||||
invoice_list = [x for x in invoice_list if x.voucher_no not in return_pos]
|
||||
|
||||
return invoice_list
|
||||
|
||||
|
||||
@@ -384,7 +384,11 @@ frappe.ui.form.on('Asset', {
|
||||
|
||||
set_values_from_purchase_doc: function(frm, doctype, purchase_doc) {
|
||||
frm.set_value('company', purchase_doc.company);
|
||||
frm.set_value('purchase_date', purchase_doc.posting_date);
|
||||
if (purchase_doc.bill_date) {
|
||||
frm.set_value('purchase_date', purchase_doc.bill_date);
|
||||
} else {
|
||||
frm.set_value('purchase_date', purchase_doc.posting_date);
|
||||
}
|
||||
const item = purchase_doc.items.find(item => item.item_code === frm.doc.item_code);
|
||||
if (!item) {
|
||||
doctype_field = frappe.scrub(doctype)
|
||||
|
||||
@@ -825,7 +825,9 @@ def update_maintenance_status():
|
||||
|
||||
for asset in assets:
|
||||
asset = frappe.get_doc("Asset", asset.name)
|
||||
if frappe.db.exists("Asset Repair", {"asset_name": asset.name, "repair_status": "Pending"}):
|
||||
if frappe.db.exists(
|
||||
"Asset Repair", {"asset_name": asset.name, "repair_status": "Pending", "docstatus": 0}
|
||||
):
|
||||
asset.set_status("Out of Order")
|
||||
elif frappe.db.exists(
|
||||
"Asset Maintenance Task", {"parent": asset.name, "next_due_date": today()}
|
||||
|
||||
@@ -200,11 +200,11 @@ def get_children(doctype, parent=None, location=None, is_root=False):
|
||||
name as value,
|
||||
is_group as expandable
|
||||
from
|
||||
`tab{doctype}` comp
|
||||
`tabLocation` comp
|
||||
where
|
||||
ifnull(parent_location, "")={parent}
|
||||
""".format(
|
||||
doctype=doctype, parent=frappe.db.escape(parent)
|
||||
parent=frappe.db.escape(parent)
|
||||
),
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
@@ -43,6 +43,11 @@ frappe.ui.form.on("Purchase Order", {
|
||||
erpnext.queries.setup_queries(frm, "Warehouse", function() {
|
||||
return erpnext.queries.warehouse(frm.doc);
|
||||
});
|
||||
|
||||
// On cancel and amending a purchase order with advance payment, reset advance paid amount
|
||||
if (frm.is_new()) {
|
||||
frm.set_value("advance_paid", 0)
|
||||
}
|
||||
},
|
||||
|
||||
apply_tds: function(frm) {
|
||||
|
||||
@@ -370,7 +370,7 @@
|
||||
{
|
||||
"fieldname": "shipping_address",
|
||||
"fieldtype": "Link",
|
||||
"label": "Company Shipping Address",
|
||||
"label": "Shipping Address",
|
||||
"options": "Address",
|
||||
"print_hide": 1
|
||||
},
|
||||
@@ -1118,7 +1118,8 @@
|
||||
"fetch_from": "supplier.is_internal_supplier",
|
||||
"fieldname": "is_internal_supplier",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Internal Supplier"
|
||||
"label": "Is Internal Supplier",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fetch_from": "supplier.represents_company",
|
||||
@@ -1169,7 +1170,7 @@
|
||||
"idx": 105,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-09-16 17:45:04.954055",
|
||||
"modified": "2022-12-25 18:08:59.074182",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Purchase Order",
|
||||
|
||||
@@ -18,7 +18,7 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
|
||||
from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import (
|
||||
get_party_tax_withholding_details,
|
||||
)
|
||||
from erpnext.accounts.party import get_party_account_currency
|
||||
from erpnext.accounts.party import get_party_account, get_party_account_currency
|
||||
from erpnext.buying.utils import check_on_hold_or_closed_status, validate_for_items
|
||||
from erpnext.controllers.buying_controller import BuyingController
|
||||
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
|
||||
@@ -533,6 +533,7 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
||||
target.set_advances()
|
||||
|
||||
target.set_payment_schedule()
|
||||
target.credit_to = get_party_account("Supplier", source.supplier, source.company)
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.amount = flt(obj.amount) - flt(obj.billed_amt)
|
||||
|
||||
@@ -22,6 +22,13 @@ frappe.ui.form.on("Request for Quotation",{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
frm.set_query('warehouse', 'items', () => ({
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
}));
|
||||
},
|
||||
|
||||
onload: function(frm) {
|
||||
|
||||
@@ -479,7 +479,7 @@ def get_rfq_containing_supplier(doctype, txt, searchfield, start, page_len, filt
|
||||
conditions += "and rfq.transaction_date = '{0}'".format(filters.get("transaction_date"))
|
||||
|
||||
rfq_data = frappe.db.sql(
|
||||
"""
|
||||
f"""
|
||||
select
|
||||
distinct rfq.name, rfq.transaction_date,
|
||||
rfq.company
|
||||
@@ -487,15 +487,18 @@ def get_rfq_containing_supplier(doctype, txt, searchfield, start, page_len, filt
|
||||
`tabRequest for Quotation` rfq, `tabRequest for Quotation Supplier` rfq_supplier
|
||||
where
|
||||
rfq.name = rfq_supplier.parent
|
||||
and rfq_supplier.supplier = '{0}'
|
||||
and rfq_supplier.supplier = %(supplier)s
|
||||
and rfq.docstatus = 1
|
||||
and rfq.company = '{1}'
|
||||
{2}
|
||||
and rfq.company = %(company)s
|
||||
{conditions}
|
||||
order by rfq.transaction_date ASC
|
||||
limit %(page_len)s offset %(start)s """.format(
|
||||
filters.get("supplier"), filters.get("company"), conditions
|
||||
),
|
||||
{"page_len": page_len, "start": start},
|
||||
limit %(page_len)s offset %(start)s """,
|
||||
{
|
||||
"page_len": page_len,
|
||||
"start": start,
|
||||
"company": filters.get("company"),
|
||||
"supplier": filters.get("supplier"),
|
||||
},
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ class AccountsController(TransactionBase):
|
||||
self.validate_inter_company_reference()
|
||||
|
||||
self.disable_pricing_rule_on_internal_transfer()
|
||||
self.disable_tax_included_prices_for_internal_transfer()
|
||||
self.set_incoming_rate()
|
||||
|
||||
if self.meta.get_field("currency"):
|
||||
@@ -395,6 +396,20 @@ class AccountsController(TransactionBase):
|
||||
alert=1,
|
||||
)
|
||||
|
||||
def disable_tax_included_prices_for_internal_transfer(self):
|
||||
if self.is_internal_transfer():
|
||||
tax_updated = False
|
||||
for tax in self.get("taxes"):
|
||||
if tax.get("included_in_print_rate"):
|
||||
tax.included_in_print_rate = 0
|
||||
tax_updated = True
|
||||
|
||||
if tax_updated:
|
||||
frappe.msgprint(
|
||||
_("Disabled tax included prices since this {} is an internal transfer").format(self.doctype),
|
||||
alert=1,
|
||||
)
|
||||
|
||||
def validate_due_date(self):
|
||||
if self.get("is_pos"):
|
||||
return
|
||||
|
||||
@@ -439,11 +439,17 @@ class SellingController(StockController):
|
||||
# For internal transfers use incoming rate as the valuation rate
|
||||
if self.is_internal_transfer():
|
||||
if d.doctype == "Packed Item":
|
||||
incoming_rate = flt(d.incoming_rate * d.conversion_factor, d.precision("incoming_rate"))
|
||||
incoming_rate = flt(
|
||||
flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
|
||||
d.precision("incoming_rate"),
|
||||
)
|
||||
if d.incoming_rate != incoming_rate:
|
||||
d.incoming_rate = incoming_rate
|
||||
else:
|
||||
rate = flt(d.incoming_rate * d.conversion_factor, d.precision("rate"))
|
||||
rate = flt(
|
||||
flt(d.incoming_rate, d.precision("incoming_rate")) * d.conversion_factor,
|
||||
d.precision("rate"),
|
||||
)
|
||||
if d.rate != rate:
|
||||
d.rate = rate
|
||||
frappe.msgprint(
|
||||
@@ -572,6 +578,7 @@ class SellingController(StockController):
|
||||
"customer_address": "address_display",
|
||||
"shipping_address_name": "shipping_address",
|
||||
"company_address": "company_address_display",
|
||||
"dispatch_address_name": "dispatch_address",
|
||||
}
|
||||
|
||||
for address_field, address_display_field in address_dict.items():
|
||||
|
||||
@@ -333,16 +333,21 @@ class StatusUpdater(Document):
|
||||
)
|
||||
|
||||
def warn_about_bypassing_with_role(self, item, qty_or_amount, role):
|
||||
action = _("Over Receipt/Delivery") if qty_or_amount == "qty" else _("Overbilling")
|
||||
if qty_or_amount == "qty":
|
||||
msg = _("Over Receipt/Delivery of {0} {1} ignored for item {2} because you have {3} role.")
|
||||
else:
|
||||
msg = _("Overbilling of {0} {1} ignored for item {2} because you have {3} role.")
|
||||
|
||||
msg = _("{} of {} {} ignored for item {} because you have {} role.").format(
|
||||
action,
|
||||
_(item["target_ref_field"].title()),
|
||||
frappe.bold(item["reduce_by"]),
|
||||
frappe.bold(item.get("item_code")),
|
||||
role,
|
||||
frappe.msgprint(
|
||||
msg.format(
|
||||
_(item["target_ref_field"].title()),
|
||||
frappe.bold(item["reduce_by"]),
|
||||
frappe.bold(item.get("item_code")),
|
||||
role,
|
||||
),
|
||||
indicator="orange",
|
||||
alert=True,
|
||||
)
|
||||
frappe.msgprint(msg, indicator="orange", alert=True)
|
||||
|
||||
def update_qty(self, update_modified=True):
|
||||
"""Updates qty or amount at row level
|
||||
|
||||
@@ -139,13 +139,15 @@ class StockController(AccountsController):
|
||||
warehouse_with_no_account = []
|
||||
precision = self.get_debit_field_precision()
|
||||
for item_row in voucher_details:
|
||||
|
||||
sle_list = sle_map.get(item_row.name)
|
||||
sle_rounding_diff = 0.0
|
||||
if sle_list:
|
||||
for sle in sle_list:
|
||||
if warehouse_account.get(sle.warehouse):
|
||||
# from warehouse account
|
||||
|
||||
sle_rounding_diff += flt(sle.stock_value_difference)
|
||||
|
||||
self.check_expense_account(item_row)
|
||||
|
||||
# expense account/ target_warehouse / source_warehouse
|
||||
@@ -188,6 +190,46 @@ class StockController(AccountsController):
|
||||
elif sle.warehouse not in warehouse_with_no_account:
|
||||
warehouse_with_no_account.append(sle.warehouse)
|
||||
|
||||
if abs(sle_rounding_diff) > (1.0 / (10**precision)) and self.is_internal_transfer():
|
||||
warehouse_asset_account = ""
|
||||
if self.get("is_internal_customer"):
|
||||
warehouse_asset_account = warehouse_account[item_row.get("target_warehouse")]["account"]
|
||||
elif self.get("is_internal_supplier"):
|
||||
warehouse_asset_account = warehouse_account[item_row.get("warehouse")]["account"]
|
||||
|
||||
expense_account = frappe.db.get_value("Company", self.company, "default_expense_account")
|
||||
|
||||
gl_list.append(
|
||||
self.get_gl_dict(
|
||||
{
|
||||
"account": expense_account,
|
||||
"against": warehouse_asset_account,
|
||||
"cost_center": item_row.cost_center,
|
||||
"project": item_row.project or self.get("project"),
|
||||
"remarks": _("Rounding gain/loss Entry for Stock Transfer"),
|
||||
"debit": sle_rounding_diff,
|
||||
"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
|
||||
},
|
||||
warehouse_account[sle.warehouse]["account_currency"],
|
||||
item=item_row,
|
||||
)
|
||||
)
|
||||
|
||||
gl_list.append(
|
||||
self.get_gl_dict(
|
||||
{
|
||||
"account": warehouse_asset_account,
|
||||
"against": expense_account,
|
||||
"cost_center": item_row.cost_center,
|
||||
"remarks": _("Rounding gain/loss Entry for Stock Transfer"),
|
||||
"credit": sle_rounding_diff,
|
||||
"project": item_row.get("project") or self.get("project"),
|
||||
"is_opening": item_row.get("is_opening") or self.get("is_opening") or "No",
|
||||
},
|
||||
item=item_row,
|
||||
)
|
||||
)
|
||||
|
||||
if warehouse_with_no_account:
|
||||
for wh in warehouse_with_no_account:
|
||||
if frappe.db.get_value("Warehouse", wh, "company"):
|
||||
|
||||
@@ -890,24 +890,33 @@ class calculate_taxes_and_totals(object):
|
||||
self.doc.other_charges_calculation = get_itemised_tax_breakup_html(self.doc)
|
||||
|
||||
def set_total_amount_to_default_mop(self, total_amount_to_pay):
|
||||
default_mode_of_payment = frappe.db.get_value(
|
||||
"POS Payment Method",
|
||||
{"parent": self.doc.pos_profile, "default": 1},
|
||||
["mode_of_payment"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if default_mode_of_payment:
|
||||
self.doc.payments = []
|
||||
self.doc.append(
|
||||
"payments",
|
||||
{
|
||||
"mode_of_payment": default_mode_of_payment.mode_of_payment,
|
||||
"amount": total_amount_to_pay,
|
||||
"default": 1,
|
||||
},
|
||||
total_paid_amount = 0
|
||||
for payment in self.doc.get("payments"):
|
||||
total_paid_amount += (
|
||||
payment.amount if self.doc.party_account_currency == self.doc.currency else payment.base_amount
|
||||
)
|
||||
|
||||
pending_amount = total_amount_to_pay - total_paid_amount
|
||||
|
||||
if pending_amount > 0:
|
||||
default_mode_of_payment = frappe.db.get_value(
|
||||
"POS Payment Method",
|
||||
{"parent": self.doc.pos_profile, "default": 1},
|
||||
["mode_of_payment"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if default_mode_of_payment:
|
||||
self.doc.payments = []
|
||||
self.doc.append(
|
||||
"payments",
|
||||
{
|
||||
"mode_of_payment": default_mode_of_payment.mode_of_payment,
|
||||
"amount": pending_amount,
|
||||
"default": 1,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def get_itemised_tax_breakup_html(doc):
|
||||
if not doc.taxes:
|
||||
|
||||
@@ -1345,7 +1345,7 @@ class QuickBooksMigrator(Document):
|
||||
)[0]["name"]
|
||||
|
||||
def _publish(self, *args, **kwargs):
|
||||
frappe.publish_realtime("quickbooks_progress_update", *args, **kwargs)
|
||||
frappe.publish_realtime("quickbooks_progress_update", *args, **kwargs, user=self.modified_by)
|
||||
|
||||
def _get_unique_account_name(self, quickbooks_name, number=0):
|
||||
if number:
|
||||
|
||||
@@ -302,6 +302,7 @@ class TallyMigration(Document):
|
||||
frappe.publish_realtime(
|
||||
"tally_migration_progress_update",
|
||||
{"title": title, "message": message, "count": count, "total": total},
|
||||
user=self.modified_by,
|
||||
)
|
||||
|
||||
def _import_master_data(self):
|
||||
|
||||
@@ -302,7 +302,7 @@ def check_for_nexus(doc, tax_dict):
|
||||
item.tax_collectable = flt(0)
|
||||
item.taxable_amount = flt(0)
|
||||
|
||||
for tax in doc.taxes:
|
||||
for tax in list(doc.taxes):
|
||||
if tax.account_head == TAX_ACCOUNT_HEAD:
|
||||
doc.taxes.remove(tax)
|
||||
return
|
||||
|
||||
@@ -334,8 +334,6 @@ has_website_permission = {
|
||||
"Patient": "erpnext.healthcare.web_form.personal_details.personal_details.has_website_permission",
|
||||
}
|
||||
|
||||
dump_report_map = "erpnext.startup.report_data_map.data_map"
|
||||
|
||||
before_tests = "erpnext.setup.utils.before_tests"
|
||||
|
||||
standard_queries = {
|
||||
@@ -528,6 +526,7 @@ scheduler_events = {
|
||||
"erpnext.loan_management.doctype.process_loan_security_shortfall.process_loan_security_shortfall.create_process_loan_security_shortfall",
|
||||
"erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual.process_loan_interest_accrual_for_term_loans",
|
||||
"erpnext.crm.doctype.lead.lead.daily_open_lead",
|
||||
"erpnext.stock.doctype.stock_entry.stock_entry.audit_incorrect_valuation_entries",
|
||||
],
|
||||
"weekly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_weekly"],
|
||||
"monthly": ["erpnext.hr.doctype.employee.employee_reminders.send_reminders_in_advance_monthly"],
|
||||
|
||||
@@ -70,11 +70,11 @@ def get_children(doctype, parent=None, company=None, is_root=False):
|
||||
select
|
||||
name as value,
|
||||
is_group as expandable
|
||||
from `tab{doctype}`
|
||||
from `tabDepartment`
|
||||
where
|
||||
{condition}
|
||||
order by name""".format(
|
||||
doctype=doctype, condition=condition
|
||||
condition=condition
|
||||
),
|
||||
var_dict,
|
||||
as_dict=1,
|
||||
|
||||
@@ -61,6 +61,10 @@ frappe.ui.form.on('Loan', {
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
if (frm.doc.repayment_schedule_type == "Pro-rated calendar months") {
|
||||
frm.set_df_property("repayment_start_date", "label", "Interest Calculation Start Date");
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus == 1) {
|
||||
if (["Disbursed", "Partially Disbursed"].includes(frm.doc.status) && (!frm.doc.repay_from_salary)) {
|
||||
frm.add_custom_button(__('Request Loan Closure'), function() {
|
||||
@@ -103,6 +107,14 @@ frappe.ui.form.on('Loan', {
|
||||
frm.trigger("toggle_fields");
|
||||
},
|
||||
|
||||
repayment_schedule_type: function(frm) {
|
||||
if (frm.doc.repayment_schedule_type == "Pro-rated calendar months") {
|
||||
frm.set_df_property("repayment_start_date", "label", "Interest Calculation Start Date");
|
||||
} else {
|
||||
frm.set_df_property("repayment_start_date", "label", "Repayment Start Date");
|
||||
}
|
||||
},
|
||||
|
||||
loan_type: function(frm) {
|
||||
frm.toggle_reqd("repayment_method", frm.doc.is_term_loan);
|
||||
frm.toggle_display("repayment_method", frm.doc.is_term_loan);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"manually_update_paid_amount_in_salary_slip",
|
||||
"section_break_8",
|
||||
"loan_type",
|
||||
"repayment_schedule_type",
|
||||
"loan_amount",
|
||||
"rate_of_interest",
|
||||
"is_secured_loan",
|
||||
@@ -167,7 +168,8 @@
|
||||
"depends_on": "is_term_loan",
|
||||
"fieldname": "repayment_start_date",
|
||||
"fieldtype": "Date",
|
||||
"label": "Repayment Start Date"
|
||||
"label": "Repayment Start Date",
|
||||
"mandatory_depends_on": "is_term_loan"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_11",
|
||||
@@ -419,12 +421,20 @@
|
||||
"fieldname": "manually_update_paid_amount_in_salary_slip",
|
||||
"fieldtype": "Check",
|
||||
"label": "Manually Update Paid Amount in Salary Slip"
|
||||
},
|
||||
{
|
||||
"depends_on": "is_term_loan",
|
||||
"fetch_from": "loan_type.repayment_schedule_type",
|
||||
"fieldname": "repayment_schedule_type",
|
||||
"fieldtype": "Data",
|
||||
"label": "Repayment Schedule Type",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-09-13 02:05:25.017190",
|
||||
"modified": "2022-11-01 10:36:47.902903",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Loan Management",
|
||||
"name": "Loan",
|
||||
|
||||
@@ -7,7 +7,16 @@ import math
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import add_months, flt, get_last_day, getdate, now_datetime, nowdate
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
add_months,
|
||||
date_diff,
|
||||
flt,
|
||||
get_last_day,
|
||||
getdate,
|
||||
now_datetime,
|
||||
nowdate,
|
||||
)
|
||||
from six import string_types
|
||||
|
||||
import erpnext
|
||||
@@ -115,30 +124,81 @@ class Loan(AccountsController):
|
||||
if not self.repayment_start_date:
|
||||
frappe.throw(_("Repayment Start Date is mandatory for term loans"))
|
||||
|
||||
schedule_type_details = frappe.db.get_value(
|
||||
"Loan Type", self.loan_type, ["repayment_schedule_type", "repayment_date_on"], as_dict=1
|
||||
)
|
||||
|
||||
self.repayment_schedule = []
|
||||
payment_date = self.repayment_start_date
|
||||
balance_amount = self.loan_amount
|
||||
while balance_amount > 0:
|
||||
interest_amount = flt(balance_amount * flt(self.rate_of_interest) / (12 * 100))
|
||||
principal_amount = self.monthly_repayment_amount - interest_amount
|
||||
balance_amount = flt(balance_amount + interest_amount - self.monthly_repayment_amount)
|
||||
if balance_amount < 0:
|
||||
principal_amount += balance_amount
|
||||
balance_amount = 0.0
|
||||
|
||||
total_payment = principal_amount + interest_amount
|
||||
self.append(
|
||||
"repayment_schedule",
|
||||
{
|
||||
"payment_date": payment_date,
|
||||
"principal_amount": principal_amount,
|
||||
"interest_amount": interest_amount,
|
||||
"total_payment": total_payment,
|
||||
"balance_loan_amount": balance_amount,
|
||||
},
|
||||
while balance_amount > 0:
|
||||
interest_amount, principal_amount, balance_amount, total_payment = self.get_amounts(
|
||||
payment_date,
|
||||
balance_amount,
|
||||
schedule_type_details.repayment_schedule_type,
|
||||
schedule_type_details.repayment_date_on,
|
||||
)
|
||||
next_payment_date = add_single_month(payment_date)
|
||||
payment_date = next_payment_date
|
||||
|
||||
if schedule_type_details.repayment_schedule_type == "Pro-rated calendar months":
|
||||
next_payment_date = get_last_day(payment_date)
|
||||
if schedule_type_details.repayment_date_on == "Start of the next month":
|
||||
next_payment_date = add_days(next_payment_date, 1)
|
||||
|
||||
payment_date = next_payment_date
|
||||
|
||||
self.add_repayment_schedule_row(
|
||||
payment_date, principal_amount, interest_amount, total_payment, balance_amount
|
||||
)
|
||||
|
||||
if (
|
||||
schedule_type_details.repayment_schedule_type == "Monthly as per repayment start date"
|
||||
or schedule_type_details.repayment_date_on == "End of the current month"
|
||||
):
|
||||
next_payment_date = add_single_month(payment_date)
|
||||
payment_date = next_payment_date
|
||||
|
||||
def get_amounts(self, payment_date, balance_amount, schedule_type, repayment_date_on):
|
||||
if schedule_type == "Monthly as per repayment start date":
|
||||
days = 1
|
||||
months = 12
|
||||
else:
|
||||
expected_payment_date = get_last_day(payment_date)
|
||||
if repayment_date_on == "Start of the next month":
|
||||
expected_payment_date = add_days(expected_payment_date, 1)
|
||||
|
||||
if expected_payment_date == payment_date:
|
||||
# using 30 days for calculating interest for all full months
|
||||
days = 30
|
||||
months = 365
|
||||
else:
|
||||
days = date_diff(get_last_day(payment_date), payment_date)
|
||||
months = 365
|
||||
|
||||
interest_amount = flt(balance_amount * flt(self.rate_of_interest) * days / (months * 100))
|
||||
principal_amount = self.monthly_repayment_amount - interest_amount
|
||||
balance_amount = flt(balance_amount + interest_amount - self.monthly_repayment_amount)
|
||||
if balance_amount < 0:
|
||||
principal_amount += balance_amount
|
||||
balance_amount = 0.0
|
||||
|
||||
total_payment = principal_amount + interest_amount
|
||||
|
||||
return interest_amount, principal_amount, balance_amount, total_payment
|
||||
|
||||
def add_repayment_schedule_row(
|
||||
self, payment_date, principal_amount, interest_amount, total_payment, balance_loan_amount
|
||||
):
|
||||
self.append(
|
||||
"repayment_schedule",
|
||||
{
|
||||
"payment_date": payment_date,
|
||||
"principal_amount": principal_amount,
|
||||
"interest_amount": interest_amount,
|
||||
"total_payment": total_payment,
|
||||
"balance_loan_amount": balance_loan_amount,
|
||||
},
|
||||
)
|
||||
|
||||
def set_repayment_period(self):
|
||||
if self.repayment_method == "Repay Fixed Amount per Period":
|
||||
|
||||
@@ -4,7 +4,16 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.utils import add_days, add_months, add_to_date, date_diff, flt, get_datetime, nowdate
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
add_months,
|
||||
add_to_date,
|
||||
date_diff,
|
||||
flt,
|
||||
format_date,
|
||||
get_datetime,
|
||||
nowdate,
|
||||
)
|
||||
|
||||
from erpnext.loan_management.doctype.loan.loan import (
|
||||
make_loan_write_off,
|
||||
@@ -50,6 +59,51 @@ class TestLoan(unittest.TestCase):
|
||||
loan_account="Loan Account - _TC",
|
||||
interest_income_account="Interest Income Account - _TC",
|
||||
penalty_income_account="Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Monthly as per repayment start date",
|
||||
)
|
||||
|
||||
create_loan_type(
|
||||
"Term Loan Type 1",
|
||||
12000,
|
||||
7.5,
|
||||
is_term_loan=1,
|
||||
mode_of_payment="Cash",
|
||||
disbursement_account="Disbursement Account - _TC",
|
||||
payment_account="Payment Account - _TC",
|
||||
loan_account="Loan Account - _TC",
|
||||
interest_income_account="Interest Income Account - _TC",
|
||||
penalty_income_account="Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Monthly as per repayment start date",
|
||||
)
|
||||
|
||||
create_loan_type(
|
||||
"Term Loan Type 2",
|
||||
12000,
|
||||
7.5,
|
||||
is_term_loan=1,
|
||||
mode_of_payment="Cash",
|
||||
disbursement_account="Disbursement Account - _TC",
|
||||
payment_account="Payment Account - _TC",
|
||||
loan_account="Loan Account - _TC",
|
||||
interest_income_account="Interest Income Account - _TC",
|
||||
penalty_income_account="Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Pro-rated calendar months",
|
||||
repayment_date_on="Start of the next month",
|
||||
)
|
||||
|
||||
create_loan_type(
|
||||
"Term Loan Type 3",
|
||||
12000,
|
||||
7.5,
|
||||
is_term_loan=1,
|
||||
mode_of_payment="Cash",
|
||||
disbursement_account="Disbursement Account - _TC",
|
||||
payment_account="Payment Account - _TC",
|
||||
loan_account="Loan Account - _TC",
|
||||
interest_income_account="Interest Income Account - _TC",
|
||||
penalty_income_account="Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Pro-rated calendar months",
|
||||
repayment_date_on="End of the current month",
|
||||
)
|
||||
|
||||
create_loan_type(
|
||||
@@ -65,6 +119,7 @@ class TestLoan(unittest.TestCase):
|
||||
"Loan Account - _TC",
|
||||
"Interest Income Account - _TC",
|
||||
"Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Monthly as per repayment start date",
|
||||
)
|
||||
|
||||
create_loan_type(
|
||||
@@ -912,6 +967,69 @@ class TestLoan(unittest.TestCase):
|
||||
amounts = calculate_amounts(loan.name, add_days(last_date, 5))
|
||||
self.assertEqual(flt(amounts["pending_principal_amount"], 0), 0)
|
||||
|
||||
def test_term_loan_schedule_types(self):
|
||||
loan = create_loan(
|
||||
self.applicant1,
|
||||
"Term Loan Type 1",
|
||||
12000,
|
||||
"Repay Over Number of Periods",
|
||||
12,
|
||||
repayment_start_date="2022-10-17",
|
||||
)
|
||||
|
||||
# Check for first, second and last installment date
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "17-10-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "17-11-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "17-09-2023"
|
||||
)
|
||||
|
||||
loan.loan_type = "Term Loan Type 2"
|
||||
loan.save()
|
||||
|
||||
# Check for first, second and last installment date
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "01-11-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "01-12-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "01-10-2023"
|
||||
)
|
||||
|
||||
loan.loan_type = "Term Loan Type 3"
|
||||
loan.save()
|
||||
|
||||
# Check for first, second and last installment date
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "31-10-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "30-11-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "30-09-2023"
|
||||
)
|
||||
|
||||
loan.repayment_method = "Repay Fixed Amount per Period"
|
||||
loan.monthly_repayment_amount = 1042
|
||||
loan.save()
|
||||
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[0].payment_date, "dd-MM-yyyy"), "31-10-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[1].payment_date, "dd-MM-yyyy"), "30-11-2022"
|
||||
)
|
||||
self.assertEqual(
|
||||
format_date(loan.get("repayment_schedule")[-1].payment_date, "dd-MM-yyyy"), "30-09-2023"
|
||||
)
|
||||
|
||||
|
||||
def create_loan_scenario_for_penalty(doc):
|
||||
pledge = [{"loan_security": "Test Security 1", "qty": 4000.00}]
|
||||
@@ -1043,6 +1161,8 @@ def create_loan_type(
|
||||
penalty_income_account=None,
|
||||
repayment_method=None,
|
||||
repayment_periods=None,
|
||||
repayment_schedule_type=None,
|
||||
repayment_date_on=None,
|
||||
):
|
||||
|
||||
if not frappe.db.exists("Loan Type", loan_name):
|
||||
@@ -1052,6 +1172,7 @@ def create_loan_type(
|
||||
"company": "_Test Company",
|
||||
"loan_name": loan_name,
|
||||
"is_term_loan": is_term_loan,
|
||||
"repayment_schedule_type": "Monthly as per repayment start date",
|
||||
"maximum_loan_amount": maximum_loan_amount,
|
||||
"rate_of_interest": rate_of_interest,
|
||||
"penalty_interest_rate": penalty_interest_rate,
|
||||
@@ -1066,8 +1187,14 @@ def create_loan_type(
|
||||
"repayment_periods": repayment_periods,
|
||||
"write_off_amount": 100,
|
||||
}
|
||||
).insert()
|
||||
)
|
||||
|
||||
if loan_type.is_term_loan:
|
||||
loan_type.repayment_schedule_type = repayment_schedule_type
|
||||
if loan_type.repayment_schedule_type != "Monthly as per repayment start date":
|
||||
loan_type.repayment_date_on = repayment_date_on
|
||||
|
||||
loan_type.insert()
|
||||
loan_type.submit()
|
||||
|
||||
|
||||
|
||||
@@ -191,7 +191,9 @@ def get_total_pledged_security_value(loan):
|
||||
|
||||
for security, qty in pledged_securities.items():
|
||||
after_haircut_percentage = 100 - hair_cut_map.get(security)
|
||||
security_value += (loan_security_price_map.get(security) * qty * after_haircut_percentage) / 100
|
||||
security_value += (
|
||||
loan_security_price_map.get(security, 0) * qty * after_haircut_percentage
|
||||
) / 100
|
||||
|
||||
return security_value
|
||||
|
||||
|
||||
@@ -577,8 +577,8 @@ def regenerate_repayment_schedule(loan, cancel=0):
|
||||
loan_doc = frappe.get_doc("Loan", loan)
|
||||
next_accrual_date = None
|
||||
accrued_entries = 0
|
||||
last_repayment_amount = 0
|
||||
last_balance_amount = 0
|
||||
last_repayment_amount = None
|
||||
last_balance_amount = None
|
||||
|
||||
for term in reversed(loan_doc.get("repayment_schedule")):
|
||||
if not term.is_accrued:
|
||||
@@ -586,9 +586,9 @@ def regenerate_repayment_schedule(loan, cancel=0):
|
||||
loan_doc.remove(term)
|
||||
else:
|
||||
accrued_entries += 1
|
||||
if not last_repayment_amount:
|
||||
if last_repayment_amount is None:
|
||||
last_repayment_amount = term.total_payment
|
||||
if not last_balance_amount:
|
||||
if last_balance_amount is None:
|
||||
last_balance_amount = term.balance_loan_amount
|
||||
|
||||
loan_doc.save()
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
"company",
|
||||
"is_term_loan",
|
||||
"disabled",
|
||||
"repayment_schedule_type",
|
||||
"repayment_date_on",
|
||||
"description",
|
||||
"account_details_section",
|
||||
"mode_of_payment",
|
||||
@@ -157,12 +159,30 @@
|
||||
"label": "Disbursement Account",
|
||||
"options": "Account",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "is_term_loan",
|
||||
"description": "The schedule type that will be used for generating the term loan schedules (will affect the payment date and monthly repayment amount)",
|
||||
"fieldname": "repayment_schedule_type",
|
||||
"fieldtype": "Select",
|
||||
"label": "Repayment Schedule Type",
|
||||
"mandatory_depends_on": "is_term_loan",
|
||||
"options": "\nMonthly as per repayment start date\nPro-rated calendar months"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.repayment_schedule_type == \"Pro-rated calendar months\"",
|
||||
"description": "Select whether the repayment date should be the end of the current month or start of the upcoming month",
|
||||
"fieldname": "repayment_date_on",
|
||||
"fieldtype": "Select",
|
||||
"label": "Repayment Date On",
|
||||
"mandatory_depends_on": "eval:doc.repayment_schedule_type == \"Pro-rated calendar months\"",
|
||||
"options": "\nStart of the next month\nEnd of the current month"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-01-25 16:23:57.009349",
|
||||
"modified": "2022-11-01 17:43:03.954201",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Loan Management",
|
||||
"name": "Loan Type",
|
||||
|
||||
@@ -384,6 +384,7 @@ class BOM(WebsiteGenerator):
|
||||
if self.docstatus == 2:
|
||||
return
|
||||
|
||||
self.flags.cost_updated = False
|
||||
existing_bom_cost = self.total_cost
|
||||
|
||||
if self.docstatus == 1:
|
||||
@@ -406,7 +407,11 @@ class BOM(WebsiteGenerator):
|
||||
frappe.get_doc("BOM", bom).update_cost(from_child_bom=True)
|
||||
|
||||
if not from_child_bom:
|
||||
frappe.msgprint(_("Cost Updated"), alert=True)
|
||||
msg = "Cost Updated"
|
||||
if not self.flags.cost_updated:
|
||||
msg = "No changes in cost found"
|
||||
|
||||
frappe.msgprint(_(msg), alert=True)
|
||||
|
||||
def update_parent_cost(self):
|
||||
if self.total_cost:
|
||||
@@ -592,11 +597,16 @@ class BOM(WebsiteGenerator):
|
||||
# not via doc event, table is not regenerated and needs updation
|
||||
self.calculate_exploded_cost()
|
||||
|
||||
old_cost = self.total_cost
|
||||
|
||||
self.total_cost = self.operating_cost + self.raw_material_cost - self.scrap_material_cost
|
||||
self.base_total_cost = (
|
||||
self.base_operating_cost + self.base_raw_material_cost - self.base_scrap_material_cost
|
||||
)
|
||||
|
||||
if self.total_cost != old_cost:
|
||||
self.flags.cost_updated = True
|
||||
|
||||
def calculate_op_cost(self, update_hour_rate=False):
|
||||
"""Update workstation rate and calculates totals"""
|
||||
self.operating_cost = 0
|
||||
|
||||
@@ -583,6 +583,28 @@ class TestBOM(FrappeTestCase):
|
||||
bom.submit()
|
||||
self.assertEqual(bom.exploded_items[0].rate, bom.items[0].base_rate)
|
||||
|
||||
def test_bom_cost_update_flag(self):
|
||||
rm_item = make_item(
|
||||
properties={"is_stock_item": 1, "valuation_rate": 99, "last_purchase_rate": 89}
|
||||
).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])
|
||||
|
||||
create_stock_reconciliation(
|
||||
item_code=rm_item, warehouse="_Test Warehouse - _TC", qty=100, rate=600
|
||||
)
|
||||
|
||||
bom.load_from_db()
|
||||
bom.update_cost()
|
||||
self.assertTrue(bom.flags.cost_updated)
|
||||
|
||||
bom.load_from_db()
|
||||
bom.update_cost()
|
||||
self.assertFalse(bom.flags.cost_updated)
|
||||
|
||||
|
||||
def get_default_bom(item_code="_Test FG Item 2"):
|
||||
return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1})
|
||||
|
||||
@@ -7,6 +7,8 @@ import frappe
|
||||
from frappe import _, bold
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder.functions import IfNull, Max, Min
|
||||
from frappe.utils import (
|
||||
add_days,
|
||||
add_to_date,
|
||||
@@ -54,6 +56,9 @@ class JobCard(Document):
|
||||
self.set_onload("job_card_excess_transfer", excess_transfer)
|
||||
self.set_onload("work_order_stopped", self.is_work_order_stopped())
|
||||
|
||||
def before_validate(self):
|
||||
self.set_wip_warehouse()
|
||||
|
||||
def validate(self):
|
||||
self.validate_time_logs()
|
||||
self.set_status()
|
||||
@@ -109,43 +114,44 @@ class JobCard(Document):
|
||||
def get_overlap_for(self, args, check_next_available_slot=False):
|
||||
production_capacity = 1
|
||||
|
||||
jc = frappe.qb.DocType("Job Card")
|
||||
jctl = frappe.qb.DocType("Job Card Time Log")
|
||||
|
||||
time_conditions = [
|
||||
((jctl.from_time < args.from_time) & (jctl.to_time > args.from_time)),
|
||||
((jctl.from_time < args.to_time) & (jctl.to_time > args.to_time)),
|
||||
((jctl.from_time >= args.from_time) & (jctl.to_time <= args.to_time)),
|
||||
]
|
||||
|
||||
if check_next_available_slot:
|
||||
time_conditions.append(((jctl.from_time >= args.from_time) & (jctl.to_time >= args.to_time)))
|
||||
|
||||
query = (
|
||||
frappe.qb.from_(jctl)
|
||||
.from_(jc)
|
||||
.select(jc.name.as_("name"), jctl.to_time)
|
||||
.where(
|
||||
(jctl.parent == jc.name)
|
||||
& (Criterion.any(time_conditions))
|
||||
& (jctl.name != f"{args.name or 'No Name'}")
|
||||
& (jc.name != f"{args.parent or 'No Name'}")
|
||||
& (jc.docstatus < 2)
|
||||
)
|
||||
.orderby(jctl.to_time, order=frappe.qb.desc)
|
||||
)
|
||||
|
||||
if self.workstation:
|
||||
production_capacity = (
|
||||
frappe.get_cached_value("Workstation", self.workstation, "production_capacity") or 1
|
||||
)
|
||||
validate_overlap_for = " and jc.workstation = %(workstation)s "
|
||||
query = query.where(jc.workstation == self.workstation)
|
||||
|
||||
if args.get("employee"):
|
||||
# override capacity for employee
|
||||
production_capacity = 1
|
||||
validate_overlap_for = " and jctl.employee = %(employee)s "
|
||||
query = query.where(jctl.employee == args.get("employee"))
|
||||
|
||||
extra_cond = ""
|
||||
if check_next_available_slot:
|
||||
extra_cond = " or (%(from_time)s <= jctl.from_time and %(to_time)s <= jctl.to_time)"
|
||||
|
||||
existing = frappe.db.sql(
|
||||
"""select jc.name as name, jctl.to_time from
|
||||
`tabJob Card Time Log` jctl, `tabJob Card` jc where jctl.parent = jc.name and
|
||||
(
|
||||
(%(from_time)s > jctl.from_time and %(from_time)s < jctl.to_time) or
|
||||
(%(to_time)s > jctl.from_time and %(to_time)s < jctl.to_time) or
|
||||
(%(from_time)s <= jctl.from_time and %(to_time)s >= jctl.to_time) {0}
|
||||
)
|
||||
and jctl.name != %(name)s and jc.name != %(parent)s and jc.docstatus < 2 {1}
|
||||
order by jctl.to_time desc limit 1""".format(
|
||||
extra_cond, validate_overlap_for
|
||||
),
|
||||
{
|
||||
"from_time": args.from_time,
|
||||
"to_time": args.to_time,
|
||||
"name": args.name or "No Name",
|
||||
"parent": args.parent or "No Name",
|
||||
"employee": args.get("employee"),
|
||||
"workstation": self.workstation,
|
||||
},
|
||||
as_dict=True,
|
||||
)
|
||||
existing = query.run(as_dict=True)
|
||||
|
||||
if existing and production_capacity > len(existing):
|
||||
return
|
||||
@@ -485,18 +491,21 @@ class JobCard(Document):
|
||||
)
|
||||
|
||||
def update_work_order_data(self, for_quantity, time_in_mins, wo):
|
||||
time_data = frappe.db.sql(
|
||||
"""
|
||||
SELECT
|
||||
min(from_time) as start_time, max(to_time) as end_time
|
||||
FROM `tabJob Card` jc, `tabJob Card Time Log` jctl
|
||||
WHERE
|
||||
jctl.parent = jc.name and jc.work_order = %s and jc.operation_id = %s
|
||||
and jc.docstatus = 1 and IFNULL(jc.is_corrective_job_card, 0) = 0
|
||||
""",
|
||||
(self.work_order, self.operation_id),
|
||||
as_dict=1,
|
||||
)
|
||||
jc = frappe.qb.DocType("Job Card")
|
||||
jctl = frappe.qb.DocType("Job Card Time Log")
|
||||
|
||||
time_data = (
|
||||
frappe.qb.from_(jc)
|
||||
.from_(jctl)
|
||||
.select(Min(jctl.from_time).as_("start_time"), Max(jctl.to_time).as_("end_time"))
|
||||
.where(
|
||||
(jctl.parent == jc.name)
|
||||
& (jc.work_order == self.work_order)
|
||||
& (jc.operation_id == self.operation_id)
|
||||
& (jc.docstatus == 1)
|
||||
& (IfNull(jc.is_corrective_job_card, 0) == 0)
|
||||
)
|
||||
).run(as_dict=True)
|
||||
|
||||
for data in wo.operations:
|
||||
if data.get("name") == self.operation_id:
|
||||
@@ -639,6 +648,12 @@ class JobCard(Document):
|
||||
if update_status:
|
||||
self.db_set("status", self.status)
|
||||
|
||||
def set_wip_warehouse(self):
|
||||
if not self.wip_warehouse:
|
||||
self.wip_warehouse = frappe.db.get_single_value(
|
||||
"Manufacturing Settings", "default_wip_warehouse"
|
||||
)
|
||||
|
||||
def validate_operation_id(self):
|
||||
if (
|
||||
self.get("operation_id")
|
||||
|
||||
@@ -133,6 +133,45 @@ class TestJobCard(FrappeTestCase):
|
||||
)
|
||||
self.assertRaises(OverlapError, jc2.save)
|
||||
|
||||
def test_job_card_overlap_with_capacity(self):
|
||||
wo2 = make_wo_order_test_record(item="_Test FG Item 2", qty=2)
|
||||
|
||||
workstation = make_workstation(workstation_name=random_string(5)).name
|
||||
frappe.db.set_value("Workstation", workstation, "production_capacity", 1)
|
||||
|
||||
jc1 = frappe.get_last_doc("Job Card", {"work_order": self.work_order.name})
|
||||
jc2 = frappe.get_last_doc("Job Card", {"work_order": wo2.name})
|
||||
|
||||
jc1.workstation = workstation
|
||||
jc1.append(
|
||||
"time_logs",
|
||||
{"from_time": "2021-01-01 00:00:00", "to_time": "2021-01-01 08:00:00", "completed_qty": 1},
|
||||
)
|
||||
jc1.save()
|
||||
|
||||
jc2.workstation = workstation
|
||||
|
||||
# add a new entry in same time slice
|
||||
jc2.append(
|
||||
"time_logs",
|
||||
{"from_time": "2021-01-01 00:01:00", "to_time": "2021-01-01 06:00:00", "completed_qty": 1},
|
||||
)
|
||||
self.assertRaises(OverlapError, jc2.save)
|
||||
|
||||
frappe.db.set_value("Workstation", workstation, "production_capacity", 2)
|
||||
jc2.load_from_db()
|
||||
|
||||
jc2.workstation = workstation
|
||||
|
||||
# add a new entry in same time slice
|
||||
jc2.append(
|
||||
"time_logs",
|
||||
{"from_time": "2021-01-01 00:01:00", "to_time": "2021-01-01 06:00:00", "completed_qty": 1},
|
||||
)
|
||||
|
||||
jc2.save()
|
||||
self.assertTrue(jc2.name)
|
||||
|
||||
def test_job_card_multiple_materials_transfer(self):
|
||||
"Test transferring RMs separately against Job Card with multiple RMs."
|
||||
self.transfer_material_against = "Job Card"
|
||||
|
||||
@@ -27,6 +27,7 @@ from six import iteritems
|
||||
from erpnext.manufacturing.doctype.bom.bom import get_children, validate_bom_no
|
||||
from erpnext.manufacturing.doctype.work_order.work_order import get_item_details
|
||||
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
|
||||
from erpnext.stock.get_item_details import get_conversion_factor
|
||||
from erpnext.utilities.transaction_base import validate_uom_is_integer
|
||||
|
||||
|
||||
@@ -977,11 +978,25 @@ def get_material_request_items(
|
||||
if include_safety_stock:
|
||||
required_qty += flt(row["safety_stock"])
|
||||
|
||||
item_details = frappe.get_cached_value(
|
||||
"Item", row.item_code, ["purchase_uom", "stock_uom"], as_dict=1
|
||||
)
|
||||
|
||||
conversion_factor = 1.0
|
||||
if (
|
||||
row.get("default_material_request_type") == "Purchase"
|
||||
and item_details.purchase_uom
|
||||
and item_details.purchase_uom != item_details.stock_uom
|
||||
):
|
||||
conversion_factor = (
|
||||
get_conversion_factor(row.item_code, item_details.purchase_uom).get("conversion_factor") or 1.0
|
||||
)
|
||||
|
||||
if required_qty > 0:
|
||||
return {
|
||||
"item_code": row.item_code,
|
||||
"item_name": row.item_name,
|
||||
"quantity": required_qty,
|
||||
"quantity": required_qty / conversion_factor,
|
||||
"required_bom_qty": total_qty,
|
||||
"stock_uom": row.get("stock_uom"),
|
||||
"warehouse": warehouse
|
||||
|
||||
@@ -732,6 +732,40 @@ class TestProductionPlan(FrappeTestCase):
|
||||
self.assertEqual(pln.status, "Completed")
|
||||
self.assertEqual(pln.po_items[0].produced_qty, 5)
|
||||
|
||||
def test_material_request_item_for_purchase_uom(self):
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
|
||||
fg_item = make_item(properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1"}).name
|
||||
bom_item = make_item(
|
||||
properties={"is_stock_item": 1, "stock_uom": "_Test UOM 1", "purchase_uom": "Nos"}
|
||||
).name
|
||||
|
||||
if not frappe.db.exists("UOM Conversion Detail", {"parent": bom_item, "uom": "Nos"}):
|
||||
doc = frappe.get_doc("Item", bom_item)
|
||||
doc.append("uoms", {"uom": "Nos", "conversion_factor": 10})
|
||||
doc.save()
|
||||
|
||||
make_bom(item=fg_item, raw_materials=[bom_item], source_warehouse="_Test Warehouse - _TC")
|
||||
|
||||
pln = create_production_plan(
|
||||
item_code=fg_item, planned_qty=10, ignore_existing_ordered_qty=1, stock_uom="_Test UOM 1"
|
||||
)
|
||||
|
||||
pln.make_material_request()
|
||||
|
||||
for row in pln.mr_items:
|
||||
self.assertEqual(row.uom, "Nos")
|
||||
self.assertEqual(row.quantity, 1)
|
||||
|
||||
for row in frappe.get_all(
|
||||
"Material Request Item",
|
||||
filters={"production_plan": pln.name},
|
||||
fields=["item_code", "uom", "qty"],
|
||||
):
|
||||
self.assertEqual(row.item_code, bom_item)
|
||||
self.assertEqual(row.uom, "Nos")
|
||||
self.assertEqual(row.qty, 1)
|
||||
|
||||
|
||||
def create_production_plan(**args):
|
||||
"""
|
||||
|
||||
@@ -625,6 +625,10 @@ class TestWorkOrder(FrappeTestCase):
|
||||
bom.submit()
|
||||
bom_name = bom.name
|
||||
|
||||
ste1 = test_stock_entry.make_stock_entry(
|
||||
item_code=rm1, target="_Test Warehouse - _TC", qty=32, basic_rate=5000.0
|
||||
)
|
||||
|
||||
work_order = make_wo_order_test_record(
|
||||
item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1
|
||||
)
|
||||
@@ -649,11 +653,29 @@ class TestWorkOrder(FrappeTestCase):
|
||||
work_order.insert()
|
||||
work_order.submit()
|
||||
self.assertEqual(work_order.has_batch_no, 1)
|
||||
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 30))
|
||||
batches = frappe.get_all("Batch", filters={"reference_name": work_order.name})
|
||||
self.assertEqual(len(batches), 3)
|
||||
batches = [batch.name for batch in batches]
|
||||
|
||||
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 10))
|
||||
for row in ste1.get("items"):
|
||||
if row.is_finished_item:
|
||||
self.assertEqual(row.item_code, fg_item)
|
||||
self.assertEqual(row.qty, 10)
|
||||
self.assertTrue(row.batch_no in batches)
|
||||
batches.remove(row.batch_no)
|
||||
|
||||
ste1.submit()
|
||||
|
||||
remaining_batches = []
|
||||
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 20))
|
||||
for row in ste1.get("items"):
|
||||
if row.is_finished_item:
|
||||
self.assertEqual(row.item_code, fg_item)
|
||||
self.assertEqual(row.qty, 10)
|
||||
remaining_batches.append(row.batch_no)
|
||||
|
||||
self.assertEqual(sorted(remaining_batches), sorted(batches))
|
||||
|
||||
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0)
|
||||
|
||||
@@ -1123,6 +1145,37 @@ class TestWorkOrder(FrappeTestCase):
|
||||
except frappe.MandatoryError:
|
||||
self.fail("Batch generation causing failing in Work Order")
|
||||
|
||||
@change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1})
|
||||
def test_auto_serial_no_creation(self):
|
||||
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||
|
||||
fg_item = frappe.generate_hash(length=20)
|
||||
child_item = frappe.generate_hash(length=20)
|
||||
|
||||
bom_tree = {fg_item: {child_item: {}}}
|
||||
|
||||
create_nested_bom(bom_tree, prefix="")
|
||||
|
||||
item = frappe.get_doc("Item", fg_item)
|
||||
item.has_serial_no = 1
|
||||
item.serial_no_series = f"{item.name}.#####"
|
||||
item.save()
|
||||
|
||||
try:
|
||||
wo_order = make_wo_order_test_record(item=fg_item, qty=2, skip_transfer=True)
|
||||
serial_nos = wo_order.serial_no
|
||||
stock_entry = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 10))
|
||||
stock_entry.set_work_order_details()
|
||||
stock_entry.set_serial_no_batch_for_finished_good()
|
||||
for row in stock_entry.items:
|
||||
if row.item_code == fg_item:
|
||||
self.assertTrue(row.serial_no)
|
||||
self.assertEqual(sorted(get_serial_nos(row.serial_no)), sorted(get_serial_nos(serial_nos)))
|
||||
|
||||
except frappe.MandatoryError:
|
||||
self.fail("Batch generation causing failing in Work Order")
|
||||
|
||||
@change_settings(
|
||||
"Manufacturing Settings",
|
||||
{"backflush_raw_materials_based_on": "Material Transferred for Manufacture"},
|
||||
|
||||
@@ -555,66 +555,69 @@ erpnext.work_order = {
|
||||
}
|
||||
}
|
||||
|
||||
if(!frm.doc.skip_transfer){
|
||||
if (frm.doc.status != 'Stopped') {
|
||||
// If "Material Consumption is check in Manufacturing Settings, allow Material Consumption
|
||||
if (flt(doc.material_transferred_for_manufacturing) > 0 && frm.doc.status != 'Stopped') {
|
||||
if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing))) {
|
||||
frm.has_finish_btn = true;
|
||||
|
||||
if (frm.doc.__onload && frm.doc.__onload.material_consumption == 1) {
|
||||
// Only show "Material Consumption" when required_qty > consumed_qty
|
||||
var counter = 0;
|
||||
var tbl = frm.doc.required_items || [];
|
||||
var tbl_lenght = tbl.length;
|
||||
for (var i = 0, len = tbl_lenght; i < len; i++) {
|
||||
let wo_item_qty = frm.doc.required_items[i].transferred_qty || frm.doc.required_items[i].required_qty;
|
||||
if (flt(wo_item_qty) > flt(frm.doc.required_items[i].consumed_qty)) {
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
if (counter > 0) {
|
||||
var consumption_btn = frm.add_custom_button(__('Material Consumption'), function() {
|
||||
const backflush_raw_materials_based_on = frm.doc.__onload.backflush_raw_materials_based_on;
|
||||
erpnext.work_order.make_consumption_se(frm, backflush_raw_materials_based_on);
|
||||
});
|
||||
consumption_btn.addClass('btn-primary');
|
||||
if (frm.doc.__onload && frm.doc.__onload.material_consumption == 1) {
|
||||
if (flt(doc.material_transferred_for_manufacturing) > 0 || frm.doc.skip_transfer) {
|
||||
// Only show "Material Consumption" when required_qty > consumed_qty
|
||||
var counter = 0;
|
||||
var tbl = frm.doc.required_items || [];
|
||||
var tbl_lenght = tbl.length;
|
||||
for (var i = 0, len = tbl_lenght; i < len; i++) {
|
||||
let wo_item_qty = frm.doc.required_items[i].transferred_qty || frm.doc.required_items[i].required_qty;
|
||||
if (flt(wo_item_qty) > flt(frm.doc.required_items[i].consumed_qty)) {
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
if (counter > 0) {
|
||||
var consumption_btn = frm.add_custom_button(__('Material Consumption'), function() {
|
||||
const backflush_raw_materials_based_on = frm.doc.__onload.backflush_raw_materials_based_on;
|
||||
erpnext.work_order.make_consumption_se(frm, backflush_raw_materials_based_on);
|
||||
});
|
||||
consumption_btn.addClass('btn-primary');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!frm.doc.skip_transfer){
|
||||
if (flt(doc.material_transferred_for_manufacturing) > 0) {
|
||||
if ((flt(doc.produced_qty) < flt(doc.material_transferred_for_manufacturing))) {
|
||||
frm.has_finish_btn = true;
|
||||
|
||||
var finish_btn = frm.add_custom_button(__('Finish'), function() {
|
||||
erpnext.work_order.make_se(frm, 'Manufacture');
|
||||
});
|
||||
|
||||
if(doc.material_transferred_for_manufacturing>=doc.qty) {
|
||||
// all materials transferred for manufacturing, make this primary
|
||||
finish_btn.addClass('btn-primary');
|
||||
}
|
||||
} else {
|
||||
frappe.db.get_doc("Manufacturing Settings").then((doc) => {
|
||||
let allowance_percentage = doc.overproduction_percentage_for_work_order;
|
||||
|
||||
if (allowance_percentage > 0) {
|
||||
let allowed_qty = frm.doc.qty + ((allowance_percentage / 100) * frm.doc.qty);
|
||||
|
||||
if ((flt(doc.produced_qty) < allowed_qty)) {
|
||||
frm.add_custom_button(__('Finish'), function() {
|
||||
erpnext.work_order.make_se(frm, 'Manufacture');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((flt(doc.produced_qty) < flt(doc.qty))) {
|
||||
var finish_btn = frm.add_custom_button(__('Finish'), function() {
|
||||
erpnext.work_order.make_se(frm, 'Manufacture');
|
||||
});
|
||||
|
||||
if(doc.material_transferred_for_manufacturing>=doc.qty) {
|
||||
// all materials transferred for manufacturing, make this primary
|
||||
finish_btn.addClass('btn-primary');
|
||||
}
|
||||
} else {
|
||||
frappe.db.get_doc("Manufacturing Settings").then((doc) => {
|
||||
let allowance_percentage = doc.overproduction_percentage_for_work_order;
|
||||
|
||||
if (allowance_percentage > 0) {
|
||||
let allowed_qty = frm.doc.qty + ((allowance_percentage / 100) * frm.doc.qty);
|
||||
|
||||
if ((flt(doc.produced_qty) < allowed_qty)) {
|
||||
frm.add_custom_button(__('Finish'), function() {
|
||||
erpnext.work_order.make_se(frm, 'Manufacture');
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
finish_btn.addClass('btn-primary');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((flt(doc.produced_qty) < flt(doc.qty)) && frm.doc.status != 'Stopped') {
|
||||
var finish_btn = frm.add_custom_button(__('Finish'), function() {
|
||||
erpnext.work_order.make_se(frm, 'Manufacture');
|
||||
});
|
||||
finish_btn.addClass('btn-primary');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
calculate_cost: function(doc) {
|
||||
if (doc.operations){
|
||||
|
||||
@@ -145,7 +145,7 @@ class WorkOrder(Document):
|
||||
frappe.throw(_("Sales Order {0} is {1}").format(self.sales_order, status))
|
||||
|
||||
def set_default_warehouse(self):
|
||||
if not self.wip_warehouse:
|
||||
if not self.wip_warehouse and not self.skip_transfer:
|
||||
self.wip_warehouse = frappe.db.get_single_value(
|
||||
"Manufacturing Settings", "default_wip_warehouse"
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.query_builder.functions import Floor, Sum
|
||||
from frappe.query_builder.functions import Sum
|
||||
from pypika.terms import ExistsCriterion
|
||||
|
||||
|
||||
@@ -58,9 +58,9 @@ def get_bom_stock(filters):
|
||||
bom_item.description,
|
||||
bom_item.stock_qty,
|
||||
bom_item.stock_uom,
|
||||
bom_item.stock_qty * qty_to_produce / bom.quantity,
|
||||
Sum(bin.actual_qty).as_("actual_qty"),
|
||||
Sum(Floor(bin.actual_qty / (bom_item.stock_qty * qty_to_produce / bom.quantity))),
|
||||
(bom_item.stock_qty / bom.quantity) * qty_to_produce,
|
||||
Sum(bin.actual_qty),
|
||||
Sum(bin.actual_qty) / (bom_item.stock_qty / bom.quantity),
|
||||
)
|
||||
.where((bom_item.parent == filters.get("bom")) & (bom_item.parenttype == "BOM"))
|
||||
.groupby(bom_item.item_code)
|
||||
|
||||
@@ -54,11 +54,11 @@ frappe.query_reports["Job Card Summary"] = {
|
||||
options: ["", "Open", "Work In Progress", "Completed", "On Hold"]
|
||||
},
|
||||
{
|
||||
label: __("Sales Orders"),
|
||||
fieldname: "sales_order",
|
||||
label: __("Work Orders"),
|
||||
fieldname: "work_order",
|
||||
fieldtype: "MultiSelectList",
|
||||
get_data: function(txt) {
|
||||
return frappe.db.get_link_options('Sales Order', txt);
|
||||
return frappe.db.get_link_options('Work Order', txt);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -36,10 +36,14 @@ def get_data(filters):
|
||||
"total_time_in_mins",
|
||||
]
|
||||
|
||||
for field in ["work_order", "workstation", "operation", "company"]:
|
||||
for field in ["work_order", "production_item"]:
|
||||
if filters.get(field):
|
||||
query_filters[field] = ("in", filters.get(field))
|
||||
|
||||
for field in ["workstation", "operation", "status", "company"]:
|
||||
if filters.get(field):
|
||||
query_filters[field] = filters.get(field)
|
||||
|
||||
data = frappe.get_all("Job Card", fields=fields, filters=query_filters)
|
||||
|
||||
if not data:
|
||||
|
||||
@@ -49,7 +49,7 @@ class ProductionPlanReport(object):
|
||||
parent.bom_no,
|
||||
parent.fg_warehouse.as_("warehouse"),
|
||||
)
|
||||
.where(parent.status.notin(["Completed", "Stopped"]))
|
||||
.where(parent.status.notin(["Completed", "Stopped", "Closed"]))
|
||||
)
|
||||
|
||||
if order_by == "Planned Start Date":
|
||||
@@ -79,10 +79,11 @@ class ProductionPlanReport(object):
|
||||
query = query.where(child.parent.isin(self.filters.docnames))
|
||||
|
||||
if doctype == "Sales Order":
|
||||
query = query.select(
|
||||
child.delivery_date,
|
||||
parent.base_grand_total,
|
||||
).where((child.stock_qty > child.produced_qty) & (parent.per_delivered < 100.0))
|
||||
query = query.select(child.delivery_date, parent.base_grand_total,).where(
|
||||
(child.stock_qty > child.produced_qty)
|
||||
& (parent.per_delivered < 100.0)
|
||||
& (parent.status.notin(["Completed", "Closed"]))
|
||||
)
|
||||
|
||||
if order_by == "Delivery Date":
|
||||
query = query.orderby(child.delivery_date, order=Order.asc)
|
||||
@@ -91,7 +92,9 @@ class ProductionPlanReport(object):
|
||||
|
||||
elif doctype == "Material Request":
|
||||
query = query.select(child.schedule_date,).where(
|
||||
(parent.per_ordered < 100) & (parent.material_request_type == "Manufacture")
|
||||
(parent.per_ordered < 100)
|
||||
& (parent.material_request_type == "Manufacture")
|
||||
& (parent.status != "Stopped")
|
||||
)
|
||||
|
||||
if order_by == "Required Date":
|
||||
|
||||
@@ -39,10 +39,14 @@ def get_data(filters):
|
||||
"lead_time",
|
||||
]
|
||||
|
||||
for field in ["sales_order", "production_item", "status", "company"]:
|
||||
for field in ["sales_order", "production_item"]:
|
||||
if filters.get(field):
|
||||
query_filters[field] = ("in", filters.get(field))
|
||||
|
||||
for field in ["status", "company"]:
|
||||
if filters.get(field):
|
||||
query_filters[field] = filters.get(field)
|
||||
|
||||
query_filters["planned_start_date"] = (">=", filters.get("from_date"))
|
||||
query_filters["planned_end_date"] = ("<=", filters.get("to_date"))
|
||||
|
||||
|
||||
@@ -374,3 +374,4 @@ erpnext.patches.v13_0.reset_corrupt_defaults
|
||||
erpnext.patches.v13_0.show_hr_payroll_deprecation_warning
|
||||
erpnext.patches.v13_0.create_accounting_dimensions_for_asset_repair
|
||||
execute:frappe.db.set_value("Naming Series", "Naming Series", {"select_doc_for_series": "", "set_options": "", "prefix": "", "current_value": 0, "user_must_always_select": 0})
|
||||
erpnext.patches.v13_0.update_schedule_type_in_loans
|
||||
@@ -13,8 +13,10 @@ from erpnext.payroll.doctype.salary_structure_assignment.salary_structure_assign
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc("Payroll", "doctype", "Payroll Settings")
|
||||
frappe.reload_doc("Payroll", "doctype", "Salary Structure")
|
||||
frappe.reload_doc("Payroll", "doctype", "Salary Structure Assignment")
|
||||
|
||||
frappe.db.sql(
|
||||
"""
|
||||
delete from `tabSalary Structure Assignment`
|
||||
|
||||
17
erpnext/patches/v13_0/update_schedule_type_in_loans.py
Normal file
17
erpnext/patches/v13_0/update_schedule_type_in_loans.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc("loan_management", "doctype", "loan")
|
||||
frappe.reload_doc("loan_management", "doctype", "loan_type")
|
||||
|
||||
loan = frappe.qb.DocType("Loan")
|
||||
loan_type = frappe.qb.DocType("Loan Type")
|
||||
|
||||
frappe.qb.update(loan_type).set(
|
||||
loan_type.repayment_schedule_type, "Monthly as per repayment start date"
|
||||
).where(loan_type.is_term_loan == 1).run()
|
||||
|
||||
frappe.qb.update(loan).set(
|
||||
loan.repayment_schedule_type, "Monthly as per repayment start date"
|
||||
).where(loan.is_term_loan == 1).run()
|
||||
@@ -346,6 +346,8 @@ class PayrollEntry(Document):
|
||||
"credit_in_account_currency": flt(payable_amt, precision),
|
||||
"exchange_rate": flt(exchange_rate),
|
||||
"cost_center": self.cost_center,
|
||||
"reference_type": self.doctype,
|
||||
"reference_name": self.name,
|
||||
},
|
||||
accounting_dimensions,
|
||||
)
|
||||
@@ -720,12 +722,21 @@ def get_month_details(year, month):
|
||||
|
||||
def get_payroll_entry_bank_entries(payroll_entry_name):
|
||||
journal_entries = frappe.db.sql(
|
||||
"select name from `tabJournal Entry Account` "
|
||||
'where reference_type="Payroll Entry" '
|
||||
"and reference_name=%s and docstatus=1",
|
||||
"""
|
||||
select
|
||||
je.name
|
||||
from
|
||||
`tabJournal Entry` je,
|
||||
`tabJournal Entry Account` jea
|
||||
where
|
||||
je.name = jea.parent
|
||||
and je.voucher_type = 'Bank Entry'
|
||||
and jea.reference_type = 'Payroll Entry'
|
||||
and jea.reference_name = %s
|
||||
""",
|
||||
payroll_entry_name,
|
||||
as_dict=1,
|
||||
)
|
||||
as_dict=True,
|
||||
) # nosemgrep
|
||||
|
||||
return journal_entries
|
||||
|
||||
|
||||
@@ -133,9 +133,17 @@ class TestPayrollEntry(FrappeTestCase):
|
||||
|
||||
payment_entry = frappe.db.sql(
|
||||
"""
|
||||
Select ifnull(sum(je.total_debit),0) as total_debit, ifnull(sum(je.total_credit),0) as total_credit from `tabJournal Entry` je, `tabJournal Entry Account` jea
|
||||
Where je.name = jea.parent
|
||||
And jea.reference_name = %s
|
||||
select
|
||||
ifnull(sum(je.total_debit),0) as total_debit,
|
||||
ifnull(sum(je.total_credit),0) as total_credit
|
||||
from
|
||||
`tabJournal Entry` je,
|
||||
`tabJournal Entry Account` jea
|
||||
Where
|
||||
je.name = jea.parent
|
||||
and je.voucher_type = 'Bank Entry'
|
||||
and jea.reference_type = 'Payroll Entry'
|
||||
and jea.reference_name = %s
|
||||
""",
|
||||
(payroll_entry.name),
|
||||
as_dict=1,
|
||||
@@ -295,6 +303,7 @@ class TestPayrollEntry(FrappeTestCase):
|
||||
loan_account="Loan Account - _TC",
|
||||
interest_income_account="Interest Income Account - _TC",
|
||||
penalty_income_account="Penalty Income Account - _TC",
|
||||
repayment_schedule_type="Monthly as per repayment start date",
|
||||
)
|
||||
|
||||
loan = create_loan(
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"max_working_hours_against_timesheet",
|
||||
"include_holidays_in_total_working_days",
|
||||
"disable_rounded_total",
|
||||
"define_opening_balance_for_earning_and_deductions",
|
||||
"column_break_11",
|
||||
"daily_wages_fraction_for_half_day",
|
||||
"email_salary_slip_to_employee",
|
||||
@@ -91,13 +92,20 @@
|
||||
"fieldname": "show_leave_balances_in_salary_slip",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Leave Balances in Salary Slip"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"description": "If checked, then the system will enable the provision to set the opening balance for earnings and deductions till date while creating a Salary Structure Assignment (if any)",
|
||||
"fieldname": "define_opening_balance_for_earning_and_deductions",
|
||||
"fieldtype": "Check",
|
||||
"label": "Define Opening Balance for Earning and Deductions"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-cog",
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-03-03 17:49:59.579723",
|
||||
"modified": "2022-12-21 17:30:08.704247",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Payroll",
|
||||
"name": "Payroll Settings",
|
||||
|
||||
@@ -1063,7 +1063,25 @@ class SalarySlip(TransactionBase):
|
||||
)
|
||||
exempted_amount = flt(exempted_amount[0][0]) if exempted_amount else 0
|
||||
|
||||
return taxable_earnings - exempted_amount
|
||||
opening_taxable_earning = self.get_opening_balance_for(
|
||||
"taxable_earnings_till_date", start_date, end_date
|
||||
)
|
||||
|
||||
return (taxable_earnings + opening_taxable_earning) - exempted_amount
|
||||
|
||||
def get_opening_balance_for(self, field_to_select, start_date, end_date):
|
||||
opening_balance = frappe.db.get_all(
|
||||
"Salary Structure Assignment",
|
||||
{
|
||||
"employee": self.employee,
|
||||
"salary_structure": self.salary_structure,
|
||||
"from_date": ["between", (start_date, end_date)],
|
||||
"docstatus": 1,
|
||||
},
|
||||
field_to_select,
|
||||
)
|
||||
|
||||
return opening_balance[0].get(field_to_select) if opening_balance else 0.0
|
||||
|
||||
def get_tax_paid_in_period(self, start_date, end_date, tax_component):
|
||||
# find total_tax_paid, tax paid for benefit, additional_salary
|
||||
@@ -1092,7 +1110,11 @@ class SalarySlip(TransactionBase):
|
||||
)[0][0]
|
||||
)
|
||||
|
||||
return total_tax_paid
|
||||
tax_deducted_till_date = self.get_opening_balance_for(
|
||||
"tax_deducted_till_date", start_date, end_date
|
||||
)
|
||||
|
||||
return total_tax_paid + tax_deducted_till_date
|
||||
|
||||
def get_taxable_earnings(
|
||||
self, allow_tax_exemption=False, based_on_payment_days=0, payroll_period=None
|
||||
|
||||
@@ -1030,6 +1030,104 @@ class TestSalarySlip(FrappeTestCase):
|
||||
activity_type.wage_rate = 25
|
||||
activity_type.save()
|
||||
|
||||
def test_salary_slip_generation_against_opening_entries_in_ssa(self):
|
||||
import math
|
||||
|
||||
from erpnext.payroll.doctype.payroll_period.payroll_period import get_period_factor
|
||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||
|
||||
payroll_period = frappe.db.get_value(
|
||||
"Payroll Period",
|
||||
{
|
||||
"company": "_Test Company",
|
||||
"start_date": ["<=", "2023-03-31"],
|
||||
"end_date": [">=", "2022-04-01"],
|
||||
},
|
||||
"name",
|
||||
)
|
||||
|
||||
if not payroll_period:
|
||||
payroll_period = create_payroll_period(
|
||||
name="_Test Payroll Period for Tax",
|
||||
company="_Test Company",
|
||||
start_date="2022-04-01",
|
||||
end_date="2023-03-31",
|
||||
)
|
||||
else:
|
||||
payroll_period = frappe.get_cached_doc("Payroll Period", payroll_period)
|
||||
|
||||
emp = make_employee(
|
||||
"test_employee_ss_with_opening_balance@salary.com",
|
||||
company="_Test Company",
|
||||
**{"date_of_joining": "2021-12-01"},
|
||||
)
|
||||
employee_doc = frappe.get_doc("Employee", emp)
|
||||
|
||||
create_tax_slab(payroll_period, allow_tax_exemption=True)
|
||||
|
||||
salary_structure_name = "Test Salary Structure for Opening Balance"
|
||||
if not frappe.db.exists("Salary Structure", salary_structure_name):
|
||||
salary_structure_doc = make_salary_structure(
|
||||
salary_structure_name,
|
||||
"Monthly",
|
||||
company="_Test Company",
|
||||
employee=emp,
|
||||
from_date="2022-04-01",
|
||||
payroll_period=payroll_period,
|
||||
test_tax=True,
|
||||
)
|
||||
|
||||
# validate no salary slip exists for the employee
|
||||
self.assertTrue(
|
||||
frappe.db.count(
|
||||
"Salary Slip",
|
||||
{
|
||||
"employee": emp,
|
||||
"salary_structure": salary_structure_doc.name,
|
||||
"docstatus": 1,
|
||||
"start_date": [">=", "2022-04-01"],
|
||||
},
|
||||
)
|
||||
== 0
|
||||
)
|
||||
|
||||
remaining_sub_periods = get_period_factor(
|
||||
emp,
|
||||
get_first_day("2022-10-01"),
|
||||
get_last_day("2022-10-01"),
|
||||
"Monthly",
|
||||
payroll_period,
|
||||
depends_on_payment_days=0,
|
||||
)[1]
|
||||
|
||||
prev_period = math.ceil(remaining_sub_periods)
|
||||
|
||||
annual_tax = 93036 # 89220 #data[0].get('applicable_tax')
|
||||
monthly_tax_amount = 7732.40 # 7435 #annual_tax/12
|
||||
annual_earnings = 933600 # data[0].get('ctc')
|
||||
monthly_earnings = 77800 # annual_earnings/12
|
||||
|
||||
# Get Salary Structure Assignment
|
||||
ssa = frappe.get_value(
|
||||
"Salary Structure Assignment",
|
||||
{"employee": emp, "salary_structure": salary_structure_doc.name},
|
||||
"name",
|
||||
)
|
||||
ssa_doc = frappe.get_doc("Salary Structure Assignment", ssa)
|
||||
|
||||
# Set opening balance for earning and tax deduction in Salary Structure Assignment
|
||||
ssa_doc.taxable_earnings_till_date = monthly_earnings * prev_period
|
||||
ssa_doc.tax_deducted_till_date = monthly_tax_amount * prev_period
|
||||
ssa_doc.save()
|
||||
|
||||
# Create Salary Slip
|
||||
salary_slip = make_salary_slip(
|
||||
salary_structure_doc.name, employee=employee_doc.name, posting_date=getdate("2022-10-01")
|
||||
)
|
||||
for deduction in salary_slip.deductions:
|
||||
if deduction.salary_component == "TDS":
|
||||
self.assertEqual(deduction.amount, rounded(monthly_tax_amount))
|
||||
|
||||
|
||||
def get_no_of_days():
|
||||
no_of_days_in_month = calendar.monthrange(getdate(nowdate()).year, getdate(nowdate()).month)
|
||||
|
||||
@@ -42,6 +42,13 @@ frappe.ui.form.on('Salary Structure Assignment', {
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
if(frm.doc.__onload){
|
||||
frm.unhide_earnings_and_taxation_section = frm.doc.__onload.earning_and_deduction_entries_does_not_exists;
|
||||
frm.trigger("set_earnings_and_taxation_section_visibility");
|
||||
}
|
||||
},
|
||||
|
||||
employee: function(frm) {
|
||||
if(frm.doc.employee){
|
||||
frappe.call({
|
||||
@@ -59,6 +66,8 @@ frappe.ui.form.on('Salary Structure Assignment', {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
frm.trigger("valiadte_joining_date_and_salary_slips");
|
||||
}
|
||||
else{
|
||||
frm.set_value("company", null);
|
||||
@@ -71,5 +80,33 @@ frappe.ui.form.on('Salary Structure Assignment', {
|
||||
frm.set_value("payroll_payable_account", r.default_payroll_payable_account);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
valiadte_joining_date_and_salary_slips: function(frm) {
|
||||
frappe.call({
|
||||
method: "earning_and_deduction_entries_does_not_exists",
|
||||
doc: frm.doc,
|
||||
callback: function(data) {
|
||||
let earning_and_deduction_entries_does_not_exists = data.message;
|
||||
frm.unhide_earnings_and_taxation_section = earning_and_deduction_entries_does_not_exists;
|
||||
frm.trigger("set_earnings_and_taxation_section_visibility");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
set_earnings_and_taxation_section_visibility: function(frm) {
|
||||
if(frm.unhide_earnings_and_taxation_section){
|
||||
frm.set_df_property('earnings_and_taxation_section', 'hidden', 0);
|
||||
}
|
||||
else{
|
||||
frm.set_df_property('earnings_and_taxation_section', 'hidden', 1);
|
||||
}
|
||||
},
|
||||
|
||||
from_date: function(frm) {
|
||||
if (frm.doc.from_date) {
|
||||
frm.trigger("valiadte_joining_date_and_salary_slips" );
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
@@ -22,6 +22,10 @@
|
||||
"base",
|
||||
"column_break_9",
|
||||
"variable",
|
||||
"earnings_and_taxation_section",
|
||||
"taxable_earnings_till_date",
|
||||
"column_break_18",
|
||||
"tax_deducted_till_date",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
@@ -141,11 +145,31 @@
|
||||
"fieldtype": "Link",
|
||||
"label": "Payroll Payable Account",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "earnings_and_taxation_section",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"fieldname": "tax_deducted_till_date",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Tax Deducted Till Date"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_18",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"fieldname": "taxable_earnings_till_date",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Taxable Earnings Till Date"
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-03-31 22:44:46.267974",
|
||||
"modified": "2022-12-26 12:47:42.521891",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Payroll",
|
||||
"name": "Salary Structure Assignment",
|
||||
|
||||
@@ -13,10 +13,32 @@ class DuplicateAssignment(frappe.ValidationError):
|
||||
|
||||
|
||||
class SalaryStructureAssignment(Document):
|
||||
def onload(self):
|
||||
if self.employee:
|
||||
self.set_onload(
|
||||
"earning_and_deduction_entries_exists", self.earning_and_deduction_entries_does_not_exists()
|
||||
)
|
||||
|
||||
def validate(self):
|
||||
self.validate_dates()
|
||||
self.validate_income_tax_slab()
|
||||
self.set_payroll_payable_account()
|
||||
self.valiadte_missing_taxable_earnings_and_deductions_till_date()
|
||||
|
||||
def valiadte_missing_taxable_earnings_and_deductions_till_date(self):
|
||||
if self.earning_and_deduction_entries_does_not_exists():
|
||||
if not self.taxable_earnings_till_date and not self.tax_deducted_till_date:
|
||||
frappe.msgprint(
|
||||
_(
|
||||
"""Not found any salary slip record(s) for the employee {0}.<br><br>Please specify {1} and {2} (if any), for the correct tax calculation in future salary slips."""
|
||||
).format(
|
||||
self.employee,
|
||||
"<b>" + _("Taxable Earnings Till Date") + "</b>",
|
||||
"<b>" + _("Tax Deducted Till Date") + "</b>",
|
||||
),
|
||||
indicator="orange",
|
||||
title=_("Warning"),
|
||||
)
|
||||
|
||||
def validate_dates(self):
|
||||
joining_date, relieving_date = frappe.db.get_value(
|
||||
@@ -76,6 +98,56 @@ class SalaryStructureAssignment(Document):
|
||||
)
|
||||
self.payroll_payable_account = payroll_payable_account
|
||||
|
||||
@frappe.whitelist()
|
||||
def earning_and_deduction_entries_does_not_exists(self):
|
||||
if self.enabled_settings_to_specify_earnings_and_deductions_till_date():
|
||||
if not self.joined_in_the_same_month() and not self.have_salary_slips():
|
||||
return True
|
||||
else:
|
||||
if self.docstatus in [1, 2] and (
|
||||
self.taxable_earnings_till_date or self.tax_deducted_till_date
|
||||
):
|
||||
return True
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def enabled_settings_to_specify_earnings_and_deductions_till_date(self):
|
||||
"""returns True if settings are enabled to specify earnings and deductions till date else False"""
|
||||
|
||||
if frappe.db.get_single_value(
|
||||
"Payroll Settings", "define_opening_balance_for_earning_and_deductions"
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
def have_salary_slips(self):
|
||||
"""returns True if salary structure assignment has salary slips else False"""
|
||||
|
||||
salary_slip = frappe.db.get_value(
|
||||
"Salary Slip", filters={"employee": self.employee, "docstatus": 1}
|
||||
)
|
||||
|
||||
if salary_slip:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def joined_in_the_same_month(self):
|
||||
"""returns True if employee joined in same month as salary structure assignment from date else False"""
|
||||
|
||||
date_of_joining = frappe.db.get_value("Employee", self.employee, "date_of_joining")
|
||||
from_date = getdate(self.from_date)
|
||||
|
||||
if not self.from_date or not date_of_joining:
|
||||
return False
|
||||
|
||||
elif date_of_joining.month == from_date.month:
|
||||
return True
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def get_assigned_salary_structure(employee, on_date):
|
||||
if not employee or not on_date:
|
||||
|
||||
@@ -545,6 +545,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
if(!this.validate_company_and_party()) {
|
||||
this.frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
|
||||
} else {
|
||||
item.pricing_rules = ''
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_item_details",
|
||||
child: item,
|
||||
@@ -1160,6 +1161,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
uom: function(doc, cdt, cdn) {
|
||||
var me = this;
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
item.pricing_rules = ''
|
||||
if(item.item_code && item.uom) {
|
||||
return this.frm.call({
|
||||
method: "erpnext.stock.get_item_details.get_conversion_factor",
|
||||
@@ -1236,6 +1238,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
|
||||
qty: function(doc, cdt, cdn) {
|
||||
let item = frappe.get_doc(cdt, cdn);
|
||||
item.pricing_rules = ''
|
||||
this.conversion_factor(doc, cdt, cdn, true);
|
||||
this.calculate_stock_uom_rate(doc, cdt, cdn);
|
||||
this.apply_pricing_rule(item, true);
|
||||
|
||||
@@ -242,20 +242,29 @@ erpnext.utils.set_taxes = function(frm, triggered_from_field) {
|
||||
});
|
||||
};
|
||||
|
||||
erpnext.utils.get_contact_details = function(frm) {
|
||||
erpnext.utils.get_contact_details = function (frm) {
|
||||
if (frm.updating_party_details) return;
|
||||
|
||||
if (frm.doc["contact_person"]) {
|
||||
frappe.call({
|
||||
method: "frappe.contacts.doctype.contact.contact.get_contact_details",
|
||||
args: {contact: frm.doc.contact_person },
|
||||
callback: function(r) {
|
||||
if (r.message)
|
||||
frm.set_value(r.message);
|
||||
}
|
||||
})
|
||||
args: { contact: frm.doc.contact_person },
|
||||
callback: function (r) {
|
||||
if (r.message) frm.set_value(r.message);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
frm.set_value({
|
||||
contact_person: "",
|
||||
contact_display: "",
|
||||
contact_email: "",
|
||||
contact_mobile: "",
|
||||
contact_phone: "",
|
||||
contact_designation: "",
|
||||
contact_department: "",
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
|
||||
if (!value) {
|
||||
|
||||
@@ -159,6 +159,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
.item-img {
|
||||
@extend .image;
|
||||
border-radius: 8px 8px 0 0;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
> .item-detail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -79,7 +79,7 @@ def get_children(doctype, parent=None, parent_quality_procedure=None, is_root=Fa
|
||||
]
|
||||
else:
|
||||
return frappe.get_all(
|
||||
doctype,
|
||||
"Quality Procedure",
|
||||
fields=["name as value", "is_group as expandable"],
|
||||
filters=dict(parent_quality_procedure=parent),
|
||||
order_by="name asc",
|
||||
|
||||
@@ -10,3 +10,8 @@ class EInvoiceSettings(Document):
|
||||
def validate(self):
|
||||
if self.enable and not self.credentials:
|
||||
frappe.throw(_("You must add atleast one credentials to be able to use E Invoicing."))
|
||||
|
||||
prev_doc = self.get_doc_before_save()
|
||||
if prev_doc.client_secret != self.client_secret or prev_doc.client_id != self.client_id:
|
||||
self.auth_token = None
|
||||
self.token_expiry = None
|
||||
|
||||
@@ -146,7 +146,9 @@ class ImportSupplierInvoice(Document):
|
||||
|
||||
def publish(self, title, message, count, total):
|
||||
frappe.publish_realtime(
|
||||
"import_invoice_update", {"title": title, "message": message, "count": count, "total": total}
|
||||
"import_invoice_update",
|
||||
{"title": title, "message": message, "count": count, "total": total},
|
||||
user=self.modified_by,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -47,6 +47,12 @@ erpnext.setup_auto_gst_taxation = (doctype) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
reverse_charge: function(frm) {
|
||||
if (frm.doc.reverse_charge == "Y") {
|
||||
frm.set_value('eligibility_for_itc', 'ITC on Reverse Charge');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -983,8 +983,6 @@ def validate_reverse_charge_transaction(doc, method):
|
||||
|
||||
frappe.throw(msg)
|
||||
|
||||
doc.eligibility_for_itc = "ITC on Reverse Charge"
|
||||
|
||||
|
||||
def update_itc_availed_fields(doc, method):
|
||||
country = frappe.get_cached_value("Company", doc.company, "country")
|
||||
|
||||
@@ -35,7 +35,7 @@ def _execute(filters=None):
|
||||
data = []
|
||||
added_item = []
|
||||
for d in item_list:
|
||||
if (d.parent, d.item_code) not in added_item:
|
||||
if (d.parent, d.gst_hsn_code, d.item_code) not in added_item:
|
||||
row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty]
|
||||
total_tax = 0
|
||||
tax_rate = 0
|
||||
@@ -52,7 +52,7 @@ def _execute(filters=None):
|
||||
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
|
||||
row += [item_tax.get("tax_amount", 0)]
|
||||
data.append(row)
|
||||
added_item.append((d.parent, d.item_code))
|
||||
added_item.append((d.parent, d.gst_hsn_code, d.item_code))
|
||||
if data:
|
||||
data = get_merged_data(columns, data) # merge same hsn code data
|
||||
return columns, data
|
||||
@@ -161,11 +161,9 @@ def get_items(filters):
|
||||
GROUP BY
|
||||
`tabSales Invoice Item`.parent,
|
||||
`tabSales Invoice Item`.item_code,
|
||||
`tabSales Invoice Item`.gst_hsn_code,
|
||||
`tabSales Invoice Item`.uom
|
||||
`tabSales Invoice Item`.gst_hsn_code
|
||||
ORDER BY
|
||||
`tabSales Invoice Item`.gst_hsn_code,
|
||||
`tabSales Invoice Item`.uom
|
||||
`tabSales Invoice Item`.gst_hsn_code
|
||||
""".format(
|
||||
conditions=conditions
|
||||
),
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user