mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-29 05:48:36 +00:00
Compare commits
272 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e16e751ee | ||
|
|
cff3407a4b | ||
|
|
502a262637 | ||
|
|
8f112c5967 | ||
|
|
dad7657853 | ||
|
|
ff84edcfad | ||
|
|
eff9595e34 | ||
|
|
8847e1c2bd | ||
|
|
1d5f406930 | ||
|
|
091272409e | ||
|
|
c2995f6800 | ||
|
|
39cd371fb6 | ||
|
|
8f6095d05f | ||
|
|
6b61eabf61 | ||
|
|
25112468bc | ||
|
|
d27fe6f57a | ||
|
|
e60064f6f1 | ||
|
|
e621a51225 | ||
|
|
054468a5ef | ||
|
|
546ab05eb5 | ||
|
|
8b2778b29f | ||
|
|
4418fb48a9 | ||
|
|
cfafd39543 | ||
|
|
794d005923 | ||
|
|
da19761fbd | ||
|
|
5fcda5f3ed | ||
|
|
763cf6ae10 | ||
|
|
b301be1a74 | ||
|
|
e568ab2255 | ||
|
|
61295e7d47 | ||
|
|
6af6fe8204 | ||
|
|
d0d776486e | ||
|
|
75b4a0a89c | ||
|
|
a2c86dbe01 | ||
|
|
2bf75a2c24 | ||
|
|
2b38bc191e | ||
|
|
62252170dd | ||
|
|
c55512c9d3 | ||
|
|
be2069883e | ||
|
|
e9573b0b93 | ||
|
|
1d64373c26 | ||
|
|
6df80901b9 | ||
|
|
3ef4fa51dc | ||
|
|
cce32507d9 | ||
|
|
d196956307 | ||
|
|
4db62cab3b | ||
|
|
fbf4305028 | ||
|
|
eef26fea9a | ||
|
|
043d208580 | ||
|
|
c508ef5b82 | ||
|
|
1da781f2ae | ||
|
|
e2b53884fe | ||
|
|
de46ac8b62 | ||
|
|
6219d7d9a5 | ||
|
|
eb0249310c | ||
|
|
dfb1722dc4 | ||
|
|
c13f3ba695 | ||
|
|
add635b9eb | ||
|
|
28a670434d | ||
|
|
90e8090dcc | ||
|
|
d983280de8 | ||
|
|
b3df300ea5 | ||
|
|
0a363f879d | ||
|
|
3008c7ad82 | ||
|
|
d82ab066bd | ||
|
|
df46841f82 | ||
|
|
14d197d9eb | ||
|
|
9819ed112b | ||
|
|
85f635ac4a | ||
|
|
d5982cab03 | ||
|
|
f618bf212f | ||
|
|
ddca3b5800 | ||
|
|
a8dbf981d8 | ||
|
|
b807f9318f | ||
|
|
a66129af29 | ||
|
|
ed05b4cc5c | ||
|
|
00ac931722 | ||
|
|
3365bc3ba3 | ||
|
|
11d23e1a4a | ||
|
|
07de3f4391 | ||
|
|
129457b2ce | ||
|
|
426516a1ee | ||
|
|
dae6adfe13 | ||
|
|
f5cae2d60b | ||
|
|
4e94e3726c | ||
|
|
d7bf1a179a | ||
|
|
6632f3d446 | ||
|
|
b909ec9388 | ||
|
|
ea0b76831f | ||
|
|
57c759dfcd | ||
|
|
c7f79d16e9 | ||
|
|
940cfb58a7 | ||
|
|
159d1d61b5 | ||
|
|
d8232c4503 | ||
|
|
ae72b99846 | ||
|
|
f9be364bd1 | ||
|
|
7ac55379ec | ||
|
|
aa43715de6 | ||
|
|
01af6c8762 | ||
|
|
ee9debe581 | ||
|
|
d83365734e | ||
|
|
1fb554c312 | ||
|
|
4c53af0494 | ||
|
|
e9c14e88df | ||
|
|
e6dbd06435 | ||
|
|
9d5a493609 | ||
|
|
530c0b0bd6 | ||
|
|
5193dbba9b | ||
|
|
42658f7b1c | ||
|
|
1bbeecff12 | ||
|
|
7db6ae8bda | ||
|
|
2bdd14c831 | ||
|
|
c805c7fac4 | ||
|
|
7238636766 | ||
|
|
8f1509dca1 | ||
|
|
a7f59fece3 | ||
|
|
1179514118 | ||
|
|
69259c9933 | ||
|
|
7aee6bdaf8 | ||
|
|
f11fb0e45f | ||
|
|
d17debabf7 | ||
|
|
0b565026a4 | ||
|
|
5fcf5d58f0 | ||
|
|
fac865a1b4 | ||
|
|
d3f2da0d59 | ||
|
|
f8fb58feaf | ||
|
|
9bba78f7a2 | ||
|
|
a0566c9e98 | ||
|
|
64a7e3f683 | ||
|
|
dbd2964139 | ||
|
|
dc10ef4287 | ||
|
|
3cc41cf643 | ||
|
|
582db48ca5 | ||
|
|
0452820ab0 | ||
|
|
1d58e9b91a | ||
|
|
7bbcafed8d | ||
|
|
d6511b0045 | ||
|
|
0d790a6cd5 | ||
|
|
728a8b0b7d | ||
|
|
d8cb65e440 | ||
|
|
eebd88529f | ||
|
|
1740fce6c8 | ||
|
|
a01dc0e205 | ||
|
|
1ec2cc3820 | ||
|
|
9ef7d45486 | ||
|
|
02203ca534 | ||
|
|
46f3ab1c39 | ||
|
|
4b6097914a | ||
|
|
decc27a446 | ||
|
|
2d49cc9ab2 | ||
|
|
5955b699c3 | ||
|
|
c8d8ec91c4 | ||
|
|
a857923853 | ||
|
|
4f6499836e | ||
|
|
6f1cfdb1de | ||
|
|
4d31012df2 | ||
|
|
944dacc12f | ||
|
|
9ef0e8beb7 | ||
|
|
cd930c05b8 | ||
|
|
c42aa4f89b | ||
|
|
3f4ffcc955 | ||
|
|
6f3904a20a | ||
|
|
e6acdf36e2 | ||
|
|
9ee40351c5 | ||
|
|
431e68741b | ||
|
|
f1c98df7bb | ||
|
|
1c40a61d23 | ||
|
|
fdf80a6d02 | ||
|
|
b9c123bd89 | ||
|
|
24f6f1e434 | ||
|
|
f263a7f65c | ||
|
|
d9888d5195 | ||
|
|
52b3740eb1 | ||
|
|
1cb22f9d05 | ||
|
|
507a561922 | ||
|
|
88e305f5a2 | ||
|
|
9d2e0f67d5 | ||
|
|
fd718833b1 | ||
|
|
c7c938c259 | ||
|
|
35ae839ab7 | ||
|
|
4753594a26 | ||
|
|
4e4d2cefda | ||
|
|
a04f560048 | ||
|
|
c9d8c5b419 | ||
|
|
93c1a3f8f3 | ||
|
|
926b4c7065 | ||
|
|
f29ad04eab | ||
|
|
8fa73b370a | ||
|
|
2645bf648d | ||
|
|
c01f20da00 | ||
|
|
d3f434b803 | ||
|
|
0687b035b5 | ||
|
|
04a98b2b64 | ||
|
|
eae1886043 | ||
|
|
5f295c5310 | ||
|
|
fe80d1d0e7 | ||
|
|
5e7b674ee4 | ||
|
|
4166c7ff47 | ||
|
|
0f2fb54756 | ||
|
|
9409155594 | ||
|
|
8a01a709a7 | ||
|
|
cc1f38010d | ||
|
|
f0aefa4274 | ||
|
|
cbcfe6ec36 | ||
|
|
6ff002dbe3 | ||
|
|
2f10b9c510 | ||
|
|
83b1e037cb | ||
|
|
5007abf7ae | ||
|
|
d31dd1a023 | ||
|
|
6df222a1ca | ||
|
|
265da1056d | ||
|
|
670beae048 | ||
|
|
6b2a077bec | ||
|
|
43831e9785 | ||
|
|
7187992170 | ||
|
|
f3d0a91fb3 | ||
|
|
f318a3658d | ||
|
|
8f52f14505 | ||
|
|
425dcee5bf | ||
|
|
06aded08ae | ||
|
|
c095938e69 | ||
|
|
aefde87a0c | ||
|
|
c89fe9f1ca | ||
|
|
658a7c536d | ||
|
|
94c430cc6e | ||
|
|
0e73c12add | ||
|
|
aba3d7821c | ||
|
|
05ad50f98b | ||
|
|
5200739d7b | ||
|
|
73643de612 | ||
|
|
fab49e41a6 | ||
|
|
bb00bb83f8 | ||
|
|
72d77a5e99 | ||
|
|
16112630ea | ||
|
|
dd19b95113 | ||
|
|
68eeba41c1 | ||
|
|
c77c426652 | ||
|
|
dc5faa8b71 | ||
|
|
26a36d807e | ||
|
|
432b33ac5f | ||
|
|
ca835c831b | ||
|
|
10b0da8bc8 | ||
|
|
e7fcacbe69 | ||
|
|
57c356a1cd | ||
|
|
6e7de0ac47 | ||
|
|
2277b1aff5 | ||
|
|
58c793f14e | ||
|
|
08cd08adcd | ||
|
|
35478bbf91 | ||
|
|
40481508f1 | ||
|
|
9ade0725e8 | ||
|
|
b20405dbf2 | ||
|
|
ac2402dd2a | ||
|
|
c827fc3259 | ||
|
|
f13db03c9b | ||
|
|
8ef09c0dc0 | ||
|
|
7f91f95f95 | ||
|
|
696a0892fa | ||
|
|
59aef4fc8c | ||
|
|
99cd7cf63e | ||
|
|
44082cae72 | ||
|
|
d7c50cfa7c | ||
|
|
5b1795b0a5 | ||
|
|
89d6a8f02e | ||
|
|
069262dd4d | ||
|
|
048865811c | ||
|
|
2d42904bfb | ||
|
|
0b6b73b500 | ||
|
|
0452b22aa6 | ||
|
|
edcf24afa9 | ||
|
|
e403dfe73a | ||
|
|
dffd5d9cdd |
@@ -4,7 +4,7 @@ import inspect
|
||||
import frappe
|
||||
from frappe.utils.user import is_website_user
|
||||
|
||||
__version__ = "15.92.2"
|
||||
__version__ = "15.95.0"
|
||||
|
||||
|
||||
def get_default_company(user=None):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,7 @@
|
||||
"receivable_payable_remarks_length",
|
||||
"accounts_receivable_payable_tuning_section",
|
||||
"receivable_payable_fetch_method",
|
||||
"default_ageing_range",
|
||||
"column_break_ntmi",
|
||||
"drop_ar_procedures",
|
||||
"legacy_section",
|
||||
@@ -306,7 +307,7 @@
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"description": "Learn about <a href=\"https://docs.erpnext.com/docs/v13/user/manual/en/accounts/articles/common_party_accounting#:~:text=Common%20Party%20Accounting%20in%20ERPNext,Invoice%20against%20a%20primary%20Supplier.\">Common Party</a>",
|
||||
"description": "Learn about <a href=\"https://docs.frappe.io/erpnext/user/manual/en/common_party_accounting\">Common Party</a>",
|
||||
"fieldname": "enable_common_party_accounting",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable Common Party Accounting"
|
||||
@@ -657,6 +658,12 @@
|
||||
"fieldname": "show_party_balance",
|
||||
"fieldtype": "Check",
|
||||
"label": "Show Party Balance"
|
||||
},
|
||||
{
|
||||
"default": "30, 60, 90, 120",
|
||||
"fieldname": "default_ageing_range",
|
||||
"fieldtype": "Data",
|
||||
"label": "Default Ageing Range"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@@ -664,7 +671,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2025-11-06 17:48:07.682837",
|
||||
"modified": "2025-12-26 19:46:55.093717",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
@@ -694,4 +701,4 @@
|
||||
"sort_order": "ASC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ class AccountsSettings(Document):
|
||||
check_supplier_invoice_uniqueness: DF.Check
|
||||
create_pr_in_draft_status: DF.Check
|
||||
credit_controller: DF.Link | None
|
||||
default_ageing_range: DF.Data | None
|
||||
delete_linked_ledger_entries: DF.Check
|
||||
determine_address_tax_category_from: DF.Literal["Billing Address", "Shipping Address"]
|
||||
enable_common_party_accounting: DF.Check
|
||||
|
||||
@@ -304,6 +304,7 @@ def create_payment_entry_bts(
|
||||
project=None,
|
||||
cost_center=None,
|
||||
allow_edit=None,
|
||||
company_bank_account=None,
|
||||
):
|
||||
# Create a new payment entry based on the bank transaction
|
||||
bank_transaction = frappe.db.get_values(
|
||||
@@ -345,6 +346,9 @@ def create_payment_entry_bts(
|
||||
pe.project = project
|
||||
pe.cost_center = cost_center
|
||||
|
||||
if company_bank_account:
|
||||
pe.bank_account = company_bank_account
|
||||
|
||||
pe.validate()
|
||||
|
||||
if allow_edit:
|
||||
|
||||
@@ -187,7 +187,6 @@ class GLEntry(Document):
|
||||
account_type == "Profit and Loss"
|
||||
and self.company == dimension.company
|
||||
and dimension.mandatory_for_pl
|
||||
and not dimension.disabled
|
||||
and not self.is_cancelled
|
||||
):
|
||||
if not self.get(dimension.fieldname):
|
||||
@@ -201,7 +200,6 @@ class GLEntry(Document):
|
||||
account_type == "Balance Sheet"
|
||||
and self.company == dimension.company
|
||||
and dimension.mandatory_for_bs
|
||||
and not dimension.disabled
|
||||
and not self.is_cancelled
|
||||
):
|
||||
if not self.get(dimension.fieldname):
|
||||
|
||||
@@ -20,6 +20,23 @@ frappe.ui.form.on("Journal Entry", {
|
||||
"Unreconcile Payment Entries",
|
||||
"Bank Transaction",
|
||||
];
|
||||
frm.trigger("set_queries");
|
||||
},
|
||||
|
||||
set_queries(frm) {
|
||||
frm.set_query("project", "accounts", function (doc, cdt, cdn) {
|
||||
let row = frappe.get_doc(cdt, cdn);
|
||||
let filters = {
|
||||
company: doc.company,
|
||||
};
|
||||
if (row.party_type == "Customer") {
|
||||
filters.customer = row.party;
|
||||
}
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_project_name",
|
||||
filters,
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import json
|
||||
|
||||
import frappe
|
||||
from frappe import _, msgprint, scrub
|
||||
from frappe.core.doctype.submission_queue.submission_queue import queue_submission
|
||||
from frappe.utils import comma_and, cstr, flt, fmt_money, formatdate, get_link_to_form, nowdate
|
||||
|
||||
import erpnext
|
||||
@@ -172,15 +173,16 @@ class JournalEntry(AccountsController):
|
||||
|
||||
def submit(self):
|
||||
if len(self.accounts) > 100:
|
||||
msgprint(_("The task has been enqueued as a background job."), alert=True)
|
||||
self.queue_action("submit", timeout=4600)
|
||||
queue_submission(self, "_submit")
|
||||
else:
|
||||
return self._submit()
|
||||
|
||||
def before_cancel(self):
|
||||
self.has_asset_adjustment_entry()
|
||||
|
||||
def cancel(self):
|
||||
if len(self.accounts) > 100:
|
||||
msgprint(_("The task has been enqueued as a background job."), alert=True)
|
||||
self.queue_action("cancel", timeout=4600)
|
||||
queue_submission(self, "_cancel")
|
||||
else:
|
||||
return self._cancel()
|
||||
|
||||
@@ -448,12 +450,27 @@ class JournalEntry(AccountsController):
|
||||
)
|
||||
frappe.db.set_value("Journal Entry", self.name, "inter_company_journal_entry_reference", "")
|
||||
|
||||
def unlink_asset_adjustment_entry(self):
|
||||
frappe.db.sql(
|
||||
""" update `tabAsset Value Adjustment`
|
||||
set journal_entry = null where journal_entry = %s""",
|
||||
self.name,
|
||||
def has_asset_adjustment_entry(self):
|
||||
if self.flags.get("via_asset_value_adjustment"):
|
||||
return
|
||||
|
||||
asset_value_adjustment = frappe.db.get_value(
|
||||
"Asset Value Adjustment", {"docstatus": 1, "journal_entry": self.name}, "name"
|
||||
)
|
||||
if asset_value_adjustment:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Cannot cancel this document as it is linked with the submitted Asset Value Adjustment <b>{0}</b>. Please cancel the Asset Value Adjustment to continue."
|
||||
).format(frappe.utils.get_link_to_form("Asset Value Adjustment", asset_value_adjustment))
|
||||
)
|
||||
|
||||
def unlink_asset_adjustment_entry(self):
|
||||
AssetValueAdjustment = frappe.qb.DocType("Asset Value Adjustment")
|
||||
(
|
||||
frappe.qb.update(AssetValueAdjustment)
|
||||
.set(AssetValueAdjustment.journal_entry, None)
|
||||
.where(AssetValueAdjustment.journal_entry == self.name)
|
||||
).run()
|
||||
|
||||
def validate_party(self):
|
||||
for d in self.get("accounts"):
|
||||
|
||||
@@ -435,6 +435,7 @@ frappe.ui.form.on("Payment Entry", {
|
||||
"paid_to",
|
||||
"references",
|
||||
"total_allocated_amount",
|
||||
"party_name",
|
||||
],
|
||||
function (i, field) {
|
||||
frm.set_value(field, null);
|
||||
@@ -1520,18 +1521,14 @@ frappe.ui.form.on("Payment Entry", {
|
||||
"Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"
|
||||
);
|
||||
d.row_id = "";
|
||||
} else if (
|
||||
(d.charge_type == "On Previous Row Amount" || d.charge_type == "On Previous Row Total") &&
|
||||
d.row_id
|
||||
) {
|
||||
} else if (d.charge_type == "On Previous Row Amount" || d.charge_type == "On Previous Row Total") {
|
||||
if (d.idx == 1) {
|
||||
msg = __(
|
||||
"Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"
|
||||
);
|
||||
d.charge_type = "";
|
||||
} else if (!d.row_id) {
|
||||
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
|
||||
d.row_id = "";
|
||||
d.row_id = d.idx - 1;
|
||||
} else if (d.row_id && d.row_id >= d.idx) {
|
||||
msg = __(
|
||||
"Cannot refer row number greater than or equal to current row number for this Charge type"
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
{
|
||||
"columns": 2,
|
||||
"fieldname": "total_amount",
|
||||
"fieldtype": "Float",
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Grand Total",
|
||||
"print_hide": 1,
|
||||
@@ -77,7 +77,7 @@
|
||||
{
|
||||
"columns": 2,
|
||||
"fieldname": "outstanding_amount",
|
||||
"fieldtype": "Float",
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Outstanding",
|
||||
"read_only": 1
|
||||
@@ -85,7 +85,7 @@
|
||||
{
|
||||
"columns": 2,
|
||||
"fieldname": "allocated_amount",
|
||||
"fieldtype": "Float",
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Allocated"
|
||||
},
|
||||
@@ -174,7 +174,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-25 04:32:11.040025",
|
||||
"modified": "2026-01-05 14:18:03.286224",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Entry Reference",
|
||||
|
||||
@@ -18,12 +18,12 @@ class PaymentEntryReference(Document):
|
||||
account_type: DF.Data | None
|
||||
advance_voucher_no: DF.DynamicLink | None
|
||||
advance_voucher_type: DF.Link | None
|
||||
allocated_amount: DF.Float
|
||||
allocated_amount: DF.Currency
|
||||
bill_no: DF.Data | None
|
||||
due_date: DF.Date | None
|
||||
exchange_gain_loss: DF.Currency
|
||||
exchange_rate: DF.Float
|
||||
outstanding_amount: DF.Float
|
||||
outstanding_amount: DF.Currency
|
||||
parent: DF.Data
|
||||
parentfield: DF.Data
|
||||
parenttype: DF.Data
|
||||
@@ -34,7 +34,7 @@ class PaymentEntryReference(Document):
|
||||
reconcile_effect_on: DF.Date | None
|
||||
reference_doctype: DF.Link
|
||||
reference_name: DF.DynamicLink
|
||||
total_amount: DF.Float
|
||||
total_amount: DF.Currency
|
||||
# end: auto-generated types
|
||||
|
||||
@property
|
||||
|
||||
@@ -133,7 +133,6 @@ class PaymentLedgerEntry(Document):
|
||||
account_type == "Profit and Loss"
|
||||
and self.company == dimension.company
|
||||
and dimension.mandatory_for_pl
|
||||
and not dimension.disabled
|
||||
):
|
||||
if not self.get(dimension.fieldname):
|
||||
frappe.throw(
|
||||
@@ -146,7 +145,6 @@ class PaymentLedgerEntry(Document):
|
||||
account_type == "Balance Sheet"
|
||||
and self.company == dimension.company
|
||||
and dimension.mandatory_for_bs
|
||||
and not dimension.disabled
|
||||
):
|
||||
if not self.get(dimension.fieldname):
|
||||
frappe.throw(
|
||||
|
||||
@@ -6,7 +6,7 @@ import frappe
|
||||
from frappe import _, msgprint, qb
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.meta import get_field_precision
|
||||
from frappe.query_builder import Criterion
|
||||
from frappe.query_builder import Case, Criterion
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.utils import flt, fmt_money, get_link_to_form, getdate, nowdate, today
|
||||
|
||||
@@ -393,6 +393,9 @@ class PaymentReconciliation(Document):
|
||||
inv.outstanding_amount = flt(entry.get("outstanding_amount"))
|
||||
|
||||
def get_difference_amount(self, payment_entry, invoice, allocated_amount):
|
||||
party_account_defaults = frappe.get_cached_value(
|
||||
"Account", self.receivable_payable_account, ["account_type", "account_currency"], as_dict=True
|
||||
)
|
||||
allocated_amount_precision = get_field_precision(
|
||||
frappe.get_meta("Payment Reconciliation Allocation").get_field("allocated_amount")
|
||||
)
|
||||
@@ -400,9 +403,9 @@ class PaymentReconciliation(Document):
|
||||
frappe.get_meta("Payment Reconciliation Allocation").get_field("difference_amount")
|
||||
)
|
||||
difference_amount = 0
|
||||
if frappe.get_cached_value(
|
||||
"Account", self.receivable_payable_account, "account_currency"
|
||||
) != frappe.get_cached_value("Company", self.company, "default_currency"):
|
||||
if party_account_defaults.get("account_currency") != frappe.get_cached_value(
|
||||
"Company", self.company, "default_currency"
|
||||
):
|
||||
if invoice.get("exchange_rate") and payment_entry.get("exchange_rate", 1) != invoice.get(
|
||||
"exchange_rate", 1
|
||||
):
|
||||
@@ -414,7 +417,14 @@ class PaymentReconciliation(Document):
|
||||
invoice.get("exchange_rate", 1) * flt(allocated_amount, allocated_amount_precision),
|
||||
difference_amount_precision,
|
||||
)
|
||||
difference_amount = allocated_amount_in_ref_rate - allocated_amount_in_inv_rate
|
||||
|
||||
# Added If clause to handle return Adhoc payments for account type holders ("Payable")
|
||||
if party_account_defaults.get("account_type") in ("Payable") and invoice.get(
|
||||
"invoice_type"
|
||||
) in ["Payment Entry", "Journal Entry"]:
|
||||
difference_amount = allocated_amount_in_inv_rate - allocated_amount_in_ref_rate
|
||||
else:
|
||||
difference_amount = allocated_amount_in_ref_rate - allocated_amount_in_inv_rate
|
||||
|
||||
return difference_amount
|
||||
|
||||
@@ -677,6 +687,28 @@ class PaymentReconciliation(Document):
|
||||
)
|
||||
invoice_exchange_map.update(journals_map)
|
||||
|
||||
payment_entries = [
|
||||
d.get("invoice_number") for d in invoices if d.get("invoice_type") == "Payment Entry"
|
||||
]
|
||||
payment_entries.extend(
|
||||
[d.get("reference_name") for d in payments if d.get("reference_type") == "Payment Entry"]
|
||||
)
|
||||
if payment_entries:
|
||||
pe = frappe.qb.DocType("Payment Entry")
|
||||
query = (
|
||||
frappe.qb.from_(pe)
|
||||
.select(
|
||||
pe.name,
|
||||
Case()
|
||||
.when(pe.payment_type == "Receive", pe.source_exchange_rate)
|
||||
.else_(pe.target_exchange_rate)
|
||||
.as_("exchange_rate"),
|
||||
)
|
||||
.where(pe.name.isin(payment_entries))
|
||||
)
|
||||
payment_entries = query.run(as_list=1)
|
||||
invoice_exchange_map.update(payment_entries)
|
||||
|
||||
return invoice_exchange_map
|
||||
|
||||
def validate_allocation(self):
|
||||
|
||||
@@ -2336,6 +2336,210 @@ class TestPaymentReconciliation(FrappeTestCase):
|
||||
|
||||
frappe.db.set_value("Company", self.company, default_settings)
|
||||
|
||||
def test_foreign_currency_reverse_payment_entry_against_payment_entry_for_customer(self):
|
||||
transaction_date = nowdate()
|
||||
customer = self.customer3
|
||||
amount = 1000
|
||||
exchange_rate_at_payment = 100
|
||||
exchange_rate_at_reverse_payment = 95
|
||||
|
||||
# Receive amount from customer - 1,00,000
|
||||
pe = self.create_payment_entry(amount=amount, posting_date=transaction_date, customer=customer)
|
||||
pe.payment_type = "Receive"
|
||||
pe.paid_from = self.debtors_eur
|
||||
pe.paid_from_account_currency = "EUR"
|
||||
pe.source_exchange_rate = exchange_rate_at_payment
|
||||
pe.paid_amount = amount
|
||||
pe.received_amount = exchange_rate_at_payment * amount
|
||||
pe.paid_to = self.cash
|
||||
pe.paid_to_account_currency = "INR"
|
||||
pe = pe.save().submit()
|
||||
|
||||
# Pay amount to customer - 95,000
|
||||
reverse_pe = self.create_payment_entry(
|
||||
amount=amount, posting_date=transaction_date, customer=customer
|
||||
)
|
||||
reverse_pe.payment_type = "Pay"
|
||||
reverse_pe.paid_from = self.cash
|
||||
reverse_pe.paid_from_account_currency = "INR"
|
||||
reverse_pe.target_exchange_rate = exchange_rate_at_reverse_payment
|
||||
reverse_pe.paid_amount = exchange_rate_at_reverse_payment * amount
|
||||
reverse_pe.received_amount = amount
|
||||
reverse_pe.paid_to = self.debtors_eur
|
||||
reverse_pe.paid_to_account_currency = "EUR"
|
||||
reverse_pe.save().submit()
|
||||
|
||||
# Reconcile payments
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.party = customer
|
||||
pr.receivable_payable_account = self.debtors_eur
|
||||
pr.get_unreconciled_entries()
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
self.assertEqual(len(pr.get("invoices")), 1)
|
||||
self.assertEqual(len(pr.get("payments")), 1)
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
# Check the difference_amount is a gain of 5000
|
||||
self.assertEqual(flt(pr.allocation[0].get("difference_amount")), 5000.0)
|
||||
pr.reconcile()
|
||||
|
||||
def test_foreign_currency_reverse_payment_entry_against_payment_entry_for_supplier(self):
|
||||
transaction_date = nowdate()
|
||||
self.supplier = "_Test Supplier USD"
|
||||
amount = 1000
|
||||
exchange_rate_at_payment = 100
|
||||
exchange_rate_at_reverse_payment = 95
|
||||
|
||||
# Pay amount to supplier - 1,00,000
|
||||
pe = self.create_payment_entry(amount=amount, posting_date=transaction_date)
|
||||
pe.payment_type = "Pay"
|
||||
pe.party_type = "Supplier"
|
||||
pe.party = self.supplier
|
||||
pe.paid_from = self.cash
|
||||
pe.paid_from_account_currency = "INR"
|
||||
pe.target_exchange_rate = exchange_rate_at_payment
|
||||
pe.paid_amount = exchange_rate_at_payment * amount
|
||||
pe.received_amount = amount
|
||||
pe.paid_to = self.creditors_usd
|
||||
pe.paid_to_account_currency = "USD"
|
||||
pe.save().submit()
|
||||
|
||||
# Receive amount from supplier - 95,000
|
||||
reverse_pe = self.create_payment_entry(amount=amount, posting_date=transaction_date)
|
||||
reverse_pe.payment_type = "Receive"
|
||||
reverse_pe.party_type = "Supplier"
|
||||
reverse_pe.party = self.supplier
|
||||
reverse_pe.paid_from = self.creditors_usd
|
||||
reverse_pe.paid_from_account_currency = "USD"
|
||||
reverse_pe.source_exchange_rate = exchange_rate_at_reverse_payment
|
||||
reverse_pe.paid_amount = amount
|
||||
reverse_pe.received_amount = exchange_rate_at_reverse_payment * amount
|
||||
reverse_pe.paid_to = self.cash
|
||||
reverse_pe.paid_to_account_currency = "INR"
|
||||
reverse_pe = reverse_pe.save().submit()
|
||||
|
||||
# Reconcile payments
|
||||
pr = self.create_payment_reconciliation(party_is_customer=False)
|
||||
pr.party = self.supplier
|
||||
pr.receivable_payable_account = self.creditors_usd
|
||||
pr.get_unreconciled_entries()
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
|
||||
self.assertEqual(len(pr.get("invoices")), 1)
|
||||
self.assertEqual(len(pr.get("payments")), 1)
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
# Check the difference_amount is a loss of 5000
|
||||
self.assertEqual(flt(pr.allocation[0].get("difference_amount")), -5000.0)
|
||||
pr.reconcile()
|
||||
|
||||
def test_foreign_currency_reverse_journal_entry_against_journal_entry_for_customer(self):
|
||||
transaction_date = nowdate()
|
||||
customer = self.customer3
|
||||
amount = 1000
|
||||
exchange_rate_at_payment = 95
|
||||
exchange_rate_at_reverse_payment = 100
|
||||
|
||||
# Receive amount from customer - 95,000
|
||||
je1 = self.create_journal_entry(self.cash, self.debtors_eur, amount, transaction_date)
|
||||
je1.multi_currency = 1
|
||||
je1.accounts[0].exchange_rate = 1
|
||||
je1.accounts[0].debit_in_account_currency = exchange_rate_at_payment * amount
|
||||
je1.accounts[0].debit = exchange_rate_at_payment * amount
|
||||
je1.accounts[1].party_type = "Customer"
|
||||
je1.accounts[1].party = customer
|
||||
je1.accounts[1].exchange_rate = exchange_rate_at_payment
|
||||
je1.accounts[1].credit_in_account_currency = amount
|
||||
je1.accounts[1].credit = exchange_rate_at_payment * amount
|
||||
je1.save()
|
||||
je1.submit()
|
||||
|
||||
# Pay amount to customer - 1,00,000
|
||||
je2 = self.create_journal_entry(self.debtors_eur, self.cash, amount, transaction_date)
|
||||
je2.multi_currency = 1
|
||||
je2.accounts[0].party_type = "Customer"
|
||||
je2.accounts[0].party = customer
|
||||
je2.accounts[0].exchange_rate = exchange_rate_at_reverse_payment
|
||||
je2.accounts[0].debit_in_account_currency = amount
|
||||
je2.accounts[0].debit = exchange_rate_at_reverse_payment * amount
|
||||
je2.accounts[1].exchange_rate = 1
|
||||
je2.accounts[1].credit_in_account_currency = exchange_rate_at_reverse_payment * amount
|
||||
je2.accounts[1].credit = exchange_rate_at_reverse_payment * amount
|
||||
je2.save()
|
||||
je2.submit()
|
||||
|
||||
# Reconcile payments
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.party = customer
|
||||
pr.receivable_payable_account = self.debtors_eur
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 1)
|
||||
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
# Check the difference_amount is a loss of 5000
|
||||
self.assertEqual(flt(pr.allocation[0].difference_amount), -5000.0)
|
||||
pr.reconcile()
|
||||
|
||||
def test_foreign_currency_reverse_journal_entry_against_journal_entry_for_supplier(self):
|
||||
transaction_date = nowdate()
|
||||
self.supplier = "_Test Supplier USD"
|
||||
amount = 1000
|
||||
exchange_rate_at_payment = 95
|
||||
exchange_rate_at_reverse_payment = 100
|
||||
|
||||
# Pay amount to supplier - 95,000
|
||||
je1 = self.create_journal_entry(self.creditors_usd, self.cash, amount, transaction_date)
|
||||
je1.multi_currency = 1
|
||||
je1.accounts[0].party_type = "Supplier"
|
||||
je1.accounts[0].party = self.supplier
|
||||
je1.accounts[0].exchange_rate = exchange_rate_at_payment
|
||||
je1.accounts[0].debit_in_account_currency = amount
|
||||
je1.accounts[0].debit = exchange_rate_at_payment * amount
|
||||
je1.accounts[1].exchange_rate = 1
|
||||
je1.accounts[1].credit = exchange_rate_at_payment * amount
|
||||
je1.accounts[1].credit_in_account_currency = exchange_rate_at_payment * amount
|
||||
je1.save()
|
||||
je1.submit()
|
||||
|
||||
# Receive amount from supplier - 1,00,000
|
||||
je2 = self.create_journal_entry(self.cash, self.creditors_usd, amount, transaction_date)
|
||||
je2.multi_currency = 1
|
||||
je2.accounts[0].exchange_rate = 1
|
||||
je2.accounts[0].debit = exchange_rate_at_reverse_payment * amount
|
||||
je2.accounts[0].debit_in_account_currency = exchange_rate_at_reverse_payment * amount
|
||||
je2.accounts[1].party_type = "Supplier"
|
||||
je2.accounts[1].party = self.supplier
|
||||
je2.accounts[1].exchange_rate = exchange_rate_at_reverse_payment
|
||||
je2.accounts[1].credit_in_account_currency = amount
|
||||
je2.accounts[1].credit = exchange_rate_at_reverse_payment * amount
|
||||
je2.save()
|
||||
je2.submit()
|
||||
|
||||
# Reconcile payments
|
||||
pr = self.create_payment_reconciliation()
|
||||
pr.party_type = "Supplier"
|
||||
pr.party = self.supplier
|
||||
pr.receivable_payable_account = self.creditors_usd
|
||||
pr.get_unreconciled_entries()
|
||||
|
||||
self.assertEqual(len(pr.invoices), 1)
|
||||
self.assertEqual(len(pr.payments), 1)
|
||||
|
||||
invoices = [invoice.as_dict() for invoice in pr.invoices]
|
||||
payments = [payment.as_dict() for payment in pr.payments]
|
||||
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||
|
||||
# Check the difference_amount is a gain of 5000
|
||||
self.assertEqual(flt(pr.allocation[0].difference_amount), 5000.0)
|
||||
pr.reconcile()
|
||||
|
||||
|
||||
def make_customer(customer_name, currency=None):
|
||||
if not frappe.db.exists("Customer", customer_name):
|
||||
|
||||
@@ -13,9 +13,9 @@ frappe.ui.form.on("Period Closing Voucher", {
|
||||
return {
|
||||
filters: [
|
||||
["Account", "company", "=", frm.doc.company],
|
||||
["Account", "is_group", "=", "0"],
|
||||
["Account", "is_group", "=", 0],
|
||||
["Account", "freeze_account", "=", "No"],
|
||||
["Account", "root_type", "in", "Liability, Equity"],
|
||||
["Account", "root_type", "in", ["Liability", "Equity"]],
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
@@ -481,6 +481,7 @@ class TestPOSInvoice(unittest.TestCase):
|
||||
rate=1000,
|
||||
serial_no=[serial_nos[0]],
|
||||
do_not_save=1,
|
||||
ignore_sabb_validation=True,
|
||||
)
|
||||
|
||||
pos2.append("payments", {"mode_of_payment": "Bank Draft", "amount": 1000})
|
||||
@@ -956,6 +957,7 @@ class TestPOSInvoice(unittest.TestCase):
|
||||
qty=1,
|
||||
rate=100,
|
||||
do_not_submit=True,
|
||||
ignore_sabb_validation=True,
|
||||
)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, pos_inv.submit)
|
||||
@@ -1097,6 +1099,7 @@ def create_pos_invoice(**args):
|
||||
"posting_time": pos_inv.posting_time,
|
||||
"type_of_transaction": type_of_transaction,
|
||||
"do_not_submit": True,
|
||||
"ignore_sabb_validation": args.ignore_sabb_validation,
|
||||
}
|
||||
)
|
||||
).name
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h2 class="text-center">{{ _("STATEMENTS OF ACCOUNTS") }}</h2>
|
||||
<h2 class="text-center">{{ _("GENERAL LEDGER") }}</h2>
|
||||
<div>
|
||||
{% if filters.party[0] == filters.party_name[0] %}
|
||||
<h5 style="float: left;">{{ _("Customer: ") }} <b>{{ filters.party_name[0] }}</b></h5>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_rename": 1,
|
||||
"autoname": "Prompt",
|
||||
"creation": "2020-05-22 16:46:18.712954",
|
||||
"doctype": "DocType",
|
||||
@@ -67,7 +68,7 @@
|
||||
"fieldname": "frequency",
|
||||
"fieldtype": "Select",
|
||||
"label": "Frequency",
|
||||
"options": "Weekly\nMonthly\nQuarterly"
|
||||
"options": "Daily\nWeekly\nBiweekly\nMonthly\nQuarterly"
|
||||
},
|
||||
{
|
||||
"fieldname": "company",
|
||||
@@ -401,7 +402,7 @@
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2025-08-04 18:21:12.603623",
|
||||
"modified": "2025-10-07 12:19:20.719898",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Process Statement Of Accounts",
|
||||
|
||||
@@ -8,7 +8,7 @@ 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 import add_days, add_months, add_to_date, format_date, getdate, today
|
||||
from frappe.utils.jinja import validate_template
|
||||
from frappe.utils.pdf import get_pdf
|
||||
from frappe.www.printview import get_print_style
|
||||
@@ -55,7 +55,7 @@ class ProcessStatementOfAccounts(Document):
|
||||
enable_auto_email: DF.Check
|
||||
filter_duration: DF.Int
|
||||
finance_book: DF.Link | None
|
||||
frequency: DF.Literal["Weekly", "Monthly", "Quarterly"]
|
||||
frequency: DF.Literal["Daily", "Weekly", "Biweekly", "Monthly", "Quarterly"]
|
||||
from_date: DF.Date | None
|
||||
ignore_cr_dr_notes: DF.Check
|
||||
ignore_exchange_rate_revaluation_journals: DF.Check
|
||||
@@ -529,8 +529,9 @@ def send_emails(document_name, from_scheduler=False, posting_date=None):
|
||||
|
||||
if doc.enable_auto_email and from_scheduler:
|
||||
new_to_date = getdate(posting_date or today())
|
||||
if doc.frequency == "Weekly":
|
||||
new_to_date = add_days(new_to_date, 7)
|
||||
if doc.frequency in ("Daily", "Weekly", "Biweekly"):
|
||||
frequency = {"Daily": 1, "Weekly": 7, "Biweekly": 14}
|
||||
new_to_date = add_days(new_to_date, frequency[doc.frequency])
|
||||
else:
|
||||
new_to_date = add_months(new_to_date, 1 if doc.frequency == "Monthly" else 3)
|
||||
new_from_date = add_months(new_to_date, -1 * doc.filter_duration)
|
||||
|
||||
@@ -6,228 +6,304 @@
|
||||
.print-format td {
|
||||
vertical-align:middle !important;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
<div id="header-html" class="hidden-pdf">
|
||||
{% if letter_head.content %}
|
||||
<div class="letter-head text-center">{{ letter_head.content }}</div>
|
||||
<hr style="height:2px;border-width:0;color:black;background-color:black;">
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="footer-html" class="visible-pdf">
|
||||
{% if letter_head.footer %}
|
||||
<div class="letter-head-footer">
|
||||
<hr style="border-width:0;color:black;background-color:black;padding-bottom:2px;">
|
||||
{{ letter_head.footer }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<h2 class="text-center" style="margin-top:0">{{ _(report.report_name) }}</h2>
|
||||
<h4 class="text-center">
|
||||
{{ filters.customer_name }}
|
||||
</h4>
|
||||
<h6 class="text-center">
|
||||
{% if (filters.tax_id) %}
|
||||
{{ _("Tax Id: ") }}{{ filters.tax_id }}
|
||||
{% endif %}
|
||||
</h6>
|
||||
<h5 class="text-center">
|
||||
{{ _(filters.ageing_based_on) }}
|
||||
{{ _("Until") }}
|
||||
{{ frappe.format(filters.report_date, 'Date') }}
|
||||
</h5>
|
||||
|
||||
<div class="clearfix">
|
||||
<div class="pull-left">
|
||||
{% if(filters.payment_terms) %}
|
||||
<strong>{{ _("Payment Terms") }}:</strong> {{ filters.payment_terms }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
{% if(filters.credit_limit) %}
|
||||
<strong>{{ _("Credit Limit") }}:</strong> {{ frappe.utils.fmt_money(filters.credit_limit) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% set balance_row = data.slice(-1).pop() %}
|
||||
{% for i in report.columns %}
|
||||
{% if i.fieldname == 'age' %}
|
||||
{% set elem = i %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% set start = report.columns.findIndex(elem) %}
|
||||
{% set range1 = report.columns[start].label %}
|
||||
{% set range2 = report.columns[start+1].label %}
|
||||
{% set range3 = report.columns[start+2].label %}
|
||||
{% set range4 = report.columns[start+3].label %}
|
||||
{% set range5 = report.columns[start+4].label %}
|
||||
{% set range6 = report.columns[start+5].label %}
|
||||
|
||||
{% if(balance_row) %}
|
||||
<table class="table table-bordered table-condensed">
|
||||
<caption class="text-right">(Amount in {{ data[0]["currency"] ~ "" }})</caption>
|
||||
<colgroup>
|
||||
<col style="width: 30mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
</colgroup>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ _(" ") }}</th>
|
||||
<th>{{ _(range1) }}</th>
|
||||
<th>{{ _(range2) }}</th>
|
||||
<th>{{ _(range3) }}</th>
|
||||
<th>{{ _(range4) }}</th>
|
||||
<th>{{ _(range5) }}</th>
|
||||
<th>{{ _(range6) }}</th>
|
||||
<th>{{ _("Total") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ _("Total Outstanding") }}</td>
|
||||
<td class="text-right">
|
||||
{{ format_number(balance_row["age"], null, 2) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range1"], data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range2"], data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range3"], data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range4"], data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range5"], data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(flt(balance_row["outstanding"]), data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
</tr>
|
||||
<td>{{ _("Future Payments") }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(flt(balance_row[("future_amount")]), data[data.length-1]["currency"]) }}
|
||||
</td>
|
||||
<tr class="cvs-footer">
|
||||
<th class="text-left">{{ _("Cheques Required") }}</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th class="text-right">
|
||||
{{ frappe.utils.fmt_money(flt(balance_row["outstanding"] - balance_row[("future_amount")]), data[data.length-1]["currency"]) }}</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
{% endif %}
|
||||
<div id="header-html" class="hidden-pdf">
|
||||
{% if letter_head.content %}
|
||||
<div class="letter-head text-center">{{ letter_head.content }}</div>
|
||||
<hr style="height:2px;border-width:0;color:black;background-color:black;">
|
||||
{% endif %}
|
||||
<table class="table table-bordered">
|
||||
</div>
|
||||
<div id="footer-html" class="visible-pdf">
|
||||
{% if letter_head.footer %}
|
||||
<div class="letter-head-footer">
|
||||
<hr style="border-width:0;color:black;background-color:black;padding-bottom:2px;">
|
||||
{{ letter_head.footer }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<h2 class="text-center" style="margin-top:0">{{ _("STATEMENT OF ACCOUNTS") }}</h2>
|
||||
<h4 class="text-center">
|
||||
{{ filters.customer_name }}
|
||||
</h4>
|
||||
<h6 class="text-center">
|
||||
{% if (filters.tax_id) %}
|
||||
{{ _("Tax Id: {0}").format(filters.tax_id) }}
|
||||
{% endif %}
|
||||
</h6>
|
||||
<h5 class="text-center">
|
||||
{{ _("{0} until {1}").format(
|
||||
_(filters.ageing_based_on),
|
||||
frappe.format(filters.report_date, 'Date')
|
||||
) }}
|
||||
</h5>
|
||||
|
||||
<div class="clearfix">
|
||||
<div class="pull-left">
|
||||
{% if(filters.payment_terms) %}
|
||||
<strong>{{ _("Payment Terms:") }}</strong> {{ filters.payment_terms }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
{% if(filters.credit_limit) %}
|
||||
<strong>{{ _("Credit Limit:") }}</strong> {{ frappe.utils.fmt_money(filters.credit_limit) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if(filters.show_future_payments)%}
|
||||
{% set balance_row = data[-1] %}
|
||||
|
||||
{% set ns = namespace(idx=None) %}
|
||||
{% for i in report.columns %}
|
||||
{% if i.fieldname == "age" and ns.idx is none %}
|
||||
{% set ns.idx = loop.index0 %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% set age = report.columns[ns.idx].label %}
|
||||
{% set range1 = report.columns[ns.idx+1].label %}
|
||||
{% set range2 = report.columns[ns.idx+2].label %}
|
||||
{% set range3 = report.columns[ns.idx+3].label %}
|
||||
{% set range4 = report.columns[ns.idx+4].label %}
|
||||
{% set range5 = report.columns[ns.idx+5].label %}
|
||||
|
||||
{% if(balance_row) %}
|
||||
<table class="table table-bordered table-condensed">
|
||||
<caption class="text-right">{{ _("Amount in {0}").format(data[0]["currency"] ~ "") }}</caption>
|
||||
<colgroup>
|
||||
<col style="width: 30mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
<col style="width: 18mm;">
|
||||
</colgroup>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
|
||||
<th style="width: 10%">{{ _("Date") }}</th>
|
||||
<th style="width: 4%">{{ _("Age (Days)") }}</th>
|
||||
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<th style="width: 14%">{{ _("Reference") }}</th>
|
||||
<th style="width: 10%">{{ _("Sales Person") }}</th>
|
||||
{% else %}
|
||||
<th style="width: 24%">{{ _("Reference") }}</th>
|
||||
{% endif %}
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<th style="width: 20%">
|
||||
{% if (filters.customer or filters.supplier or filters.customer_name) %}
|
||||
{{ _("Remarks") }}
|
||||
{% else %}
|
||||
{{ _("Party") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Invoiced Amount") }}</th>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Paid Amount") }}</th>
|
||||
<th style="width: 10%; text-align: right">
|
||||
{% if report.report_name == "Accounts Receivable" %}
|
||||
{{ _('Credit Note') }}
|
||||
{% else %}
|
||||
{{ _('Debit Note') }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Outstanding Amount") }}</th>
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<th style="width: 12%">{{ _("Customer LPO No.") }}</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%">{{ _("Future Payment Ref") }}</th>
|
||||
<th style="width: 10%">{{ _("Future Payment Amount") }}</th>
|
||||
<th style="width: 10%">{{ _("Remaining Balance") }}</th>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<th style="width: 40%">
|
||||
{% if (filters.customer or filters.supplier or filters.customer_name) %}
|
||||
{{ _("Remarks")}}
|
||||
{% else %}
|
||||
{{ _("Party") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
<th style="width: 15%">{{ _("Total Invoiced Amount") }}</th>
|
||||
<th style="width: 15%">{{ _("Total Paid Amount") }}</th>
|
||||
<th style="width: 15%">
|
||||
{% if report.report_name == "Accounts Receivable Summary" %}
|
||||
{{ _('Credit Note Amount') }}
|
||||
{% else %}
|
||||
{{ _('Debit Note Amount') }}
|
||||
{% endif %}
|
||||
</th>
|
||||
<th style="width: 15%">{{ _("Total Outstanding Amount") }}</th>
|
||||
{% endif %}
|
||||
<th>{{ _(" ") }}</th>
|
||||
<th>{{ _(age) }}</th>
|
||||
<th>{{ _(range1) }}</th>
|
||||
<th>{{ _(range2) }}</th>
|
||||
<th>{{ _(range3) }}</th>
|
||||
<th>{{ _(range4) }}</th>
|
||||
<th>{{ _(range5) }}</th>
|
||||
<th>{{ _("Total") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in range(data|length) %}
|
||||
<tr>
|
||||
{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
|
||||
{% if(data[i]["party"]) %}
|
||||
<td>{{ frappe.format((data[i]["posting_date"]), 'Date') }}</td>
|
||||
<td style="text-align: right">{{ data[i]["age"] }}</td>
|
||||
<td>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
{{ data[i]["voucher_type"] }}
|
||||
<br>
|
||||
{% endif %}
|
||||
{{ data[i]["voucher_no"] }}
|
||||
</td>
|
||||
<tr>
|
||||
<td>{{ _("Total Outstanding") }}</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.flt(balance_row["age"], 2) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range1"], currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range2"], currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range3"], currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range4"], currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(balance_row["range5"], currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(frappe.utils.flt(balance_row["outstanding"]), currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
</tr>
|
||||
<td>{{ _("Future Payments") }}</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td class="text-right">
|
||||
{{ frappe.utils.fmt_money(frappe.utils.flt(balance_row["future_amount"]), currency=balance_row["currency"]) }}
|
||||
</td>
|
||||
<tr class="cvs-footer">
|
||||
<th class="text-left">{{ _("Cheques Required") }}</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th class="text-right">
|
||||
{{ frappe.utils.fmt_money(frappe.utils.flt(balance_row["outstanding"] - balance_row["future_amount"]), currency=balance_row["currency"]) }}</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<td>{{ data[i]["sales_person"] }}</td>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
|
||||
<th style="width: 10%">{{ _("Date") }}</th>
|
||||
<th style="width: 4%">{{ _("Age (Days)") }}</th>
|
||||
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<th style="width: 14%">{{ _("Reference") }}</th>
|
||||
<th style="width: 10%">{{ _("Sales Person") }}</th>
|
||||
{% else %}
|
||||
<th style="width: 24%">{{ _("Reference") }}</th>
|
||||
{% endif %}
|
||||
{% if not(filters.show_future_payments) and filters.show_remarks %}
|
||||
<th style="width: 20%">
|
||||
{% if (filters.customer or filters.supplier or filters.customer_name) %}
|
||||
{{ _("Remarks") }}
|
||||
{% else %}
|
||||
{{ _("Party") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Invoiced Amount") }}</th>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Paid Amount") }}</th>
|
||||
<th style="width: 10%; text-align: right">
|
||||
{% if report.report_name == "Accounts Receivable" %}
|
||||
{{ _("Credit Note") }}
|
||||
{% else %}
|
||||
{{ _("Debit Note") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%; text-align: right">{{ _("Outstanding Amount") }}</th>
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<th style="width: 12%">{{ _("Customer LPO No.") }}</th>
|
||||
{% endif %}
|
||||
<th style="width: 10%">{{ _("Future Payment Ref") }}</th>
|
||||
<th style="width: 10%">{{ _("Future Payment Amount") }}</th>
|
||||
<th style="width: 10%">{{ _("Remaining Balance") }}</th>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<th style="width: 40%">
|
||||
{% if (filters.customer or filters.supplier or filters.customer_name) %}
|
||||
{{ _("Remarks")}}
|
||||
{% else %}
|
||||
{{ _("Party") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
<th style="width: 15%">{{ _("Total Invoiced Amount") }}</th>
|
||||
<th style="width: 15%">{{ _("Total Paid Amount") }}</th>
|
||||
<th style="width: 15%">
|
||||
{% if report.report_name == "Accounts Receivable Summary" %}
|
||||
{{ _("Credit Note Amount") }}
|
||||
{% else %}
|
||||
{{ _("Debit Note Amount") }}
|
||||
{% endif %}
|
||||
</th>
|
||||
<th style="width: 15%">{{ _("Total Outstanding Amount") }}</th>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for i in range(data|length) %}
|
||||
<tr>
|
||||
{% if(report.report_name == "Accounts Receivable" or report.report_name == "Accounts Payable") %}
|
||||
{% if(data[i]["party"]) %}
|
||||
<td>{{ frappe.format(data[i]["posting_date"], 'Date') }}</td>
|
||||
<td style="text-align: right">{{ data[i]["age"] }}</td>
|
||||
<td>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
{{ data[i]["voucher_type"] }}
|
||||
<br>
|
||||
{% endif %}
|
||||
{{ data[i]["voucher_no"] }}
|
||||
</td>
|
||||
|
||||
{% if not (filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<td>{{ data[i]["sales_person"] }}</td>
|
||||
{% endif %}
|
||||
|
||||
{% if not (filters.show_future_payments) and filters.show_remarks %}
|
||||
<td>
|
||||
{% if(not(filters.customer or filters.supplier or filters.customer_name)) %}
|
||||
{{ data[i]["party"] }}
|
||||
{% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
|
||||
<br> {{ data[i]["customer_name"] }}
|
||||
{% elif(data[i]["supplier_name"] != data[i]["party"]) %}
|
||||
<br> {{ data[i]["supplier_name"] }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<div>
|
||||
{% if data[i]["remarks"] %}
|
||||
{{ _("Remarks") }}:
|
||||
{{ data[i]["remarks"] }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<td style="text-align: right">
|
||||
{{ data[i]["po_no"] }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
<td></td>
|
||||
<td style="text-align: right"><b>{{ _("Total") }}</b></td>
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["invoiced"], data[i]["currency"]) }}</td>
|
||||
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }} </td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<td style="text-align: right">
|
||||
{{ data[i]["po_no"] }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if(data[i]["party"] or " ") %}
|
||||
{% if not(data[i]["is_total_row"]) %}
|
||||
<td>
|
||||
{% if(not(filters.customer or filters.supplier or filters.customer_name)) %}
|
||||
{% if(not(filters.customer | filters.supplier)) %}
|
||||
{{ data[i]["party"] }}
|
||||
{% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
|
||||
<br> {{ data[i]["customer_name"] }}
|
||||
@@ -235,132 +311,73 @@
|
||||
<br> {{ data[i]["supplier_name"] }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<div>
|
||||
{% if data[i]["remarks"] %}
|
||||
{{ _("Remarks") }}:
|
||||
{{ data[i]["remarks"] }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<br>{{ _("Remarks") }}:
|
||||
{{ data[i]["remarks"] }}
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<td style="text-align: right">
|
||||
{{ data[i]["po_no"] }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% if(report.report_name == "Accounts Receivable" and filters.show_sales_person) %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
<td></td>
|
||||
<td style="text-align: right"><b>{{ _("Total") }}</b></td>
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["invoiced"], data[i]["currency"]) }}</td>
|
||||
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }} </td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">
|
||||
{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
|
||||
{% if(filters.show_future_payments) %}
|
||||
{% if(report.report_name == "Accounts Receivable") %}
|
||||
<td style="text-align: right">
|
||||
{{ data[i]["po_no"] }}</td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ data[i]["future_ref"] }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["future_amount"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["remaining_balance"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if(data[i]["party"] or " ") %}
|
||||
{% if not(data[i]["is_total_row"]) %}
|
||||
<td>
|
||||
{% if(not(filters.customer | filters.supplier)) %}
|
||||
{{ data[i]["party"] }}
|
||||
{% if(data[i]["customer_name"] and data[i]["customer_name"] != data[i]["party"]) %}
|
||||
<br> {{ data[i]["customer_name"] }}
|
||||
{% elif(data[i]["supplier_name"] != data[i]["party"]) %}
|
||||
<br> {{ data[i]["supplier_name"] }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<br>{{ _("Remarks") }}:
|
||||
{{ data[i]["remarks"] }}
|
||||
</td>
|
||||
{% else %}
|
||||
<td><b>{{ _("Total") }}</b></td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
<td><b>{{ _("Total") }}</b></td>
|
||||
{% endif %}
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["invoiced"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["paid"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["credit_note"], currency=data[i]["currency"]) }}</td>
|
||||
<td style="text-align: right">{{ frappe.utils.fmt_money(data[i]["outstanding"], currency=data[i]["currency"]) }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<td></td>
|
||||
<td></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<td></td>
|
||||
<td></td>
|
||||
{% if (filters.show_future_payments) or filters.show_remarks %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% if not(filters.show_future_payments) %}
|
||||
<td></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="invoiced"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="paid"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="credit_note"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="outstanding"), currency=data[0]["currency"]) }}</b></td>
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
{% if ageing %}
|
||||
<h4 class="text-center">{{ _("Ageing Report based on ") }} {{ ageing.ageing_based_on }}
|
||||
{{ _("up to " ) }} {{ frappe.format(filters.report_date, 'Date')}}
|
||||
</h4>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 25%">0 - 30 Days</th>
|
||||
<th style="width: 25%">30 - 60 Days</th>
|
||||
<th style="width: 25%">60 - 90 Days</th>
|
||||
<th style="width: 25%">90 - 120 Days</th>
|
||||
<th style="width: 20%">Above 120 Days</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range1, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range2, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range3, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range4, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range5, currency=filters.presentation_currency) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if terms_and_conditions %}
|
||||
<div>
|
||||
{{ terms_and_conditions }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="text-right text-muted">{{ _("Printed On ") }}{{ frappe.utils.now() }}</p>
|
||||
{% else %}
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="invoiced"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="outstanding"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="future_amount"), currency=data[0]["currency"]) }}</b></td>
|
||||
<td style="text-align: right"><b>{{ frappe.utils.fmt_money(data|sum(attribute="remaining_balance"), currency=data[0]["currency"]) }}</b></td>
|
||||
{% endif %}
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
{% if ageing %}
|
||||
<h4 class="text-center">
|
||||
{{ _("Ageing Report based on {0} up to {1}").format(
|
||||
ageing.ageing_based_on,
|
||||
frappe.format(filters.report_date, "Date")
|
||||
) }}
|
||||
</h4>
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 25%">{{ _("0 - 30 Days") }}</th>
|
||||
<th style="width: 25%">{{ _("30 - 60 Days") }}</th>
|
||||
<th style="width: 25%">{{ _("60 - 90 Days") }}</th>
|
||||
<th style="width: 25%">{{ _("90 - 120 Days") }}</th>
|
||||
<th style="width: 20%">{{ _("Above 120 Days") }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range1, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range2, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range3, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range4, currency=data[0]["currency"]) }}</td>
|
||||
<td>{{ frappe.utils.fmt_money(ageing.range5, currency=filters.presentation_currency) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endif %}
|
||||
{% if terms_and_conditions %}
|
||||
<div>
|
||||
{{ terms_and_conditions }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="text-right text-muted">{{ _("Printed on {0}").format(frappe.utils.now()) }}</p>
|
||||
|
||||
@@ -115,6 +115,10 @@ class RepostAccountingLedger(Document):
|
||||
def generate_preview(self):
|
||||
from erpnext.accounts.report.general_ledger.general_ledger import get_columns as get_gl_columns
|
||||
|
||||
if not self.vouchers:
|
||||
frappe.msgprint(_("Add vouchers to generate preview."))
|
||||
return
|
||||
|
||||
gl_columns = []
|
||||
gl_data = []
|
||||
|
||||
@@ -142,6 +146,7 @@ class RepostAccountingLedger(Document):
|
||||
account_repost_doc=self.name,
|
||||
is_async=True,
|
||||
job_name=job_name,
|
||||
enqueue_after_commit=True,
|
||||
)
|
||||
frappe.msgprint(_("Repost has started in the background"))
|
||||
else:
|
||||
@@ -210,16 +215,22 @@ def start_repost(account_repost_doc=str) -> None:
|
||||
|
||||
|
||||
def get_allowed_types_from_settings(child_doc: bool = False):
|
||||
repost_docs = [
|
||||
x.document_type
|
||||
for x in frappe.db.get_all(
|
||||
"Repost Allowed Types", filters={"allowed": True}, fields=["distinct(document_type)"]
|
||||
)
|
||||
]
|
||||
# Avoid DISTINCT(...) here: Frappe applies a default ORDER BY which breaks on Postgres
|
||||
# when used with SELECT DISTINCT.
|
||||
repost_docs = frappe.db.get_all(
|
||||
"Repost Allowed Types",
|
||||
filters={"allowed": True},
|
||||
pluck="document_type",
|
||||
)
|
||||
|
||||
# De-dupe while preserving order (first occurrence wins)
|
||||
repost_docs = list(dict.fromkeys(repost_docs))
|
||||
result = repost_docs
|
||||
|
||||
if repost_docs and child_doc:
|
||||
result.extend(get_child_docs(repost_docs))
|
||||
# Keep uniqueness after extending
|
||||
result = list(dict.fromkeys(result))
|
||||
|
||||
return result
|
||||
|
||||
@@ -286,8 +297,11 @@ def get_repost_allowed_types(doctype, txt, searchfield, start, page_len, filters
|
||||
if txt:
|
||||
filters.update({"document_type": ("like", f"%{txt}%")})
|
||||
|
||||
if allowed_types := frappe.db.get_all(
|
||||
"Repost Allowed Types", filters=filters, fields=["distinct(document_type)"], as_list=1
|
||||
):
|
||||
return allowed_types
|
||||
return []
|
||||
allowed_types = frappe.db.get_all(
|
||||
"Repost Allowed Types",
|
||||
filters=filters,
|
||||
pluck="document_type",
|
||||
)
|
||||
|
||||
allowed_types = list(dict.fromkeys(allowed_types))
|
||||
return [[dt] for dt in allowed_types]
|
||||
|
||||
@@ -362,21 +362,34 @@ class SalesInvoice(SellingController):
|
||||
validate_docs_for_deferred_accounting([self.name], [])
|
||||
|
||||
def validate_fixed_asset(self):
|
||||
for d in self.get("items"):
|
||||
if d.is_fixed_asset and d.meta.get_field("asset") and d.asset:
|
||||
asset = frappe.get_doc("Asset", d.asset)
|
||||
if self.doctype == "Sales Invoice" and self.docstatus == 1:
|
||||
if self.update_stock:
|
||||
frappe.throw(_("'Update Stock' cannot be checked for fixed asset sale"))
|
||||
if self.doctype != "Sales Invoice":
|
||||
return
|
||||
|
||||
elif asset.status in ("Scrapped", "Cancelled", "Capitalized") or (
|
||||
asset.status == "Sold" and not self.is_return
|
||||
):
|
||||
frappe.throw(
|
||||
_("Row #{0}: Asset {1} cannot be submitted, it is already {2}").format(
|
||||
d.idx, d.asset, asset.status
|
||||
for d in self.get("items"):
|
||||
if d.is_fixed_asset:
|
||||
if d.asset:
|
||||
if not self.is_return:
|
||||
asset_status = frappe.db.get_value("Asset", d.asset, "status")
|
||||
if self.update_stock:
|
||||
frappe.throw(_("'Update Stock' cannot be checked for fixed asset sale"))
|
||||
|
||||
elif asset_status in ("Scrapped", "Cancelled", "Capitalized"):
|
||||
frappe.throw(
|
||||
_("Row #{0}: Asset {1} cannot be sold, it is already {2}").format(
|
||||
d.idx, d.asset, asset_status
|
||||
)
|
||||
)
|
||||
elif asset_status == "Sold" and not self.is_return:
|
||||
frappe.throw(_("Row #{0}: Asset {1} is already sold").format(d.idx, d.asset))
|
||||
elif not self.return_against:
|
||||
frappe.throw(
|
||||
_("Row #{0}: Return Against is required for returning asset").format(d.idx)
|
||||
)
|
||||
else:
|
||||
frappe.throw(
|
||||
_("Row #{0}: You must select an Asset for Item {1}.").format(d.idx, d.item_code),
|
||||
title=_("Missing Asset"),
|
||||
)
|
||||
|
||||
def validate_item_cost_centers(self):
|
||||
for item in self.items:
|
||||
@@ -465,6 +478,8 @@ class SalesInvoice(SellingController):
|
||||
self.update_stock_reservation_entries()
|
||||
self.update_stock_ledger()
|
||||
|
||||
self.process_asset_depreciation()
|
||||
|
||||
# this sequence because outstanding may get -ve
|
||||
self.make_gl_entries()
|
||||
|
||||
@@ -561,6 +576,8 @@ class SalesInvoice(SellingController):
|
||||
if self.update_stock == 1:
|
||||
self.update_stock_ledger()
|
||||
|
||||
self.process_asset_depreciation()
|
||||
|
||||
self.make_gl_entries_on_cancel()
|
||||
|
||||
if self.update_stock == 1:
|
||||
@@ -1182,6 +1199,91 @@ class SalesInvoice(SellingController):
|
||||
):
|
||||
throw(_("Delivery Note {0} is not submitted").format(d.delivery_note))
|
||||
|
||||
def process_asset_depreciation(self):
|
||||
if (self.is_return and self.docstatus == 2) or (not self.is_return and self.docstatus == 1):
|
||||
self.depreciate_asset_on_sale()
|
||||
else:
|
||||
self.restore_asset()
|
||||
|
||||
self.update_asset()
|
||||
|
||||
def depreciate_asset_on_sale(self):
|
||||
"""
|
||||
Depreciate asset on sale or cancellation of return sales invoice
|
||||
"""
|
||||
disposal_date = self.get_disposal_date()
|
||||
for d in self.get("items"):
|
||||
if d.asset:
|
||||
asset = frappe.get_doc("Asset", d.asset)
|
||||
if asset.calculate_depreciation and asset.status != "Fully Depreciated":
|
||||
depreciate_asset(asset, disposal_date, self.get_note_for_asset_sale(asset))
|
||||
|
||||
def get_note_for_asset_sale(self, asset):
|
||||
return _("This schedule was created when Asset {0} was {1} through Sales Invoice {2}.").format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
_("returned") if self.is_return else _("sold"),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
|
||||
def restore_asset(self):
|
||||
"""
|
||||
Restore asset on return or cancellation of original sales invoice
|
||||
"""
|
||||
|
||||
for d in self.get("items"):
|
||||
if d.asset:
|
||||
asset = frappe.get_cached_doc("Asset", d.asset)
|
||||
if asset.calculate_depreciation:
|
||||
posting_date = self.get_disposal_date()
|
||||
reverse_depreciation_entry_made_after_disposal(asset, posting_date)
|
||||
|
||||
note = self.get_note_for_asset_return(asset)
|
||||
reset_depreciation_schedule(asset, self.posting_date, note)
|
||||
|
||||
def get_note_for_asset_return(self, asset):
|
||||
asset_link = get_link_to_form(asset.doctype, asset.name)
|
||||
invoice_link = get_link_to_form(self.doctype, self.get("name"))
|
||||
if self.is_return:
|
||||
return _(
|
||||
"This schedule was created when Asset {0} was returned through Sales Invoice {1}."
|
||||
).format(asset_link, invoice_link)
|
||||
else:
|
||||
return _(
|
||||
"This schedule was created when Asset {0} was restored due to Sales Invoice {1} cancellation."
|
||||
).format(asset_link, invoice_link)
|
||||
|
||||
def update_asset(self):
|
||||
"""
|
||||
Update asset status, disposal date and asset activity on sale or return sales invoice
|
||||
"""
|
||||
|
||||
def _update_asset(asset, disposal_date, note, asset_status=None):
|
||||
frappe.db.set_value("Asset", d.asset, "disposal_date", disposal_date)
|
||||
add_asset_activity(asset.name, note)
|
||||
asset.set_status(asset_status)
|
||||
|
||||
disposal_date = self.get_disposal_date()
|
||||
for d in self.get("items"):
|
||||
if d.asset:
|
||||
asset = frappe.get_cached_doc("Asset", d.asset)
|
||||
|
||||
if (self.is_return and self.docstatus == 1) or (not self.is_return and self.docstatus == 2):
|
||||
note = _("Asset returned") if self.is_return else _("Asset sold")
|
||||
asset_status, disposal_date = None, None
|
||||
else:
|
||||
note = _("Asset sold") if not self.is_return else _("Return invoice of asset cancelled")
|
||||
asset_status = "Sold"
|
||||
|
||||
_update_asset(asset, disposal_date, note, asset_status)
|
||||
|
||||
def get_disposal_date(self):
|
||||
if self.is_return:
|
||||
disposal_date = frappe.db.get_value("Sales Invoice", self.return_against, "posting_date")
|
||||
else:
|
||||
disposal_date = self.posting_date
|
||||
|
||||
return disposal_date
|
||||
|
||||
def make_gl_entries(self, gl_entries=None, from_repost=False):
|
||||
from erpnext.accounts.general_ledger import make_gl_entries, make_reverse_gl_entries
|
||||
|
||||
@@ -1358,68 +1460,8 @@ class SalesInvoice(SellingController):
|
||||
if self.is_internal_transfer():
|
||||
continue
|
||||
|
||||
if item.is_fixed_asset:
|
||||
asset = self.get_asset(item)
|
||||
|
||||
if (self.docstatus == 2 and not self.is_return) or (
|
||||
self.docstatus == 1 and self.is_return
|
||||
):
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_regain(
|
||||
asset,
|
||||
item.base_net_amount,
|
||||
item.finance_book,
|
||||
self.get("doctype"),
|
||||
self.get("name"),
|
||||
self.get("posting_date"),
|
||||
)
|
||||
asset.db_set("disposal_date", None)
|
||||
add_asset_activity(asset.name, _("Asset returned"))
|
||||
asset_status = asset.get_status()
|
||||
|
||||
if asset.calculate_depreciation and not asset_status == "Fully Depreciated":
|
||||
posting_date = (
|
||||
frappe.db.get_value("Sales Invoice", self.return_against, "posting_date")
|
||||
if self.is_return
|
||||
else self.posting_date
|
||||
)
|
||||
reverse_depreciation_entry_made_after_disposal(asset, posting_date)
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was returned through Sales Invoice {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
reset_depreciation_schedule(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
else:
|
||||
if asset.calculate_depreciation:
|
||||
if not asset.status == "Fully Depreciated":
|
||||
notes = _(
|
||||
"This schedule was created when Asset {0} was sold through Sales Invoice {1}."
|
||||
).format(
|
||||
get_link_to_form(asset.doctype, asset.name),
|
||||
get_link_to_form(self.doctype, self.get("name")),
|
||||
)
|
||||
depreciate_asset(asset, self.posting_date, notes)
|
||||
asset.reload()
|
||||
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
asset,
|
||||
item.base_net_amount,
|
||||
item.finance_book,
|
||||
self.get("doctype"),
|
||||
self.get("name"),
|
||||
self.get("posting_date"),
|
||||
)
|
||||
asset.db_set("disposal_date", self.posting_date)
|
||||
add_asset_activity(asset.name, _("Asset sold"))
|
||||
|
||||
for gle in fixed_asset_gl_entries:
|
||||
gle["against"] = self.customer
|
||||
gl_entries.append(self.get_gl_dict(gle, item=item))
|
||||
|
||||
self.set_asset_status(asset)
|
||||
if item.is_fixed_asset and item.asset:
|
||||
self.get_gl_entries_for_fixed_asset(item, gl_entries)
|
||||
|
||||
else:
|
||||
income_account = (
|
||||
@@ -1455,17 +1497,31 @@ class SalesInvoice(SellingController):
|
||||
if cint(self.update_stock) and erpnext.is_perpetual_inventory_enabled(self.company):
|
||||
gl_entries += super().get_gl_entries()
|
||||
|
||||
def get_asset(self, item):
|
||||
if item.get("asset"):
|
||||
asset = frappe.get_doc("Asset", item.asset)
|
||||
def get_gl_entries_for_fixed_asset(self, item, gl_entries):
|
||||
asset = frappe.get_cached_doc("Asset", item.asset)
|
||||
|
||||
if self.is_return:
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_regain(
|
||||
asset,
|
||||
item.base_net_amount,
|
||||
item.finance_book,
|
||||
self.get("doctype"),
|
||||
self.get("name"),
|
||||
self.get("posting_date"),
|
||||
)
|
||||
else:
|
||||
frappe.throw(
|
||||
_("Row #{0}: You must select an Asset for Item {1}.").format(item.idx, item.item_name),
|
||||
title=_("Missing Asset"),
|
||||
fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(
|
||||
asset,
|
||||
item.base_net_amount,
|
||||
item.finance_book,
|
||||
self.get("doctype"),
|
||||
self.get("name"),
|
||||
self.get("posting_date"),
|
||||
)
|
||||
|
||||
self.check_finance_books(item, asset)
|
||||
return asset
|
||||
for gle in fixed_asset_gl_entries:
|
||||
gle["against"] = self.customer
|
||||
gl_entries.append(self.get_gl_dict(gle, item=item))
|
||||
|
||||
@property
|
||||
def enable_discount_accounting(self):
|
||||
|
||||
@@ -2974,6 +2974,60 @@ class TestSalesInvoice(FrappeTestCase):
|
||||
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")
|
||||
self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map)
|
||||
|
||||
def test_item_tax_template_change_with_grand_total_discount(self):
|
||||
"""
|
||||
Test that when item tax template changes due to discount on Grand Total,
|
||||
the tax calculations are consistent.
|
||||
"""
|
||||
item = create_item("Test Item With Multiple Tax Templates")
|
||||
|
||||
item.set("taxes", [])
|
||||
item.append(
|
||||
"taxes",
|
||||
{
|
||||
"item_tax_template": "_Test Account Excise Duty @ 10 - _TC",
|
||||
"minimum_net_rate": 0,
|
||||
"maximum_net_rate": 500,
|
||||
},
|
||||
)
|
||||
|
||||
item.append(
|
||||
"taxes",
|
||||
{
|
||||
"item_tax_template": "_Test Account Excise Duty @ 12 - _TC",
|
||||
"minimum_net_rate": 501,
|
||||
"maximum_net_rate": 1000,
|
||||
},
|
||||
)
|
||||
|
||||
item.save()
|
||||
|
||||
si = create_sales_invoice(item=item.name, rate=700, do_not_save=True)
|
||||
si.append(
|
||||
"taxes",
|
||||
{
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": "_Test Account Excise Duty - _TC",
|
||||
"cost_center": "_Test Cost Center - _TC",
|
||||
"description": "Excise Duty",
|
||||
"rate": 0,
|
||||
},
|
||||
)
|
||||
si.insert()
|
||||
|
||||
self.assertEqual(si.items[0].item_tax_template, "_Test Account Excise Duty @ 12 - _TC")
|
||||
|
||||
si.apply_discount_on = "Grand Total"
|
||||
si.discount_amount = 300
|
||||
si.save()
|
||||
|
||||
# Verify template changed to 10%
|
||||
self.assertEqual(si.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")
|
||||
self.assertEqual(si.taxes[0].tax_amount, 70) # 10% of 700
|
||||
self.assertEqual(si.grand_total, 470) # 700 + 70 - 300
|
||||
|
||||
si.submit()
|
||||
|
||||
@change_settings("Selling Settings", {"enable_discount_accounting": 1})
|
||||
def test_sales_invoice_with_discount_accounting_enabled(self):
|
||||
discount_account = create_account(
|
||||
|
||||
@@ -12,6 +12,7 @@ from frappe.utils import cint, flt, formatdate, get_link_to_form, getdate, now
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
get_accounting_dimensions,
|
||||
get_checks_for_pl_and_bs_accounts,
|
||||
)
|
||||
from erpnext.accounts.doctype.accounting_dimension_filter.accounting_dimension_filter import (
|
||||
get_dimension_filter_map,
|
||||
@@ -612,6 +613,18 @@ def update_accounting_dimensions(round_off_gle):
|
||||
|
||||
for dimension in dimensions:
|
||||
round_off_gle[dimension] = dimension_values.get(dimension)
|
||||
else:
|
||||
report_type = frappe.get_cached_value("Account", round_off_gle.account, "report_type")
|
||||
for dimension in get_checks_for_pl_and_bs_accounts():
|
||||
if (
|
||||
round_off_gle.company == dimension.company
|
||||
and (
|
||||
(report_type == "Profit and Loss" and dimension.mandatory_for_pl)
|
||||
or (report_type == "Balance Sheet" and dimension.mandatory_for_bs)
|
||||
)
|
||||
and dimension.default_dimension
|
||||
):
|
||||
round_off_gle[dimension.fieldname] = dimension.default_dimension
|
||||
|
||||
|
||||
def get_round_off_account_and_cost_center(company, voucher_type, voucher_no, use_company_default=False):
|
||||
|
||||
@@ -1056,3 +1056,21 @@ def add_party_account(party_type, party, company, account):
|
||||
|
||||
def render_address(address, check_permissions=True):
|
||||
return frappe.call(_render_address, address, check_permissions=check_permissions)
|
||||
|
||||
|
||||
def validate_party_currency_before_merging(party_type, old_party, new_party):
|
||||
for company in frappe.get_all("Company"):
|
||||
old_party_currency = get_party_gle_currency(party_type, old_party, company.name)
|
||||
new_party_currency = get_party_gle_currency(party_type, new_party, company.name)
|
||||
|
||||
if old_party_currency and new_party_currency and old_party_currency != new_party_currency:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Cannot merge {0} '{1}' into '{2}' as both have existing accounting entries in different currencies for company '{3}'."
|
||||
).format(
|
||||
party_type,
|
||||
old_party,
|
||||
new_party,
|
||||
company.name,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -165,6 +165,10 @@ frappe.query_reports["Accounts Payable"] = {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route("query-report", "Accounts Payable Summary", { company: filters.company });
|
||||
});
|
||||
|
||||
if (frappe.boot.sysdefaults.default_ageing_range) {
|
||||
report.set_filter_value("range", frappe.boot.sysdefaults.default_ageing_range);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -102,6 +102,11 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
||||
label: __("Revaluation Journals"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
{
|
||||
fieldname: "show_gl_balance",
|
||||
label: __("Show GL Balance"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
],
|
||||
|
||||
onload: function (report) {
|
||||
@@ -109,6 +114,10 @@ frappe.query_reports["Accounts Payable Summary"] = {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route("query-report", "Accounts Payable", { company: filters.company });
|
||||
});
|
||||
|
||||
if (frappe.boot.sysdefaults.default_ageing_range) {
|
||||
report.set_filter_value("range", frappe.boot.sysdefaults.default_ageing_range);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -192,6 +192,10 @@ frappe.query_reports["Accounts Receivable"] = {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route("query-report", "Accounts Receivable Summary", { company: filters.company });
|
||||
});
|
||||
|
||||
if (frappe.boot.sysdefaults.default_ageing_range) {
|
||||
report.set_filter_value("range", frappe.boot.sysdefaults.default_ageing_range);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -137,6 +137,10 @@ frappe.query_reports["Accounts Receivable Summary"] = {
|
||||
var filters = report.get_values();
|
||||
frappe.set_route("query-report", "Accounts Receivable", { company: filters.company });
|
||||
});
|
||||
|
||||
if (frappe.boot.sysdefaults.default_ageing_range) {
|
||||
report.set_filter_value("range", frappe.boot.sysdefaults.default_ageing_range);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class AccountsReceivableSummary(ReceivablePayableReport):
|
||||
)
|
||||
|
||||
if self.filters.show_gl_balance:
|
||||
gl_balance_map = get_gl_balance(self.filters.report_date, self.filters.company)
|
||||
gl_balance_map = get_gl_balance(self.filters.report_date, self.filters.company, self.account_type)
|
||||
|
||||
for party, party_dict in self.party_total.items():
|
||||
if flt(party_dict.outstanding, self.currency_precision) == 0:
|
||||
@@ -206,11 +206,15 @@ class AccountsReceivableSummary(ReceivablePayableReport):
|
||||
)
|
||||
|
||||
|
||||
def get_gl_balance(report_date, company):
|
||||
def get_gl_balance(report_date, company, account_type):
|
||||
if account_type == "Payable":
|
||||
balance_calc_fields = ["party", "SUM(credit - debit) AS balance"]
|
||||
else:
|
||||
balance_calc_fields = ["party", "SUM(debit - credit) AS balance"]
|
||||
return frappe._dict(
|
||||
frappe.db.get_all(
|
||||
"GL Entry",
|
||||
fields=["party", "sum(debit - credit)"],
|
||||
fields=balance_calc_fields,
|
||||
filters={"posting_date": ("<=", report_date), "is_cancelled": 0, "company": company},
|
||||
group_by="party",
|
||||
as_list=1,
|
||||
|
||||
@@ -219,13 +219,18 @@ def get_net_profit(
|
||||
|
||||
has_value = False
|
||||
|
||||
gross_income_roots = [row for row in (gross_income or []) if not flt(row.get("indent"))]
|
||||
non_gross_income_roots = [row for row in (non_gross_income or []) if not flt(row.get("indent"))]
|
||||
gross_expense_roots = [row for row in (gross_expense or []) if not flt(row.get("indent"))]
|
||||
non_gross_expense_roots = [row for row in (non_gross_expense or []) if not flt(row.get("indent"))]
|
||||
|
||||
for period in period_list:
|
||||
key = period if consolidated else period.key
|
||||
gross_income_for_period = flt(gross_income[0].get(key, 0)) if gross_income else 0
|
||||
non_gross_income_for_period = flt(non_gross_income[0].get(key, 0)) if non_gross_income else 0
|
||||
|
||||
gross_expense_for_period = flt(gross_expense[0].get(key, 0)) if gross_expense else 0
|
||||
non_gross_expense_for_period = flt(non_gross_expense[0].get(key, 0)) if non_gross_expense else 0
|
||||
gross_income_for_period = sum(flt(row.get(key, 0)) for row in gross_income_roots)
|
||||
non_gross_income_for_period = sum(flt(row.get(key, 0)) for row in non_gross_income_roots)
|
||||
gross_expense_for_period = sum(flt(row.get(key, 0)) for row in gross_expense_roots)
|
||||
non_gross_expense_for_period = sum(flt(row.get(key, 0)) for row in non_gross_expense_roots)
|
||||
|
||||
total_income = gross_income_for_period + non_gross_income_for_period
|
||||
total_expense = gross_expense_for_period + non_gross_expense_for_period
|
||||
|
||||
@@ -105,7 +105,7 @@ def _execute(filters=None, additional_table_columns=None, additional_conditions=
|
||||
{
|
||||
"total_tax": total_tax,
|
||||
"total_other_charges": total_other_charges,
|
||||
"total": d.base_net_amount + total_tax,
|
||||
"total": d.base_net_amount + total_tax + total_other_charges,
|
||||
"currency": company_currency,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -81,5 +81,11 @@ frappe.query_reports["Trial Balance for Party"] = {
|
||||
label: __("Show zero values"),
|
||||
fieldtype: "Check",
|
||||
},
|
||||
{
|
||||
fieldname: "exclude_zero_balance_parties",
|
||||
label: __("Exclude Zero Balance Parties"),
|
||||
fieldtype: "Check",
|
||||
default: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -75,20 +75,20 @@ def get_data(filters, show_party_name):
|
||||
closing_debit, closing_credit = toggle_debit_credit(opening_debit + debit, opening_credit + credit)
|
||||
row.update({"closing_debit": closing_debit, "closing_credit": closing_credit})
|
||||
|
||||
# totals
|
||||
for col in total_row:
|
||||
total_row[col] += row.get(col)
|
||||
|
||||
row.update({"currency": company_currency})
|
||||
|
||||
has_value = False
|
||||
if opening_debit or opening_credit or debit or credit or closing_debit or closing_credit:
|
||||
has_value = True
|
||||
# Exclude zero balance parties if filter is set
|
||||
if filters.get("exclude_zero_balance_parties") and not closing_debit and not closing_credit:
|
||||
continue
|
||||
|
||||
if cint(filters.show_zero_values) or has_value:
|
||||
data.append(row)
|
||||
|
||||
# Add total row
|
||||
# totals
|
||||
for col in total_row:
|
||||
total_row[col] += row.get(col)
|
||||
|
||||
total_row.update({"party": "'" + _("Totals") + "'", "currency": company_currency})
|
||||
data.append(total_row)
|
||||
|
||||
@@ -511,6 +511,7 @@ def reconcile_against_document(
|
||||
doc.make_advance_gl_entries(entry=row)
|
||||
else:
|
||||
_delete_pl_entries(voucher_type, voucher_no)
|
||||
_delete_adv_pl_entries(voucher_type, voucher_no)
|
||||
gl_map = doc.build_gl_map()
|
||||
# Make sure there is no overallocation
|
||||
from erpnext.accounts.general_ledger import process_debit_credit_difference
|
||||
|
||||
@@ -80,6 +80,12 @@ frappe.ui.form.on("Asset", {
|
||||
}
|
||||
},
|
||||
|
||||
before_submit: function (frm) {
|
||||
if (frm.doc.is_composite_asset && !frm.has_active_capitalization) {
|
||||
frappe.throw(__("Please capitalize this asset before submitting."));
|
||||
}
|
||||
},
|
||||
|
||||
refresh: function (frm) {
|
||||
frappe.ui.form.trigger("Asset", "is_existing_asset");
|
||||
frm.toggle_display("next_depreciation_date", frm.doc.docstatus < 1);
|
||||
@@ -200,9 +206,10 @@ frappe.ui.form.on("Asset", {
|
||||
asset: frm.doc.name,
|
||||
},
|
||||
callback: function (r) {
|
||||
frm.has_active_capitalization = r.message;
|
||||
|
||||
if (!r.message) {
|
||||
$(".primary-action").prop("hidden", true);
|
||||
$(".form-message").text(__("Capitalize this asset to confirm"));
|
||||
$(".form-message").text(__("Capitalize this asset before submitting."));
|
||||
|
||||
frm.add_custom_button(__("Capitalize Asset"), function () {
|
||||
frm.trigger("create_asset_capitalization");
|
||||
@@ -228,26 +235,64 @@ frappe.ui.form.on("Asset", {
|
||||
},
|
||||
|
||||
toggle_reference_doc: function (frm) {
|
||||
if (frm.doc.purchase_receipt && frm.doc.purchase_invoice && frm.doc.docstatus === 1) {
|
||||
frm.set_df_property("purchase_invoice", "read_only", 1);
|
||||
frm.set_df_property("purchase_receipt", "read_only", 1);
|
||||
} else if (frm.doc.is_existing_asset || frm.doc.is_composite_asset) {
|
||||
frm.toggle_reqd("purchase_receipt", 0);
|
||||
frm.toggle_reqd("purchase_invoice", 0);
|
||||
} else if (frm.doc.purchase_receipt) {
|
||||
// if purchase receipt link is set then set PI disabled
|
||||
frm.toggle_reqd("purchase_invoice", 0);
|
||||
frm.set_df_property("purchase_invoice", "read_only", 1);
|
||||
} else if (frm.doc.purchase_invoice) {
|
||||
// if purchase invoice link is set then set PR disabled
|
||||
frm.toggle_reqd("purchase_receipt", 0);
|
||||
frm.set_df_property("purchase_receipt", "read_only", 1);
|
||||
} else {
|
||||
frm.toggle_reqd("purchase_receipt", 1);
|
||||
frm.set_df_property("purchase_receipt", "read_only", 0);
|
||||
frm.toggle_reqd("purchase_invoice", 1);
|
||||
frm.set_df_property("purchase_invoice", "read_only", 0);
|
||||
const is_submitted = frm.doc.docstatus === 1;
|
||||
const is_special_asset = frm.doc.is_existing_asset || frm.doc.is_composite_asset;
|
||||
|
||||
const clear_field = (field) => {
|
||||
if (frm.doc[field]) {
|
||||
frm.set_value(field, "");
|
||||
}
|
||||
};
|
||||
|
||||
["purchase_receipt", "purchase_receipt_item", "purchase_invoice", "purchase_invoice_item"].forEach(
|
||||
(field) => {
|
||||
frm.toggle_reqd(field, 0);
|
||||
frm.set_df_property(field, "read_only", 0);
|
||||
}
|
||||
);
|
||||
|
||||
if (is_submitted) {
|
||||
[
|
||||
"purchase_receipt",
|
||||
"purchase_receipt_item",
|
||||
"purchase_invoice",
|
||||
"purchase_invoice_item",
|
||||
].forEach((field) => {
|
||||
frm.set_df_property(field, "read_only", 1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_special_asset) {
|
||||
clear_field("purchase_receipt");
|
||||
clear_field("purchase_receipt_item");
|
||||
clear_field("purchase_invoice");
|
||||
clear_field("purchase_invoice_item");
|
||||
return;
|
||||
}
|
||||
|
||||
if (frm.doc.purchase_receipt) {
|
||||
frm.toggle_reqd("purchase_receipt_item", 1);
|
||||
|
||||
["purchase_invoice", "purchase_invoice_item"].forEach((field) => {
|
||||
clear_field(field);
|
||||
frm.set_df_property(field, "read_only", 1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (frm.doc.purchase_invoice) {
|
||||
frm.toggle_reqd("purchase_invoice_item", 1);
|
||||
|
||||
["purchase_receipt", "purchase_receipt_item"].forEach((field) => {
|
||||
clear_field(field);
|
||||
frm.set_df_property(field, "read_only", 1);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
frm.toggle_reqd("purchase_receipt", 1);
|
||||
frm.toggle_reqd("purchase_invoice", 1);
|
||||
},
|
||||
|
||||
make_journal_entry: function (frm) {
|
||||
@@ -274,8 +319,14 @@ frappe.ui.form.on("Asset", {
|
||||
const row = [
|
||||
sch["idx"],
|
||||
frappe.format(sch["schedule_date"], { fieldtype: "Date" }),
|
||||
frappe.format(sch["depreciation_amount"], { fieldtype: "Currency" }),
|
||||
frappe.format(sch["accumulated_depreciation_amount"], { fieldtype: "Currency" }),
|
||||
frappe.format(sch["depreciation_amount"], {
|
||||
fieldtype: "Currency",
|
||||
options: "Company:company:default_currency",
|
||||
}),
|
||||
frappe.format(sch["accumulated_depreciation_amount"], {
|
||||
fieldtype: "Currency",
|
||||
options: "Company:company:default_currency",
|
||||
}),
|
||||
sch["journal_entry"] || "",
|
||||
];
|
||||
|
||||
@@ -468,11 +519,9 @@ frappe.ui.form.on("Asset", {
|
||||
is_composite_asset: function (frm) {
|
||||
if (frm.doc.is_composite_asset) {
|
||||
frm.set_value("gross_purchase_amount", 0);
|
||||
frm.set_df_property("gross_purchase_amount", "read_only", 1);
|
||||
} else {
|
||||
frm.set_df_property("gross_purchase_amount", "read_only", 0);
|
||||
}
|
||||
|
||||
frm.trigger("toggle_reference_doc");
|
||||
},
|
||||
|
||||
@@ -536,7 +585,6 @@ frappe.ui.form.on("Asset", {
|
||||
callback: function (r) {
|
||||
var doclist = frappe.model.sync(r.message);
|
||||
frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
|
||||
$(".primary-action").prop("hidden", false);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -229,7 +229,8 @@
|
||||
"fieldtype": "Currency",
|
||||
"label": "Net Purchase Amount",
|
||||
"mandatory_depends_on": "eval:(!doc.is_composite_asset || doc.docstatus==1)",
|
||||
"options": "Company:company:default_currency"
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only_depends_on": "eval: doc.is_composite_asset"
|
||||
},
|
||||
{
|
||||
"fieldname": "available_for_use_date",
|
||||
@@ -596,7 +597,7 @@
|
||||
"link_fieldname": "target_asset"
|
||||
}
|
||||
],
|
||||
"modified": "2025-11-17 18:01:51.417942",
|
||||
"modified": "2025-12-23 16:01:10.195932",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset",
|
||||
|
||||
@@ -69,7 +69,6 @@ class Asset(AccountsController):
|
||||
default_finance_book: DF.Link | None
|
||||
department: DF.Link | None
|
||||
depr_entry_posting_status: DF.Literal["", "Successful", "Failed"]
|
||||
depreciation_completed: DF.Check
|
||||
depreciation_method: DF.Literal["", "Straight Line", "Double Declining Balance", "Manual"]
|
||||
disposal_date: DF.Date | None
|
||||
finance_books: DF.Table[AssetFinanceBook]
|
||||
@@ -159,6 +158,10 @@ class Asset(AccountsController):
|
||||
self.total_asset_cost = self.gross_purchase_amount + self.additional_asset_cost
|
||||
self.status = self.get_status()
|
||||
|
||||
def before_submit(self):
|
||||
if self.is_composite_asset and not has_active_capitalization(self.name):
|
||||
frappe.throw(_("Please capitalize this asset before submitting."))
|
||||
|
||||
def on_submit(self):
|
||||
self.validate_in_use_date()
|
||||
self.make_asset_movement()
|
||||
@@ -477,6 +480,7 @@ class Asset(AccountsController):
|
||||
|
||||
def set_depreciation_rate(self):
|
||||
for d in self.get("finance_books"):
|
||||
self.validate_asset_finance_books(d)
|
||||
d.rate_of_depreciation = flt(
|
||||
self.get_depreciation_rate(d, on_validate=True), d.precision("rate_of_depreciation")
|
||||
)
|
||||
@@ -485,6 +489,10 @@ class Asset(AccountsController):
|
||||
row.expected_value_after_useful_life = flt(
|
||||
row.expected_value_after_useful_life, self.precision("gross_purchase_amount")
|
||||
)
|
||||
|
||||
if flt(row.expected_value_after_useful_life) < 0:
|
||||
frappe.throw(_("Row {0}: Expected Value After Useful Life cannot be negative").format(row.idx))
|
||||
|
||||
if flt(row.expected_value_after_useful_life) >= flt(self.gross_purchase_amount):
|
||||
frappe.throw(
|
||||
_("Row {0}: Expected Value After Useful Life must be less than Gross Purchase Amount").format(
|
||||
@@ -500,50 +508,71 @@ class Asset(AccountsController):
|
||||
title=_("Invalid Schedule"),
|
||||
)
|
||||
row.depreciation_start_date = get_last_day(self.available_for_use_date)
|
||||
self.validate_depreciation_start_date(row)
|
||||
self.validate_total_number_of_depreciations_and_frequency(row)
|
||||
|
||||
if not self.is_existing_asset:
|
||||
self.opening_accumulated_depreciation = 0
|
||||
self.opening_number_of_booked_depreciations = 0
|
||||
else:
|
||||
depreciable_amount = flt(
|
||||
flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life),
|
||||
self.precision("gross_purchase_amount"),
|
||||
)
|
||||
if flt(self.opening_accumulated_depreciation) > depreciable_amount:
|
||||
self.validate_opening_depreciation_values(row)
|
||||
|
||||
def validate_depreciation_start_date(self, row):
|
||||
if row.depreciation_start_date:
|
||||
if getdate(row.depreciation_start_date) < getdate(self.purchase_date):
|
||||
frappe.throw(
|
||||
_("Opening Accumulated Depreciation must be less than or equal to {0}").format(
|
||||
depreciable_amount
|
||||
_("Row #{0}: Next Depreciation Date cannot be before Purchase Date").format(row.idx)
|
||||
)
|
||||
|
||||
if getdate(row.depreciation_start_date) < getdate(self.available_for_use_date):
|
||||
frappe.throw(
|
||||
_("Row #{0}: Next Depreciation Date cannot be before Available-for-use Date").format(
|
||||
row.idx
|
||||
)
|
||||
)
|
||||
|
||||
if self.opening_accumulated_depreciation:
|
||||
if not self.opening_number_of_booked_depreciations:
|
||||
frappe.throw(_("Please set Opening Number of Booked Depreciations"))
|
||||
else:
|
||||
self.opening_number_of_booked_depreciations = 0
|
||||
|
||||
if flt(row.total_number_of_depreciations) <= cint(self.opening_number_of_booked_depreciations):
|
||||
frappe.throw(
|
||||
_(
|
||||
"Row {0}: Total Number of Depreciations cannot be less than or equal to Opening Number of Booked Depreciations"
|
||||
).format(row.idx),
|
||||
title=_("Invalid Schedule"),
|
||||
)
|
||||
|
||||
if row.depreciation_start_date and getdate(row.depreciation_start_date) < getdate(self.purchase_date):
|
||||
else:
|
||||
frappe.throw(
|
||||
_("Depreciation Row {0}: Next Depreciation Date cannot be before Purchase Date").format(
|
||||
row.idx
|
||||
_("Row #{0}: Depreciation Start Date is required").format(row.idx),
|
||||
title=_("Invalid Schedule"),
|
||||
)
|
||||
|
||||
def validate_total_number_of_depreciations_and_frequency(self, row):
|
||||
if row.total_number_of_depreciations <= 0:
|
||||
frappe.throw(
|
||||
_("Row #{0}: Total Number of Depreciations must be greater than zero").format(row.idx)
|
||||
)
|
||||
|
||||
if row.frequency_of_depreciation <= 0:
|
||||
frappe.throw(_("Row #{0}: Frequency of Depreciation must be greater than zero").format(row.idx))
|
||||
|
||||
def validate_opening_depreciation_values(self, row):
|
||||
row.expected_value_after_useful_life = flt(
|
||||
row.expected_value_after_useful_life, self.precision("gross_purchase_amount")
|
||||
)
|
||||
|
||||
depreciable_amount = flt(
|
||||
flt(self.gross_purchase_amount) - flt(row.expected_value_after_useful_life),
|
||||
self.precision("gross_purchase_amount"),
|
||||
)
|
||||
if flt(self.opening_accumulated_depreciation) > depreciable_amount:
|
||||
frappe.throw(
|
||||
_("Opening Accumulated Depreciation must be less than or equal to {0}").format(
|
||||
depreciable_amount
|
||||
)
|
||||
)
|
||||
|
||||
if row.depreciation_start_date and getdate(row.depreciation_start_date) < getdate(
|
||||
self.available_for_use_date
|
||||
):
|
||||
if self.opening_accumulated_depreciation:
|
||||
if not self.opening_number_of_booked_depreciations:
|
||||
frappe.throw(_("Please set Opening Number of Booked Depreciations"))
|
||||
else:
|
||||
self.opening_number_of_booked_depreciations = 0
|
||||
|
||||
if flt(row.total_number_of_depreciations) <= cint(self.opening_number_of_booked_depreciations):
|
||||
frappe.throw(
|
||||
_(
|
||||
"Depreciation Row {0}: Next Depreciation Date cannot be before Available-for-use Date"
|
||||
).format(row.idx)
|
||||
"Row {0}: Total Number of Depreciations cannot be less than or equal to Opening Number of Booked Depreciations"
|
||||
).format(row.idx),
|
||||
title=_("Invalid Schedule"),
|
||||
)
|
||||
|
||||
def set_total_booked_depreciations(self):
|
||||
|
||||
@@ -197,6 +197,13 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
|
||||
}
|
||||
}
|
||||
|
||||
serial_and_batch_bundle(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
if (cdt === "Asset Capitalization Stock Item") {
|
||||
this.get_warehouse_details(row);
|
||||
}
|
||||
}
|
||||
|
||||
asset(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
if (cdt === "Asset Capitalization Asset Item") {
|
||||
@@ -410,6 +417,7 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
|
||||
voucher_type: me.frm.doc.doctype,
|
||||
voucher_no: me.frm.doc.name,
|
||||
allow_zero_valuation: 1,
|
||||
serial_and_batch_bundle: item.serial_and_batch_bundle,
|
||||
},
|
||||
},
|
||||
callback: function (r) {
|
||||
|
||||
@@ -177,6 +177,7 @@
|
||||
"default": "1",
|
||||
"fieldname": "target_qty",
|
||||
"fieldtype": "Float",
|
||||
"hidden": 1,
|
||||
"label": "Target Qty"
|
||||
},
|
||||
{
|
||||
@@ -290,10 +291,10 @@
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"label": "Project",
|
||||
"options": "Project"
|
||||
"fieldname": "project",
|
||||
"fieldtype": "Link",
|
||||
"label": "Project",
|
||||
"options": "Project"
|
||||
},
|
||||
{
|
||||
"fieldname": "dimension_col_break",
|
||||
@@ -324,7 +325,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-01-08 13:14:33.008458",
|
||||
"modified": "2026-01-13 17:25:01.352568",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Capitalization",
|
||||
@@ -362,10 +363,11 @@
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"title_field": "title",
|
||||
"track_changes": 1,
|
||||
"track_seen": 1
|
||||
}
|
||||
}
|
||||
@@ -76,6 +76,7 @@ class AssetCapitalization(StockController):
|
||||
naming_series: DF.Literal["ACC-ASC-.YYYY.-"]
|
||||
posting_date: DF.Date
|
||||
posting_time: DF.Time
|
||||
project: DF.Link | None
|
||||
service_items: DF.Table[AssetCapitalizationServiceItem]
|
||||
service_items_total: DF.Currency
|
||||
set_posting_time: DF.Check
|
||||
@@ -363,6 +364,7 @@ class AssetCapitalization(StockController):
|
||||
"voucher_no": self.name,
|
||||
"company": self.company,
|
||||
"allow_zero_valuation": cint(item.get("allow_zero_valuation_rate")),
|
||||
"serial_and_batch_bundle": item.serial_and_batch_bundle,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -763,6 +765,7 @@ def get_consumed_stock_item_details(args):
|
||||
"company": args.company,
|
||||
"serial_no": args.serial_no,
|
||||
"batch_no": args.batch_no,
|
||||
"serial_and_batch_bundle": args.serial_and_batch_bundle,
|
||||
}
|
||||
)
|
||||
out.update(get_warehouse_details(incoming_rate_args))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"actions": [],
|
||||
"allow_import": 1,
|
||||
"autoname": "naming_series:",
|
||||
"creation": "2017-10-23 11:38:54.004355",
|
||||
"doctype": "DocType",
|
||||
@@ -250,7 +251,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-11-17 18:35:54.575265",
|
||||
"modified": "2026-01-06 15:48:13.862505",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Assets",
|
||||
"name": "Asset Repair",
|
||||
@@ -264,6 +265,7 @@
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"import": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
@@ -279,6 +281,7 @@
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 1,
|
||||
"import": 1,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
@@ -295,4 +298,4 @@
|
||||
"title_field": "asset_name",
|
||||
"track_changes": 1,
|
||||
"track_seen": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class AssetValueAdjustment(Document):
|
||||
)
|
||||
|
||||
def on_cancel(self):
|
||||
frappe.get_doc("Journal Entry", self.journal_entry).cancel()
|
||||
self.cancel_asset_revaluation_entry()
|
||||
self.update_asset()
|
||||
add_asset_activity(
|
||||
self.asset,
|
||||
@@ -159,6 +159,16 @@ class AssetValueAdjustment(Document):
|
||||
|
||||
self.db_set("journal_entry", je.name)
|
||||
|
||||
def cancel_asset_revaluation_entry(self):
|
||||
if not self.journal_entry:
|
||||
return
|
||||
|
||||
revaluation_entry = frappe.get_doc("Journal Entry", self.journal_entry)
|
||||
if revaluation_entry.docstatus == 1:
|
||||
revaluation_entry.flags.ignore_permissions = True
|
||||
revaluation_entry.flags.via_asset_value_adjustment = True
|
||||
revaluation_entry.cancel()
|
||||
|
||||
def update_asset(self, asset_value=None):
|
||||
difference_amount = self.difference_amount if self.docstatus == 1 else -1 * self.difference_amount
|
||||
asset = self.update_asset_value_after_depreciation(difference_amount)
|
||||
|
||||
@@ -794,7 +794,7 @@ def make_purchase_invoice(source_name, target_doc=None, args=None):
|
||||
@frappe.whitelist()
|
||||
def make_purchase_invoice_from_portal(purchase_order_name):
|
||||
doc = get_mapped_purchase_invoice(purchase_order_name, ignore_permissions=True)
|
||||
if doc.contact_email != frappe.session.user:
|
||||
if frappe.session.user not in frappe.get_all("Portal User", {"parent": doc.supplier}, pluck="user"):
|
||||
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
||||
doc.save()
|
||||
frappe.db.commit()
|
||||
|
||||
@@ -1297,6 +1297,55 @@ class TestPurchaseOrder(FrappeTestCase):
|
||||
pi = make_pi_from_po(po.name)
|
||||
self.assertEqual(pi.items[0].qty, 50)
|
||||
|
||||
def test_multiple_advances_against_purchase_order_are_allocated_across_partial_purchase_invoices(self):
|
||||
# step - 1: create PO
|
||||
po = create_purchase_order(qty=10, rate=10)
|
||||
|
||||
# step - 2: create first partial advance payment
|
||||
pe1 = get_payment_entry("Purchase Order", po.name, bank_account="_Test Bank - _TC")
|
||||
pe1.reference_no = "1"
|
||||
pe1.reference_date = nowdate()
|
||||
pe1.paid_amount = 50
|
||||
pe1.references[0].allocated_amount = 50
|
||||
pe1.save(ignore_permissions=True).submit()
|
||||
|
||||
# check first advance paid against PO
|
||||
po.reload()
|
||||
self.assertEqual(po.advance_paid, 50)
|
||||
|
||||
# step - 3: create first PI for partial qty and allocate first advance
|
||||
pi_1 = make_pi_from_po(po.name)
|
||||
pi_1.update_stock = 1
|
||||
pi_1.allocate_advances_automatically = 1
|
||||
pi_1.items[0].qty = 5
|
||||
pi_1.save(ignore_permissions=True).submit()
|
||||
|
||||
# step - 4: create second advance payment for remaining
|
||||
pe2 = get_payment_entry("Purchase Order", po.name, bank_account="_Test Bank - _TC")
|
||||
pe2.reference_no = "2"
|
||||
pe2.reference_date = nowdate()
|
||||
pe2.paid_amount = 50
|
||||
pe2.references[0].allocated_amount = 50
|
||||
pe2.save(ignore_permissions=True).submit()
|
||||
|
||||
# check second advance paid against PO
|
||||
po.reload()
|
||||
self.assertEqual(po.advance_paid, 100)
|
||||
|
||||
# step - 5: create second PI for remaining qty and allocate second advance
|
||||
pi_2 = make_pi_from_po(po.name)
|
||||
pi_2.update_stock = 1
|
||||
pi_2.allocate_advances_automatically = 1
|
||||
pi_2.save(ignore_permissions=True).submit()
|
||||
|
||||
# check PO and PI status
|
||||
po.reload()
|
||||
pi_1.reload()
|
||||
pi_2.reload()
|
||||
self.assertEqual(pi_1.status, "Paid")
|
||||
self.assertEqual(pi_2.status, "Paid")
|
||||
self.assertEqual(po.status, "Completed")
|
||||
|
||||
|
||||
def create_po_for_sc_testing():
|
||||
from erpnext.controllers.tests.test_subcontracting_controller import (
|
||||
|
||||
@@ -34,15 +34,6 @@ frappe.ui.form.on("Request for Quotation", {
|
||||
});
|
||||
},
|
||||
|
||||
onload: function (frm) {
|
||||
if (!frm.doc.message_for_supplier) {
|
||||
frm.set_value(
|
||||
"message_for_supplier",
|
||||
__("Please supply the specified items at the best possible rates")
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
refresh: function (frm, cdt, cdn) {
|
||||
if (frm.doc.docstatus === 1) {
|
||||
frm.add_custom_button(
|
||||
@@ -248,6 +239,25 @@ frappe.ui.form.on("Request for Quotation", {
|
||||
}
|
||||
refresh_field("items");
|
||||
},
|
||||
|
||||
email_template(frm) {
|
||||
if (frm.doc.email_template) {
|
||||
frappe.db
|
||||
.get_value("Email Template", frm.doc.email_template, [
|
||||
"use_html",
|
||||
"response",
|
||||
"response_html",
|
||||
"subject",
|
||||
])
|
||||
.then((r) => {
|
||||
frm.set_value(
|
||||
"message_for_supplier",
|
||||
r.message.use_html ? r.message.response_html : r.message.response
|
||||
);
|
||||
frm.set_value("subject", r.message.subject);
|
||||
});
|
||||
}
|
||||
},
|
||||
preview: (frm) => {
|
||||
let dialog = new frappe.ui.Dialog({
|
||||
title: __("Preview Email"),
|
||||
@@ -555,7 +565,10 @@ erpnext.buying.RequestforQuotationController = class RequestforQuotationControll
|
||||
doctype: "Supplier",
|
||||
order_by: "name",
|
||||
fields: ["name"],
|
||||
filters: [["Supplier", "supplier_group", "=", args.supplier_group]],
|
||||
filters: [
|
||||
["Supplier", "supplier_group", "=", args.supplier_group],
|
||||
["disabled", "=", 0],
|
||||
],
|
||||
},
|
||||
callback: load_suppliers,
|
||||
});
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
"send_attached_files",
|
||||
"send_document_print",
|
||||
"sec_break_email_2",
|
||||
"subject",
|
||||
"message_for_supplier",
|
||||
"terms_section_break",
|
||||
"incoterm",
|
||||
@@ -126,6 +127,7 @@
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.suppliers.some((item) => item.send_email) && !(doc.docstatus == 1 && !doc.email_template)",
|
||||
"fieldname": "supplier_response_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Email Details"
|
||||
@@ -139,8 +141,7 @@
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"fetch_from": "email_template.response",
|
||||
"fetch_if_empty": 1,
|
||||
"default": "Please supply the specified items at the best possible rates",
|
||||
"fieldname": "message_for_supplier",
|
||||
"fieldtype": "Text Editor",
|
||||
"in_list_view": 1,
|
||||
@@ -251,7 +252,7 @@
|
||||
"label": "Preview Email"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:!doc.__islocal",
|
||||
"depends_on": "eval:doc.suppliers.some((item) => item.send_email)",
|
||||
"fieldname": "sec_break_email_2",
|
||||
"fieldtype": "Section Break",
|
||||
"hide_border": 1
|
||||
@@ -315,6 +316,14 @@
|
||||
"hidden": 1,
|
||||
"label": "Has Unit Price Items",
|
||||
"no_copy": 1
|
||||
},
|
||||
{
|
||||
"default": "Request for Quotation",
|
||||
"fieldname": "subject",
|
||||
"fieldtype": "Data",
|
||||
"label": "Subject",
|
||||
"not_nullable": 1,
|
||||
"reqd": 1
|
||||
}
|
||||
],
|
||||
"grid_page_length": 50,
|
||||
@@ -322,7 +331,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-03-03 16:48:39.856779",
|
||||
"modified": "2026-01-05 14:27:33.329810",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation",
|
||||
@@ -393,4 +402,4 @@
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"states": []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ class RequestforQuotation(BuyingController):
|
||||
send_attached_files: DF.Check
|
||||
send_document_print: DF.Check
|
||||
status: DF.Literal["", "Draft", "Submitted", "Cancelled"]
|
||||
subject: DF.Data
|
||||
suppliers: DF.Table[RequestforQuotationSupplier]
|
||||
tc_name: DF.Link | None
|
||||
terms: DF.TextEditor | None
|
||||
@@ -66,6 +67,7 @@ class RequestforQuotation(BuyingController):
|
||||
def before_validate(self):
|
||||
self.set_has_unit_price_items()
|
||||
self.flags.allow_zero_qty = self.has_unit_price_items
|
||||
self.set_data_for_supplier()
|
||||
|
||||
def validate(self):
|
||||
self.validate_duplicate_supplier()
|
||||
@@ -90,6 +92,19 @@ class RequestforQuotation(BuyingController):
|
||||
not row.qty for row in self.get("items") if (row.item_code and not row.qty)
|
||||
)
|
||||
|
||||
def set_data_for_supplier(self):
|
||||
if self.email_template:
|
||||
data = frappe.get_value(
|
||||
"Email Template",
|
||||
self.email_template,
|
||||
["use_html", "response", "response_html", "subject"],
|
||||
as_dict=True,
|
||||
)
|
||||
if not self.message_for_supplier:
|
||||
self.message_for_supplier = data.response_html if data.use_html else data.response
|
||||
if not self.subject:
|
||||
self.subject = data.subject
|
||||
|
||||
def validate_duplicate_supplier(self):
|
||||
supplier_list = [d.supplier for d in self.suppliers]
|
||||
if len(supplier_list) != len(set(supplier_list)):
|
||||
@@ -283,12 +298,6 @@ class RequestforQuotation(BuyingController):
|
||||
}
|
||||
)
|
||||
|
||||
if not self.email_template:
|
||||
return
|
||||
|
||||
email_template = frappe.get_doc("Email Template", self.email_template)
|
||||
message = frappe.render_template(email_template.response_, doc_args)
|
||||
subject = frappe.render_template(email_template.subject, doc_args)
|
||||
fixed_procurement_email = frappe.db.get_single_value("Buying Settings", "fixed_email")
|
||||
if fixed_procurement_email:
|
||||
sender = frappe.db.get_value("Email Account", fixed_procurement_email, "email_id")
|
||||
@@ -296,7 +305,12 @@ class RequestforQuotation(BuyingController):
|
||||
sender = frappe.session.user not in STANDARD_USERS and frappe.session.user or None
|
||||
|
||||
if preview:
|
||||
return {"message": message, "subject": subject}
|
||||
return {
|
||||
"message": self.message_for_supplier,
|
||||
"subject": self.subject
|
||||
or frappe.get_value("Email Template", self.email_template, "subject")
|
||||
or _("Request for Quotation"),
|
||||
}
|
||||
|
||||
attachments = []
|
||||
if self.send_attached_files:
|
||||
@@ -316,7 +330,15 @@ class RequestforQuotation(BuyingController):
|
||||
)
|
||||
)
|
||||
|
||||
self.send_email(data, sender, subject, message, attachments)
|
||||
self.send_email(
|
||||
data,
|
||||
sender,
|
||||
self.subject
|
||||
or frappe.get_value("Email Template", self.email_template, "subject")
|
||||
or _("Request for Quotation"),
|
||||
self.message_for_supplier,
|
||||
attachments,
|
||||
)
|
||||
|
||||
def send_email(self, data, sender, subject, message, attachments):
|
||||
make(
|
||||
|
||||
@@ -80,20 +80,21 @@
|
||||
"fieldname": "email_id",
|
||||
"fieldtype": "Data",
|
||||
"in_list_view": 1,
|
||||
"label": "Email Id",
|
||||
"label": "Email ID",
|
||||
"no_copy": 1
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2020-11-04 22:01:43.832942",
|
||||
"modified": "2026-01-05 14:08:27.274538",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Request for Quotation Supplier",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"row_format": "Dynamic",
|
||||
"sort_field": "creation",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_
|
||||
from erpnext.accounts.party import (
|
||||
get_dashboard_info,
|
||||
validate_party_accounts,
|
||||
validate_party_currency_before_merging,
|
||||
)
|
||||
from erpnext.controllers.website_list_for_contact import add_role_for_portal_user
|
||||
from erpnext.utilities.transaction_base import TransactionBase
|
||||
@@ -208,6 +209,10 @@ class Supplier(TransactionBase):
|
||||
|
||||
delete_contact_and_address("Supplier", self.name)
|
||||
|
||||
def before_rename(self, olddn, newdn, merge=False):
|
||||
if merge:
|
||||
validate_party_currency_before_merging("Supplier", olddn, newdn)
|
||||
|
||||
def after_rename(self, olddn, newdn, merge=False):
|
||||
if frappe.defaults.get_global_default("supp_master_name") == "Supplier Name":
|
||||
self.db_set("supplier_name", newdn)
|
||||
|
||||
9
erpnext/change_log/v15/v15_94_2.md
Normal file
9
erpnext/change_log/v15/v15_94_2.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Version 16 Released!
|
||||
|
||||
ERPNext version 16 has been released!
|
||||
|
||||
Since it's the latest version of ERPNext, we recommend that you update to it to get the latest features, bug fixes and other improvements.
|
||||
|
||||
[Click here to know more about v16](https://frappe.io/erpnext/version-16)
|
||||
|
||||
If you're on [Frappe Cloud](https://frappe.io/cloud), [click here to learn how to update to v16](https://docs.frappe.io/cloud/sites/version-upgrade)
|
||||
@@ -184,9 +184,8 @@ class AccountsController(TransactionBase):
|
||||
|
||||
msg = ""
|
||||
if self.get("update_outstanding_for_self"):
|
||||
msg = (
|
||||
"We can see {0} is made against {1}. If you want {1}'s outstanding to be updated, "
|
||||
"uncheck '{2}' checkbox. <br><br>Or"
|
||||
msg = _(
|
||||
"We can see {0} is made against {1}. If you want {1}'s outstanding to be updated, uncheck the '{2}' checkbox."
|
||||
).format(
|
||||
frappe.bold(document_type),
|
||||
get_link_to_form(self.doctype, self.get("return_against")),
|
||||
@@ -197,8 +196,8 @@ class AccountsController(TransactionBase):
|
||||
abs(flt(self.rounded_total) or flt(self.grand_total)) > flt(against_voucher_outstanding)
|
||||
):
|
||||
self.update_outstanding_for_self = 1
|
||||
msg = (
|
||||
"The outstanding amount {} in {} is lesser than {}. Updating the outstanding to this invoice. <br><br>And"
|
||||
msg = _(
|
||||
"The outstanding amount {0} in {1} is lesser than {2}. Updating the outstanding to this invoice."
|
||||
).format(
|
||||
against_voucher_outstanding,
|
||||
get_link_to_form(self.doctype, self.get("return_against")),
|
||||
@@ -206,11 +205,11 @@ class AccountsController(TransactionBase):
|
||||
)
|
||||
|
||||
if msg:
|
||||
msg += " you can use {} tool to reconcile against {} later.".format(
|
||||
msg += "<br><br>" + _("You can use {0} to reconcile against {1} later.").format(
|
||||
get_link_to_form("Payment Reconciliation", "Payment Reconciliation"),
|
||||
get_link_to_form(self.doctype, self.get("return_against")),
|
||||
)
|
||||
frappe.msgprint(_(msg))
|
||||
frappe.msgprint(msg)
|
||||
|
||||
def validate(self):
|
||||
if not self.get("is_return") and not self.get("is_debit_note"):
|
||||
@@ -3714,9 +3713,9 @@ def validate_child_on_delete(row, parent):
|
||||
)
|
||||
if flt(row.ordered_qty):
|
||||
frappe.throw(
|
||||
_("Row #{0}: Cannot delete item {1} which is assigned to customer's purchase order.").format(
|
||||
row.idx, row.item_code
|
||||
)
|
||||
_(
|
||||
"Row #{0}: Cannot delete item {1} which is already ordered against this Sales Order."
|
||||
).format(row.idx, row.item_code)
|
||||
)
|
||||
|
||||
if parent.doctype == "Purchase Order" and flt(row.received_qty):
|
||||
|
||||
@@ -1004,10 +1004,19 @@ class SellingController(StockController):
|
||||
|
||||
|
||||
def set_default_income_account_for_item(obj):
|
||||
for d in obj.get("items"):
|
||||
if d.item_code:
|
||||
if getattr(d, "income_account", None):
|
||||
set_item_default(d.item_code, obj.company, "income_account", d.income_account)
|
||||
"""Set income account as default for items in the transaction.
|
||||
|
||||
Updates the item default income account for each item in the transaction
|
||||
if it differs from the company's default income account.
|
||||
|
||||
Args:
|
||||
obj: Transaction document containing items table with income_account field
|
||||
"""
|
||||
company_default = frappe.get_cached_value("Company", obj.company, "default_income_account")
|
||||
for d in obj.get("items", default=[]):
|
||||
income_account = getattr(d, "income_account", None)
|
||||
if d.item_code and income_account and income_account != company_default:
|
||||
set_item_default(d.item_code, obj.company, "income_account", income_account)
|
||||
|
||||
|
||||
def get_serial_and_batch_bundle(child, parent, delivery_note_child=None):
|
||||
|
||||
@@ -46,17 +46,23 @@ class calculate_taxes_and_totals:
|
||||
items = list(filter(lambda item: not item.get("is_alternative"), self.doc.get("items")))
|
||||
return items
|
||||
|
||||
def calculate(self):
|
||||
def calculate(self, ignore_tax_template_validation=False):
|
||||
if not len(self.doc.items):
|
||||
return
|
||||
|
||||
self.discount_amount_applied = False
|
||||
self.need_recomputation = False
|
||||
self.ignore_tax_template_validation = ignore_tax_template_validation
|
||||
|
||||
self._calculate()
|
||||
|
||||
if self.doc.meta.get_field("discount_amount"):
|
||||
self.set_discount_amount()
|
||||
self.apply_discount_amount()
|
||||
|
||||
if not ignore_tax_template_validation and self.need_recomputation:
|
||||
return self.calculate(ignore_tax_template_validation=True)
|
||||
|
||||
# Update grand total as per cash and non trade discount
|
||||
if self.doc.apply_discount_on == "Grand Total" and self.doc.get("is_cash_or_non_trade_discount"):
|
||||
self.doc.grand_total -= self.doc.discount_amount
|
||||
@@ -100,6 +106,9 @@ class calculate_taxes_and_totals:
|
||||
self.doc.base_tax_withholding_net_total = sum_base_net_amount
|
||||
|
||||
def validate_item_tax_template(self):
|
||||
if self.ignore_tax_template_validation:
|
||||
return
|
||||
|
||||
if self.doc.get("is_return") and self.doc.get("return_against"):
|
||||
return
|
||||
|
||||
@@ -141,6 +150,10 @@ class calculate_taxes_and_totals:
|
||||
)
|
||||
)
|
||||
|
||||
# For correct tax_amount calculation re-computation is required
|
||||
if self.discount_amount_applied and self.doc.apply_discount_on == "Grand Total":
|
||||
self.need_recomputation = True
|
||||
|
||||
def update_item_tax_map(self):
|
||||
for item in self.doc.items:
|
||||
item.item_tax_rate = get_item_tax_map(
|
||||
|
||||
@@ -778,9 +778,8 @@ class TestSubcontractingController(FrappeTestCase):
|
||||
row.serial_no = "ABC"
|
||||
break
|
||||
|
||||
bundle.save()
|
||||
self.assertRaises(frappe.ValidationError, bundle.save)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, scr1.save)
|
||||
bundle.load_from_db()
|
||||
for row in bundle.entries:
|
||||
if row.idx == 1:
|
||||
|
||||
@@ -559,6 +559,7 @@ accounting_dimension_doctypes = [
|
||||
"Payment Request",
|
||||
"Asset Movement Item",
|
||||
"Asset Depreciation Schedule",
|
||||
"Advance Taxes and Charges",
|
||||
]
|
||||
|
||||
get_matching_queries = (
|
||||
|
||||
@@ -369,6 +369,15 @@ class ProductionPlan(Document):
|
||||
|
||||
pi = frappe.qb.DocType("Packed Item")
|
||||
|
||||
pending_qty = (
|
||||
frappe.qb.terms.Case()
|
||||
.when(
|
||||
(so_item.work_order_qty > so_item.delivered_qty),
|
||||
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty),
|
||||
)
|
||||
.else_(((so_item.qty - so_item.delivered_qty) * pi.qty) / so_item.qty)
|
||||
)
|
||||
|
||||
packed_items_query = (
|
||||
frappe.qb.from_(so_item)
|
||||
.from_(pi)
|
||||
@@ -376,7 +385,7 @@ class ProductionPlan(Document):
|
||||
pi.parent,
|
||||
pi.item_code,
|
||||
pi.warehouse.as_("warehouse"),
|
||||
(((so_item.qty - so_item.work_order_qty) * pi.qty) / so_item.qty).as_("pending_qty"),
|
||||
pending_qty.as_("pending_qty"),
|
||||
pi.parent_item,
|
||||
pi.description,
|
||||
so_item.name,
|
||||
@@ -387,7 +396,16 @@ class ProductionPlan(Document):
|
||||
& (so_item.docstatus == 1)
|
||||
& (pi.parent_item == so_item.item_code)
|
||||
& (so_item.parent.isin(so_list))
|
||||
& (so_item.qty > so_item.work_order_qty)
|
||||
& (
|
||||
(
|
||||
(so_item.work_order_qty > so_item.delivered_qty)
|
||||
& (so_item.qty > so_item.work_order_qty)
|
||||
)
|
||||
| (
|
||||
(so_item.work_order_qty <= so_item.delivered_qty)
|
||||
& (so_item.qty > so_item.delivered_qty)
|
||||
)
|
||||
)
|
||||
& (
|
||||
ExistsCriterion(
|
||||
frappe.qb.from_(bom)
|
||||
@@ -1303,14 +1321,21 @@ def get_material_request_items(
|
||||
include_safety_stock,
|
||||
warehouse,
|
||||
bin_dict,
|
||||
consumed_qty,
|
||||
):
|
||||
total_qty = row["qty"]
|
||||
|
||||
required_qty = 0
|
||||
item_code = row.get("item_code")
|
||||
|
||||
if ignore_existing_ordered_qty or bin_dict.get("projected_qty", 0) < 0:
|
||||
required_qty = total_qty
|
||||
elif total_qty > bin_dict.get("projected_qty", 0):
|
||||
required_qty = total_qty - bin_dict.get("projected_qty", 0)
|
||||
required_qty = flt(row.get("qty"))
|
||||
else:
|
||||
key = (item_code, warehouse)
|
||||
available_qty = flt(bin_dict.get("projected_qty", 0)) - consumed_qty[key]
|
||||
if available_qty > 0:
|
||||
required_qty = max(0, flt(row.get("qty")) - available_qty)
|
||||
consumed_qty[key] += min(flt(row.get("qty")), available_qty)
|
||||
else:
|
||||
required_qty = flt(row.get("qty"))
|
||||
|
||||
if doc.get("consider_minimum_order_qty") and required_qty > 0 and required_qty < row["min_order_qty"]:
|
||||
required_qty = row["min_order_qty"]
|
||||
@@ -1354,7 +1379,7 @@ def get_material_request_items(
|
||||
"item_name": row.item_name,
|
||||
"quantity": required_qty / conversion_factor,
|
||||
"conversion_factor": conversion_factor,
|
||||
"required_bom_qty": total_qty,
|
||||
"required_bom_qty": row.get("qty"),
|
||||
"stock_uom": row.get("stock_uom"),
|
||||
"warehouse": warehouse
|
||||
or row.get("source_warehouse")
|
||||
@@ -1648,9 +1673,12 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
|
||||
so_item_details[sales_order][item_code] = details
|
||||
|
||||
mr_items = []
|
||||
consumed_qty = defaultdict(float)
|
||||
|
||||
for sales_order in so_item_details:
|
||||
item_dict = so_item_details[sales_order]
|
||||
for details in item_dict.values():
|
||||
warehouse = warehouse or details.get("source_warehouse") or details.get("default_warehouse")
|
||||
bin_dict = get_bin_details(details, doc.company, warehouse)
|
||||
bin_dict = bin_dict[0] if bin_dict else {}
|
||||
|
||||
@@ -1664,6 +1692,7 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
|
||||
include_safety_stock,
|
||||
warehouse,
|
||||
bin_dict,
|
||||
consumed_qty,
|
||||
)
|
||||
if items:
|
||||
mr_items.append(items)
|
||||
|
||||
@@ -145,6 +145,84 @@ class TestProductionPlan(FrappeTestCase):
|
||||
sr2.cancel()
|
||||
pln.cancel()
|
||||
|
||||
def test_projected_qty_cascading_across_multiple_sales_orders(self):
|
||||
rm_item = make_item(
|
||||
"_Test RM For Cascading",
|
||||
{"is_stock_item": 1, "valuation_rate": 100},
|
||||
).name
|
||||
|
||||
fg_item_a = make_item(
|
||||
"_Test FG A For Cascading",
|
||||
{"is_stock_item": 1, "valuation_rate": 200},
|
||||
).name
|
||||
|
||||
if not frappe.db.exists("BOM", {"item": fg_item_a, "docstatus": 1}):
|
||||
make_bom(item=fg_item_a, raw_materials=[rm_item], rm_qty=1)
|
||||
|
||||
# Stock for RM
|
||||
sr = create_stock_reconciliation(item_code=rm_item, target="_Test Warehouse - _TC", qty=1, rate=100)
|
||||
|
||||
# Sales orders
|
||||
so1 = make_sales_order(item_code=fg_item_a, qty=1)
|
||||
so2 = make_sales_order(item_code=fg_item_a, qty=1)
|
||||
so3 = make_sales_order(item_code=fg_item_a, qty=1)
|
||||
|
||||
# Production plan
|
||||
pln = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Production Plan",
|
||||
"company": "_Test Company",
|
||||
"posting_date": nowdate(),
|
||||
"get_items_from": "Sales Order",
|
||||
"ignore_existing_ordered_qty": 0,
|
||||
}
|
||||
)
|
||||
pln.append(
|
||||
"sales_orders",
|
||||
{
|
||||
"sales_order": so1.name,
|
||||
"sales_order_date": so1.transaction_date,
|
||||
"customer": so1.customer,
|
||||
"grand_total": so1.grand_total,
|
||||
},
|
||||
)
|
||||
pln.append(
|
||||
"sales_orders",
|
||||
{
|
||||
"sales_order": so2.name,
|
||||
"sales_order_date": so2.transaction_date,
|
||||
"customer": so2.customer,
|
||||
"grand_total": so2.grand_total,
|
||||
},
|
||||
)
|
||||
pln.append(
|
||||
"sales_orders",
|
||||
{
|
||||
"sales_order": so3.name,
|
||||
"sales_order_date": so3.transaction_date,
|
||||
"customer": so3.customer,
|
||||
"grand_total": so3.grand_total,
|
||||
},
|
||||
)
|
||||
|
||||
pln.get_items()
|
||||
pln.insert()
|
||||
|
||||
mr_items = get_items_for_material_requests(pln.as_dict())
|
||||
quantities = [d["quantity"] for d in mr_items]
|
||||
rm_qty = sum(quantities)
|
||||
|
||||
# Only 2 MR item created - the first SO's requirement is fully covered by stock (v15 behaviour)
|
||||
self.assertEqual(len(mr_items), 2)
|
||||
self.assertEqual(rm_qty, 2, "Cascading failed: total MR qty should be 2 (3 needed - 1 in stock)")
|
||||
self.assertEqual(
|
||||
quantities,
|
||||
[1, 1],
|
||||
"Cascading failed: only second and third SO should need procurement (qty=1) since first SO consumed stock",
|
||||
)
|
||||
|
||||
sr.cancel()
|
||||
|
||||
def test_production_plan_with_non_stock_item(self):
|
||||
"Test if MR Planning table includes Non Stock RM."
|
||||
pln = create_production_plan(item_code="Test Production Item 1", include_non_stock_items=1)
|
||||
@@ -678,6 +756,109 @@ class TestProductionPlan(FrappeTestCase):
|
||||
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_get_sales_order_items_for_product_bundle(self):
|
||||
"""Testing the Planned Qty for Product Bundle Item"""
|
||||
from erpnext.manufacturing.doctype.work_order.test_work_order import (
|
||||
make_stock_entry as create_stock_entry,
|
||||
)
|
||||
from erpnext.manufacturing.doctype.work_order.test_work_order import (
|
||||
make_wo_order_test_record,
|
||||
)
|
||||
from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
|
||||
# 1. Create required items
|
||||
bundle_item = create_item(item_code="Bundle Item", is_stock_item=0)
|
||||
bom_item = create_item(item_code="BOM Item")
|
||||
rm_item = create_item(item_code="RM Item")
|
||||
|
||||
fg_warehouse = "_Test FG Warehouse - _TC"
|
||||
|
||||
# Create warehouse if it doesn't exist
|
||||
if not frappe.db.exists("Warehouse", fg_warehouse):
|
||||
create_warehouse(warehouse_name="_Test FG Warehouse")
|
||||
|
||||
# 2. Create initial stock for components
|
||||
make_stock_entry(item_code=bom_item.name, target="_Test FG Warehouse - _TC", qty=15)
|
||||
make_stock_entry(item_code=rm_item.name, target="Stores - _TC", qty=25)
|
||||
|
||||
# 3. Create BOM for manufactured item
|
||||
bom = make_bom(
|
||||
item=bom_item.name,
|
||||
raw_materials=[rm_item.name],
|
||||
set_as_default_bom=1,
|
||||
)
|
||||
|
||||
# 4. Create Product Bundle (Bundle Item → contains BOM Item)
|
||||
make_product_bundle(parent=bundle_item.name, items=[bom_item.name])
|
||||
|
||||
# 5. Create Sales Order for 50 units of Bundle Item
|
||||
sales_order = make_sales_order(item_code=bundle_item.name, qty=50, warehouse=fg_warehouse)
|
||||
|
||||
# 6. Create Work Order for partial quantity (25 out of 50)
|
||||
work_order_qty = 25
|
||||
work_order = make_wo_order_test_record(
|
||||
production_item=bom_item.name,
|
||||
bom_no=bom.name,
|
||||
qty=work_order_qty,
|
||||
sales_order=sales_order.name,
|
||||
source_warehouse="Stores - _TC",
|
||||
fg_warehouse=fg_warehouse,
|
||||
do_not_save=1,
|
||||
)
|
||||
|
||||
# Link Work Order to correct Sales Order Item row
|
||||
work_order.sales_order_item = sales_order.items[0].name
|
||||
work_order.save()
|
||||
work_order.submit()
|
||||
|
||||
# 7. Material transfer from Stores → WIP
|
||||
transfer_entry = frappe.get_doc(
|
||||
create_stock_entry(work_order.name, "Material Transfer for Manufacture")
|
||||
)
|
||||
for d in transfer_entry.get("items"):
|
||||
d.s_warehouse = "Stores - _TC"
|
||||
transfer_entry.insert()
|
||||
transfer_entry.submit()
|
||||
|
||||
# 8. Complete manufacturing (WIP → Finished Goods)
|
||||
manufacture_entry = frappe.get_doc(create_stock_entry(work_order.name, "Manufacture"))
|
||||
manufacture_entry.insert()
|
||||
manufacture_entry.submit()
|
||||
|
||||
# 9. Verify work order qty is correctly updated in Sales Order
|
||||
sales_order.reload()
|
||||
self.assertEqual(sales_order.items[0].work_order_qty, work_order_qty)
|
||||
|
||||
# 10. Create partial Delivery Note (40 out of 50)
|
||||
dn = make_delivery_note(sales_order.name)
|
||||
dn.items[0].qty = 40
|
||||
dn.save()
|
||||
dn.submit()
|
||||
|
||||
# 11. Check delivered quantity updated correctly
|
||||
sales_order.reload()
|
||||
self.assertEqual(sales_order.items[0].delivered_qty, 40)
|
||||
|
||||
# 12. Create Production Plan from remaining open Sales Order quantity
|
||||
pln = frappe.new_doc("Production Plan")
|
||||
pln.company = sales_order.company
|
||||
pln.get_items_from = "Sales Order"
|
||||
pln.item_code = bundle_item.name
|
||||
|
||||
# Fetch open sales orders
|
||||
pln.get_open_sales_orders()
|
||||
self.assertEqual(pln.sales_orders[0].sales_order, sales_order.name)
|
||||
|
||||
# Pull items → should plan remaining 10 qty
|
||||
pln.get_so_items()
|
||||
|
||||
"""
|
||||
Test Case: Production Plan should plan remaining 10 units
|
||||
(50 ordered - 25 manufactured - 40 delivered = 10 pending)
|
||||
"""
|
||||
self.assertEqual(pln.po_items[0].planned_qty, 10)
|
||||
|
||||
def test_multiple_work_order_for_production_plan_item(self):
|
||||
"Test producing Prod Plan (making WO) in parts."
|
||||
|
||||
|
||||
@@ -2467,6 +2467,259 @@ class TestWorkOrder(FrappeTestCase):
|
||||
f"Work Order disassembled_qty mismatch: expected {disassemble_qty}, got {wo.disassembled_qty}",
|
||||
)
|
||||
|
||||
def test_disassembly_with_multiple_manufacture_entries(self):
|
||||
"""
|
||||
Test that disassembly does not create duplicate items when manufacturing
|
||||
is done in multiple batches (multiple manufacture stock entries).
|
||||
|
||||
Scenario:
|
||||
1. Create Work Order for 10 units
|
||||
2. Transfer raw materials
|
||||
3. Manufacture in 2 parts (3 units, then 7 units) - creates 2 stock entries
|
||||
4. Create Disassembly for 4 units
|
||||
5. Verify no duplicate items in the disassembly stock entry
|
||||
"""
|
||||
# Create RM and FG item
|
||||
raw_item1 = make_item("Test Raw for Multi Batch Disassembly 1", {"is_stock_item": 1}).name
|
||||
raw_item2 = make_item("Test Raw for Multi Batch Disassembly 2", {"is_stock_item": 1}).name
|
||||
fg_item = make_item("Test FG for Multi Batch Disassembly", {"is_stock_item": 1}).name
|
||||
bom = make_bom(item=fg_item, quantity=1, raw_materials=[raw_item1, raw_item2], rm_qty=2)
|
||||
|
||||
# Create WO
|
||||
wo = make_wo_order_test_record(production_item=fg_item, qty=10, bom_no=bom.name, status="Not Started")
|
||||
|
||||
# Ensure enough stock
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import (
|
||||
make_stock_entry as make_stock_entry_test_record,
|
||||
)
|
||||
|
||||
make_stock_entry_test_record(
|
||||
item_code=raw_item1,
|
||||
purpose="Material Receipt",
|
||||
target=wo.wip_warehouse,
|
||||
qty=50,
|
||||
basic_rate=100,
|
||||
)
|
||||
make_stock_entry_test_record(
|
||||
item_code=raw_item2,
|
||||
purpose="Material Receipt",
|
||||
target=wo.wip_warehouse,
|
||||
qty=50,
|
||||
basic_rate=100,
|
||||
)
|
||||
|
||||
# Transfer for manufacture
|
||||
se_for_material_transfer = frappe.get_doc(
|
||||
make_stock_entry(wo.name, "Material Transfer for Manufacture", wo.qty)
|
||||
)
|
||||
for item in se_for_material_transfer.items:
|
||||
item.s_warehouse = wo.wip_warehouse
|
||||
se_for_material_transfer.save()
|
||||
se_for_material_transfer.submit()
|
||||
|
||||
# First Manufacture Entry - 3 units
|
||||
se_manufacture1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 3))
|
||||
se_manufacture1.submit()
|
||||
|
||||
# Second Manufacture Entry - 7 units
|
||||
se_manufacture2 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 7))
|
||||
se_manufacture2.submit()
|
||||
|
||||
wo.reload()
|
||||
self.assertEqual(wo.produced_qty, 10)
|
||||
|
||||
# Count manufacture entries
|
||||
manufacture_entries = frappe.get_all(
|
||||
"Stock Entry",
|
||||
filters={
|
||||
"work_order": wo.name,
|
||||
"purpose": "Manufacture",
|
||||
"docstatus": 1,
|
||||
},
|
||||
)
|
||||
self.assertEqual(len(manufacture_entries), 2, "Expected 2 manufacture entries")
|
||||
|
||||
# Disassembly for 4 units
|
||||
disassemble_qty = 4
|
||||
stock_entry = frappe.get_doc(make_stock_entry(wo.name, "Disassemble", disassemble_qty))
|
||||
stock_entry.save()
|
||||
stock_entry.submit()
|
||||
|
||||
item_counts = {}
|
||||
for item in stock_entry.items:
|
||||
item_code = item.item_code
|
||||
item_counts[item_code] = item_counts.get(item_code, 0) + 1
|
||||
|
||||
# No duplicates
|
||||
duplicates = {k: v for k, v in item_counts.items() if v > 1}
|
||||
self.assertEqual(
|
||||
len(duplicates),
|
||||
0,
|
||||
f"Found duplicate items in disassembly stock entry: {duplicates}",
|
||||
)
|
||||
|
||||
expected_items = 3 # FG item + 2 raw materials
|
||||
self.assertEqual(
|
||||
len(stock_entry.items),
|
||||
expected_items,
|
||||
f"Expected {expected_items} items, found {len(stock_entry.items)}",
|
||||
)
|
||||
|
||||
# FG item qty
|
||||
fg_item_row = next((i for i in stock_entry.items if i.item_code == fg_item), None)
|
||||
self.assertEqual(fg_item_row.qty, disassemble_qty)
|
||||
|
||||
# RM quantities
|
||||
for bom_item in bom.items:
|
||||
expected_qty = (bom_item.qty / bom.quantity) * disassemble_qty
|
||||
rm_row = next((i for i in stock_entry.items if i.item_code == bom_item.item_code), None)
|
||||
self.assertAlmostEqual(
|
||||
rm_row.qty,
|
||||
expected_qty,
|
||||
places=3,
|
||||
msg=f"Raw material {bom_item.item_code} qty mismatch",
|
||||
)
|
||||
|
||||
def test_disassembly_with_additional_rm_not_in_bom(self):
|
||||
"""
|
||||
Test that disassembly correctly handles additional raw materials that were
|
||||
manually added during manufacturing (not part of the BOM).
|
||||
|
||||
Scenario:
|
||||
1. Create Work Order for 10 units with 2 raw materials in BOM
|
||||
2. Transfer raw materials for manufacture
|
||||
3. Manufacture in 2 parts (3 units, then 7 units)
|
||||
4. In each manufacture entry, manually add an extra consumable item
|
||||
(not in BOM) in proportion to the manufactured qty
|
||||
5. Create Disassembly for 4 units
|
||||
6. Verify that the additional RM is included in disassembly with proportional qty
|
||||
"""
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import (
|
||||
make_stock_entry as make_stock_entry_test_record,
|
||||
)
|
||||
|
||||
# Create RM and FG item
|
||||
raw_item1 = make_item("Test BOM Raw 1 for Additional RM Disassembly", {"is_stock_item": 1}).name
|
||||
raw_item2 = make_item("Test BOM Raw 2 for Additional RM Disassembly", {"is_stock_item": 1}).name
|
||||
additional_rm = make_item("Test Additional RM for Disassembly", {"is_stock_item": 1}).name
|
||||
fg_item = make_item("Test FG for Additional RM Disassembly", {"is_stock_item": 1}).name
|
||||
|
||||
bom = make_bom(item=fg_item, quantity=1, raw_materials=[raw_item1, raw_item2], rm_qty=2)
|
||||
|
||||
# Create WO
|
||||
wo = make_wo_order_test_record(production_item=fg_item, qty=10, bom_no=bom.name, status="Not Started")
|
||||
|
||||
# Ensure enough stock
|
||||
for item in [raw_item1, raw_item2, additional_rm]:
|
||||
make_stock_entry_test_record(
|
||||
item_code=item,
|
||||
purpose="Material Receipt",
|
||||
target=wo.wip_warehouse,
|
||||
qty=100,
|
||||
basic_rate=100,
|
||||
)
|
||||
|
||||
# Transfer for manufacture
|
||||
se_for_material_transfer = frappe.get_doc(
|
||||
make_stock_entry(wo.name, "Material Transfer for Manufacture", wo.qty)
|
||||
)
|
||||
for item in se_for_material_transfer.items:
|
||||
item.s_warehouse = wo.wip_warehouse
|
||||
se_for_material_transfer.save()
|
||||
se_for_material_transfer.submit()
|
||||
|
||||
# First Manufacture Entry - 3 units
|
||||
se_manufacture1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 3))
|
||||
# Additional RM
|
||||
se_manufacture1.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": additional_rm,
|
||||
"qty": 3, # 1 per unit
|
||||
"s_warehouse": wo.wip_warehouse,
|
||||
"is_finished_item": 0,
|
||||
},
|
||||
)
|
||||
se_manufacture1.save()
|
||||
se_manufacture1.submit()
|
||||
|
||||
# Second Manufacture Entry - 7 units
|
||||
se_manufacture2 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 7))
|
||||
# AAdditional RM
|
||||
se_manufacture2.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": additional_rm,
|
||||
"qty": 7, # 1 per unit
|
||||
"s_warehouse": wo.wip_warehouse,
|
||||
"is_finished_item": 0,
|
||||
},
|
||||
)
|
||||
se_manufacture2.save()
|
||||
se_manufacture2.submit()
|
||||
|
||||
wo.reload()
|
||||
self.assertEqual(wo.produced_qty, 10)
|
||||
|
||||
# Disassembly for 4 units
|
||||
disassemble_qty = 4
|
||||
stock_entry = frappe.get_doc(make_stock_entry(wo.name, "Disassemble", disassemble_qty))
|
||||
stock_entry.save()
|
||||
stock_entry.submit()
|
||||
|
||||
# No duplicate
|
||||
item_counts = {}
|
||||
for item in stock_entry.items:
|
||||
item_code = item.item_code
|
||||
item_counts[item_code] = item_counts.get(item_code, 0) + 1
|
||||
|
||||
duplicates = {k: v for k, v in item_counts.items() if v > 1}
|
||||
self.assertEqual(
|
||||
len(duplicates),
|
||||
0,
|
||||
f"Found duplicate items in disassembly stock entry: {duplicates}",
|
||||
)
|
||||
|
||||
# Additional RM qty
|
||||
additional_rm_row = next((i for i in stock_entry.items if i.item_code == additional_rm), None)
|
||||
self.assertIsNotNone(
|
||||
additional_rm_row,
|
||||
f"Additional raw material {additional_rm} not found in disassembly",
|
||||
)
|
||||
|
||||
# intentional full reversal as not part of BOM
|
||||
# eg: dies or consumables used during manufacturing
|
||||
expected_additional_rm_qty = 3 + 7
|
||||
self.assertAlmostEqual(
|
||||
additional_rm_row.qty,
|
||||
expected_additional_rm_qty,
|
||||
places=3,
|
||||
msg=f"Additional RM qty mismatch: expected {expected_additional_rm_qty}, got {additional_rm_row.qty}",
|
||||
)
|
||||
|
||||
# RM qty
|
||||
for bom_item in bom.items:
|
||||
expected_qty = (bom_item.qty / bom.quantity) * disassemble_qty
|
||||
rm_row = next((i for i in stock_entry.items if i.item_code == bom_item.item_code), None)
|
||||
self.assertIsNotNone(rm_row, f"BOM raw material {bom_item.item_code} not found")
|
||||
self.assertAlmostEqual(
|
||||
rm_row.qty,
|
||||
expected_qty,
|
||||
places=3,
|
||||
msg=f"BOM raw material {bom_item.item_code} qty mismatch",
|
||||
)
|
||||
|
||||
# FG qty
|
||||
fg_item_row = next((i for i in stock_entry.items if i.item_code == fg_item), None)
|
||||
self.assertEqual(fg_item_row.qty, disassemble_qty)
|
||||
|
||||
expected_items = 4
|
||||
self.assertEqual(
|
||||
len(stock_entry.items),
|
||||
expected_items,
|
||||
f"Expected {expected_items} items, found {len(stock_entry.items)}",
|
||||
)
|
||||
|
||||
def test_components_alternate_item_for_bom_based_manufacture_entry(self):
|
||||
frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
|
||||
frappe.db.set_single_value("Manufacturing Settings", "validate_components_quantities_per_bom", 1)
|
||||
|
||||
@@ -315,8 +315,8 @@ class WorkOrder(Document):
|
||||
def validate_work_order_against_so(self):
|
||||
# already ordered qty
|
||||
ordered_qty_against_so = frappe.db.sql(
|
||||
"""select sum(qty) from `tabWork Order`
|
||||
where production_item = %s and sales_order = %s and docstatus < 2 and name != %s""",
|
||||
"""select sum(qty - process_loss_qty) from `tabWork Order`
|
||||
where production_item = %s and sales_order = %s and docstatus < 2 and status != 'Closed' and name != %s""",
|
||||
(self.production_item, self.sales_order, self.name),
|
||||
)[0][0]
|
||||
|
||||
@@ -351,15 +351,16 @@ class WorkOrder(Document):
|
||||
|
||||
def update_status(self, status=None):
|
||||
"""Update status of work order if unknown"""
|
||||
if status != "Stopped" and status != "Closed":
|
||||
status = self.get_status(status)
|
||||
if self.status != "Closed":
|
||||
if status not in ["Stopped", "Closed"]:
|
||||
status = self.get_status(status)
|
||||
|
||||
if status != self.status:
|
||||
self.db_set("status", status)
|
||||
if status != self.status:
|
||||
self.db_set("status", status)
|
||||
|
||||
self.update_required_items()
|
||||
self.update_required_items()
|
||||
|
||||
return status
|
||||
return status or self.status
|
||||
|
||||
def get_status(self, status=None):
|
||||
"""Return the status based on stock entries against this work order"""
|
||||
@@ -515,6 +516,9 @@ class WorkOrder(Document):
|
||||
self.validate_cancel()
|
||||
self.db_set("status", "Cancelled")
|
||||
|
||||
self.on_close_or_cancel()
|
||||
|
||||
def on_close_or_cancel(self):
|
||||
if self.production_plan and frappe.db.exists(
|
||||
"Production Plan Item Reference", {"parent": self.production_plan}
|
||||
):
|
||||
@@ -842,7 +846,7 @@ class WorkOrder(Document):
|
||||
|
||||
qty = frappe.db.sql(
|
||||
f""" select sum(qty) from
|
||||
`tabWork Order` where sales_order = %s and docstatus = 1 and {cond}
|
||||
`tabWork Order` where sales_order = %s and docstatus = 1 and status <> 'Closed' and {cond}
|
||||
""",
|
||||
(self.sales_order, (self.product_bundle_item or self.production_item)),
|
||||
as_list=1,
|
||||
@@ -1603,8 +1607,8 @@ def close_work_order(work_order, status):
|
||||
)
|
||||
)
|
||||
|
||||
work_order.on_close_or_cancel()
|
||||
work_order.update_status(status)
|
||||
work_order.update_planned_qty()
|
||||
frappe.msgprint(_("Work Order has been {0}").format(status))
|
||||
work_order.notify_update()
|
||||
return work_order.status
|
||||
|
||||
@@ -427,3 +427,4 @@ erpnext.patches.v15_0.toggle_legacy_controller_for_period_closing
|
||||
execute:frappe.db.set_single_value("Accounts Settings", "show_party_balance", 1)
|
||||
execute:frappe.db.set_single_value("Accounts Settings", "show_account_balance", 1)
|
||||
erpnext.patches.v16_0.update_currency_exchange_settings_for_frankfurter #2025-12-11
|
||||
erpnext.patches.v15_0.create_accounting_dimensions_in_advance_taxes_and_charges
|
||||
|
||||
@@ -2,6 +2,15 @@ import frappe
|
||||
|
||||
|
||||
def execute():
|
||||
try:
|
||||
from erpnext.patches.v16_0.update_currency_exchange_settings_for_frankfurter import execute
|
||||
|
||||
execute()
|
||||
except ImportError:
|
||||
update_frankfurter_app_parameter_and_result()
|
||||
|
||||
|
||||
def update_frankfurter_app_parameter_and_result():
|
||||
settings = frappe.get_doc("Currency Exchange Settings")
|
||||
if settings.service_provider != "frankfurter.app":
|
||||
return
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||
create_accounting_dimensions_for_doctype,
|
||||
)
|
||||
|
||||
|
||||
def execute():
|
||||
create_accounting_dimensions_for_doctype(doctype="Advance Taxes and Charges")
|
||||
@@ -8,12 +8,24 @@ def execute():
|
||||
|
||||
|
||||
def update_delivery_note():
|
||||
DN = frappe.qb.DocType("Delivery Note")
|
||||
DNI = frappe.qb.DocType("Delivery Note Item")
|
||||
|
||||
frappe.qb.update(DNI).join(DN).on(DN.name == DNI.parent).set(DNI.against_pick_list, DN.pick_list).where(
|
||||
IfNull(DN.pick_list, "") != ""
|
||||
).run()
|
||||
# Postgres doesn't support UPDATE ... JOIN. Use UPDATE ... FROM instead.
|
||||
frappe.db.multisql(
|
||||
{
|
||||
"mariadb": """
|
||||
UPDATE `tabDelivery Note Item` dni
|
||||
JOIN `tabDelivery Note` dn ON dn.`name` = dni.`parent`
|
||||
SET dni.`against_pick_list` = dn.`pick_list`
|
||||
WHERE COALESCE(dn.`pick_list`, '') <> ''
|
||||
""",
|
||||
"postgres": """
|
||||
UPDATE "tabDelivery Note Item" dni
|
||||
SET against_pick_list = dn.pick_list
|
||||
FROM "tabDelivery Note" dn
|
||||
WHERE dn.name = dni.parent
|
||||
AND COALESCE(dn.pick_list, '') <> ''
|
||||
""",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def update_pick_list_items():
|
||||
|
||||
@@ -17,6 +17,15 @@ class TestTimesheet(unittest.TestCase):
|
||||
def setUp(self):
|
||||
frappe.db.delete("Timesheet")
|
||||
|
||||
def test_timesheet_base_amount(self):
|
||||
emp = make_employee("test_employee_6@salary.com")
|
||||
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
|
||||
|
||||
self.assertEqual(timesheet.time_logs[0].base_billing_rate, 50)
|
||||
self.assertEqual(timesheet.time_logs[0].base_costing_rate, 20)
|
||||
self.assertEqual(timesheet.time_logs[0].base_billing_amount, 100)
|
||||
self.assertEqual(timesheet.time_logs[0].base_costing_amount, 40)
|
||||
|
||||
def test_timesheet_billing_amount(self):
|
||||
emp = make_employee("test_employee_6@salary.com")
|
||||
timesheet = make_timesheet(emp, simulate=True, is_billable=1)
|
||||
@@ -236,4 +245,5 @@ def make_timesheet(
|
||||
def update_activity_type(activity_type):
|
||||
activity_type = frappe.get_doc("Activity Type", activity_type)
|
||||
activity_type.billing_rate = 50.0
|
||||
activity_type.costing_rate = 20.0
|
||||
activity_type.save(ignore_permissions=True)
|
||||
|
||||
@@ -296,6 +296,20 @@ class Timesheet(Document):
|
||||
data.billing_amount = data.billing_rate * hours
|
||||
data.costing_amount = data.costing_rate * costing_hours
|
||||
|
||||
exchange_rate = flt(self.get("exchange_rate")) or 1.0
|
||||
data.base_billing_rate = flt(
|
||||
data.billing_rate * exchange_rate, data.precision("base_billing_rate")
|
||||
)
|
||||
data.base_costing_rate = flt(
|
||||
data.costing_rate * exchange_rate, data.precision("base_costing_rate")
|
||||
)
|
||||
data.base_billing_amount = flt(
|
||||
data.billing_amount * exchange_rate, data.precision("base_billing_amount")
|
||||
)
|
||||
data.base_costing_amount = flt(
|
||||
data.costing_amount * exchange_rate, data.precision("base_costing_amount")
|
||||
)
|
||||
|
||||
def update_time_rates(self, ts_detail):
|
||||
if not ts_detail.is_billable:
|
||||
ts_detail.billing_rate = 0.0
|
||||
|
||||
@@ -361,6 +361,21 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
||||
mandatory_depends_on:
|
||||
"eval:doc.action=='Create Voucher' && doc.document_type=='Payment Entry'",
|
||||
},
|
||||
{
|
||||
fieldname: "bank_account",
|
||||
fieldtype: "Link",
|
||||
label: "Company Bank Account",
|
||||
options: "Bank Account",
|
||||
depends_on: "eval:doc.party",
|
||||
get_query: function () {
|
||||
return {
|
||||
filters: {
|
||||
is_company_account: 1,
|
||||
company: this.company,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldname: "project",
|
||||
fieldtype: "Link",
|
||||
@@ -511,6 +526,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
||||
mode_of_payment: values.mode_of_payment,
|
||||
project: values.project,
|
||||
cost_center: values.cost_center,
|
||||
company_bank_account: values?.bank_account || this?.bank_account,
|
||||
},
|
||||
callback: (response) => {
|
||||
const alert_string = __("Bank Transaction {0} added as Payment Entry", [
|
||||
@@ -582,6 +598,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
||||
project: values.project,
|
||||
cost_center: values.cost_center,
|
||||
allow_edit: true,
|
||||
company_bank_account: values?.bank_account || this?.bank_account,
|
||||
},
|
||||
callback: (r) => {
|
||||
const doc = frappe.model.sync(r.message);
|
||||
|
||||
@@ -479,7 +479,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
|
||||
barcode(doc, cdt, cdn) {
|
||||
let row = locals[cdt][cdn];
|
||||
if (row.barcode) {
|
||||
if (row.barcode && !frappe.flags.trigger_from_barcode_scanner) {
|
||||
erpnext.stock.utils.set_item_details_using_barcode(this.frm, row, (r) => {
|
||||
frappe.model.set_value(cdt, cdn, {
|
||||
"item_code": r.message.item_code,
|
||||
@@ -555,10 +555,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
|
||||
var item = frappe.get_doc(cdt, cdn);
|
||||
var update_stock = 0, show_batch_dialog = 0;
|
||||
|
||||
item.weight_per_unit = 0;
|
||||
item.weight_uom = '';
|
||||
item.uom = null // make UOM blank to update the existing UOM when item changes
|
||||
if(!item.barcode){
|
||||
item.uom = null // make UOM blank to update the existing UOM when item changes
|
||||
}
|
||||
item.conversion_factor = 0;
|
||||
|
||||
if(['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
|
||||
@@ -574,6 +575,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
show_batch_dialog = 0;
|
||||
}
|
||||
|
||||
|
||||
item.barcode = null;
|
||||
|
||||
|
||||
@@ -1330,9 +1332,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
||||
plc_conversion_rate() {
|
||||
if(this.frm.doc.price_list_currency === this.get_company_currency()) {
|
||||
this.frm.set_value("plc_conversion_rate", 1.0);
|
||||
} else if(this.frm.doc.price_list_currency === this.frm.doc.currency
|
||||
&& this.frm.doc.plc_conversion_rate && cint(this.frm.doc.plc_conversion_rate) != 1 &&
|
||||
cint(this.frm.doc.plc_conversion_rate) != cint(this.frm.doc.conversion_rate)) {
|
||||
} else if (
|
||||
this.frm.doc.price_list_currency === this.frm.doc.currency &&
|
||||
this.frm.doc.plc_conversion_rate &&
|
||||
flt(this.frm.doc.plc_conversion_rate) != 1 &&
|
||||
flt(this.frm.doc.plc_conversion_rate) != flt(this.frm.doc.conversion_rate)
|
||||
) {
|
||||
this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,6 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
||||
|
||||
frappe.run_serially([
|
||||
() => this.set_selector_trigger_flag(data),
|
||||
() => this.set_barcode_uom(row, uom),
|
||||
() => this.set_serial_no(row, serial_no),
|
||||
() => this.set_batch_no(row, batch_no),
|
||||
() => this.set_barcode(row, barcode),
|
||||
@@ -148,6 +147,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
||||
this.show_scan_message(row.idx, !is_new_row, qty);
|
||||
}),
|
||||
() => this.clean_up(),
|
||||
() => this.set_barcode_uom(row, uom),
|
||||
() => this.revert_selector_flag(),
|
||||
() => resolve(row),
|
||||
]);
|
||||
@@ -404,6 +404,8 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
|
||||
async set_barcode(row, barcode) {
|
||||
if (barcode && frappe.meta.has_field(row.doctype, this.barcode_field)) {
|
||||
await frappe.model.set_value(row.doctype, row.name, this.barcode_field, barcode);
|
||||
} else {
|
||||
row.barcode = barcode;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,11 @@ from frappe.utils import cint, cstr, flt, get_formatted_email, today
|
||||
from frappe.utils.deprecations import deprecated
|
||||
from frappe.utils.user import get_users_with_role
|
||||
|
||||
from erpnext.accounts.party import get_dashboard_info, validate_party_accounts
|
||||
from erpnext.accounts.party import (
|
||||
get_dashboard_info,
|
||||
validate_party_accounts,
|
||||
validate_party_currency_before_merging,
|
||||
)
|
||||
from erpnext.controllers.website_list_for_contact import add_role_for_portal_user
|
||||
from erpnext.utilities.transaction_base import TransactionBase
|
||||
|
||||
@@ -367,6 +371,10 @@ class Customer(TransactionBase):
|
||||
if self.lead_name:
|
||||
frappe.db.sql("update `tabLead` set status='Interested' where name=%s", self.lead_name)
|
||||
|
||||
def before_rename(self, olddn, newdn, merge=False):
|
||||
if merge:
|
||||
validate_party_currency_before_merging("Customer", olddn, newdn)
|
||||
|
||||
def after_rename(self, olddn, newdn, merge=False):
|
||||
if frappe.defaults.get_global_default("cust_master_name") == "Customer Name":
|
||||
self.db_set("customer_name", newdn)
|
||||
|
||||
@@ -1869,12 +1869,13 @@ def get_work_order_items(sales_order, for_raw_material_request=0):
|
||||
if not for_raw_material_request:
|
||||
total_work_order_qty = flt(
|
||||
qb.from_(wo)
|
||||
.select(Sum(wo.qty))
|
||||
.select(Sum(wo.qty - wo.process_loss_qty))
|
||||
.where(
|
||||
(wo.production_item == i.item_code)
|
||||
& (wo.sales_order == so.name)
|
||||
& (wo.sales_order_item == i.name)
|
||||
& (wo.docstatus.lt(2))
|
||||
& (wo.status != "Closed")
|
||||
)
|
||||
.run()[0][0]
|
||||
)
|
||||
|
||||
@@ -606,6 +606,9 @@ erpnext.PointOfSale.Controller = class {
|
||||
|
||||
async on_cart_update(args) {
|
||||
frappe.dom.freeze();
|
||||
if (this.frm.doc.set_warehouse !== this.settings.warehouse) {
|
||||
this.frm.set_value("set_warehouse", this.settings.warehouse);
|
||||
}
|
||||
let item_row = undefined;
|
||||
try {
|
||||
let { field, value, item } = args;
|
||||
|
||||
@@ -73,6 +73,18 @@ frappe.query_reports["Sales Analytics"] = {
|
||||
default: "Monthly",
|
||||
reqd: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "curves",
|
||||
label: __("Curves"),
|
||||
fieldtype: "Select",
|
||||
options: [
|
||||
{ value: "all", label: __("All") },
|
||||
{ value: "non-zeros", label: __("Non-Zeros") },
|
||||
{ value: "total", label: __("Total Only") },
|
||||
],
|
||||
default: "all",
|
||||
reqd: 1,
|
||||
},
|
||||
{
|
||||
fieldname: "show_aggregate_value_from_subsidiary_companies",
|
||||
label: __("Show Aggregate Value from Subsidiary Companies"),
|
||||
|
||||
@@ -460,7 +460,31 @@ class Analytics:
|
||||
labels = [d.get("label") for d in self.columns[3 : length - 1]]
|
||||
else:
|
||||
labels = [d.get("label") for d in self.columns[1 : length - 1]]
|
||||
self.chart = {"data": {"labels": labels, "datasets": []}, "type": "line"}
|
||||
|
||||
datasets = []
|
||||
for curve in self.data:
|
||||
data = {
|
||||
"name": curve.get("entity_name", curve["entity"]),
|
||||
"values": [curve.get(scrub(label), 0) for label in labels],
|
||||
}
|
||||
if self.filters.curves == "non-zeros" and not sum(data["values"]):
|
||||
continue
|
||||
elif self.filters.curves == "total" and "indent" in curve:
|
||||
if curve["indent"] == 0:
|
||||
datasets.append(data)
|
||||
elif self.filters.curves == "total":
|
||||
if datasets:
|
||||
a = [
|
||||
data["values"][idx] + datasets[0]["values"][idx] for idx in range(len(data["values"]))
|
||||
]
|
||||
datasets[0]["values"] = a
|
||||
else:
|
||||
datasets.append(data)
|
||||
datasets[0]["name"] = _("Total")
|
||||
else:
|
||||
datasets.append(data)
|
||||
|
||||
self.chart = {"data": {"labels": labels, "datasets": datasets}, "type": "line"}
|
||||
|
||||
if self.filters["value_quantity"] == "Value":
|
||||
self.chart["fieldtype"] = "Currency"
|
||||
|
||||
@@ -11,7 +11,16 @@ from frappe.cache_manager import clear_defaults_cache
|
||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||
from frappe.desk.page.setup_wizard.setup_wizard import make_records
|
||||
from frappe.utils import cint, formatdate, get_link_to_form, get_timestamp, today
|
||||
from frappe.utils import (
|
||||
add_months,
|
||||
cint,
|
||||
formatdate,
|
||||
get_first_day,
|
||||
get_last_day,
|
||||
get_link_to_form,
|
||||
get_timestamp,
|
||||
today,
|
||||
)
|
||||
from frappe.utils.nestedset import NestedSet, rebuild_tree
|
||||
|
||||
from erpnext.accounts.doctype.account.account import get_account_currency
|
||||
@@ -762,29 +771,41 @@ def install_country_fixtures(company, country):
|
||||
|
||||
|
||||
def update_company_current_month_sales(company):
|
||||
current_month_year = formatdate(today(), "MM-yyyy")
|
||||
"""Update Company's Total Monthly Sales.
|
||||
|
||||
results = frappe.db.sql(
|
||||
f"""
|
||||
SELECT
|
||||
SUM(base_grand_total) AS total,
|
||||
DATE_FORMAT(`posting_date`, '%m-%Y') AS month_year
|
||||
FROM
|
||||
`tabSales Invoice`
|
||||
WHERE
|
||||
DATE_FORMAT(`posting_date`, '%m-%Y') = '{current_month_year}'
|
||||
AND docstatus = 1
|
||||
AND company = {frappe.db.escape(company)}
|
||||
GROUP BY
|
||||
month_year
|
||||
""",
|
||||
as_dict=True,
|
||||
Postgres compatibility:
|
||||
- Avoid MariaDB-only DATE_FORMAT().
|
||||
- Use a date range for the current month instead (portable + index-friendly).
|
||||
"""
|
||||
|
||||
# Local imports so you don't have to touch file-level imports
|
||||
from frappe.query_builder.functions import Sum
|
||||
|
||||
start_date = get_first_day(today())
|
||||
end_date = get_last_day(today())
|
||||
|
||||
si = frappe.qb.DocType("Sales Invoice")
|
||||
|
||||
total_monthly_sales = (
|
||||
frappe.qb.from_(si)
|
||||
.select(Sum(si.base_grand_total))
|
||||
.where(
|
||||
(si.docstatus == 1)
|
||||
& (si.company == company)
|
||||
& (si.posting_date >= start_date)
|
||||
& (si.posting_date <= end_date)
|
||||
)
|
||||
).run(pluck=True)[0] or 0
|
||||
|
||||
# Fieldname in standard ERPNext is `total_monthly_sales`
|
||||
frappe.db.set_value(
|
||||
"Company",
|
||||
company,
|
||||
"total_monthly_sales",
|
||||
total_monthly_sales,
|
||||
update_modified=False,
|
||||
)
|
||||
|
||||
monthly_total = results[0]["total"] if len(results) > 0 else 0
|
||||
|
||||
frappe.db.set_value("Company", company, "total_monthly_sales", monthly_total)
|
||||
|
||||
|
||||
def update_company_monthly_sales(company):
|
||||
"""Cache past year monthly sales of every company based on sales invoices"""
|
||||
|
||||
@@ -64,6 +64,9 @@ def boot_session(bootinfo):
|
||||
bootinfo.party_account_types = frappe._dict(party_account_types)
|
||||
|
||||
bootinfo.sysdefaults.demo_company = frappe.db.get_single_value("Global Defaults", "demo_company")
|
||||
bootinfo.sysdefaults.default_ageing_range = frappe.db.get_single_value(
|
||||
"Accounts Settings", "default_ageing_range"
|
||||
)
|
||||
|
||||
|
||||
def update_page_info(bootinfo):
|
||||
|
||||
@@ -159,8 +159,13 @@ class Batch(Document):
|
||||
@frappe.whitelist()
|
||||
def recalculate_batch_qty(self):
|
||||
batches = get_batch_qty(
|
||||
batch_no=self.name, item_code=self.item, for_stock_levels=True, consider_negative_batches=True
|
||||
batch_no=self.name,
|
||||
item_code=self.item,
|
||||
for_stock_levels=True,
|
||||
consider_negative_batches=True,
|
||||
ignore_reserved_stock=True,
|
||||
)
|
||||
|
||||
batch_qty = 0.0
|
||||
if batches:
|
||||
for row in batches:
|
||||
@@ -240,6 +245,7 @@ def get_batch_qty(
|
||||
for_stock_levels=False,
|
||||
consider_negative_batches=False,
|
||||
do_not_check_future_batches=False,
|
||||
ignore_reserved_stock=False,
|
||||
):
|
||||
"""Returns batch actual qty if warehouse is passed,
|
||||
or returns dict of qty by warehouse if warehouse is None
|
||||
@@ -269,6 +275,7 @@ def get_batch_qty(
|
||||
"for_stock_levels": for_stock_levels,
|
||||
"consider_negative_batches": consider_negative_batches,
|
||||
"do_not_check_future_batches": do_not_check_future_batches,
|
||||
"ignore_reserved_stock": ignore_reserved_stock,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -324,6 +324,38 @@ class TestBatch(FrappeTestCase):
|
||||
|
||||
self.assertEqual(get_batch_qty("batch a", "_Test Warehouse - _TC"), 90)
|
||||
|
||||
def test_ignore_reserved_qty(self):
|
||||
from erpnext.selling.doctype.sales_order.sales_order import create_pick_list
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||
|
||||
batch_item_name = "Reserve Batch Item"
|
||||
batch_id = "Reserve Batch 1"
|
||||
# Create Batch Item
|
||||
self.make_batch_item(batch_item_name)
|
||||
# Create Batch and Material Receipt Entry with qty 90
|
||||
self.make_new_batch_and_entry(batch_item_name, batch_id, "_Test Warehouse - _TC")
|
||||
|
||||
# Enable Stock Reservation
|
||||
frappe.db.set_single_value("Stock Settings", "enable_stock_reservation", 1)
|
||||
|
||||
# Create Sales Order with qty 50
|
||||
sales_order = make_sales_order(
|
||||
item_code=batch_item_name, warehouse="_Test Warehouse - _TC", qty=50, rate=20
|
||||
)
|
||||
|
||||
# Create Pick List for the Sales Order
|
||||
pl = create_pick_list(sales_order.name)
|
||||
pl.submit()
|
||||
# Create Stock Reservation Entries
|
||||
pl.create_stock_reservation_entries(notify=False)
|
||||
|
||||
batch = frappe.get_doc("Batch", batch_id)
|
||||
# Recalculate Batch Qty
|
||||
batch.recalculate_batch_qty()
|
||||
batch.reload()
|
||||
# Case: Ignore Reserved Qty
|
||||
self.assertEqual(batch.batch_qty, 90)
|
||||
|
||||
def test_total_batch_qty(self):
|
||||
self.make_batch_item("ITEM-BATCH-3")
|
||||
existing_batch_qty = flt(frappe.db.get_value("Batch", "B100", "batch_qty"))
|
||||
|
||||
@@ -2790,6 +2790,23 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
self.assertEqual(sre_details[0].reserved_qty, so.items[0].qty)
|
||||
self.assertEqual(sre_details[0].delivered_qty, dn.items[0].qty)
|
||||
|
||||
def test_negative_stock_with_higher_precision(self):
|
||||
original_flt_precision = frappe.db.get_default("float_precision")
|
||||
frappe.db.set_single_value("System Settings", "float_precision", 7)
|
||||
|
||||
item_code = make_item(
|
||||
"Test Negative Stock High Precision Item", properties={"is_stock_item": 1, "valuation_rate": 1}
|
||||
).name
|
||||
dn = create_delivery_note(
|
||||
item_code=item_code,
|
||||
qty=0.0000010,
|
||||
do_not_submit=True,
|
||||
)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, dn.submit)
|
||||
|
||||
frappe.db.set_single_value("System Settings", "float_precision", original_flt_precision)
|
||||
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
||||
@@ -977,7 +977,7 @@ frappe.tour["Item"] = [
|
||||
fieldname: "valuation_rate",
|
||||
title: "Valuation Rate",
|
||||
description: __(
|
||||
"There are two options to maintain valuation of stock. FIFO (first in - first out) and Moving Average. To understand this topic in detail please visit <a href='https://docs.erpnext.com/docs/v13/user/manual/en/stock/articles/item-valuation-fifo-and-moving-average' target='_blank'>Item Valuation, FIFO and Moving Average.</a>"
|
||||
"There are two options to maintain valuation of stock. FIFO (first in - first out) and Moving Average. To understand this topic in detail please visit <a href='https://docs.frappe.io/erpnext/user/manual/en/calculation-of-valuation-rate-in-fifo-and-moving-average' target='_blank'>Item Valuation, FIFO and Moving Average.</a>"
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -273,6 +273,9 @@ class MaterialRequest(BuyingController):
|
||||
.groupby(doctype.material_request_item)
|
||||
)
|
||||
|
||||
if self.material_request_type == "Manufacture":
|
||||
query = query.where(doctype.status != "Closed")
|
||||
|
||||
mr_items_ordered_qty = frappe._dict(query.run())
|
||||
|
||||
return mr_items_ordered_qty
|
||||
|
||||
@@ -1004,7 +1004,8 @@ def make_material_request(**args):
|
||||
mr = frappe.new_doc("Material Request")
|
||||
mr.material_request_type = args.material_request_type or "Purchase"
|
||||
mr.company = args.company or "_Test Company"
|
||||
mr.customer = args.customer or "_Test Customer"
|
||||
if mr.material_request_type == "Customer Provided":
|
||||
mr.customer = args.customer or "_Test Customer"
|
||||
mr.append(
|
||||
"items",
|
||||
{
|
||||
@@ -1013,6 +1014,7 @@ def make_material_request(**args):
|
||||
"uom": args.uom or "_Test UOM",
|
||||
"conversion_factor": args.conversion_factor or 1,
|
||||
"schedule_date": args.schedule_date or today(),
|
||||
"from_warehouse": args.from_warehouse,
|
||||
"warehouse": args.warehouse or "_Test Warehouse - _TC",
|
||||
"cost_center": args.cost_center or "_Test Cost Center - _TC",
|
||||
},
|
||||
|
||||
@@ -383,35 +383,23 @@ class PickList(TransactionBase):
|
||||
picked_items = get_picked_items_qty(packed_items, contains_packed_items=True)
|
||||
self.validate_picked_qty(picked_items)
|
||||
|
||||
picked_qty = frappe._dict()
|
||||
doc_updates = {item: {"picked_qty": 0} for item in set(packed_items)}
|
||||
for d in picked_items:
|
||||
picked_qty[d.product_bundle_item] = d.picked_qty
|
||||
doc_updates[d.product_bundle_item] = {"picked_qty": flt(d.picked_qty)}
|
||||
|
||||
for packed_item in packed_items:
|
||||
frappe.db.set_value(
|
||||
"Packed Item",
|
||||
packed_item,
|
||||
"picked_qty",
|
||||
flt(picked_qty.get(packed_item)),
|
||||
update_modified=False,
|
||||
)
|
||||
if doc_updates:
|
||||
frappe.db.bulk_update("Packed Item", doc_updates, update_modified=False)
|
||||
|
||||
def update_sales_order_item_qty(self, so_items):
|
||||
picked_items = get_picked_items_qty(so_items)
|
||||
self.validate_picked_qty(picked_items)
|
||||
|
||||
picked_qty = frappe._dict()
|
||||
doc_updates = {item: {"picked_qty": 0} for item in set(so_items)}
|
||||
for d in picked_items:
|
||||
picked_qty[d.sales_order_item] = d.picked_qty
|
||||
doc_updates[d.sales_order_item] = {"picked_qty": flt(d.picked_qty)}
|
||||
|
||||
for so_item in so_items:
|
||||
frappe.db.set_value(
|
||||
"Sales Order Item",
|
||||
so_item,
|
||||
"picked_qty",
|
||||
flt(picked_qty.get(so_item)),
|
||||
update_modified=False,
|
||||
)
|
||||
if doc_updates:
|
||||
frappe.db.bulk_update("Sales Order Item", doc_updates, update_modified=False)
|
||||
|
||||
def update_sales_order_picking_status(self) -> None:
|
||||
sales_orders = []
|
||||
|
||||
@@ -17,13 +17,6 @@ frappe.ui.form.on("Purchase Receipt", {
|
||||
"Landed Cost Voucher": "Landed Cost Voucher",
|
||||
};
|
||||
|
||||
frm.set_query("expense_account", "items", function () {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_expense_account",
|
||||
filters: { company: frm.doc.company },
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("wip_composite_asset", "items", function () {
|
||||
return {
|
||||
filters: { is_composite_asset: 1, docstatus: 0 },
|
||||
@@ -171,6 +164,16 @@ erpnext.stock.PurchaseReceiptController = class PurchaseReceiptController extend
|
||||
this.setup_accounting_dimension_triggers();
|
||||
this.setup_posting_date_time_check();
|
||||
super.setup(doc);
|
||||
|
||||
this.frm.set_query("expense_account", "items", () => {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_expense_account",
|
||||
filters: {
|
||||
company: this.frm.doc.company,
|
||||
disabled: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
refresh() {
|
||||
|
||||
@@ -4529,6 +4529,154 @@ class TestPurchaseReceipt(FrappeTestCase):
|
||||
|
||||
self.assertEqual(sles, [1500.0, 1500.0])
|
||||
|
||||
def test_do_not_use_batchwise_valuation_with_fifo(self):
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
|
||||
item_code = make_item(
|
||||
"Test Item Do Not Use Batchwise Valuation with FIFO",
|
||||
{
|
||||
"is_stock_item": 1,
|
||||
"has_batch_no": 1,
|
||||
"batch_number_series": "BN-TESTDNUBVWF-.#####",
|
||||
"valuation_method": "FIFO",
|
||||
},
|
||||
).name
|
||||
|
||||
doc = frappe.new_doc("Batch")
|
||||
doc.update(
|
||||
{
|
||||
"batch_id": "BN-TESTDNUBVWF-00001",
|
||||
"item": item_code,
|
||||
}
|
||||
).insert()
|
||||
|
||||
doc.db_set("use_batchwise_valuation", 0)
|
||||
doc.reload()
|
||||
|
||||
self.assertTrue(doc.use_batchwise_valuation == 0)
|
||||
|
||||
doc = frappe.new_doc("Batch")
|
||||
doc.update(
|
||||
{
|
||||
"batch_id": "BN-TESTDNUBVWF-00002",
|
||||
"item": item_code,
|
||||
}
|
||||
).insert()
|
||||
|
||||
self.assertTrue(doc.use_batchwise_valuation == 1)
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
rate=100,
|
||||
target=warehouse,
|
||||
batch_no="BN-TESTDNUBVWF-00001",
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
se1 = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
rate=200,
|
||||
target=warehouse,
|
||||
batch_no="BN-TESTDNUBVWF-00001",
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
stock_queue = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"is_cancelled": 0,
|
||||
"voucher_type": "Stock Entry",
|
||||
"voucher_no": se1.name,
|
||||
},
|
||||
"stock_queue",
|
||||
)
|
||||
|
||||
stock_queue = frappe.parse_json(stock_queue)
|
||||
|
||||
self.assertEqual(stock_queue, [[10, 100.0], [10, 200.0]])
|
||||
|
||||
se2 = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=10,
|
||||
rate=2,
|
||||
target=warehouse,
|
||||
batch_no="BN-TESTDNUBVWF-00002",
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
stock_queue = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"is_cancelled": 0,
|
||||
"voucher_type": "Stock Entry",
|
||||
"voucher_no": se2.name,
|
||||
},
|
||||
"stock_queue",
|
||||
)
|
||||
|
||||
stock_queue = frappe.parse_json(stock_queue)
|
||||
self.assertEqual(stock_queue, [[10, 100.0], [10, 200.0]])
|
||||
|
||||
se3 = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=20,
|
||||
source=warehouse,
|
||||
batch_no="BN-TESTDNUBVWF-00001",
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
ste_details = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"is_cancelled": 0,
|
||||
"voucher_type": "Stock Entry",
|
||||
"voucher_no": se3.name,
|
||||
},
|
||||
["stock_queue", "stock_value_difference"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
stock_queue = frappe.parse_json(ste_details.stock_queue)
|
||||
self.assertEqual(stock_queue, [])
|
||||
self.assertEqual(ste_details.stock_value_difference, 3000 * -1)
|
||||
|
||||
se4 = make_stock_entry(
|
||||
item_code=item_code,
|
||||
qty=20,
|
||||
rate=0,
|
||||
target=warehouse,
|
||||
batch_no="BN-TESTDNUBVWF-00001",
|
||||
use_serial_batch_fields=1,
|
||||
do_not_submit=1,
|
||||
)
|
||||
|
||||
se4.items[0].basic_rate = 0.0
|
||||
se4.items[0].allow_zero_valuation_rate = 1
|
||||
se4.submit()
|
||||
|
||||
stock_queue = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{
|
||||
"item_code": item_code,
|
||||
"warehouse": warehouse,
|
||||
"is_cancelled": 0,
|
||||
"voucher_type": "Stock Entry",
|
||||
"voucher_no": se4.name,
|
||||
},
|
||||
"stock_queue",
|
||||
)
|
||||
|
||||
self.assertEqual(frappe.parse_json(stock_queue), [[20, 0.0]])
|
||||
|
||||
|
||||
def prepare_data_for_internal_transfer():
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
|
||||
|
||||
@@ -69,6 +69,9 @@ class RepostItemValuation(Document):
|
||||
),
|
||||
)
|
||||
|
||||
def repost_now(self):
|
||||
repost(self)
|
||||
|
||||
def validate(self):
|
||||
self.set_company()
|
||||
self.validate_period_closing_voucher()
|
||||
|
||||
@@ -116,10 +116,20 @@ class SerialandBatchBundle(Document):
|
||||
return
|
||||
|
||||
self.allow_existing_serial_nos()
|
||||
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
|
||||
self.validate_serial_nos_duplicate()
|
||||
if self.docstatus == 1:
|
||||
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
|
||||
self.validate_serial_nos_duplicate()
|
||||
|
||||
self.check_future_entries_exists()
|
||||
|
||||
elif (
|
||||
self.has_serial_no
|
||||
and self.type_of_transaction == "Outward"
|
||||
and self.voucher_type != "Stock Reconciliation"
|
||||
and self.voucher_no
|
||||
):
|
||||
self.validate_serial_no_status()
|
||||
|
||||
self.check_future_entries_exists()
|
||||
self.set_is_outward()
|
||||
self.calculate_total_qty()
|
||||
self.set_warehouse()
|
||||
@@ -129,6 +139,25 @@ class SerialandBatchBundle(Document):
|
||||
|
||||
self.calculate_qty_and_amount()
|
||||
|
||||
def validate_serial_no_status(self):
|
||||
serial_nos = [d.serial_no for d in self.entries if d.serial_no]
|
||||
invalid_serial_nos = frappe.get_all(
|
||||
"Serial No",
|
||||
filters={
|
||||
"name": ("in", serial_nos),
|
||||
"warehouse": ("!=", self.warehouse),
|
||||
},
|
||||
pluck="name",
|
||||
)
|
||||
|
||||
if invalid_serial_nos:
|
||||
msg = _(
|
||||
"You cannot outward following {0} as either they are Delivered, Inactive or located in a different warehouse."
|
||||
).format(_("Serial Nos") if len(invalid_serial_nos) > 1 else _("Serial No"))
|
||||
msg += "<hr>"
|
||||
msg += ", ".join(sn for sn in invalid_serial_nos)
|
||||
frappe.throw(msg)
|
||||
|
||||
def validate_voucher_detail_no(self):
|
||||
if self.type_of_transaction not in ["Inward", "Outward"] or self.voucher_type in [
|
||||
"Installation Note",
|
||||
@@ -241,6 +270,7 @@ class SerialandBatchBundle(Document):
|
||||
"check_serial_nos": True,
|
||||
"serial_nos": serial_nos,
|
||||
}
|
||||
|
||||
if self.voucher_type == "POS Invoice":
|
||||
kwargs["ignore_voucher_nos"] = [self.voucher_no]
|
||||
|
||||
@@ -311,6 +341,30 @@ class SerialandBatchBundle(Document):
|
||||
SerialNoDuplicateError,
|
||||
)
|
||||
|
||||
if (
|
||||
self.voucher_type == "Stock Entry"
|
||||
and self.type_of_transaction == "Inward"
|
||||
and frappe.get_cached_value("Stock Entry", self.voucher_no, "purpose")
|
||||
in ["Manufacture", "Repack"]
|
||||
):
|
||||
serial_nos = frappe.get_all(
|
||||
"Serial No", filters={"name": ("in", serial_nos), "status": "Delivered"}, pluck="name"
|
||||
)
|
||||
|
||||
if serial_nos:
|
||||
if len(serial_nos) == 1:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Serial No {0} is already Delivered. You cannot use them again in Manufacture / Repack entry."
|
||||
).format(bold(serial_nos[0]))
|
||||
)
|
||||
else:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Serial Nos {0} are already Delivered. You cannot use them again in Manufacture / Repack entry."
|
||||
).format(bold(", ".join(serial_nos)))
|
||||
)
|
||||
|
||||
def throw_error_message(self, message, exception=frappe.ValidationError):
|
||||
frappe.throw(_(message), exception, title=_("Error"))
|
||||
|
||||
@@ -529,7 +583,7 @@ class SerialandBatchBundle(Document):
|
||||
available_qty += flt(d.qty, precision)
|
||||
|
||||
if not allow_negative_stock:
|
||||
self.validate_negative_batch(d.batch_no, available_qty)
|
||||
self.validate_negative_batch(d.batch_no, available_qty, field)
|
||||
|
||||
d.stock_value_difference = flt(d.qty) * flt(d.incoming_rate)
|
||||
|
||||
@@ -542,8 +596,8 @@ class SerialandBatchBundle(Document):
|
||||
}
|
||||
)
|
||||
|
||||
def validate_negative_batch(self, batch_no, available_qty):
|
||||
if available_qty < 0 and not self.is_stock_reco_for_valuation_adjustment(available_qty):
|
||||
def validate_negative_batch(self, batch_no, available_qty, field=None):
|
||||
if available_qty < 0 and not self.is_stock_reco_for_valuation_adjustment(available_qty, field=field):
|
||||
msg = f"""Batch No {bold(batch_no)} of an Item {bold(self.item_code)}
|
||||
has negative stock
|
||||
of quantity {bold(available_qty)} in the
|
||||
@@ -551,13 +605,16 @@ class SerialandBatchBundle(Document):
|
||||
|
||||
frappe.throw(_(msg), BatchNegativeStockError)
|
||||
|
||||
def is_stock_reco_for_valuation_adjustment(self, available_qty):
|
||||
def is_stock_reco_for_valuation_adjustment(self, available_qty, field=None):
|
||||
if (
|
||||
self.voucher_type == "Stock Reconciliation"
|
||||
and self.type_of_transaction == "Outward"
|
||||
and self.voucher_detail_no
|
||||
and abs(frappe.db.get_value("Stock Reconciliation Item", self.voucher_detail_no, "qty"))
|
||||
== abs(available_qty)
|
||||
and (
|
||||
abs(frappe.db.get_value("Stock Reconciliation Item", self.voucher_detail_no, "qty"))
|
||||
== abs(available_qty)
|
||||
or field == "total_qty"
|
||||
)
|
||||
):
|
||||
return True
|
||||
|
||||
@@ -656,17 +713,16 @@ class SerialandBatchBundle(Document):
|
||||
is_packed_item = True
|
||||
|
||||
stock_queue = []
|
||||
batches = []
|
||||
if prev_sle and prev_sle.stock_queue:
|
||||
batches = frappe.get_all(
|
||||
"Batch",
|
||||
filters={
|
||||
"name": ("in", [d.batch_no for d in self.entries if d.batch_no]),
|
||||
"use_batchwise_valuation": 0,
|
||||
},
|
||||
pluck="name",
|
||||
)
|
||||
batches = frappe.get_all(
|
||||
"Batch",
|
||||
filters={
|
||||
"name": ("in", [d.batch_no for d in self.entries if d.batch_no]),
|
||||
"use_batchwise_valuation": 0,
|
||||
},
|
||||
pluck="name",
|
||||
)
|
||||
|
||||
if prev_sle and prev_sle.stock_queue and parse_json(prev_sle.stock_queue):
|
||||
if batches and valuation_method == "FIFO":
|
||||
stock_queue = parse_json(prev_sle.stock_queue)
|
||||
|
||||
@@ -674,10 +730,16 @@ class SerialandBatchBundle(Document):
|
||||
"Buying Settings", "set_valuation_rate_for_rejected_materials"
|
||||
)
|
||||
|
||||
precision = frappe.get_precision("Serial and Batch Entry", "incoming_rate")
|
||||
for d in self.entries:
|
||||
if self.is_rejected and not set_valuation_rate_for_rejected_materials:
|
||||
rate = 0.0
|
||||
elif (d.incoming_rate == rate) and not stock_queue and d.qty and d.stock_value_difference:
|
||||
elif (
|
||||
(flt(d.incoming_rate, precision) == flt(rate, precision))
|
||||
and not stock_queue
|
||||
and d.qty
|
||||
and d.stock_value_difference
|
||||
):
|
||||
continue
|
||||
|
||||
if is_packed_item and d.incoming_rate:
|
||||
@@ -687,7 +749,7 @@ class SerialandBatchBundle(Document):
|
||||
if d.qty:
|
||||
d.stock_value_difference = flt(d.qty) * d.incoming_rate
|
||||
|
||||
if stock_queue and valuation_method == "FIFO" and d.batch_no in batches:
|
||||
if valuation_method == "FIFO" and d.batch_no in batches and d.incoming_rate is not None:
|
||||
stock_queue.append([d.qty, d.incoming_rate])
|
||||
d.stock_queue = json.dumps(stock_queue)
|
||||
|
||||
@@ -738,7 +800,7 @@ class SerialandBatchBundle(Document):
|
||||
self.calculate_total_qty(save=True)
|
||||
|
||||
# If user has changed the rate in the child table
|
||||
if self.docstatus == 0:
|
||||
if self.docstatus == 0 and self.type_of_transaction == "Inward":
|
||||
self.set_incoming_rate(parent=parent, row=row, save=True)
|
||||
|
||||
if self.docstatus == 0 and parent.get("is_return") and parent.is_new():
|
||||
@@ -1976,9 +2038,9 @@ def get_available_serial_nos(kwargs):
|
||||
|
||||
order_by = "creation"
|
||||
if kwargs.based_on == "LIFO":
|
||||
order_by = "creation desc"
|
||||
order_by = "creation"
|
||||
elif kwargs.based_on == "Expiry":
|
||||
order_by = "amc_expiry_date asc"
|
||||
order_by = "amc_expiry_date"
|
||||
|
||||
filters = {"item_code": kwargs.item_code}
|
||||
|
||||
@@ -2018,13 +2080,52 @@ def get_available_serial_nos(kwargs):
|
||||
|
||||
filters["batch_no"] = ("in", batches)
|
||||
|
||||
return frappe.get_all(
|
||||
"Serial No",
|
||||
fields=fields,
|
||||
filters=filters,
|
||||
limit=cint(kwargs.qty) or 10000000,
|
||||
order_by=order_by,
|
||||
)
|
||||
return get_serial_nos_based_on_filters(filters, fields, order_by, kwargs)
|
||||
|
||||
|
||||
def get_serial_nos_based_on_filters(filters, fields, order_by, kwargs):
|
||||
doctype = frappe.qb.DocType("Serial No")
|
||||
|
||||
order_by_column = getattr(doctype, order_by)
|
||||
query = frappe.qb.from_(doctype).limit(cint(kwargs.qty) or 10000000).for_update()
|
||||
|
||||
if kwargs.based_on == "LIFO":
|
||||
query = query.orderby(order_by_column, order=frappe.query_builder.Order.desc)
|
||||
else:
|
||||
query = query.orderby(order_by_column)
|
||||
|
||||
for key, value in filters.items():
|
||||
column = getattr(doctype, key)
|
||||
|
||||
if isinstance(value, tuple):
|
||||
operator = value[0]
|
||||
|
||||
if operator == "between":
|
||||
query = query.where(column.between(value[1], value[2]))
|
||||
|
||||
elif operator == "in":
|
||||
query = query.where(column.isin(value[1]))
|
||||
|
||||
elif operator == "not in":
|
||||
query = query.where(column.notin(value[1]))
|
||||
|
||||
elif operator == "is":
|
||||
if value[1] == "set":
|
||||
query = query.where(column.isnotnull())
|
||||
elif value[1] == "not set":
|
||||
query = query.where(column.isnull())
|
||||
else:
|
||||
query = query.where(column == value)
|
||||
|
||||
for field in fields:
|
||||
if " as " in field.lower():
|
||||
# Split field and alias
|
||||
field_name, alias = field.split(" as ", 1)
|
||||
query = query.select(getattr(doctype, field_name).as_(alias))
|
||||
else:
|
||||
query = query.select(getattr(doctype, field))
|
||||
|
||||
return query.run(as_dict=True)
|
||||
|
||||
|
||||
def get_non_expired_batches(batches):
|
||||
|
||||
@@ -982,6 +982,7 @@ def make_serial_batch_bundle(kwargs):
|
||||
"type_of_transaction": type_of_transaction,
|
||||
"company": kwargs.company or "_Test Company",
|
||||
"do_not_submit": kwargs.do_not_submit,
|
||||
"ignore_sabb_validation": kwargs.ignore_sabb_validation or False,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@
|
||||
"icon": "fa fa-barcode",
|
||||
"idx": 1,
|
||||
"links": [],
|
||||
"modified": "2025-07-15 13:40:21.938700",
|
||||
"modified": "2025-12-24 20:14:52.942251",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Serial No",
|
||||
|
||||
@@ -302,3 +302,7 @@ def get_serial_nos_for_outward(kwargs):
|
||||
return []
|
||||
|
||||
return [d.serial_no for d in serial_nos]
|
||||
|
||||
|
||||
def on_doctype_update():
|
||||
frappe.db.add_index("Serial No", ["item_code", "warehouse"])
|
||||
|
||||
@@ -382,6 +382,7 @@
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"fieldname": "tracking_status",
|
||||
"fieldtype": "Select",
|
||||
"label": "Tracking Status",
|
||||
@@ -440,7 +441,7 @@
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2025-02-20 16:55:20.076418",
|
||||
"modified": "2026-01-07 19:24:23.566312",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Shipment",
|
||||
|
||||
@@ -20,9 +20,7 @@ class Shipment(Document):
|
||||
if TYPE_CHECKING:
|
||||
from frappe.types import DF
|
||||
|
||||
from erpnext.stock.doctype.shipment_delivery_note.shipment_delivery_note import (
|
||||
ShipmentDeliveryNote,
|
||||
)
|
||||
from erpnext.stock.doctype.shipment_delivery_note.shipment_delivery_note import ShipmentDeliveryNote
|
||||
from erpnext.stock.doctype.shipment_parcel.shipment_parcel import ShipmentParcel
|
||||
|
||||
amended_from: DF.Link | None
|
||||
|
||||
@@ -140,6 +140,24 @@ frappe.ui.form.on("Stock Entry", {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("project", "items", function (doc) {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_project_name",
|
||||
filters: {
|
||||
company: doc.company,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("project", function (doc) {
|
||||
return {
|
||||
query: "erpnext.controllers.queries.get_project_name",
|
||||
filters: {
|
||||
company: doc.company,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
frm.add_fetch("bom_no", "inspection_required", "inspection_required");
|
||||
erpnext.accounts.dimensions.setup_dimension_filters(frm, frm.doctype);
|
||||
|
||||
@@ -914,6 +932,9 @@ frappe.ui.form.on("Stock Entry Detail", {
|
||||
|
||||
item_code(frm, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
// since some items may not have image, so empty the image field to avoid setting the image of previous item
|
||||
d.image = "";
|
||||
|
||||
if (d.item_code) {
|
||||
var args = {
|
||||
item_code: d.item_code,
|
||||
|
||||
@@ -646,7 +646,7 @@ class StockEntry(StockController):
|
||||
"Material Transfer for Manufacture",
|
||||
]
|
||||
|
||||
validate_for_manufacture = any([d.bom_no for d in self.get("items")])
|
||||
has_bom = any([d.bom_no for d in self.get("items")])
|
||||
|
||||
if self.purpose in source_mandatory and self.purpose not in target_mandatory:
|
||||
self.to_warehouse = None
|
||||
@@ -675,7 +675,7 @@ class StockEntry(StockController):
|
||||
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
|
||||
|
||||
if self.purpose == "Manufacture":
|
||||
if validate_for_manufacture:
|
||||
if has_bom:
|
||||
if d.is_finished_item or d.is_scrap_item:
|
||||
d.s_warehouse = None
|
||||
if not d.t_warehouse:
|
||||
@@ -685,6 +685,17 @@ class StockEntry(StockController):
|
||||
if not d.s_warehouse:
|
||||
frappe.throw(_("Source warehouse is mandatory for row {0}").format(d.idx))
|
||||
|
||||
if self.purpose == "Disassemble":
|
||||
if has_bom:
|
||||
if d.is_finished_item:
|
||||
d.t_warehouse = None
|
||||
if not d.s_warehouse:
|
||||
frappe.throw(_("Source warehouse is mandatory for row {0}").format(d.idx))
|
||||
else:
|
||||
d.s_warehouse = None
|
||||
if not d.t_warehouse:
|
||||
frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx))
|
||||
|
||||
if cstr(d.s_warehouse) == cstr(d.t_warehouse) and self.purpose not in [
|
||||
"Material Transfer for Manufacture",
|
||||
"Material Transfer",
|
||||
@@ -1838,9 +1849,7 @@ class StockEntry(StockController):
|
||||
if self.purpose == "Material Issue":
|
||||
ret["expense_account"] = item.get("expense_account") or item_group_defaults.get("expense_account")
|
||||
|
||||
if (self.purpose == "Manufacture" and not args.get("is_finished_item")) or not ret.get(
|
||||
"expense_account"
|
||||
):
|
||||
if not ret.get("expense_account"):
|
||||
ret["expense_account"] = frappe.get_cached_value(
|
||||
"Company", self.company, "stock_adjustment_account"
|
||||
)
|
||||
@@ -1909,9 +1918,12 @@ class StockEntry(StockController):
|
||||
def get_items_for_disassembly(self):
|
||||
"""Get items for Disassembly Order"""
|
||||
|
||||
if not self.work_order:
|
||||
frappe.throw(_("The Work Order is mandatory for Disassembly Order"))
|
||||
if self.work_order:
|
||||
return self._add_items_for_disassembly_from_work_order()
|
||||
|
||||
return self._add_items_for_disassembly_from_bom()
|
||||
|
||||
def _add_items_for_disassembly_from_work_order(self):
|
||||
items = self.get_items_from_manufacture_entry()
|
||||
|
||||
s_warehouse = frappe.db.get_value("Work Order", self.work_order, "fg_warehouse")
|
||||
@@ -1943,6 +1955,23 @@ class StockEntry(StockController):
|
||||
child_row.t_warehouse = row.s_warehouse
|
||||
child_row.is_finished_item = 0 if row.is_finished_item else 1
|
||||
|
||||
def _add_items_for_disassembly_from_bom(self):
|
||||
if not self.bom_no or not self.fg_completed_qty:
|
||||
frappe.throw(_("BOM and Finished Good Quantity is mandatory for Disassembly"))
|
||||
|
||||
# Raw Materials
|
||||
item_dict = self.get_bom_raw_materials(self.fg_completed_qty)
|
||||
|
||||
for item_row in item_dict.values():
|
||||
item_row["to_warehouse"] = self.to_warehouse
|
||||
item_row["from_warehouse"] = ""
|
||||
item_row["is_finished_item"] = 0
|
||||
|
||||
self.add_to_stock_entry_detail(item_dict)
|
||||
|
||||
# Finished goods
|
||||
self.load_items_from_bom()
|
||||
|
||||
def get_items_from_manufacture_entry(self):
|
||||
return frappe.get_all(
|
||||
"Stock Entry",
|
||||
@@ -1950,8 +1979,8 @@ class StockEntry(StockController):
|
||||
"`tabStock Entry Detail`.`item_code`",
|
||||
"`tabStock Entry Detail`.`item_name`",
|
||||
"`tabStock Entry Detail`.`description`",
|
||||
"`tabStock Entry Detail`.`qty`",
|
||||
"`tabStock Entry Detail`.`transfer_qty`",
|
||||
"sum(`tabStock Entry Detail`.qty) as qty",
|
||||
"sum(`tabStock Entry Detail`.transfer_qty) as transfer_qty",
|
||||
"`tabStock Entry Detail`.`stock_uom`",
|
||||
"`tabStock Entry Detail`.`uom`",
|
||||
"`tabStock Entry Detail`.`basic_rate`",
|
||||
@@ -1970,6 +1999,7 @@ class StockEntry(StockController):
|
||||
["Stock Entry Detail", "docstatus", "=", 1],
|
||||
],
|
||||
order_by="`tabStock Entry Detail`.`idx` desc, `tabStock Entry Detail`.`is_finished_item` desc",
|
||||
group_by="`tabStock Entry Detail`.`item_code`",
|
||||
)
|
||||
|
||||
@frappe.whitelist()
|
||||
@@ -2165,6 +2195,7 @@ class StockEntry(StockController):
|
||||
expense_account = item.get("expense_account")
|
||||
if not expense_account:
|
||||
expense_account = frappe.get_cached_value("Company", self.company, "stock_adjustment_account")
|
||||
|
||||
args = {
|
||||
"to_warehouse": to_warehouse,
|
||||
"from_warehouse": "",
|
||||
@@ -2177,6 +2208,15 @@ class StockEntry(StockController):
|
||||
"is_finished_item": 1,
|
||||
}
|
||||
|
||||
if self.purpose == "Disassemble":
|
||||
args.update(
|
||||
{
|
||||
"from_warehouse": self.from_warehouse,
|
||||
"to_warehouse": "",
|
||||
"qty": flt(self.fg_completed_qty),
|
||||
}
|
||||
)
|
||||
|
||||
if (
|
||||
self.work_order
|
||||
and self.pro_doc.has_batch_no
|
||||
@@ -2808,7 +2848,7 @@ class StockEntry(StockController):
|
||||
stock_entries_child_list.append(d.ste_detail)
|
||||
transferred_qty = frappe.get_all(
|
||||
"Stock Entry Detail",
|
||||
fields=["sum(qty) as qty"],
|
||||
fields=["sum(transfer_qty) as qty"],
|
||||
filters={
|
||||
"against_stock_entry": d.against_stock_entry,
|
||||
"ste_detail": d.ste_detail,
|
||||
|
||||
@@ -14,6 +14,13 @@ from erpnext.stock.doctype.item.test_item import (
|
||||
make_item_variant,
|
||||
set_item_variant_settings,
|
||||
)
|
||||
from erpnext.stock.doctype.material_request.material_request import (
|
||||
make_in_transit_stock_entry,
|
||||
)
|
||||
from erpnext.stock.doctype.material_request.test_material_request import (
|
||||
get_in_transit_warehouse,
|
||||
make_material_request,
|
||||
)
|
||||
from erpnext.stock.doctype.serial_and_batch_bundle.test_serial_and_batch_bundle import (
|
||||
get_batch_from_bundle,
|
||||
get_serial_nos_from_bundle,
|
||||
@@ -1285,7 +1292,7 @@ class TestStockEntry(FrappeTestCase):
|
||||
self.assertEqual(se.value_difference, 0.0)
|
||||
self.assertEqual(se.total_incoming_value, se.total_outgoing_value)
|
||||
|
||||
self.assertEqual(se.items[0].expense_account, "Stock Adjustment - _TC")
|
||||
self.assertEqual(se.items[0].expense_account, "_Test Account Cost for Goods Sold - _TC")
|
||||
self.assertEqual(se.items[1].expense_account, "_Test Account Cost for Goods Sold - _TC")
|
||||
|
||||
@change_settings("Stock Settings", {"allow_negative_stock": 0})
|
||||
@@ -2088,6 +2095,143 @@ class TestStockEntry(FrappeTestCase):
|
||||
|
||||
self.assertEqual(incoming_rate, 125.0)
|
||||
|
||||
def test_prevent_reuse_delivered_serial_no_in_repack(self):
|
||||
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
|
||||
|
||||
item = "Test Prevent Reuse Delivered Serial No"
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
|
||||
item_doc = make_item(item, {"is_stock_item": 1, "has_serial_no": 1, "serial_no_series": "SHGJ.####"})
|
||||
|
||||
make_stock_entry(item_code="_Test Item", target=warehouse, qty=2, rate=100)
|
||||
make_stock_entry(item_code=item, target=warehouse, qty=2, rate=100)
|
||||
|
||||
dn = create_delivery_note(item_code=item, qty=2)
|
||||
delivered_serial_no = get_serial_nos_from_bundle(dn.get("items")[0].serial_and_batch_bundle)[0]
|
||||
|
||||
se = make_stock_entry(
|
||||
item_code="_Test Item", source=warehouse, qty=1, purpose="Repack", do_not_save=True
|
||||
)
|
||||
se.append(
|
||||
"items",
|
||||
{
|
||||
"item_code": item_doc.name,
|
||||
"item_name": item_doc.item_name,
|
||||
"s_warehouse": None,
|
||||
"t_warehouse": warehouse,
|
||||
"description": item_doc.description,
|
||||
"uom": item_doc.stock_uom,
|
||||
"qty": 1,
|
||||
"use_serial_batch_fields": 1,
|
||||
"serial_no": delivered_serial_no,
|
||||
},
|
||||
)
|
||||
|
||||
se.save()
|
||||
status = frappe.db.get_value("Serial No", delivered_serial_no, "status")
|
||||
|
||||
self.assertEqual(status, "Delivered")
|
||||
self.assertEqual(se.purpose, "Repack")
|
||||
self.assertRaises(frappe.ValidationError, se.submit)
|
||||
|
||||
def test_transferred_qty_in_material_transfer(self):
|
||||
item_code = "_Test Item"
|
||||
source_warehouse = "_Test Warehouse - _TC"
|
||||
target_warehouse = "_Test Warehouse 1 - _TC"
|
||||
|
||||
if not frappe.db.get_value("UOM Conversion Detail", {"parent": item_code, "uom": "Box"}):
|
||||
item_doc = frappe.get_doc("Item", item_code)
|
||||
item_doc.append("uoms", {"uom": "Box", "conversion_factor": 12})
|
||||
item_doc.save(ignore_permissions=True)
|
||||
|
||||
make_stock_entry(item_code=item_code, target=source_warehouse, qty=12, rate=100)
|
||||
|
||||
# Create a Material Request for Material Transfer
|
||||
material_request = make_material_request(
|
||||
material_request_type="Material Transfer",
|
||||
qty=1,
|
||||
item_code=item_code,
|
||||
uom="Box",
|
||||
conversion_factor=12,
|
||||
from_warehouse=source_warehouse,
|
||||
warehouse=target_warehouse,
|
||||
)
|
||||
in_transit_wh = get_in_transit_warehouse(material_request.company)
|
||||
|
||||
# Create first Stock Entry (Source -> In-Transit)
|
||||
stock_entry_1 = make_in_transit_stock_entry(material_request.name, in_transit_wh)
|
||||
stock_entry_1.items[0].update(
|
||||
{
|
||||
"qty": 1,
|
||||
"s_warehouse": source_warehouse,
|
||||
}
|
||||
)
|
||||
stock_entry_1.save().submit()
|
||||
|
||||
# Validate transfer status after first transfer
|
||||
material_request.reload()
|
||||
self.assertEqual(material_request.transfer_status, "In Transit")
|
||||
|
||||
# Create final Stock Entry (In-Transit -> Target)
|
||||
end_transit_1 = make_stock_in_entry(stock_entry_1.name)
|
||||
end_transit_1.save().submit()
|
||||
end_transit_1.reload()
|
||||
|
||||
# Validate quantities
|
||||
stock_entry_1.reload()
|
||||
self.assertEqual(stock_entry_1.items[0].qty, 1)
|
||||
self.assertEqual(stock_entry_1.items[0].transfer_qty, 12)
|
||||
self.assertEqual(stock_entry_1.items[0].transferred_qty, 12)
|
||||
|
||||
# Validate transfer status after final transfer
|
||||
material_request.reload()
|
||||
self.assertEqual(material_request.transfer_status, "Completed")
|
||||
|
||||
def test_disassemble_entry_without_wo(self):
|
||||
from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom
|
||||
|
||||
fg_item = make_item("_Disassemble Mobile", properties={"is_stock_item": 1}).name
|
||||
rm_item1 = make_item("_Disassemble Temper Glass", properties={"is_stock_item": 1}).name
|
||||
rm_item2 = make_item("_Disassemble Battery", properties={"is_stock_item": 1}).name
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
|
||||
# Stock up the FG item (what we'll disassemble)
|
||||
make_stock_entry(item_code=fg_item, target=warehouse, qty=5, purpose="Material Receipt")
|
||||
|
||||
bom_no = make_bom(item=fg_item, raw_materials=[rm_item1, rm_item2]).name
|
||||
|
||||
se = make_stock_entry(item_code=fg_item, qty=1, purpose="Disassemble", do_not_save=True)
|
||||
se.from_bom = 1
|
||||
se.use_multi_level_bom = 1
|
||||
se.bom_no = bom_no
|
||||
se.fg_completed_qty = 1
|
||||
se.from_warehouse = warehouse
|
||||
se.to_warehouse = warehouse
|
||||
|
||||
se.get_items()
|
||||
|
||||
# Verify FG as source (being consumed)
|
||||
fg_items = [d for d in se.items if d.is_finished_item]
|
||||
self.assertEqual(len(fg_items), 1)
|
||||
self.assertEqual(fg_items[0].item_code, fg_item)
|
||||
self.assertEqual(fg_items[0].qty, 1)
|
||||
self.assertEqual(fg_items[0].s_warehouse, warehouse)
|
||||
self.assertFalse(fg_items[0].t_warehouse)
|
||||
|
||||
# Verify RM as target (being received)
|
||||
rm_items = {d.item_code: d for d in se.items if not d.is_finished_item}
|
||||
self.assertEqual(len(rm_items), 2)
|
||||
self.assertIn(rm_item1, rm_items)
|
||||
self.assertIn(rm_item2, rm_items)
|
||||
self.assertEqual(rm_items[rm_item1].qty, 1)
|
||||
self.assertEqual(rm_items[rm_item2].qty, 1)
|
||||
self.assertEqual(rm_items[rm_item1].t_warehouse, warehouse)
|
||||
self.assertFalse(rm_items[rm_item1].s_warehouse)
|
||||
|
||||
se.calculate_rate_and_amount()
|
||||
se.save()
|
||||
se.submit()
|
||||
|
||||
|
||||
def make_serialized_item(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
@@ -74,6 +74,7 @@ class StockReconciliation(StockController):
|
||||
self.validate_duplicate_serial_and_batch_bundle("items")
|
||||
self.remove_items_with_no_change()
|
||||
self.validate_data()
|
||||
self.change_row_indexes()
|
||||
self.validate_expense_account()
|
||||
self.validate_customer_provided_item()
|
||||
self.set_zero_value_for_customer_provided_items()
|
||||
@@ -557,8 +558,7 @@ class StockReconciliation(StockController):
|
||||
|
||||
elif len(items) != len(self.items):
|
||||
self.items = items
|
||||
for i, item in enumerate(self.items):
|
||||
item.idx = i + 1
|
||||
self.change_idx = True
|
||||
frappe.msgprint(_("Removed items with no change in quantity or value."))
|
||||
|
||||
def calculate_difference_amount(self, item, item_dict):
|
||||
@@ -575,14 +575,14 @@ class StockReconciliation(StockController):
|
||||
|
||||
def validate_data(self):
|
||||
def _get_msg(row_num, msg):
|
||||
return _("Row # {0}:").format(row_num + 1) + " " + msg
|
||||
return _("Row #{0}:").format(row_num) + " " + msg
|
||||
|
||||
self.validation_messages = []
|
||||
item_warehouse_combinations = []
|
||||
|
||||
default_currency = frappe.db.get_default("currency")
|
||||
|
||||
for row_num, row in enumerate(self.items):
|
||||
for row in self.items:
|
||||
# find duplicates
|
||||
key = [row.item_code, row.warehouse]
|
||||
for field in ["serial_no", "batch_no"]:
|
||||
@@ -595,7 +595,7 @@ class StockReconciliation(StockController):
|
||||
|
||||
if key in item_warehouse_combinations:
|
||||
self.validation_messages.append(
|
||||
_get_msg(row_num, _("Same item and warehouse combination already entered."))
|
||||
_get_msg(row.idx, _("Same item and warehouse combination already entered."))
|
||||
)
|
||||
else:
|
||||
item_warehouse_combinations.append(key)
|
||||
@@ -605,29 +605,29 @@ class StockReconciliation(StockController):
|
||||
if row.serial_no and not row.qty:
|
||||
self.validation_messages.append(
|
||||
_get_msg(
|
||||
row_num,
|
||||
row.idx,
|
||||
f"Quantity should not be zero for the {bold(row.item_code)} since serial nos are specified",
|
||||
)
|
||||
)
|
||||
|
||||
# validate warehouse
|
||||
if not frappe.db.get_value("Warehouse", row.warehouse):
|
||||
self.validation_messages.append(_get_msg(row_num, _("Warehouse not found in the system")))
|
||||
self.validation_messages.append(_get_msg(row.idx, _("Warehouse not found in the system")))
|
||||
|
||||
# if both not specified
|
||||
if row.qty in ["", None] and row.valuation_rate in ["", None]:
|
||||
self.validation_messages.append(
|
||||
_get_msg(row_num, _("Please specify either Quantity or Valuation Rate or both"))
|
||||
_get_msg(row.idx, _("Please specify either Quantity or Valuation Rate or both"))
|
||||
)
|
||||
|
||||
# do not allow negative quantity
|
||||
if flt(row.qty) < 0:
|
||||
self.validation_messages.append(_get_msg(row_num, _("Negative Quantity is not allowed")))
|
||||
self.validation_messages.append(_get_msg(row.idx, _("Negative Quantity is not allowed")))
|
||||
|
||||
# do not allow negative valuation
|
||||
if flt(row.valuation_rate) < 0:
|
||||
self.validation_messages.append(
|
||||
_get_msg(row_num, _("Negative Valuation Rate is not allowed"))
|
||||
_get_msg(row.idx, _("Negative Valuation Rate is not allowed"))
|
||||
)
|
||||
|
||||
if row.qty and row.valuation_rate in ["", None]:
|
||||
@@ -659,6 +659,11 @@ class StockReconciliation(StockController):
|
||||
|
||||
raise frappe.ValidationError(self.validation_messages)
|
||||
|
||||
def change_row_indexes(self):
|
||||
if getattr(self, "change_idx", False):
|
||||
for i, item in enumerate(self.items):
|
||||
item.idx = i + 1
|
||||
|
||||
def validate_item(self, item_code, row):
|
||||
from erpnext.stock.doctype.item.item import (
|
||||
validate_cancelled_item,
|
||||
@@ -879,7 +884,7 @@ class StockReconciliation(StockController):
|
||||
if row.get(dimension.get("fieldname")):
|
||||
has_dimensions = True
|
||||
|
||||
if self.docstatus == 2 and (not row.batch_no or not row.serial_and_batch_bundle):
|
||||
if self.docstatus == 2:
|
||||
if row.current_qty and current_bundle:
|
||||
data.actual_qty = -1 * row.current_qty
|
||||
data.qty_after_transaction = flt(row.current_qty)
|
||||
|
||||
@@ -1557,6 +1557,147 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin):
|
||||
|
||||
self.assertFalse(status == "Active")
|
||||
|
||||
def test_change_valuation_of_batch_using_backdated_stock_reco(self):
|
||||
from erpnext.stock.doctype.batch.batch import get_batch_qty
|
||||
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
|
||||
|
||||
item_code = self.make_item(
|
||||
"Test Item Change Valuation of Batch",
|
||||
{
|
||||
"is_stock_item": 1,
|
||||
"has_batch_no": 1,
|
||||
"create_new_batch": 1,
|
||||
"batch_number_series": "TEST-BATCH-CVB-.###",
|
||||
},
|
||||
).name
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
|
||||
reco = create_stock_reconciliation(
|
||||
item_code=item_code,
|
||||
posting_date=add_days(nowdate(), -6),
|
||||
warehouse=warehouse,
|
||||
qty=10,
|
||||
rate=80,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
batch_no = get_batch_from_bundle(reco.items[0].serial_and_batch_bundle)
|
||||
|
||||
make_stock_entry(
|
||||
item_code=item_code,
|
||||
source=warehouse,
|
||||
qty=2,
|
||||
posting_date=add_days(nowdate(), -4),
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
make_stock_entry(
|
||||
item_code=item_code,
|
||||
source=warehouse,
|
||||
qty=2,
|
||||
posting_date=add_days(nowdate(), -3),
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
se4 = make_stock_entry(
|
||||
item_code=item_code,
|
||||
source=warehouse,
|
||||
qty=2,
|
||||
posting_date=add_days(nowdate(), -2),
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
sle = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{"voucher_no": se4.name, "is_cancelled": 0},
|
||||
["actual_qty", "stock_value_difference"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
valuation_rate = sle.stock_value_difference / sle.actual_qty
|
||||
self.assertEqual(valuation_rate, 80)
|
||||
|
||||
create_stock_reconciliation(
|
||||
item_code=item_code,
|
||||
posting_date=add_days(nowdate(), -5),
|
||||
warehouse=warehouse,
|
||||
qty=10,
|
||||
rate=100,
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
sle = frappe.db.get_value(
|
||||
"Stock Ledger Entry",
|
||||
{"voucher_no": se4.name, "is_cancelled": 0},
|
||||
["actual_qty", "stock_value_difference"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
valuation_rate = sle.stock_value_difference / sle.actual_qty
|
||||
|
||||
self.assertEqual(valuation_rate, 100)
|
||||
|
||||
batch_qty = get_batch_qty(batch_no, warehouse, item_code)
|
||||
self.assertEqual(batch_qty, 4)
|
||||
|
||||
def test_sabb_cancel_on_stock_reco_cancellation(self):
|
||||
item_code = self.make_item(
|
||||
"Test Item for SABB Cancel on Stock Reco Cancellation",
|
||||
{
|
||||
"is_stock_item": 1,
|
||||
"has_batch_no": 1,
|
||||
"create_new_batch": 1,
|
||||
"batch_number_series": "TEST-BATCH-SABBCANC-.###",
|
||||
},
|
||||
).name
|
||||
|
||||
warehouse = "_Test Warehouse - _TC"
|
||||
|
||||
sr = create_stock_reconciliation(
|
||||
item_code=item_code,
|
||||
warehouse=warehouse,
|
||||
qty=10,
|
||||
rate=100,
|
||||
use_serial_batch_fields=1,
|
||||
)
|
||||
|
||||
sr.reload()
|
||||
|
||||
batch_no = get_batch_from_bundle(sr.items[0].serial_and_batch_bundle)
|
||||
|
||||
sr1 = create_stock_reconciliation(
|
||||
item_code=item_code,
|
||||
warehouse=warehouse,
|
||||
qty=20,
|
||||
rate=100,
|
||||
use_serial_batch_fields=1,
|
||||
batch_no=batch_no,
|
||||
)
|
||||
|
||||
sr1.reload()
|
||||
|
||||
current_serial_and_batch_bundle = sr1.items[0].current_serial_and_batch_bundle
|
||||
serial_and_batch_bundle = sr1.items[0].serial_and_batch_bundle
|
||||
|
||||
self.assertTrue(current_serial_and_batch_bundle)
|
||||
self.assertTrue(serial_and_batch_bundle)
|
||||
|
||||
sr1.cancel()
|
||||
|
||||
for sabb in [serial_and_batch_bundle, current_serial_and_batch_bundle]:
|
||||
docstatus = frappe.db.get_value(
|
||||
"Serial and Batch Bundle",
|
||||
sabb,
|
||||
"docstatus",
|
||||
)
|
||||
|
||||
self.assertEqual(docstatus, 2)
|
||||
|
||||
|
||||
def create_batch_item_with_batch(item_name, batch_id):
|
||||
batch_item_doc = create_item(item_name, is_stock_item=1)
|
||||
|
||||
@@ -445,6 +445,7 @@ class StockReservationEntry(Document):
|
||||
voucher_delivered_qty = flt(delivered_qty) * flt(conversion_factor)
|
||||
|
||||
allowed_qty = min(self.available_qty, (self.voucher_qty - voucher_delivered_qty - total_reserved_qty))
|
||||
allowed_qty = flt(allowed_qty, self.precision("reserved_qty"))
|
||||
qty_to_be_reserved = flt(qty_to_be_reserved, self.precision("reserved_qty"))
|
||||
|
||||
if self.get("_action") != "submit" and self.voucher_type == "Sales Order" and allowed_qty <= 0:
|
||||
@@ -537,6 +538,7 @@ def get_available_qty_to_reserve(
|
||||
& (sre.reserved_qty >= sre.delivered_qty)
|
||||
& (sre.status.notin(["Delivered", "Cancelled"]))
|
||||
)
|
||||
.for_update()
|
||||
)
|
||||
|
||||
if ignore_sre:
|
||||
|
||||
@@ -204,6 +204,7 @@ def update_stock(ctx, out, doc=None):
|
||||
"item_code": ctx.item_code,
|
||||
"warehouse": ctx.warehouse,
|
||||
"based_on": frappe.db.get_single_value("Stock Settings", "pick_serial_and_batch_based_on"),
|
||||
"qty": out.stock_qty,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user