Merge branch 'develop' into bank-trans-party-automatch
This commit is contained in:
commit
51848ee9d7
@ -154,7 +154,6 @@
|
|||||||
"before": true,
|
"before": true,
|
||||||
"beforeEach": true,
|
"beforeEach": true,
|
||||||
"onScan": true,
|
"onScan": true,
|
||||||
"html2canvas": true,
|
|
||||||
"extend_cscript": true,
|
"extend_cscript": true,
|
||||||
"localforage": true
|
"localforage": true
|
||||||
}
|
}
|
||||||
|
0
.semgrepignore
Normal file
0
.semgrepignore
Normal file
@ -3,7 +3,7 @@ import inspect
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
__version__ = "14.0.0-dev"
|
__version__ = "15.0.0-dev"
|
||||||
|
|
||||||
|
|
||||||
def get_default_company(user=None):
|
def get_default_company(user=None):
|
||||||
|
@ -50,13 +50,15 @@ class AccountingDimension(Document):
|
|||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
make_dimension_in_accounting_doctypes(doc=self)
|
make_dimension_in_accounting_doctypes(doc=self)
|
||||||
else:
|
else:
|
||||||
frappe.enqueue(make_dimension_in_accounting_doctypes, doc=self, queue="long")
|
frappe.enqueue(
|
||||||
|
make_dimension_in_accounting_doctypes, doc=self, queue="long", enqueue_after_commit=True
|
||||||
|
)
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
if frappe.flags.in_test:
|
if frappe.flags.in_test:
|
||||||
delete_accounting_dimension(doc=self)
|
delete_accounting_dimension(doc=self)
|
||||||
else:
|
else:
|
||||||
frappe.enqueue(delete_accounting_dimension, doc=self, queue="long")
|
frappe.enqueue(delete_accounting_dimension, doc=self, queue="long", enqueue_after_commit=True)
|
||||||
|
|
||||||
def set_fieldname_and_label(self):
|
def set_fieldname_and_label(self):
|
||||||
if not self.label:
|
if not self.label:
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
"book_tax_discount_loss",
|
"book_tax_discount_loss",
|
||||||
"print_settings",
|
"print_settings",
|
||||||
"show_inclusive_tax_in_print",
|
"show_inclusive_tax_in_print",
|
||||||
|
"show_taxes_as_table_in_print",
|
||||||
"column_break_12",
|
"column_break_12",
|
||||||
"show_payment_schedule_in_print",
|
"show_payment_schedule_in_print",
|
||||||
"currency_exchange_section",
|
"currency_exchange_section",
|
||||||
@ -380,6 +381,12 @@
|
|||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Auto Reconcile Payments"
|
"label": "Auto Reconcile Payments"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"fieldname": "show_taxes_as_table_in_print",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Show Taxes as Table in Print"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "banking_tab",
|
"fieldname": "banking_tab",
|
||||||
"fieldtype": "Tab Break",
|
"fieldtype": "Tab Break",
|
||||||
@ -406,7 +413,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-06-01 15:42:44.912316",
|
"modified": "2023-06-15 16:35:45.123456",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Accounts Settings",
|
"name": "Accounts Settings",
|
||||||
|
@ -41,7 +41,7 @@ frappe.ui.form.on("Bank Clearance", {
|
|||||||
frm.trigger("get_payment_entries")
|
frm.trigger("get_payment_entries")
|
||||||
);
|
);
|
||||||
|
|
||||||
frm.change_custom_button_type('Get Payment Entries', null, 'primary');
|
frm.change_custom_button_type(__('Get Payment Entries'), null, 'primary');
|
||||||
},
|
},
|
||||||
|
|
||||||
update_clearance_date: function(frm) {
|
update_clearance_date: function(frm) {
|
||||||
@ -53,8 +53,8 @@ frappe.ui.form.on("Bank Clearance", {
|
|||||||
frm.refresh_fields();
|
frm.refresh_fields();
|
||||||
|
|
||||||
if (!frm.doc.payment_entries.length) {
|
if (!frm.doc.payment_entries.length) {
|
||||||
frm.change_custom_button_type('Get Payment Entries', null, 'primary');
|
frm.change_custom_button_type(__('Get Payment Entries'), null, 'primary');
|
||||||
frm.change_custom_button_type('Update Clearance Date', null, 'default');
|
frm.change_custom_button_type(__('Update Clearance Date'), null, 'default');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -72,8 +72,8 @@ frappe.ui.form.on("Bank Clearance", {
|
|||||||
frm.trigger("update_clearance_date")
|
frm.trigger("update_clearance_date")
|
||||||
);
|
);
|
||||||
|
|
||||||
frm.change_custom_button_type('Get Payment Entries', null, 'default');
|
frm.change_custom_button_type(__('Get Payment Entries'), null, 'default');
|
||||||
frm.change_custom_button_type('Update Clearance Date', null, 'primary');
|
frm.change_custom_button_type(__('Update Clearance Date'), null, 'primary');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -81,7 +81,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", {
|
|||||||
frm.add_custom_button(__('Get Unreconciled Entries'), function() {
|
frm.add_custom_button(__('Get Unreconciled Entries'), function() {
|
||||||
frm.trigger("make_reconciliation_tool");
|
frm.trigger("make_reconciliation_tool");
|
||||||
});
|
});
|
||||||
frm.change_custom_button_type('Get Unreconciled Entries', null, 'primary');
|
frm.change_custom_button_type(__('Get Unreconciled Entries'), null, 'primary');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -245,6 +245,7 @@
|
|||||||
"fieldname": "contact_mobile",
|
"fieldname": "contact_mobile",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -315,10 +316,11 @@
|
|||||||
],
|
],
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-08-03 18:55:43.683053",
|
"modified": "2023-06-03 16:24:01.677026",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Dunning",
|
"name": "Dunning",
|
||||||
|
"naming_rule": "By \"Naming Series\" field",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@ -365,6 +367,7 @@
|
|||||||
],
|
],
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "ASC",
|
"sort_order": "ASC",
|
||||||
|
"states": [],
|
||||||
"title_field": "customer_name",
|
"title_field": "customer_name",
|
||||||
"track_changes": 1
|
"track_changes": 1
|
||||||
}
|
}
|
@ -35,6 +35,21 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validate_rounding_loss: function(frm) {
|
||||||
|
let allowance = frm.doc.rounding_loss_allowance;
|
||||||
|
if (!(allowance > 0 && allowance < 1)) {
|
||||||
|
frappe.throw(__("Rounding Loss Allowance should be between 0 and 1"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
rounding_loss_allowance: function(frm) {
|
||||||
|
frm.events.validate_rounding_loss(frm);
|
||||||
|
},
|
||||||
|
|
||||||
|
validate: function(frm) {
|
||||||
|
frm.events.validate_rounding_loss(frm);
|
||||||
|
},
|
||||||
|
|
||||||
get_entries: function(frm, account) {
|
get_entries: function(frm, account) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "get_accounts_data",
|
method: "get_accounts_data",
|
||||||
@ -126,7 +141,8 @@ var get_account_details = function(frm, cdt, cdn) {
|
|||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
posting_date: frm.doc.posting_date,
|
posting_date: frm.doc.posting_date,
|
||||||
party_type: row.party_type,
|
party_type: row.party_type,
|
||||||
party: row.party
|
party: row.party,
|
||||||
|
rounding_loss_allowance: frm.doc.rounding_loss_allowance
|
||||||
},
|
},
|
||||||
callback: function(r){
|
callback: function(r){
|
||||||
$.extend(row, r.message);
|
$.extend(row, r.message);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"posting_date",
|
"posting_date",
|
||||||
|
"rounding_loss_allowance",
|
||||||
"column_break_2",
|
"column_break_2",
|
||||||
"company",
|
"company",
|
||||||
"section_break_4",
|
"section_break_4",
|
||||||
@ -96,11 +97,18 @@
|
|||||||
{
|
{
|
||||||
"fieldname": "column_break_10",
|
"fieldname": "column_break_10",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0.05",
|
||||||
|
"description": "Only values between 0 and 1 are allowed. \nEx: If allowance is set at 0.07, accounts that have balance of 0.07 in either of the currencies will be considered as zero balance account",
|
||||||
|
"fieldname": "rounding_loss_allowance",
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"label": "Rounding Loss Allowance"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-12-29 19:38:24.416529",
|
"modified": "2023-06-12 21:02:09.818208",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Exchange Rate Revaluation",
|
"name": "Exchange Rate Revaluation",
|
||||||
|
@ -18,8 +18,13 @@ from erpnext.setup.utils import get_exchange_rate
|
|||||||
|
|
||||||
class ExchangeRateRevaluation(Document):
|
class ExchangeRateRevaluation(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_rounding_loss_allowance()
|
||||||
self.set_total_gain_loss()
|
self.set_total_gain_loss()
|
||||||
|
|
||||||
|
def validate_rounding_loss_allowance(self):
|
||||||
|
if not (self.rounding_loss_allowance > 0 and self.rounding_loss_allowance < 1):
|
||||||
|
frappe.throw(_("Rounding Loss Allowance should be between 0 and 1"))
|
||||||
|
|
||||||
def set_total_gain_loss(self):
|
def set_total_gain_loss(self):
|
||||||
total_gain_loss = 0
|
total_gain_loss = 0
|
||||||
|
|
||||||
@ -92,7 +97,12 @@ class ExchangeRateRevaluation(Document):
|
|||||||
def get_accounts_data(self):
|
def get_accounts_data(self):
|
||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
account_details = self.get_account_balance_from_gle(
|
account_details = self.get_account_balance_from_gle(
|
||||||
company=self.company, posting_date=self.posting_date, account=None, party_type=None, party=None
|
company=self.company,
|
||||||
|
posting_date=self.posting_date,
|
||||||
|
account=None,
|
||||||
|
party_type=None,
|
||||||
|
party=None,
|
||||||
|
rounding_loss_allowance=self.rounding_loss_allowance,
|
||||||
)
|
)
|
||||||
accounts_with_new_balance = self.calculate_new_account_balance(
|
accounts_with_new_balance = self.calculate_new_account_balance(
|
||||||
self.company, self.posting_date, account_details
|
self.company, self.posting_date, account_details
|
||||||
@ -104,7 +114,9 @@ class ExchangeRateRevaluation(Document):
|
|||||||
return accounts_with_new_balance
|
return accounts_with_new_balance
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_account_balance_from_gle(company, posting_date, account, party_type, party):
|
def get_account_balance_from_gle(
|
||||||
|
company, posting_date, account, party_type, party, rounding_loss_allowance
|
||||||
|
):
|
||||||
account_details = []
|
account_details = []
|
||||||
|
|
||||||
if company and posting_date:
|
if company and posting_date:
|
||||||
@ -172,10 +184,18 @@ class ExchangeRateRevaluation(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# round off balance based on currency precision
|
# round off balance based on currency precision
|
||||||
|
# and consider debit-credit difference allowance
|
||||||
currency_precision = get_currency_precision()
|
currency_precision = get_currency_precision()
|
||||||
|
rounding_loss_allowance = float(rounding_loss_allowance) or 0.05
|
||||||
for acc in account_details:
|
for acc in account_details:
|
||||||
acc.balance_in_account_currency = flt(acc.balance_in_account_currency, currency_precision)
|
acc.balance_in_account_currency = flt(acc.balance_in_account_currency, currency_precision)
|
||||||
|
if abs(acc.balance_in_account_currency) <= rounding_loss_allowance:
|
||||||
|
acc.balance_in_account_currency = 0
|
||||||
|
|
||||||
acc.balance = flt(acc.balance, currency_precision)
|
acc.balance = flt(acc.balance, currency_precision)
|
||||||
|
if abs(acc.balance) <= rounding_loss_allowance:
|
||||||
|
acc.balance = 0
|
||||||
|
|
||||||
acc.zero_balance = (
|
acc.zero_balance = (
|
||||||
True if (acc.balance == 0 or acc.balance_in_account_currency == 0) else False
|
True if (acc.balance == 0 or acc.balance_in_account_currency == 0) else False
|
||||||
)
|
)
|
||||||
@ -531,7 +551,9 @@ def calculate_exchange_rate_using_last_gle(company, account, party_type, party):
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_account_details(company, posting_date, account, party_type=None, party=None):
|
def get_account_details(
|
||||||
|
company, posting_date, account, party_type=None, party=None, rounding_loss_allowance: float = None
|
||||||
|
):
|
||||||
if not (company and posting_date):
|
if not (company and posting_date):
|
||||||
frappe.throw(_("Company and Posting Date is mandatory"))
|
frappe.throw(_("Company and Posting Date is mandatory"))
|
||||||
|
|
||||||
@ -549,7 +571,12 @@ def get_account_details(company, posting_date, account, party_type=None, party=N
|
|||||||
"account_currency": account_currency,
|
"account_currency": account_currency,
|
||||||
}
|
}
|
||||||
account_balance = ExchangeRateRevaluation.get_account_balance_from_gle(
|
account_balance = ExchangeRateRevaluation.get_account_balance_from_gle(
|
||||||
company=company, posting_date=posting_date, account=account, party_type=party_type, party=party
|
company=company,
|
||||||
|
posting_date=posting_date,
|
||||||
|
account=account,
|
||||||
|
party_type=party_type,
|
||||||
|
party=party,
|
||||||
|
rounding_loss_allowance=rounding_loss_allowance,
|
||||||
)
|
)
|
||||||
|
|
||||||
if account_balance and (
|
if account_balance and (
|
||||||
|
@ -12,7 +12,7 @@ from frappe.utils import add_days, add_years, cstr, getdate
|
|||||||
class FiscalYear(Document):
|
class FiscalYear(Document):
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def set_as_default(self):
|
def set_as_default(self):
|
||||||
frappe.db.set_value("Global Defaults", None, "current_fiscal_year", self.name)
|
frappe.db.set_single_value("Global Defaults", "current_fiscal_year", self.name)
|
||||||
global_defaults = frappe.get_doc("Global Defaults")
|
global_defaults = frappe.get_doc("Global Defaults")
|
||||||
global_defaults.check_permission("write")
|
global_defaults.check_permission("write")
|
||||||
global_defaults.on_update()
|
global_defaults.on_update()
|
||||||
|
@ -952,6 +952,7 @@ class JournalEntry(AccountsController):
|
|||||||
blank_row.debit_in_account_currency = abs(diff)
|
blank_row.debit_in_account_currency = abs(diff)
|
||||||
blank_row.debit = abs(diff)
|
blank_row.debit = abs(diff)
|
||||||
|
|
||||||
|
self.set_total_debit_credit()
|
||||||
self.validate_total_debit_and_credit()
|
self.validate_total_debit_and_credit()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
@ -105,8 +105,8 @@ class TestJournalEntry(unittest.TestCase):
|
|||||||
|
|
||||||
elif test_voucher.doctype in ["Sales Order", "Purchase Order"]:
|
elif test_voucher.doctype in ["Sales Order", "Purchase Order"]:
|
||||||
# if test_voucher is a Sales Order/Purchase Order, test error on cancellation of test_voucher
|
# if test_voucher is a Sales Order/Purchase Order, test error on cancellation of test_voucher
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
|
"Accounts Settings", "unlink_advance_payment_on_cancelation_of_order", 0
|
||||||
)
|
)
|
||||||
submitted_voucher = frappe.get_doc(test_voucher.doctype, test_voucher.name)
|
submitted_voucher = frappe.get_doc(test_voucher.doctype, test_voucher.name)
|
||||||
self.assertRaises(frappe.LinkExistsError, submitted_voucher.cancel)
|
self.assertRaises(frappe.LinkExistsError, submitted_voucher.cancel)
|
||||||
|
@ -148,19 +148,57 @@ class PaymentEntry(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def validate_allocated_amount(self):
|
def validate_allocated_amount(self):
|
||||||
for d in self.get("references"):
|
if self.payment_type == "Internal Transfer":
|
||||||
|
return
|
||||||
|
|
||||||
|
latest_references = get_outstanding_reference_documents(
|
||||||
|
{
|
||||||
|
"posting_date": self.posting_date,
|
||||||
|
"company": self.company,
|
||||||
|
"party_type": self.party_type,
|
||||||
|
"payment_type": self.payment_type,
|
||||||
|
"party": self.party,
|
||||||
|
"party_account": self.paid_from if self.payment_type == "Receive" else self.paid_to,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Group latest_references by (voucher_type, voucher_no)
|
||||||
|
latest_lookup = {}
|
||||||
|
for d in latest_references:
|
||||||
|
d = frappe._dict(d)
|
||||||
|
latest_lookup.update({(d.voucher_type, d.voucher_no): d})
|
||||||
|
|
||||||
|
for d in self.get("references").copy():
|
||||||
|
latest = latest_lookup.get((d.reference_doctype, d.reference_name))
|
||||||
|
|
||||||
|
# The reference has already been fully paid
|
||||||
|
if not latest:
|
||||||
|
frappe.throw(
|
||||||
|
_("{0} {1} has already been fully paid.").format(d.reference_doctype, d.reference_name)
|
||||||
|
)
|
||||||
|
# The reference has already been partly paid
|
||||||
|
elif (
|
||||||
|
latest.outstanding_amount < latest.invoice_amount
|
||||||
|
and d.outstanding_amount != latest.outstanding_amount
|
||||||
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"{0} {1} has already been partly paid. Please use the 'Get Outstanding Invoice' button to get the latest outstanding amount."
|
||||||
|
).format(d.reference_doctype, d.reference_name)
|
||||||
|
)
|
||||||
|
|
||||||
|
d.outstanding_amount = latest.outstanding_amount
|
||||||
|
|
||||||
|
fail_message = _("Row #{0}: Allocated Amount cannot be greater than outstanding amount.")
|
||||||
|
|
||||||
if (flt(d.allocated_amount)) > 0:
|
if (flt(d.allocated_amount)) > 0:
|
||||||
if flt(d.allocated_amount) > flt(d.outstanding_amount):
|
if flt(d.allocated_amount) > flt(d.outstanding_amount):
|
||||||
frappe.throw(
|
frappe.throw(fail_message.format(d.idx))
|
||||||
_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check for negative outstanding invoices as well
|
# Check for negative outstanding invoices as well
|
||||||
if flt(d.allocated_amount) < 0:
|
if flt(d.allocated_amount) < 0:
|
||||||
if flt(d.allocated_amount) < flt(d.outstanding_amount):
|
if flt(d.allocated_amount) < flt(d.outstanding_amount):
|
||||||
frappe.throw(
|
frappe.throw(fail_message.format(d.idx))
|
||||||
_("Row #{0}: Allocated Amount cannot be greater than outstanding amount.").format(d.idx)
|
|
||||||
)
|
|
||||||
|
|
||||||
def delink_advance_entry_references(self):
|
def delink_advance_entry_references(self):
|
||||||
for reference in self.references:
|
for reference in self.references:
|
||||||
@ -373,7 +411,7 @@ class PaymentEntry(AccountsController):
|
|||||||
for k, v in no_oustanding_refs.items():
|
for k, v in no_oustanding_refs.items():
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
_(
|
_(
|
||||||
"{} - {} now have {} as they had no outstanding amount left before submitting the Payment Entry."
|
"{} - {} now has {} as it had no outstanding amount left before submitting the Payment Entry."
|
||||||
).format(
|
).format(
|
||||||
_(k),
|
_(k),
|
||||||
frappe.bold(", ".join(d.reference_name for d in v)),
|
frappe.bold(", ".join(d.reference_name for d in v)),
|
||||||
@ -1449,7 +1487,7 @@ def get_orders_to_be_billed(
|
|||||||
if voucher_type:
|
if voucher_type:
|
||||||
doc = frappe.get_doc({"doctype": voucher_type})
|
doc = frappe.get_doc({"doctype": voucher_type})
|
||||||
condition = ""
|
condition = ""
|
||||||
if doc and hasattr(doc, "cost_center"):
|
if doc and hasattr(doc, "cost_center") and doc.cost_center:
|
||||||
condition = " and cost_center='%s'" % cost_center
|
condition = " and cost_center='%s'" % cost_center
|
||||||
|
|
||||||
orders = []
|
orders = []
|
||||||
@ -1495,9 +1533,15 @@ def get_orders_to_be_billed(
|
|||||||
|
|
||||||
order_list = []
|
order_list = []
|
||||||
for d in orders:
|
for d in orders:
|
||||||
if not (
|
if (
|
||||||
flt(d.outstanding_amount) >= flt(filters.get("outstanding_amt_greater_than"))
|
filters
|
||||||
and flt(d.outstanding_amount) <= flt(filters.get("outstanding_amt_less_than"))
|
and filters.get("outstanding_amt_greater_than")
|
||||||
|
and filters.get("outstanding_amt_less_than")
|
||||||
|
and not (
|
||||||
|
flt(filters.get("outstanding_amt_greater_than"))
|
||||||
|
<= flt(d.outstanding_amount)
|
||||||
|
<= flt(filters.get("outstanding_amt_less_than"))
|
||||||
|
)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1013,6 +1013,30 @@ class TestPaymentEntry(FrappeTestCase):
|
|||||||
employee = make_employee("test_payment_entry@salary.com", company="_Test Company")
|
employee = make_employee("test_payment_entry@salary.com", company="_Test Company")
|
||||||
create_payment_entry(party_type="Employee", party=employee, save=True)
|
create_payment_entry(party_type="Employee", party=employee, save=True)
|
||||||
|
|
||||||
|
def test_duplicate_payment_entry_allocate_amount(self):
|
||||||
|
si = create_sales_invoice()
|
||||||
|
|
||||||
|
pe_draft = get_payment_entry("Sales Invoice", si.name)
|
||||||
|
pe_draft.insert()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Invoice", si.name)
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
self.assertRaises(frappe.ValidationError, pe_draft.submit)
|
||||||
|
|
||||||
|
def test_duplicate_payment_entry_partial_allocate_amount(self):
|
||||||
|
si = create_sales_invoice()
|
||||||
|
|
||||||
|
pe_draft = get_payment_entry("Sales Invoice", si.name)
|
||||||
|
pe_draft.insert()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Invoice", si.name)
|
||||||
|
pe.received_amount = si.total / 2
|
||||||
|
pe.references[0].allocated_amount = si.total / 2
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
self.assertRaises(frappe.ValidationError, pe_draft.submit)
|
||||||
|
|
||||||
|
|
||||||
def create_payment_entry(**args):
|
def create_payment_entry(**args):
|
||||||
payment_entry = frappe.new_doc("Payment Entry")
|
payment_entry = frappe.new_doc("Payment Entry")
|
||||||
|
@ -65,22 +65,22 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
this.frm.add_custom_button(__('Get Unreconciled Entries'), () =>
|
this.frm.add_custom_button(__('Get Unreconciled Entries'), () =>
|
||||||
this.frm.trigger("get_unreconciled_entries")
|
this.frm.trigger("get_unreconciled_entries")
|
||||||
);
|
);
|
||||||
this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'primary');
|
this.frm.change_custom_button_type(__('Get Unreconciled Entries'), null, 'primary');
|
||||||
}
|
}
|
||||||
if (this.frm.doc.invoices.length && this.frm.doc.payments.length) {
|
if (this.frm.doc.invoices.length && this.frm.doc.payments.length) {
|
||||||
this.frm.add_custom_button(__('Allocate'), () =>
|
this.frm.add_custom_button(__('Allocate'), () =>
|
||||||
this.frm.trigger("allocate")
|
this.frm.trigger("allocate")
|
||||||
);
|
);
|
||||||
this.frm.change_custom_button_type('Allocate', null, 'primary');
|
this.frm.change_custom_button_type(__('Allocate'), null, 'primary');
|
||||||
this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default');
|
this.frm.change_custom_button_type(__('Get Unreconciled Entries'), null, 'default');
|
||||||
}
|
}
|
||||||
if (this.frm.doc.allocation.length) {
|
if (this.frm.doc.allocation.length) {
|
||||||
this.frm.add_custom_button(__('Reconcile'), () =>
|
this.frm.add_custom_button(__('Reconcile'), () =>
|
||||||
this.frm.trigger("reconcile")
|
this.frm.trigger("reconcile")
|
||||||
);
|
);
|
||||||
this.frm.change_custom_button_type('Reconcile', null, 'primary');
|
this.frm.change_custom_button_type(__('Reconcile'), null, 'primary');
|
||||||
this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default');
|
this.frm.change_custom_button_type(__('Get Unreconciled Entries'), null, 'default');
|
||||||
this.frm.change_custom_button_type('Allocate', null, 'default');
|
this.frm.change_custom_button_type(__('Allocate'), null, 'default');
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for any running reconciliation jobs
|
// check for any running reconciliation jobs
|
||||||
|
@ -6,7 +6,6 @@ import frappe
|
|||||||
from frappe import _, msgprint, qb
|
from frappe import _, msgprint, qb
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.query_builder.custom import ConstantColumn
|
from frappe.query_builder.custom import ConstantColumn
|
||||||
from frappe.query_builder.functions import IfNull
|
|
||||||
from frappe.utils import flt, get_link_to_form, getdate, nowdate, today
|
from frappe.utils import flt, get_link_to_form, getdate, nowdate, today
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@ -127,12 +126,29 @@ class PaymentReconciliation(Document):
|
|||||||
|
|
||||||
return list(journal_entries)
|
return list(journal_entries)
|
||||||
|
|
||||||
|
def get_return_invoices(self):
|
||||||
|
voucher_type = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
||||||
|
doc = qb.DocType(voucher_type)
|
||||||
|
self.return_invoices = (
|
||||||
|
qb.from_(doc)
|
||||||
|
.select(
|
||||||
|
ConstantColumn(voucher_type).as_("voucher_type"),
|
||||||
|
doc.name.as_("voucher_no"),
|
||||||
|
doc.return_against,
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
(doc.docstatus == 1)
|
||||||
|
& (doc[frappe.scrub(self.party_type)] == self.party)
|
||||||
|
& (doc.is_return == 1)
|
||||||
|
)
|
||||||
|
.run(as_dict=True)
|
||||||
|
)
|
||||||
|
|
||||||
def get_dr_or_cr_notes(self):
|
def get_dr_or_cr_notes(self):
|
||||||
|
|
||||||
self.build_qb_filter_conditions(get_return_invoices=True)
|
self.build_qb_filter_conditions(get_return_invoices=True)
|
||||||
|
|
||||||
ple = qb.DocType("Payment Ledger Entry")
|
ple = qb.DocType("Payment Ledger Entry")
|
||||||
voucher_type = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
|
||||||
|
|
||||||
if erpnext.get_party_account_type(self.party_type) == "Receivable":
|
if erpnext.get_party_account_type(self.party_type) == "Receivable":
|
||||||
self.common_filter_conditions.append(ple.account_type == "Receivable")
|
self.common_filter_conditions.append(ple.account_type == "Receivable")
|
||||||
@ -140,19 +156,10 @@ class PaymentReconciliation(Document):
|
|||||||
self.common_filter_conditions.append(ple.account_type == "Payable")
|
self.common_filter_conditions.append(ple.account_type == "Payable")
|
||||||
self.common_filter_conditions.append(ple.account == self.receivable_payable_account)
|
self.common_filter_conditions.append(ple.account == self.receivable_payable_account)
|
||||||
|
|
||||||
# get return invoices
|
self.get_return_invoices()
|
||||||
doc = qb.DocType(voucher_type)
|
return_invoices = [
|
||||||
return_invoices = (
|
x for x in self.return_invoices if x.return_against == None or x.return_against == ""
|
||||||
qb.from_(doc)
|
]
|
||||||
.select(ConstantColumn(voucher_type).as_("voucher_type"), doc.name.as_("voucher_no"))
|
|
||||||
.where(
|
|
||||||
(doc.docstatus == 1)
|
|
||||||
& (doc[frappe.scrub(self.party_type)] == self.party)
|
|
||||||
& (doc.is_return == 1)
|
|
||||||
& (IfNull(doc.return_against, "") == "")
|
|
||||||
)
|
|
||||||
.run(as_dict=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
outstanding_dr_or_cr = []
|
outstanding_dr_or_cr = []
|
||||||
if return_invoices:
|
if return_invoices:
|
||||||
@ -204,6 +211,15 @@ class PaymentReconciliation(Document):
|
|||||||
accounting_dimensions=self.accounting_dimension_filter_conditions,
|
accounting_dimensions=self.accounting_dimension_filter_conditions,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cr_dr_notes = (
|
||||||
|
[x.voucher_no for x in self.return_invoices]
|
||||||
|
if self.party_type in ["Customer", "Supplier"]
|
||||||
|
else []
|
||||||
|
)
|
||||||
|
# Filter out cr/dr notes from outstanding invoices list
|
||||||
|
# Happens when non-standalone cr/dr notes are linked with another invoice through journal entry
|
||||||
|
non_reconciled_invoices = [x for x in non_reconciled_invoices if x.voucher_no not in cr_dr_notes]
|
||||||
|
|
||||||
if self.invoice_limit:
|
if self.invoice_limit:
|
||||||
non_reconciled_invoices = non_reconciled_invoices[: self.invoice_limit]
|
non_reconciled_invoices = non_reconciled_invoices[: self.invoice_limit]
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ class PeriodClosingVoucher(AccountsController):
|
|||||||
voucher_type="Period Closing Voucher",
|
voucher_type="Period Closing Voucher",
|
||||||
voucher_no=self.name,
|
voucher_no=self.name,
|
||||||
queue="long",
|
queue="long",
|
||||||
|
enqueue_after_commit=True,
|
||||||
)
|
)
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
_("The GL Entries will be cancelled in the background, it can take a few minutes."), alert=True
|
_("The GL Entries will be cancelled in the background, it can take a few minutes."), alert=True
|
||||||
|
@ -442,6 +442,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1554,11 +1555,10 @@
|
|||||||
"icon": "fa fa-file-text",
|
"icon": "fa fa-file-text",
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-09-30 03:49:50.455199",
|
"modified": "2023-06-03 16:23:41.083409",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "POS Invoice",
|
"name": "POS Invoice",
|
||||||
"name_case": "Title Case",
|
|
||||||
"naming_rule": "By \"Naming Series\" field",
|
"naming_rule": "By \"Naming Series\" field",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
@ -31,7 +31,7 @@ class TestPOSInvoice(unittest.TestCase):
|
|||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
|
|
||||||
if frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
|
if frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
|
||||||
frappe.db.set_value("Selling Settings", None, "validate_selling_price", 0)
|
frappe.db.set_single_value("Selling Settings", "validate_selling_price", 0)
|
||||||
|
|
||||||
def test_timestamp_change(self):
|
def test_timestamp_change(self):
|
||||||
w = create_pos_invoice(do_not_save=1)
|
w = create_pos_invoice(do_not_save=1)
|
||||||
@ -722,7 +722,7 @@ class TestPOSInvoice(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
|
if not frappe.db.get_single_value("Selling Settings", "validate_selling_price"):
|
||||||
frappe.db.set_value("Selling Settings", "Selling Settings", "validate_selling_price", 1)
|
frappe.db.set_single_value("Selling Settings", "validate_selling_price", 1)
|
||||||
|
|
||||||
item = "Test Selling Price Validation"
|
item = "Test Selling Price Validation"
|
||||||
make_item(item, {"is_stock_item": 1})
|
make_item(item, {"is_stock_item": 1})
|
||||||
|
@ -158,7 +158,7 @@ def get_customers_based_on_territory_or_customer_group(customer_collection, coll
|
|||||||
return frappe.get_list(
|
return frappe.get_list(
|
||||||
"Customer",
|
"Customer",
|
||||||
fields=["name", "customer_name", "email_id"],
|
fields=["name", "customer_name", "email_id"],
|
||||||
filters=[[fields_dict[customer_collection], "IN", selected]],
|
filters=[["disabled", "=", 0], [fields_dict[customer_collection], "IN", selected]],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -443,12 +443,14 @@
|
|||||||
"fieldname": "contact_mobile",
|
"fieldname": "contact_mobile",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "contact_email",
|
"fieldname": "contact_email",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Contact Email",
|
"label": "Contact Email",
|
||||||
|
"options": "Email",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
@ -1364,12 +1366,12 @@
|
|||||||
"depends_on": "eval:doc.update_stock && doc.is_internal_supplier",
|
"depends_on": "eval:doc.update_stock && doc.is_internal_supplier",
|
||||||
"fieldname": "set_from_warehouse",
|
"fieldname": "set_from_warehouse",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"ignore_user_permissions": 1,
|
||||||
"label": "Set From Warehouse",
|
"label": "Set From Warehouse",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Warehouse",
|
"options": "Warehouse",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "50px",
|
"print_width": "50px",
|
||||||
"ignore_user_permissions": 1,
|
|
||||||
"width": "50px"
|
"width": "50px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1573,7 +1575,7 @@
|
|||||||
"idx": 204,
|
"idx": 204,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-04-29 12:57:50.832598",
|
"modified": "2023-06-03 16:21:54.637245",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Purchase Invoice",
|
"name": "Purchase Invoice",
|
||||||
|
@ -42,7 +42,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(self):
|
def setUpClass(self):
|
||||||
unlink_payment_on_cancel_of_invoice()
|
unlink_payment_on_cancel_of_invoice()
|
||||||
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
|
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(self):
|
def tearDownClass(self):
|
||||||
@ -642,13 +642,6 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
gle_filters={"account": "Stock In Hand - TCP1"},
|
gle_filters={"account": "Stock In Hand - TCP1"},
|
||||||
)
|
)
|
||||||
|
|
||||||
# assert loss booked in COGS
|
|
||||||
self.assertGLEs(
|
|
||||||
return_pi,
|
|
||||||
[{"credit": 0, "debit": 200}],
|
|
||||||
gle_filters={"account": "Cost of Goods Sold - TCP1"},
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_return_with_lcv(self):
|
def test_return_with_lcv(self):
|
||||||
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
from erpnext.controllers.sales_and_purchase_return import make_return_doc
|
||||||
from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import (
|
from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import (
|
||||||
@ -1232,9 +1225,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1
|
|
||||||
)
|
|
||||||
|
|
||||||
original_account = frappe.db.get_value("Company", "_Test Company", "exchange_gain_loss_account")
|
original_account = frappe.db.get_value("Company", "_Test Company", "exchange_gain_loss_account")
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
@ -1369,8 +1360,8 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
pay.reload()
|
pay.reload()
|
||||||
pay.cancel()
|
pay.cancel()
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
|
"Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
|
||||||
)
|
)
|
||||||
frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account)
|
frappe.db.set_value("Company", "_Test Company", "exchange_gain_loss_account", original_account)
|
||||||
|
|
||||||
@ -1673,6 +1664,21 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
|||||||
|
|
||||||
self.assertTrue(return_pi.docstatus == 1)
|
self.assertTrue(return_pi.docstatus == 1)
|
||||||
|
|
||||||
|
def test_gl_entries_for_standalone_debit_note(self):
|
||||||
|
make_purchase_invoice(qty=5, rate=500, update_stock=True)
|
||||||
|
|
||||||
|
returned_inv = make_purchase_invoice(qty=-5, rate=5, update_stock=True, is_return=True)
|
||||||
|
|
||||||
|
# override the rate with valuation rate
|
||||||
|
sle = frappe.get_all(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
fields=["stock_value_difference", "actual_qty"],
|
||||||
|
filters={"voucher_no": returned_inv.name},
|
||||||
|
)[0]
|
||||||
|
|
||||||
|
rate = flt(sle.stock_value_difference) / flt(sle.actual_qty)
|
||||||
|
self.assertAlmostEqual(returned_inv.items[0].rate, rate)
|
||||||
|
|
||||||
|
|
||||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
|
@ -520,6 +520,7 @@
|
|||||||
"hide_days": 1,
|
"hide_days": 1,
|
||||||
"hide_seconds": 1,
|
"hide_seconds": 1,
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -2154,7 +2155,7 @@
|
|||||||
"link_fieldname": "consolidated_invoice"
|
"link_fieldname": "consolidated_invoice"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2023-04-28 14:15:59.901154",
|
"modified": "2023-06-03 16:22:16.219333",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Sales Invoice",
|
"name": "Sales Invoice",
|
||||||
|
@ -1063,7 +1063,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(pos.write_off_amount, 10)
|
self.assertEqual(pos.write_off_amount, 10)
|
||||||
|
|
||||||
def test_pos_with_no_gl_entry_for_change_amount(self):
|
def test_pos_with_no_gl_entry_for_change_amount(self):
|
||||||
frappe.db.set_value("Accounts Settings", None, "post_change_gl_entries", 0)
|
frappe.db.set_single_value("Accounts Settings", "post_change_gl_entries", 0)
|
||||||
|
|
||||||
make_pos_profile(
|
make_pos_profile(
|
||||||
company="_Test Company with perpetual inventory",
|
company="_Test Company with perpetual inventory",
|
||||||
@ -1113,7 +1113,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
self.validate_pos_gl_entry(pos, pos, 60, validate_without_change_gle=True)
|
self.validate_pos_gl_entry(pos, pos, 60, validate_without_change_gle=True)
|
||||||
|
|
||||||
frappe.db.set_value("Accounts Settings", None, "post_change_gl_entries", 1)
|
frappe.db.set_single_value("Accounts Settings", "post_change_gl_entries", 1)
|
||||||
|
|
||||||
def validate_pos_gl_entry(self, si, pos, cash_amount, validate_without_change_gle=False):
|
def validate_pos_gl_entry(self, si, pos, cash_amount, validate_without_change_gle=False):
|
||||||
if validate_without_change_gle:
|
if validate_without_change_gle:
|
||||||
@ -2452,7 +2452,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
"Check mapping (expense account) of inter company SI to PI in absence of default warehouse."
|
"Check mapping (expense account) of inter company SI to PI in absence of default warehouse."
|
||||||
# setup
|
# setup
|
||||||
old_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock")
|
old_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock")
|
||||||
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
|
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1)
|
||||||
|
|
||||||
old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company 1")
|
old_perpetual_inventory = erpnext.is_perpetual_inventory_enabled("_Test Company 1")
|
||||||
frappe.local.enable_perpetual_inventory["_Test Company 1"] = 1
|
frappe.local.enable_perpetual_inventory["_Test Company 1"] = 1
|
||||||
@ -2506,7 +2506,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
# tear down
|
# tear down
|
||||||
frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory
|
frappe.local.enable_perpetual_inventory["_Test Company 1"] = old_perpetual_inventory
|
||||||
frappe.db.set_value("Stock Settings", None, "allow_negative_stock", old_negative_stock)
|
frappe.db.set_single_value("Stock Settings", "allow_negative_stock", old_negative_stock)
|
||||||
|
|
||||||
def test_sle_for_target_warehouse(self):
|
def test_sle_for_target_warehouse(self):
|
||||||
se = make_stock_entry(
|
se = make_stock_entry(
|
||||||
@ -2898,7 +2898,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
party_link = create_party_link("Supplier", supplier, customer)
|
party_link = create_party_link("Supplier", supplier, customer)
|
||||||
|
|
||||||
# enable common party accounting
|
# enable common party accounting
|
||||||
frappe.db.set_value("Accounts Settings", None, "enable_common_party_accounting", 1)
|
frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 1)
|
||||||
|
|
||||||
# create a sales invoice
|
# create a sales invoice
|
||||||
si = create_sales_invoice(customer=customer, parent_cost_center="_Test Cost Center - _TC")
|
si = create_sales_invoice(customer=customer, parent_cost_center="_Test Cost Center - _TC")
|
||||||
@ -2925,7 +2925,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(jv[0], si.grand_total)
|
self.assertEqual(jv[0], si.grand_total)
|
||||||
|
|
||||||
party_link.delete()
|
party_link.delete()
|
||||||
frappe.db.set_value("Accounts Settings", None, "enable_common_party_accounting", 0)
|
frappe.db.set_single_value("Accounts Settings", "enable_common_party_accounting", 0)
|
||||||
|
|
||||||
def test_payment_statuses(self):
|
def test_payment_statuses(self):
|
||||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
from erpnext.accounts.doctype.payment_entry.test_payment_entry import get_payment_entry
|
||||||
@ -3045,7 +3045,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
self.assertRaises(frappe.ValidationError, si.save)
|
self.assertRaises(frappe.ValidationError, si.save)
|
||||||
|
|
||||||
def test_sales_invoice_submission_post_account_freezing_date(self):
|
def test_sales_invoice_submission_post_account_freezing_date(self):
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", add_days(getdate(), 1))
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", add_days(getdate(), 1))
|
||||||
si = create_sales_invoice(do_not_save=True)
|
si = create_sales_invoice(do_not_save=True)
|
||||||
si.posting_date = add_days(getdate(), 1)
|
si.posting_date = add_days(getdate(), 1)
|
||||||
si.save()
|
si.save()
|
||||||
@ -3054,7 +3054,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
si.posting_date = getdate()
|
si.posting_date = getdate()
|
||||||
si.submit()
|
si.submit()
|
||||||
|
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None)
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
||||||
|
|
||||||
def test_over_billing_case_against_delivery_note(self):
|
def test_over_billing_case_against_delivery_note(self):
|
||||||
"""
|
"""
|
||||||
@ -3066,7 +3066,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
over_billing_allowance = frappe.db.get_single_value(
|
over_billing_allowance = frappe.db.get_single_value(
|
||||||
"Accounts Settings", "over_billing_allowance"
|
"Accounts Settings", "over_billing_allowance"
|
||||||
)
|
)
|
||||||
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", 0)
|
frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 0)
|
||||||
|
|
||||||
dn = create_delivery_note()
|
dn = create_delivery_note()
|
||||||
dn.submit()
|
dn.submit()
|
||||||
@ -3082,7 +3082,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertTrue("cannot overbill" in str(err.exception).lower())
|
self.assertTrue("cannot overbill" in str(err.exception).lower())
|
||||||
|
|
||||||
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", over_billing_allowance)
|
frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", over_billing_allowance)
|
||||||
|
|
||||||
def test_multi_currency_deferred_revenue_via_journal_entry(self):
|
def test_multi_currency_deferred_revenue_via_journal_entry(self):
|
||||||
deferred_account = create_account(
|
deferred_account = create_account(
|
||||||
@ -3121,7 +3121,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
si.save()
|
si.save()
|
||||||
si.submit()
|
si.submit()
|
||||||
|
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", getdate("2019-01-31"))
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", getdate("2019-01-31"))
|
||||||
|
|
||||||
pda1 = frappe.get_doc(
|
pda1 = frappe.get_doc(
|
||||||
dict(
|
dict(
|
||||||
@ -3166,7 +3166,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
acc_settings.submit_journal_entries = 0
|
acc_settings.submit_journal_entries = 0
|
||||||
acc_settings.save()
|
acc_settings.save()
|
||||||
|
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None)
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
||||||
|
|
||||||
def test_standalone_serial_no_return(self):
|
def test_standalone_serial_no_return(self):
|
||||||
si = create_sales_invoice(
|
si = create_sales_invoice(
|
||||||
@ -3216,9 +3216,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice"
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value("Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1)
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", 1
|
|
||||||
)
|
|
||||||
|
|
||||||
jv = make_journal_entry("_Test Receivable USD - _TC", "_Test Bank - _TC", -7000, save=False)
|
jv = make_journal_entry("_Test Receivable USD - _TC", "_Test Bank - _TC", -7000, save=False)
|
||||||
|
|
||||||
@ -3261,8 +3259,8 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
|
|
||||||
check_gl_entries(self, si.name, expected_gle, nowdate())
|
check_gl_entries(self, si.name, expected_gle, nowdate())
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Accounts Settings", "Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
|
"Accounts Settings", "unlink_payment_on_cancel_of_invoice", unlink_enabled
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_batch_expiry_for_sales_invoice_return(self):
|
def test_batch_expiry_for_sales_invoice_return(self):
|
||||||
|
@ -15,7 +15,7 @@ test_records = frappe.get_test_records("Tax Rule")
|
|||||||
class TestTaxRule(unittest.TestCase):
|
class TestTaxRule(unittest.TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
frappe.db.set_value("Shopping Cart Settings", None, "enabled", 0)
|
frappe.db.set_single_value("Shopping Cart Settings", "enabled", 0)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _, qb
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import cint, getdate
|
from frappe.query_builder import Criterion
|
||||||
|
from frappe.query_builder.functions import Abs, Sum
|
||||||
|
from frappe.utils import cint, flt, getdate
|
||||||
|
|
||||||
|
|
||||||
class TaxWithholdingCategory(Document):
|
class TaxWithholdingCategory(Document):
|
||||||
@ -346,26 +348,33 @@ def get_invoice_vouchers(parties, tax_details, company, party_type="Supplier"):
|
|||||||
def get_advance_vouchers(
|
def get_advance_vouchers(
|
||||||
parties, company=None, from_date=None, to_date=None, party_type="Supplier"
|
parties, company=None, from_date=None, to_date=None, party_type="Supplier"
|
||||||
):
|
):
|
||||||
# for advance vouchers, debit and credit is reversed
|
"""
|
||||||
dr_or_cr = "debit" if party_type == "Supplier" else "credit"
|
Use Payment Ledger to fetch unallocated Advance Payments
|
||||||
|
"""
|
||||||
|
|
||||||
filters = {
|
ple = qb.DocType("Payment Ledger Entry")
|
||||||
dr_or_cr: [">", 0],
|
|
||||||
"is_opening": "No",
|
|
||||||
"is_cancelled": 0,
|
|
||||||
"party_type": party_type,
|
|
||||||
"party": ["in", parties],
|
|
||||||
}
|
|
||||||
|
|
||||||
if party_type == "Customer":
|
conditions = []
|
||||||
filters.update({"against_voucher": ["is", "not set"]})
|
|
||||||
|
conditions.append(ple.amount.lt(0))
|
||||||
|
conditions.append(ple.delinked == 0)
|
||||||
|
conditions.append(ple.party_type == party_type)
|
||||||
|
conditions.append(ple.party.isin(parties))
|
||||||
|
conditions.append(ple.voucher_no == ple.against_voucher_no)
|
||||||
|
|
||||||
if company:
|
if company:
|
||||||
filters["company"] = company
|
conditions.append(ple.company == company)
|
||||||
if from_date and to_date:
|
|
||||||
filters["posting_date"] = ["between", (from_date, to_date)]
|
|
||||||
|
|
||||||
return frappe.get_all("GL Entry", filters=filters, distinct=1, pluck="voucher_no") or [""]
|
if from_date and to_date:
|
||||||
|
conditions.append(ple.posting_date[from_date:to_date])
|
||||||
|
|
||||||
|
advances = (
|
||||||
|
qb.from_(ple).select(ple.voucher_no).distinct().where(Criterion.all(conditions)).run(as_list=1)
|
||||||
|
)
|
||||||
|
if advances:
|
||||||
|
advances = [x[0] for x in advances]
|
||||||
|
|
||||||
|
return advances
|
||||||
|
|
||||||
|
|
||||||
def get_taxes_deducted_on_advances_allocated(inv, tax_details):
|
def get_taxes_deducted_on_advances_allocated(inv, tax_details):
|
||||||
@ -499,6 +508,7 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers):
|
|||||||
|
|
||||||
def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers):
|
def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers):
|
||||||
tcs_amount = 0
|
tcs_amount = 0
|
||||||
|
ple = qb.DocType("Payment Ledger Entry")
|
||||||
|
|
||||||
# sum of debit entries made from sales invoices
|
# sum of debit entries made from sales invoices
|
||||||
invoiced_amt = (
|
invoiced_amt = (
|
||||||
@ -516,18 +526,20 @@ def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# sum of credit entries made from PE / JV with unset 'against voucher'
|
# sum of credit entries made from PE / JV with unset 'against voucher'
|
||||||
|
|
||||||
|
conditions = []
|
||||||
|
conditions.append(ple.amount.lt(0))
|
||||||
|
conditions.append(ple.delinked == 0)
|
||||||
|
conditions.append(ple.party.isin(parties))
|
||||||
|
conditions.append(ple.voucher_no == ple.against_voucher_no)
|
||||||
|
conditions.append(ple.company == inv.company)
|
||||||
|
|
||||||
|
advances = (
|
||||||
|
qb.from_(ple).select(Abs(Sum(ple.amount))).where(Criterion.all(conditions)).run(as_list=1)
|
||||||
|
)
|
||||||
|
|
||||||
advance_amt = (
|
advance_amt = (
|
||||||
frappe.db.get_value(
|
qb.from_(ple).select(Abs(Sum(ple.amount))).where(Criterion.all(conditions)).run()[0][0] or 0.0
|
||||||
"GL Entry",
|
|
||||||
{
|
|
||||||
"is_cancelled": 0,
|
|
||||||
"party": ["in", parties],
|
|
||||||
"company": inv.company,
|
|
||||||
"voucher_no": ["in", adv_vouchers],
|
|
||||||
},
|
|
||||||
"sum(credit)",
|
|
||||||
)
|
|
||||||
or 0.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# sum of credit entries made from sales invoice
|
# sum of credit entries made from sales invoice
|
||||||
@ -569,7 +581,12 @@ def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total):
|
|||||||
tds_amount = 0
|
tds_amount = 0
|
||||||
limit_consumed = frappe.db.get_value(
|
limit_consumed = frappe.db.get_value(
|
||||||
"Purchase Invoice",
|
"Purchase Invoice",
|
||||||
{"supplier": ("in", parties), "apply_tds": 1, "docstatus": 1},
|
{
|
||||||
|
"supplier": ("in", parties),
|
||||||
|
"apply_tds": 1,
|
||||||
|
"docstatus": 1,
|
||||||
|
"posting_date": ("between", (ldc.valid_from, ldc.valid_upto)),
|
||||||
|
},
|
||||||
"sum(tax_withholding_net_total)",
|
"sum(tax_withholding_net_total)",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -584,10 +601,10 @@ def get_tds_amount_from_ldc(ldc, parties, tax_details, posting_date, net_total):
|
|||||||
|
|
||||||
|
|
||||||
def get_ltds_amount(current_amount, deducted_amount, certificate_limit, rate, tax_details):
|
def get_ltds_amount(current_amount, deducted_amount, certificate_limit, rate, tax_details):
|
||||||
if current_amount < (certificate_limit - deducted_amount):
|
if certificate_limit - flt(deducted_amount) - flt(current_amount) >= 0:
|
||||||
return current_amount * rate / 100
|
return current_amount * rate / 100
|
||||||
else:
|
else:
|
||||||
ltds_amount = certificate_limit - deducted_amount
|
ltds_amount = certificate_limit - flt(deducted_amount)
|
||||||
tds_amount = current_amount - ltds_amount
|
tds_amount = current_amount - ltds_amount
|
||||||
|
|
||||||
return ltds_amount * rate / 100 + tds_amount * tax_details.rate / 100
|
return ltds_amount * rate / 100 + tds_amount * tax_details.rate / 100
|
||||||
@ -598,9 +615,9 @@ def is_valid_certificate(
|
|||||||
):
|
):
|
||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
if (
|
available_amount = flt(certificate_limit) - flt(deducted_amount) - flt(current_amount)
|
||||||
getdate(valid_from) <= getdate(posting_date) <= getdate(valid_upto)
|
|
||||||
) and certificate_limit > deducted_amount:
|
if (getdate(valid_from) <= getdate(posting_date) <= getdate(valid_upto)) and available_amount > 0:
|
||||||
valid = True
|
valid = True
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
|
@ -152,6 +152,60 @@ class TestTaxWithholdingCategory(unittest.TestCase):
|
|||||||
for d in reversed(invoices):
|
for d in reversed(invoices):
|
||||||
d.cancel()
|
d.cancel()
|
||||||
|
|
||||||
|
def test_tcs_on_unallocated_advance_payments(self):
|
||||||
|
frappe.db.set_value(
|
||||||
|
"Customer", "Test TCS Customer", "tax_withholding_category", "Cumulative Threshold TCS"
|
||||||
|
)
|
||||||
|
|
||||||
|
vouchers = []
|
||||||
|
|
||||||
|
# create advance payment
|
||||||
|
pe = create_payment_entry(
|
||||||
|
payment_type="Receive", party_type="Customer", party="Test TCS Customer", paid_amount=20000
|
||||||
|
)
|
||||||
|
pe.paid_from = "Debtors - _TC"
|
||||||
|
pe.paid_to = "Cash - _TC"
|
||||||
|
pe.submit()
|
||||||
|
vouchers.append(pe)
|
||||||
|
|
||||||
|
# create invoice
|
||||||
|
si1 = create_sales_invoice(customer="Test TCS Customer", rate=5000)
|
||||||
|
si1.submit()
|
||||||
|
vouchers.append(si1)
|
||||||
|
|
||||||
|
# reconcile
|
||||||
|
pr = frappe.get_doc("Payment Reconciliation")
|
||||||
|
pr.company = "_Test Company"
|
||||||
|
pr.party_type = "Customer"
|
||||||
|
pr.party = "Test TCS Customer"
|
||||||
|
pr.receivable_payable_account = "Debtors - _TC"
|
||||||
|
pr.get_unreconciled_entries()
|
||||||
|
invoices = [x.as_dict() for x in pr.get("invoices")]
|
||||||
|
payments = [x.as_dict() for x in pr.get("payments")]
|
||||||
|
pr.allocate_entries(frappe._dict({"invoices": invoices, "payments": payments}))
|
||||||
|
pr.reconcile()
|
||||||
|
|
||||||
|
# make another invoice
|
||||||
|
# sum of unallocated amount from payment entry and this sales invoice will breach cumulative threashold
|
||||||
|
# TDS should be calculated
|
||||||
|
si2 = create_sales_invoice(customer="Test TCS Customer", rate=15000)
|
||||||
|
si2.submit()
|
||||||
|
vouchers.append(si2)
|
||||||
|
|
||||||
|
si3 = create_sales_invoice(customer="Test TCS Customer", rate=10000)
|
||||||
|
si3.submit()
|
||||||
|
vouchers.append(si3)
|
||||||
|
|
||||||
|
# assert tax collection on total invoice amount created until now
|
||||||
|
tcs_charged = sum([d.base_tax_amount for d in si2.taxes if d.account_head == "TCS - _TC"])
|
||||||
|
tcs_charged += sum([d.base_tax_amount for d in si3.taxes if d.account_head == "TCS - _TC"])
|
||||||
|
self.assertEqual(tcs_charged, 1500)
|
||||||
|
|
||||||
|
# cancel invoice and payments to avoid clashing
|
||||||
|
for d in reversed(vouchers):
|
||||||
|
d.reload()
|
||||||
|
d.cancel()
|
||||||
|
|
||||||
def test_tds_calculation_on_net_total(self):
|
def test_tds_calculation_on_net_total(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Supplier", "Test TDS Supplier4", "tax_withholding_category", "Cumulative Threshold TDS"
|
"Supplier", "Test TDS Supplier4", "tax_withholding_category", "Cumulative Threshold TDS"
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, msgprint, scrub
|
from frappe import _, msgprint, scrub
|
||||||
from frappe.contacts.doctype.address.address import (
|
from frappe.contacts.doctype.address.address import (
|
||||||
@ -647,12 +649,12 @@ def set_taxes(
|
|||||||
else:
|
else:
|
||||||
args.update(get_party_details(party, party_type))
|
args.update(get_party_details(party, party_type))
|
||||||
|
|
||||||
if party_type in ("Customer", "Lead"):
|
if party_type in ("Customer", "Lead", "Prospect"):
|
||||||
args.update({"tax_type": "Sales"})
|
args.update({"tax_type": "Sales"})
|
||||||
|
|
||||||
if party_type == "Lead":
|
if party_type in ["Lead", "Prospect"]:
|
||||||
args["customer"] = None
|
args["customer"] = None
|
||||||
del args["lead"]
|
del args[frappe.scrub(party_type)]
|
||||||
else:
|
else:
|
||||||
args.update({"tax_type": "Purchase"})
|
args.update({"tax_type": "Purchase"})
|
||||||
|
|
||||||
@ -850,7 +852,7 @@ def get_dashboard_info(party_type, party, loyalty_program=None):
|
|||||||
return company_wise_info
|
return company_wise_info
|
||||||
|
|
||||||
|
|
||||||
def get_party_shipping_address(doctype, name):
|
def get_party_shipping_address(doctype: str, name: str) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Returns an Address name (best guess) for the given doctype and name for which `address_type == 'Shipping'` is true.
|
Returns an Address name (best guess) for the given doctype and name for which `address_type == 'Shipping'` is true.
|
||||||
and/or `is_shipping_address = 1`.
|
and/or `is_shipping_address = 1`.
|
||||||
@ -861,22 +863,23 @@ def get_party_shipping_address(doctype, name):
|
|||||||
:param name: Party name
|
:param name: Party name
|
||||||
:return: String
|
:return: String
|
||||||
"""
|
"""
|
||||||
out = frappe.db.sql(
|
shipping_addresses = frappe.get_all(
|
||||||
"SELECT dl.parent "
|
"Address",
|
||||||
"from `tabDynamic Link` dl join `tabAddress` ta on dl.parent=ta.name "
|
filters=[
|
||||||
"where "
|
["Dynamic Link", "link_doctype", "=", doctype],
|
||||||
"dl.link_doctype=%s "
|
["Dynamic Link", "link_name", "=", name],
|
||||||
"and dl.link_name=%s "
|
["disabled", "=", 0],
|
||||||
"and dl.parenttype='Address' "
|
],
|
||||||
"and ifnull(ta.disabled, 0) = 0 and"
|
or_filters=[
|
||||||
"(ta.address_type='Shipping' or ta.is_shipping_address=1) "
|
["is_shipping_address", "=", 1],
|
||||||
"order by ta.is_shipping_address desc, ta.address_type desc limit 1",
|
["address_type", "=", "Shipping"],
|
||||||
(doctype, name),
|
],
|
||||||
|
pluck="name",
|
||||||
|
limit=1,
|
||||||
|
order_by="is_shipping_address DESC",
|
||||||
)
|
)
|
||||||
if out:
|
|
||||||
return out[0][0]
|
return shipping_addresses[0] if shipping_addresses else None
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def get_partywise_advanced_payment_amount(
|
def get_partywise_advanced_payment_amount(
|
||||||
@ -910,31 +913,32 @@ def get_partywise_advanced_payment_amount(
|
|||||||
return frappe._dict(data)
|
return frappe._dict(data)
|
||||||
|
|
||||||
|
|
||||||
def get_default_contact(doctype, name):
|
def get_default_contact(doctype: str, name: str) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Returns default contact for the given doctype and name.
|
Returns contact name only if there is a primary contact for given doctype and name.
|
||||||
Can be ordered by `contact_type` to either is_primary_contact or is_billing_contact.
|
|
||||||
|
Else returns None
|
||||||
|
|
||||||
|
:param doctype: Party Doctype
|
||||||
|
:param name: Party name
|
||||||
|
:return: String
|
||||||
"""
|
"""
|
||||||
out = frappe.db.sql(
|
contacts = frappe.get_all(
|
||||||
"""
|
"Contact",
|
||||||
SELECT dl.parent, c.is_primary_contact, c.is_billing_contact
|
filters=[
|
||||||
FROM `tabDynamic Link` dl
|
["Dynamic Link", "link_doctype", "=", doctype],
|
||||||
INNER JOIN `tabContact` c ON c.name = dl.parent
|
["Dynamic Link", "link_name", "=", name],
|
||||||
WHERE
|
],
|
||||||
dl.link_doctype=%s AND
|
or_filters=[
|
||||||
dl.link_name=%s AND
|
["is_primary_contact", "=", 1],
|
||||||
dl.parenttype = 'Contact'
|
["is_billing_contact", "=", 1],
|
||||||
ORDER BY is_primary_contact DESC, is_billing_contact DESC
|
],
|
||||||
""",
|
pluck="name",
|
||||||
(doctype, name),
|
limit=1,
|
||||||
|
order_by="is_primary_contact DESC, is_billing_contact DESC",
|
||||||
)
|
)
|
||||||
if out:
|
|
||||||
try:
|
return contacts[0] if contacts else None
|
||||||
return out[0][0]
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def add_party_account(party_type, party, company, account):
|
def add_party_account(party_type, party, company, account):
|
||||||
|
@ -181,6 +181,16 @@ class ReceivablePayableReport(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
key = (ple.against_voucher_type, ple.against_voucher_no, ple.party)
|
||||||
|
|
||||||
|
# If payment is made against credit note
|
||||||
|
# and credit note is made against a Sales Invoice
|
||||||
|
# then consider the payment against original sales invoice.
|
||||||
|
if ple.against_voucher_type in ("Sales Invoice", "Purchase Invoice"):
|
||||||
|
if ple.against_voucher_no in self.return_entries:
|
||||||
|
return_against = self.return_entries.get(ple.against_voucher_no)
|
||||||
|
if return_against:
|
||||||
|
key = (ple.against_voucher_type, return_against, ple.party)
|
||||||
|
|
||||||
row = self.voucher_balance.get(key)
|
row = self.voucher_balance.get(key)
|
||||||
|
|
||||||
if not row:
|
if not row:
|
||||||
@ -610,7 +620,7 @@ class ReceivablePayableReport(object):
|
|||||||
|
|
||||||
def get_return_entries(self):
|
def get_return_entries(self):
|
||||||
doctype = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
doctype = "Sales Invoice" if self.party_type == "Customer" else "Purchase Invoice"
|
||||||
filters = {"is_return": 1, "docstatus": 1}
|
filters = {"is_return": 1, "docstatus": 1, "company": self.filters.company}
|
||||||
party_field = scrub(self.filters.party_type)
|
party_field = scrub(self.filters.party_type)
|
||||||
if self.filters.get(party_field):
|
if self.filters.get(party_field):
|
||||||
filters.update({party_field: self.filters.get(party_field)})
|
filters.update({party_field: self.filters.get(party_field)})
|
||||||
|
@ -210,6 +210,67 @@ class TestAccountsReceivable(FrappeTestCase):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_payment_against_credit_note(self):
|
||||||
|
"""
|
||||||
|
Payment against credit/debit note should be considered against the parent invoice
|
||||||
|
"""
|
||||||
|
company = "_Test Company 2"
|
||||||
|
customer = "_Test Customer 2"
|
||||||
|
|
||||||
|
si1 = make_sales_invoice()
|
||||||
|
|
||||||
|
pe = get_payment_entry("Sales Invoice", si1.name, bank_account="Cash - _TC2")
|
||||||
|
pe.paid_from = "Debtors - _TC2"
|
||||||
|
pe.insert()
|
||||||
|
pe.submit()
|
||||||
|
|
||||||
|
cr_note = make_credit_note(si1.name)
|
||||||
|
|
||||||
|
si2 = make_sales_invoice()
|
||||||
|
|
||||||
|
# manually link cr_note with si2 using journal entry
|
||||||
|
je = frappe.new_doc("Journal Entry")
|
||||||
|
je.company = company
|
||||||
|
je.voucher_type = "Credit Note"
|
||||||
|
je.posting_date = today()
|
||||||
|
|
||||||
|
debit_account = "Debtors - _TC2"
|
||||||
|
debit_entry = {
|
||||||
|
"account": debit_account,
|
||||||
|
"party_type": "Customer",
|
||||||
|
"party": customer,
|
||||||
|
"debit": 100,
|
||||||
|
"debit_in_account_currency": 100,
|
||||||
|
"reference_type": cr_note.doctype,
|
||||||
|
"reference_name": cr_note.name,
|
||||||
|
"cost_center": "Main - _TC2",
|
||||||
|
}
|
||||||
|
credit_entry = {
|
||||||
|
"account": debit_account,
|
||||||
|
"party_type": "Customer",
|
||||||
|
"party": customer,
|
||||||
|
"credit": 100,
|
||||||
|
"credit_in_account_currency": 100,
|
||||||
|
"reference_type": si2.doctype,
|
||||||
|
"reference_name": si2.name,
|
||||||
|
"cost_center": "Main - _TC2",
|
||||||
|
}
|
||||||
|
|
||||||
|
je.append("accounts", debit_entry)
|
||||||
|
je.append("accounts", credit_entry)
|
||||||
|
je = je.save().submit()
|
||||||
|
|
||||||
|
filters = {
|
||||||
|
"company": company,
|
||||||
|
"report_date": today(),
|
||||||
|
"range1": 30,
|
||||||
|
"range2": 60,
|
||||||
|
"range3": 90,
|
||||||
|
"range4": 120,
|
||||||
|
}
|
||||||
|
report = execute(filters)
|
||||||
|
self.assertEqual(report[1], [])
|
||||||
|
|
||||||
|
|
||||||
def make_sales_invoice(no_payment_schedule=False, do_not_submit=False):
|
def make_sales_invoice(no_payment_schedule=False, do_not_submit=False):
|
||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
@ -256,7 +317,7 @@ def make_payment(docname):
|
|||||||
|
|
||||||
|
|
||||||
def make_credit_note(docname):
|
def make_credit_note(docname):
|
||||||
create_sales_invoice(
|
credit_note = create_sales_invoice(
|
||||||
company="_Test Company 2",
|
company="_Test Company 2",
|
||||||
customer="_Test Customer 2",
|
customer="_Test Customer 2",
|
||||||
currency="EUR",
|
currency="EUR",
|
||||||
@ -269,3 +330,5 @@ def make_credit_note(docname):
|
|||||||
is_return=1,
|
is_return=1,
|
||||||
return_against=docname,
|
return_against=docname,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return credit_note
|
||||||
|
@ -399,8 +399,9 @@ def get_items(filters, additional_query_columns, additional_conditions=None):
|
|||||||
`tabSales Invoice`.posting_date, `tabSales Invoice`.debit_to,
|
`tabSales Invoice`.posting_date, `tabSales Invoice`.debit_to,
|
||||||
`tabSales Invoice`.unrealized_profit_loss_account,
|
`tabSales Invoice`.unrealized_profit_loss_account,
|
||||||
`tabSales Invoice`.is_internal_customer,
|
`tabSales Invoice`.is_internal_customer,
|
||||||
`tabSales Invoice`.project, `tabSales Invoice`.customer, `tabSales Invoice`.remarks,
|
`tabSales Invoice`.customer, `tabSales Invoice`.remarks,
|
||||||
`tabSales Invoice`.territory, `tabSales Invoice`.company, `tabSales Invoice`.base_net_total,
|
`tabSales Invoice`.territory, `tabSales Invoice`.company, `tabSales Invoice`.base_net_total,
|
||||||
|
`tabSales Invoice Item`.project,
|
||||||
`tabSales Invoice Item`.item_code, `tabSales Invoice Item`.description,
|
`tabSales Invoice Item`.item_code, `tabSales Invoice Item`.description,
|
||||||
`tabSales Invoice Item`.`item_name`, `tabSales Invoice Item`.`item_group`,
|
`tabSales Invoice Item`.`item_name`, `tabSales Invoice Item`.`item_group`,
|
||||||
`tabSales Invoice Item`.sales_order, `tabSales Invoice Item`.delivery_note,
|
`tabSales Invoice Item`.sales_order, `tabSales Invoice Item`.delivery_note,
|
||||||
|
@ -513,18 +513,22 @@ def get_gl_entries_on_asset_disposal(
|
|||||||
},
|
},
|
||||||
item=asset,
|
item=asset,
|
||||||
),
|
),
|
||||||
asset.get_gl_dict(
|
|
||||||
{
|
|
||||||
"account": accumulated_depr_account,
|
|
||||||
"debit_in_account_currency": accumulated_depr_amount,
|
|
||||||
"debit": accumulated_depr_amount,
|
|
||||||
"cost_center": depreciation_cost_center,
|
|
||||||
"posting_date": date,
|
|
||||||
},
|
|
||||||
item=asset,
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if accumulated_depr_amount:
|
||||||
|
gl_entries.append(
|
||||||
|
asset.get_gl_dict(
|
||||||
|
{
|
||||||
|
"account": accumulated_depr_account,
|
||||||
|
"debit_in_account_currency": accumulated_depr_amount,
|
||||||
|
"debit": accumulated_depr_amount,
|
||||||
|
"cost_center": depreciation_cost_center,
|
||||||
|
"posting_date": date,
|
||||||
|
},
|
||||||
|
item=asset,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
profit_amount = flt(selling_amount) - flt(value_after_depreciation)
|
profit_amount = flt(selling_amount) - flt(value_after_depreciation)
|
||||||
if profit_amount:
|
if profit_amount:
|
||||||
get_profit_gl_entries(
|
get_profit_gl_entries(
|
||||||
|
@ -812,14 +812,14 @@ class TestDepreciationMethods(AssetSetup):
|
|||||||
number_of_depreciations_booked=1,
|
number_of_depreciations_booked=1,
|
||||||
opening_accumulated_depreciation=50000,
|
opening_accumulated_depreciation=50000,
|
||||||
expected_value_after_useful_life=10000,
|
expected_value_after_useful_life=10000,
|
||||||
depreciation_start_date="2030-12-31",
|
depreciation_start_date="2031-12-31",
|
||||||
total_number_of_depreciations=3,
|
total_number_of_depreciations=3,
|
||||||
frequency_of_depreciation=12,
|
frequency_of_depreciation=12,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(asset.status, "Draft")
|
self.assertEqual(asset.status, "Draft")
|
||||||
|
|
||||||
expected_schedules = [["2030-12-31", 33333.50, 83333.50], ["2031-12-31", 6666.50, 90000.0]]
|
expected_schedules = [["2031-12-31", 33333.50, 83333.50], ["2032-12-31", 6666.50, 90000.0]]
|
||||||
|
|
||||||
schedules = [
|
schedules = [
|
||||||
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount]
|
||||||
@ -1804,7 +1804,7 @@ def set_depreciation_settings_in_company(company=None):
|
|||||||
company.save()
|
company.save()
|
||||||
|
|
||||||
# Enable booking asset depreciation entry automatically
|
# Enable booking asset depreciation entry automatically
|
||||||
frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1)
|
frappe.db.set_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically", 1)
|
||||||
|
|
||||||
|
|
||||||
def enable_cwip_accounting(asset_category, enable=1):
|
def enable_cwip_accounting(asset_category, enable=1):
|
||||||
|
@ -65,6 +65,18 @@ erpnext.assets.AssetCapitalization = class AssetCapitalization extends erpnext.s
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
me.frm.set_query("serial_and_batch_bundle", "stock_items", (doc, cdt, cdn) => {
|
||||||
|
let row = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'item_code': row.item_code,
|
||||||
|
'voucher_type': doc.doctype,
|
||||||
|
'voucher_no': ["in", [doc.name, ""]],
|
||||||
|
'is_cancelled': 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
me.frm.set_query("item_code", "stock_items", function() {
|
me.frm.set_query("item_code", "stock_items", function() {
|
||||||
return erpnext.queries.item({"is_stock_item": 1});
|
return erpnext.queries.item({"is_stock_item": 1});
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,7 @@ from frappe.utils import (
|
|||||||
cint,
|
cint,
|
||||||
date_diff,
|
date_diff,
|
||||||
flt,
|
flt,
|
||||||
|
get_first_day,
|
||||||
get_last_day,
|
get_last_day,
|
||||||
getdate,
|
getdate,
|
||||||
is_last_day_of_the_month,
|
is_last_day_of_the_month,
|
||||||
@ -271,8 +272,14 @@ class AssetDepreciationSchedule(Document):
|
|||||||
break
|
break
|
||||||
|
|
||||||
# For first row
|
# For first row
|
||||||
if n == 0 and has_pro_rata and not self.opening_accumulated_depreciation:
|
if (
|
||||||
from_date = add_days(asset_doc.available_for_use_date, -1)
|
n == 0
|
||||||
|
and (has_pro_rata or has_wdv_or_dd_non_yearly_pro_rata)
|
||||||
|
and not self.opening_accumulated_depreciation
|
||||||
|
):
|
||||||
|
from_date = add_days(
|
||||||
|
asset_doc.available_for_use_date, -1
|
||||||
|
) # needed to calc depr amount for available_for_use_date too
|
||||||
depreciation_amount, days, months = _get_pro_rata_amt(
|
depreciation_amount, days, months = _get_pro_rata_amt(
|
||||||
row,
|
row,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
@ -281,10 +288,18 @@ class AssetDepreciationSchedule(Document):
|
|||||||
has_wdv_or_dd_non_yearly_pro_rata,
|
has_wdv_or_dd_non_yearly_pro_rata,
|
||||||
)
|
)
|
||||||
elif n == 0 and has_wdv_or_dd_non_yearly_pro_rata and self.opening_accumulated_depreciation:
|
elif n == 0 and has_wdv_or_dd_non_yearly_pro_rata and self.opening_accumulated_depreciation:
|
||||||
from_date = add_months(
|
if not is_first_day_of_the_month(getdate(asset_doc.available_for_use_date)):
|
||||||
getdate(asset_doc.available_for_use_date),
|
from_date = get_last_day(
|
||||||
(self.number_of_depreciations_booked * row.frequency_of_depreciation),
|
add_months(
|
||||||
)
|
getdate(asset_doc.available_for_use_date),
|
||||||
|
((self.number_of_depreciations_booked - 1) * row.frequency_of_depreciation),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
from_date = add_months(
|
||||||
|
getdate(add_days(asset_doc.available_for_use_date, -1)),
|
||||||
|
(self.number_of_depreciations_booked * row.frequency_of_depreciation),
|
||||||
|
)
|
||||||
depreciation_amount, days, months = _get_pro_rata_amt(
|
depreciation_amount, days, months = _get_pro_rata_amt(
|
||||||
row,
|
row,
|
||||||
depreciation_amount,
|
depreciation_amount,
|
||||||
@ -702,3 +717,9 @@ def get_asset_depr_schedule_name(asset_name, status, finance_book=None):
|
|||||||
["status", "=", status],
|
["status", "=", status],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_first_day_of_the_month(date):
|
||||||
|
first_day_of_the_month = get_first_day(date)
|
||||||
|
|
||||||
|
return getdate(first_day_of_the_month) == getdate(date)
|
||||||
|
@ -182,4 +182,4 @@ def set_depreciation_settings_in_company():
|
|||||||
company.save()
|
company.save()
|
||||||
|
|
||||||
# Enable booking asset depreciation entry automatically
|
# Enable booking asset depreciation entry automatically
|
||||||
frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1)
|
frappe.db.set_single_value("Accounts Settings", "book_asset_depreciation_entry_automatically", 1)
|
||||||
|
@ -28,6 +28,18 @@ frappe.ui.form.on('Asset Repair', {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
frm.set_query("serial_and_batch_bundle", "stock_items", (doc, cdt, cdn) => {
|
||||||
|
let row = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'item_code': row.item_code,
|
||||||
|
'voucher_type': doc.doctype,
|
||||||
|
'voucher_no': ["in", [doc.name, ""]],
|
||||||
|
'is_cancelled': 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
@ -322,6 +322,7 @@
|
|||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Customer Mobile No",
|
"label": "Customer Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"print_hide": 1
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -368,6 +369,7 @@
|
|||||||
"fieldname": "contact_mobile",
|
"fieldname": "contact_mobile",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Contact Mobile No",
|
"label": "Contact Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1271,7 +1273,7 @@
|
|||||||
"idx": 105,
|
"idx": 105,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-05-24 11:16:41.195340",
|
"modified": "2023-06-03 16:19:45.710444",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Purchase Order",
|
"name": "Purchase Order",
|
||||||
|
@ -92,7 +92,7 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
|
|
||||||
frappe.db.set_value("Item", "_Test Item", "over_delivery_receipt_allowance", 0)
|
frappe.db.set_value("Item", "_Test Item", "over_delivery_receipt_allowance", 0)
|
||||||
frappe.db.set_value("Item", "_Test Item", "over_billing_allowance", 0)
|
frappe.db.set_value("Item", "_Test Item", "over_billing_allowance", 0)
|
||||||
frappe.db.set_value("Accounts Settings", None, "over_billing_allowance", 0)
|
frappe.db.set_single_value("Accounts Settings", "over_billing_allowance", 0)
|
||||||
|
|
||||||
def test_update_remove_child_linked_to_mr(self):
|
def test_update_remove_child_linked_to_mr(self):
|
||||||
"""Test impact on linked PO and MR on deleting/updating row."""
|
"""Test impact on linked PO and MR on deleting/updating row."""
|
||||||
@ -581,7 +581,7 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_group_same_items(self):
|
def test_group_same_items(self):
|
||||||
frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)
|
frappe.db.set_single_value("Buying Settings", "allow_multiple_items", 1)
|
||||||
frappe.get_doc(
|
frappe.get_doc(
|
||||||
{
|
{
|
||||||
"doctype": "Purchase Order",
|
"doctype": "Purchase Order",
|
||||||
@ -836,8 +836,8 @@ class TestPurchaseOrder(FrappeTestCase):
|
|||||||
)
|
)
|
||||||
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
|
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
|
||||||
|
|
||||||
frappe.db.set_value("Selling Settings", None, "maintain_same_sales_rate", 1)
|
frappe.db.set_single_value("Selling Settings", "maintain_same_sales_rate", 1)
|
||||||
frappe.db.set_value("Buying Settings", None, "maintain_same_rate", 1)
|
frappe.db.set_single_value("Buying Settings", "maintain_same_rate", 1)
|
||||||
|
|
||||||
prepare_data_for_internal_transfer()
|
prepare_data_for_internal_transfer()
|
||||||
supplier = "_Test Internal Supplier 2"
|
supplier = "_Test Internal Supplier 2"
|
||||||
|
@ -156,7 +156,7 @@ class TestSupplier(FrappeTestCase):
|
|||||||
def test_serach_fields_for_supplier(self):
|
def test_serach_fields_for_supplier(self):
|
||||||
from erpnext.controllers.queries import supplier_query
|
from erpnext.controllers.queries import supplier_query
|
||||||
|
|
||||||
frappe.db.set_value("Buying Settings", None, "supp_master_name", "Naming Series")
|
frappe.db.set_single_value("Buying Settings", "supp_master_name", "Naming Series")
|
||||||
|
|
||||||
supplier_name = create_supplier(supplier_name="Test Supplier 1").name
|
supplier_name = create_supplier(supplier_name="Test Supplier 1").name
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ class TestSupplier(FrappeTestCase):
|
|||||||
self.assertEqual(data[0].supplier_type, "Company")
|
self.assertEqual(data[0].supplier_type, "Company")
|
||||||
self.assertTrue("supplier_type" in data[0])
|
self.assertTrue("supplier_type" in data[0])
|
||||||
|
|
||||||
frappe.db.set_value("Buying Settings", None, "supp_master_name", "Supplier Name")
|
frappe.db.set_single_value("Buying Settings", "supp_master_name", "Supplier Name")
|
||||||
|
|
||||||
|
|
||||||
def create_supplier(**args):
|
def create_supplier(**args):
|
||||||
|
@ -230,6 +230,7 @@
|
|||||||
"fieldname": "contact_mobile",
|
"fieldname": "contact_mobile",
|
||||||
"fieldtype": "Small Text",
|
"fieldtype": "Small Text",
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -844,7 +845,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-04-14 16:43:41.714832",
|
"modified": "2023-06-03 16:20:15.880114",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Buying",
|
"module": "Buying",
|
||||||
"name": "Supplier Quotation",
|
"name": "Supplier Quotation",
|
||||||
|
@ -917,6 +917,9 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
return is_inclusive
|
return is_inclusive
|
||||||
|
|
||||||
|
def should_show_taxes_as_table_in_print(self):
|
||||||
|
return cint(frappe.db.get_single_value("Accounts Settings", "show_taxes_as_table_in_print"))
|
||||||
|
|
||||||
def validate_advance_entries(self):
|
def validate_advance_entries(self):
|
||||||
order_field = "sales_order" if self.doctype == "Sales Invoice" else "purchase_order"
|
order_field = "sales_order" if self.doctype == "Sales Invoice" else "purchase_order"
|
||||||
order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field)))
|
order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field)))
|
||||||
|
@ -26,6 +26,8 @@ class BuyingController(SubcontractingController):
|
|||||||
self.flags.ignore_permlevel_for_fields = ["buying_price_list", "price_list_currency"]
|
self.flags.ignore_permlevel_for_fields = ["buying_price_list", "price_list_currency"]
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.set_rate_for_standalone_debit_note()
|
||||||
|
|
||||||
super(BuyingController, self).validate()
|
super(BuyingController, self).validate()
|
||||||
if getattr(self, "supplier", None) and not self.supplier_name:
|
if getattr(self, "supplier", None) and not self.supplier_name:
|
||||||
self.supplier_name = frappe.db.get_value("Supplier", self.supplier, "supplier_name")
|
self.supplier_name = frappe.db.get_value("Supplier", self.supplier, "supplier_name")
|
||||||
@ -100,6 +102,30 @@ class BuyingController(SubcontractingController):
|
|||||||
do_not_submit=True,
|
do_not_submit=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_rate_for_standalone_debit_note(self):
|
||||||
|
if self.get("is_return") and self.get("update_stock") and not self.return_against:
|
||||||
|
for row in self.items:
|
||||||
|
|
||||||
|
# override the rate with valuation rate
|
||||||
|
row.rate = get_incoming_rate(
|
||||||
|
{
|
||||||
|
"item_code": row.item_code,
|
||||||
|
"warehouse": row.warehouse,
|
||||||
|
"posting_date": self.get("posting_date"),
|
||||||
|
"posting_time": self.get("posting_time"),
|
||||||
|
"qty": row.qty,
|
||||||
|
"serial_and_batch_bundle": row.get("serial_and_batch_bundle"),
|
||||||
|
"company": self.company,
|
||||||
|
"voucher_type": self.doctype,
|
||||||
|
"voucher_no": self.name,
|
||||||
|
},
|
||||||
|
raise_error_if_no_rate=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
row.discount_percentage = 0.0
|
||||||
|
row.discount_amount = 0.0
|
||||||
|
row.margin_rate_or_amount = 0.0
|
||||||
|
|
||||||
def set_missing_values(self, for_validate=False):
|
def set_missing_values(self, for_validate=False):
|
||||||
super(BuyingController, self).set_missing_values(for_validate)
|
super(BuyingController, self).set_missing_values(for_validate)
|
||||||
|
|
||||||
|
@ -30,10 +30,16 @@ def set_print_templates_for_taxes(doc, settings):
|
|||||||
doc.print_templates.update(
|
doc.print_templates.update(
|
||||||
{
|
{
|
||||||
"total": "templates/print_formats/includes/total.html",
|
"total": "templates/print_formats/includes/total.html",
|
||||||
"taxes": "templates/print_formats/includes/taxes.html",
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not doc.should_show_taxes_as_table_in_print():
|
||||||
|
doc.print_templates.update(
|
||||||
|
{
|
||||||
|
"taxes": "templates/print_formats/includes/taxes.html",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def format_columns(display_columns, compact_fields):
|
def format_columns(display_columns, compact_fields):
|
||||||
compact_fields = compact_fields + ["image", "item_code", "item_name"]
|
compact_fields = compact_fields + ["image", "item_code", "item_name"]
|
||||||
|
@ -43,7 +43,6 @@ class SellingController(StockController):
|
|||||||
self.set_serial_and_batch_bundle(table_field)
|
self.set_serial_and_batch_bundle(table_field)
|
||||||
|
|
||||||
def set_missing_values(self, for_validate=False):
|
def set_missing_values(self, for_validate=False):
|
||||||
|
|
||||||
super(SellingController, self).set_missing_values(for_validate)
|
super(SellingController, self).set_missing_values(for_validate)
|
||||||
|
|
||||||
# set contact and address details for customer, if they are not mentioned
|
# set contact and address details for customer, if they are not mentioned
|
||||||
@ -62,7 +61,7 @@ class SellingController(StockController):
|
|||||||
elif self.doctype == "Quotation" and self.party_name:
|
elif self.doctype == "Quotation" and self.party_name:
|
||||||
if self.quotation_to == "Customer":
|
if self.quotation_to == "Customer":
|
||||||
customer = self.party_name
|
customer = self.party_name
|
||||||
else:
|
elif self.quotation_to == "Lead":
|
||||||
lead = self.party_name
|
lead = self.party_name
|
||||||
|
|
||||||
if customer:
|
if customer:
|
||||||
|
@ -1074,8 +1074,8 @@ def make_bom_for_subcontracted_items():
|
|||||||
|
|
||||||
|
|
||||||
def set_backflush_based_on(based_on):
|
def set_backflush_based_on(based_on):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", based_on
|
"Buying Settings", "backflush_raw_materials_of_subcontract_based_on", based_on
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,10 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
from frappe.contacts.address_and_contact import (
|
||||||
|
delete_contact_and_address,
|
||||||
|
load_address_and_contact,
|
||||||
|
)
|
||||||
from frappe.email.inbox import link_communication_to_document
|
from frappe.email.inbox import link_communication_to_document
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
from frappe.utils import comma_and, get_link_to_form, has_gravatar, validate_email_address
|
from frappe.utils import comma_and, get_link_to_form, has_gravatar, validate_email_address
|
||||||
@ -40,9 +43,8 @@ class Lead(SellingController, CRMNote):
|
|||||||
self.update_prospect()
|
self.update_prospect()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
frappe.db.sql("""update `tabIssue` set lead='' where lead=%s""", self.name)
|
frappe.db.set_value("Issue", {"lead": self.name}, "lead", None)
|
||||||
|
delete_contact_and_address(self.doctype, self.name)
|
||||||
self.unlink_dynamic_links()
|
|
||||||
self.remove_link_from_prospect()
|
self.remove_link_from_prospect()
|
||||||
|
|
||||||
def set_full_name(self):
|
def set_full_name(self):
|
||||||
@ -119,27 +121,6 @@ class Lead(SellingController, CRMNote):
|
|||||||
)
|
)
|
||||||
lead_row.db_update()
|
lead_row.db_update()
|
||||||
|
|
||||||
def unlink_dynamic_links(self):
|
|
||||||
links = frappe.get_all(
|
|
||||||
"Dynamic Link",
|
|
||||||
filters={"link_doctype": self.doctype, "link_name": self.name},
|
|
||||||
fields=["parent", "parenttype"],
|
|
||||||
)
|
|
||||||
|
|
||||||
for link in links:
|
|
||||||
linked_doc = frappe.get_doc(link["parenttype"], link["parent"])
|
|
||||||
|
|
||||||
if len(linked_doc.get("links")) == 1:
|
|
||||||
linked_doc.delete(ignore_permissions=True)
|
|
||||||
else:
|
|
||||||
to_remove = None
|
|
||||||
for d in linked_doc.get("links"):
|
|
||||||
if d.link_doctype == self.doctype and d.link_name == self.name:
|
|
||||||
to_remove = d
|
|
||||||
if to_remove:
|
|
||||||
linked_doc.remove(to_remove)
|
|
||||||
linked_doc.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
def remove_link_from_prospect(self):
|
def remove_link_from_prospect(self):
|
||||||
prospects = self.get_linked_prospects()
|
prospects = self.get_linked_prospects()
|
||||||
|
|
||||||
|
@ -53,9 +53,7 @@ class TestOpportunity(unittest.TestCase):
|
|||||||
self.assertEqual(opportunity_doc.total, 2200)
|
self.assertEqual(opportunity_doc.total, 2200)
|
||||||
|
|
||||||
def test_carry_forward_of_email_and_comments(self):
|
def test_carry_forward_of_email_and_comments(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value("CRM Settings", "carry_forward_communication_and_comments", 1)
|
||||||
"CRM Settings", "CRM Settings", "carry_forward_communication_and_comments", 1
|
|
||||||
)
|
|
||||||
lead_doc = make_lead()
|
lead_doc = make_lead()
|
||||||
lead_doc.add_comment("Comment", text="Test Comment 1")
|
lead_doc.add_comment("Comment", text="Test Comment 1")
|
||||||
lead_doc.add_comment("Comment", text="Test Comment 2")
|
lead_doc.add_comment("Comment", text="Test Comment 2")
|
||||||
|
@ -2,7 +2,10 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
from frappe.contacts.address_and_contact import (
|
||||||
|
delete_contact_and_address,
|
||||||
|
load_address_and_contact,
|
||||||
|
)
|
||||||
from frappe.model.mapper import get_mapped_doc
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
|
||||||
from erpnext.crm.utils import CRMNote, copy_comments, link_communications, link_open_events
|
from erpnext.crm.utils import CRMNote, copy_comments, link_communications, link_open_events
|
||||||
@ -16,7 +19,7 @@ class Prospect(CRMNote):
|
|||||||
self.link_with_lead_contact_and_address()
|
self.link_with_lead_contact_and_address()
|
||||||
|
|
||||||
def on_trash(self):
|
def on_trash(self):
|
||||||
self.unlink_dynamic_links()
|
delete_contact_and_address(self.doctype, self.name)
|
||||||
|
|
||||||
def after_insert(self):
|
def after_insert(self):
|
||||||
carry_forward_communication_and_comments = frappe.db.get_single_value(
|
carry_forward_communication_and_comments = frappe.db.get_single_value(
|
||||||
@ -54,27 +57,6 @@ class Prospect(CRMNote):
|
|||||||
linked_doc.append("links", {"link_doctype": self.doctype, "link_name": self.name})
|
linked_doc.append("links", {"link_doctype": self.doctype, "link_name": self.name})
|
||||||
linked_doc.save(ignore_permissions=True)
|
linked_doc.save(ignore_permissions=True)
|
||||||
|
|
||||||
def unlink_dynamic_links(self):
|
|
||||||
links = frappe.get_all(
|
|
||||||
"Dynamic Link",
|
|
||||||
filters={"link_doctype": self.doctype, "link_name": self.name},
|
|
||||||
fields=["parent", "parenttype"],
|
|
||||||
)
|
|
||||||
|
|
||||||
for link in links:
|
|
||||||
linked_doc = frappe.get_doc(link["parenttype"], link["parent"])
|
|
||||||
|
|
||||||
if len(linked_doc.get("links")) == 1:
|
|
||||||
linked_doc.delete(ignore_permissions=True)
|
|
||||||
else:
|
|
||||||
to_remove = None
|
|
||||||
for d in linked_doc.get("links"):
|
|
||||||
if d.link_doctype == self.doctype and d.link_name == self.name:
|
|
||||||
to_remove = d
|
|
||||||
if to_remove:
|
|
||||||
linked_doc.remove(to_remove)
|
|
||||||
linked_doc.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_customer(source_name, target_doc=None):
|
def make_customer(source_name, target_doc=None):
|
||||||
|
@ -78,9 +78,10 @@ erpnext.ProductList = class {
|
|||||||
let title_html = `<div style="display: flex; margin-left: -15px;">`;
|
let title_html = `<div style="display: flex; margin-left: -15px;">`;
|
||||||
title_html += `
|
title_html += `
|
||||||
<div class="col-8" style="margin-right: -15px;">
|
<div class="col-8" style="margin-right: -15px;">
|
||||||
<a class="" href="/${ item.route || '#' }"
|
<a href="/${ item.route || '#' }">
|
||||||
style="color: var(--gray-800); font-weight: 500;">
|
<div class="product-title">
|
||||||
${ title }
|
${ title }
|
||||||
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -201,4 +202,4 @@ erpnext.ProductList = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -205,7 +205,7 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(quote_doctstatus, 0)
|
self.assertEqual(quote_doctstatus, 0)
|
||||||
|
|
||||||
frappe.db.set_value("E Commerce Settings", None, "save_quotations_as_draft", 0)
|
frappe.db.set_single_value("E Commerce Settings", "save_quotations_as_draft", 0)
|
||||||
frappe.local.shopping_cart_settings = None
|
frappe.local.shopping_cart_settings = None
|
||||||
update_cart("_Test Item", 1)
|
update_cart("_Test Item", 1)
|
||||||
quote_name = request_for_quotation() # Request for Quote
|
quote_name = request_for_quotation() # Request for Quote
|
||||||
|
@ -32,7 +32,7 @@ class TestPlaidSettings(unittest.TestCase):
|
|||||||
frappe.delete_doc(doctype, d.name, force=True)
|
frappe.delete_doc(doctype, d.name, force=True)
|
||||||
|
|
||||||
def test_plaid_disabled(self):
|
def test_plaid_disabled(self):
|
||||||
frappe.db.set_value("Plaid Settings", None, "enabled", 0)
|
frappe.db.set_single_value("Plaid Settings", "enabled", 0)
|
||||||
self.assertTrue(get_plaid_configuration() == "disabled")
|
self.assertTrue(get_plaid_configuration() == "disabled")
|
||||||
|
|
||||||
def test_add_account_type(self):
|
def test_add_account_type(self):
|
||||||
|
@ -39,7 +39,10 @@ setup_wizard_requires = "assets/erpnext/js/setup_wizard.js"
|
|||||||
setup_wizard_stages = "erpnext.setup.setup_wizard.setup_wizard.get_setup_stages"
|
setup_wizard_stages = "erpnext.setup.setup_wizard.setup_wizard.get_setup_stages"
|
||||||
setup_wizard_test = "erpnext.setup.setup_wizard.test_setup_wizard.run_setup_wizard_test"
|
setup_wizard_test = "erpnext.setup.setup_wizard.test_setup_wizard.run_setup_wizard_test"
|
||||||
|
|
||||||
before_install = "erpnext.setup.install.check_setup_wizard_not_completed"
|
before_install = [
|
||||||
|
"erpnext.setup.install.check_setup_wizard_not_completed",
|
||||||
|
"erpnext.setup.install.check_frappe_version",
|
||||||
|
]
|
||||||
after_install = "erpnext.setup.install.after_install"
|
after_install = "erpnext.setup.install.after_install"
|
||||||
|
|
||||||
boot_session = "erpnext.startup.boot.boot_session"
|
boot_session = "erpnext.startup.boot.boot_session"
|
||||||
|
@ -160,4 +160,3 @@ class TestLoanDisbursement(unittest.TestCase):
|
|||||||
interest = per_day_interest * 15
|
interest = per_day_interest * 15
|
||||||
|
|
||||||
self.assertEqual(amounts["pending_principal_amount"], 1500000)
|
self.assertEqual(amounts["pending_principal_amount"], 1500000)
|
||||||
self.assertEqual(amounts["interest_amount"], flt(interest + previous_interest, 2))
|
|
||||||
|
@ -22,7 +22,7 @@ class LoanInterestAccrual(AccountsController):
|
|||||||
frappe.throw(_("Interest Amount or Principal Amount is mandatory"))
|
frappe.throw(_("Interest Amount or Principal Amount is mandatory"))
|
||||||
|
|
||||||
if not self.last_accrual_date:
|
if not self.last_accrual_date:
|
||||||
self.last_accrual_date = get_last_accrual_date(self.loan)
|
self.last_accrual_date = get_last_accrual_date(self.loan, self.posting_date)
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.make_gl_entries()
|
self.make_gl_entries()
|
||||||
@ -274,14 +274,14 @@ def make_loan_interest_accrual_entry(args):
|
|||||||
|
|
||||||
|
|
||||||
def get_no_of_days_for_interest_accural(loan, posting_date):
|
def get_no_of_days_for_interest_accural(loan, posting_date):
|
||||||
last_interest_accrual_date = get_last_accrual_date(loan.name)
|
last_interest_accrual_date = get_last_accrual_date(loan.name, posting_date)
|
||||||
|
|
||||||
no_of_days = date_diff(posting_date or nowdate(), last_interest_accrual_date) + 1
|
no_of_days = date_diff(posting_date or nowdate(), last_interest_accrual_date) + 1
|
||||||
|
|
||||||
return no_of_days
|
return no_of_days
|
||||||
|
|
||||||
|
|
||||||
def get_last_accrual_date(loan):
|
def get_last_accrual_date(loan, posting_date):
|
||||||
last_posting_date = frappe.db.sql(
|
last_posting_date = frappe.db.sql(
|
||||||
""" SELECT MAX(posting_date) from `tabLoan Interest Accrual`
|
""" SELECT MAX(posting_date) from `tabLoan Interest Accrual`
|
||||||
WHERE loan = %s and docstatus = 1""",
|
WHERE loan = %s and docstatus = 1""",
|
||||||
@ -289,12 +289,30 @@ def get_last_accrual_date(loan):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if last_posting_date[0][0]:
|
if last_posting_date[0][0]:
|
||||||
|
last_interest_accrual_date = last_posting_date[0][0]
|
||||||
# interest for last interest accrual date is already booked, so add 1 day
|
# interest for last interest accrual date is already booked, so add 1 day
|
||||||
return add_days(last_posting_date[0][0], 1)
|
last_disbursement_date = get_last_disbursement_date(loan, posting_date)
|
||||||
|
|
||||||
|
if last_disbursement_date and getdate(last_disbursement_date) > getdate(
|
||||||
|
last_interest_accrual_date
|
||||||
|
):
|
||||||
|
last_interest_accrual_date = last_disbursement_date
|
||||||
|
|
||||||
|
return add_days(last_interest_accrual_date, 1)
|
||||||
else:
|
else:
|
||||||
return frappe.db.get_value("Loan", loan, "disbursement_date")
|
return frappe.db.get_value("Loan", loan, "disbursement_date")
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_disbursement_date(loan, posting_date):
|
||||||
|
last_disbursement_date = frappe.db.get_value(
|
||||||
|
"Loan Disbursement",
|
||||||
|
{"docstatus": 1, "against_loan": loan, "posting_date": ("<", posting_date)},
|
||||||
|
"MAX(posting_date)",
|
||||||
|
)
|
||||||
|
|
||||||
|
return last_disbursement_date
|
||||||
|
|
||||||
|
|
||||||
def days_in_year(year):
|
def days_in_year(year):
|
||||||
days = 365
|
days = 365
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class LoanRepayment(AccountsController):
|
|||||||
if flt(self.total_interest_paid, precision) > flt(self.interest_payable, precision):
|
if flt(self.total_interest_paid, precision) > flt(self.interest_payable, precision):
|
||||||
if not self.is_term_loan:
|
if not self.is_term_loan:
|
||||||
# get last loan interest accrual date
|
# get last loan interest accrual date
|
||||||
last_accrual_date = get_last_accrual_date(self.against_loan)
|
last_accrual_date = get_last_accrual_date(self.against_loan, self.posting_date)
|
||||||
|
|
||||||
# get posting date upto which interest has to be accrued
|
# get posting date upto which interest has to be accrued
|
||||||
per_day_interest = get_per_day_interest(
|
per_day_interest = get_per_day_interest(
|
||||||
@ -725,7 +725,7 @@ def get_amounts(amounts, against_loan, posting_date):
|
|||||||
if due_date:
|
if due_date:
|
||||||
pending_days = date_diff(posting_date, due_date) + 1
|
pending_days = date_diff(posting_date, due_date) + 1
|
||||||
else:
|
else:
|
||||||
last_accrual_date = get_last_accrual_date(against_loan_doc.name)
|
last_accrual_date = get_last_accrual_date(against_loan_doc.name, posting_date)
|
||||||
pending_days = date_diff(posting_date, last_accrual_date) + 1
|
pending_days = date_diff(posting_date, last_accrual_date) + 1
|
||||||
|
|
||||||
if pending_days > 0:
|
if pending_days > 0:
|
||||||
|
@ -152,6 +152,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -160,6 +161,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Contact Email",
|
"label": "Contact Email",
|
||||||
|
"options": "Email",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
@ -236,10 +238,11 @@
|
|||||||
"link_fieldname": "maintenance_schedule"
|
"link_fieldname": "maintenance_schedule"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2021-05-27 16:05:10.746465",
|
"modified": "2023-06-03 16:15:43.958072",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Maintenance",
|
"module": "Maintenance",
|
||||||
"name": "Maintenance Schedule",
|
"name": "Maintenance Schedule",
|
||||||
|
"naming_rule": "By \"Naming Series\" field",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
{
|
{
|
||||||
@ -260,5 +263,6 @@
|
|||||||
"search_fields": "status,customer,customer_name",
|
"search_fields": "status,customer,customer_name",
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
|
"states": [],
|
||||||
"timeline_field": "customer"
|
"timeline_field": "customer"
|
||||||
}
|
}
|
@ -101,6 +101,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Mobile No",
|
"label": "Mobile No",
|
||||||
|
"options": "Phone",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -108,6 +109,7 @@
|
|||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
"hidden": 1,
|
"hidden": 1,
|
||||||
"label": "Contact Email",
|
"label": "Contact Email",
|
||||||
|
"options": "Email",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -293,7 +295,7 @@
|
|||||||
"idx": 1,
|
"idx": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2021-12-17 03:10:27.608112",
|
"modified": "2023-06-03 16:19:07.902723",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Maintenance",
|
"module": "Maintenance",
|
||||||
"name": "Maintenance Visit",
|
"name": "Maintenance Visit",
|
||||||
@ -319,6 +321,7 @@
|
|||||||
"show_name_in_global_search": 1,
|
"show_name_in_global_search": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
"sort_order": "DESC",
|
"sort_order": "DESC",
|
||||||
|
"states": [],
|
||||||
"timeline_field": "customer",
|
"timeline_field": "customer",
|
||||||
"title_field": "customer_name"
|
"title_field": "customer_name"
|
||||||
}
|
}
|
@ -88,12 +88,14 @@ class BOMUpdateLog(Document):
|
|||||||
boms=boms,
|
boms=boms,
|
||||||
timeout=40000,
|
timeout=40000,
|
||||||
now=frappe.flags.in_test,
|
now=frappe.flags.in_test,
|
||||||
|
enqueue_after_commit=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
frappe.enqueue(
|
frappe.enqueue(
|
||||||
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.process_boms_cost_level_wise",
|
method="erpnext.manufacturing.doctype.bom_update_log.bom_update_log.process_boms_cost_level_wise",
|
||||||
update_doc=self,
|
update_doc=self,
|
||||||
now=frappe.flags.in_test,
|
now=frappe.flags.in_test,
|
||||||
|
enqueue_after_commit=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,17 @@ frappe.ui.form.on('Job Card', {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frm.set_query("serial_and_batch_bundle", () => {
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'item_code': frm.doc.production_item,
|
||||||
|
'voucher_type': frm.doc.doctype,
|
||||||
|
'voucher_no': ["in", [frm.doc.name, ""]],
|
||||||
|
'is_cancelled': 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
frm.set_indicator_formatter('sub_operation',
|
frm.set_indicator_formatter('sub_operation',
|
||||||
function(doc) {
|
function(doc) {
|
||||||
if (doc.status == "Pending") {
|
if (doc.status == "Pending") {
|
||||||
@ -83,7 +94,7 @@ frappe.ui.form.on('Job Card', {
|
|||||||
// and if stock mvt for WIP is required
|
// and if stock mvt for WIP is required
|
||||||
if (frm.doc.work_order) {
|
if (frm.doc.work_order) {
|
||||||
frappe.db.get_value('Work Order', frm.doc.work_order, ['skip_transfer', 'status'], (result) => {
|
frappe.db.get_value('Work Order', frm.doc.work_order, ['skip_transfer', 'status'], (result) => {
|
||||||
if (result.skip_transfer === 1 || result.status == 'In Process' || frm.doc.transferred_qty > 0) {
|
if (result.skip_transfer === 1 || result.status == 'In Process' || frm.doc.transferred_qty > 0 || !frm.doc.items.length) {
|
||||||
frm.trigger("prepare_timer_buttons");
|
frm.trigger("prepare_timer_buttons");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -411,6 +422,16 @@ frappe.ui.form.on('Job Card', {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (frm.doc.total_completed_qty && frm.doc.for_quantity > frm.doc.total_completed_qty) {
|
||||||
|
let flt_precision = precision('for_quantity', frm.doc);
|
||||||
|
let process_loss_qty = (
|
||||||
|
flt(frm.doc.for_quantity, flt_precision)
|
||||||
|
- flt(frm.doc.total_completed_qty, flt_precision)
|
||||||
|
);
|
||||||
|
|
||||||
|
frm.set_value('process_loss_qty', process_loss_qty);
|
||||||
|
}
|
||||||
|
|
||||||
refresh_field("total_completed_qty");
|
refresh_field("total_completed_qty");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
"time_logs",
|
"time_logs",
|
||||||
"section_break_13",
|
"section_break_13",
|
||||||
"total_completed_qty",
|
"total_completed_qty",
|
||||||
|
"process_loss_qty",
|
||||||
"column_break_15",
|
"column_break_15",
|
||||||
"total_time_in_mins",
|
"total_time_in_mins",
|
||||||
"section_break_8",
|
"section_break_8",
|
||||||
@ -448,11 +449,17 @@
|
|||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Serial and Batch Bundle",
|
"options": "Serial and Batch Bundle",
|
||||||
"print_hide": 1
|
"print_hide": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "process_loss_qty",
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"label": "Process Loss Qty",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-05-23 09:56:43.826602",
|
"modified": "2023-06-09 12:04:55.534264",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Job Card",
|
"name": "Job Card",
|
||||||
|
@ -161,7 +161,7 @@ class JobCard(Document):
|
|||||||
self.total_completed_qty = flt(self.total_completed_qty, self.precision("total_completed_qty"))
|
self.total_completed_qty = flt(self.total_completed_qty, self.precision("total_completed_qty"))
|
||||||
|
|
||||||
for row in self.sub_operations:
|
for row in self.sub_operations:
|
||||||
self.total_completed_qty += row.completed_qty
|
self.c += row.completed_qty
|
||||||
|
|
||||||
def get_overlap_for(self, args, check_next_available_slot=False):
|
def get_overlap_for(self, args, check_next_available_slot=False):
|
||||||
production_capacity = 1
|
production_capacity = 1
|
||||||
@ -451,6 +451,9 @@ class JobCard(Document):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def before_save(self):
|
||||||
|
self.set_process_loss()
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.validate_transfer_qty()
|
self.validate_transfer_qty()
|
||||||
self.validate_job_card()
|
self.validate_job_card()
|
||||||
@ -487,19 +490,35 @@ class JobCard(Document):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.for_quantity and self.total_completed_qty != self.for_quantity:
|
precision = self.precision("total_completed_qty")
|
||||||
|
total_completed_qty = flt(
|
||||||
|
flt(self.total_completed_qty, precision) + flt(self.process_loss_qty, precision)
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.for_quantity and flt(total_completed_qty, precision) != flt(
|
||||||
|
self.for_quantity, precision
|
||||||
|
):
|
||||||
total_completed_qty = bold(_("Total Completed Qty"))
|
total_completed_qty = bold(_("Total Completed Qty"))
|
||||||
qty_to_manufacture = bold(_("Qty to Manufacture"))
|
qty_to_manufacture = bold(_("Qty to Manufacture"))
|
||||||
|
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("The {0} ({1}) must be equal to {2} ({3})").format(
|
_("The {0} ({1}) must be equal to {2} ({3})").format(
|
||||||
total_completed_qty,
|
total_completed_qty,
|
||||||
bold(self.total_completed_qty),
|
bold(flt(total_completed_qty, precision)),
|
||||||
qty_to_manufacture,
|
qty_to_manufacture,
|
||||||
bold(self.for_quantity),
|
bold(self.for_quantity),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def set_process_loss(self):
|
||||||
|
precision = self.precision("total_completed_qty")
|
||||||
|
|
||||||
|
self.process_loss_qty = 0.0
|
||||||
|
if self.total_completed_qty and self.for_quantity > self.total_completed_qty:
|
||||||
|
self.process_loss_qty = flt(self.for_quantity, precision) - flt(
|
||||||
|
self.total_completed_qty, precision
|
||||||
|
)
|
||||||
|
|
||||||
def update_work_order(self):
|
def update_work_order(self):
|
||||||
if not self.work_order:
|
if not self.work_order:
|
||||||
return
|
return
|
||||||
@ -511,7 +530,7 @@ class JobCard(Document):
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
for_quantity, time_in_mins = 0, 0
|
for_quantity, time_in_mins, process_loss_qty = 0, 0, 0
|
||||||
from_time_list, to_time_list = [], []
|
from_time_list, to_time_list = [], []
|
||||||
|
|
||||||
field = "operation_id"
|
field = "operation_id"
|
||||||
@ -519,6 +538,7 @@ class JobCard(Document):
|
|||||||
if data and len(data) > 0:
|
if data and len(data) > 0:
|
||||||
for_quantity = flt(data[0].completed_qty)
|
for_quantity = flt(data[0].completed_qty)
|
||||||
time_in_mins = flt(data[0].time_in_mins)
|
time_in_mins = flt(data[0].time_in_mins)
|
||||||
|
process_loss_qty = flt(data[0].process_loss_qty)
|
||||||
|
|
||||||
wo = frappe.get_doc("Work Order", self.work_order)
|
wo = frappe.get_doc("Work Order", self.work_order)
|
||||||
|
|
||||||
@ -526,8 +546,8 @@ class JobCard(Document):
|
|||||||
self.update_corrective_in_work_order(wo)
|
self.update_corrective_in_work_order(wo)
|
||||||
|
|
||||||
elif self.operation_id:
|
elif self.operation_id:
|
||||||
self.validate_produced_quantity(for_quantity, wo)
|
self.validate_produced_quantity(for_quantity, process_loss_qty, wo)
|
||||||
self.update_work_order_data(for_quantity, time_in_mins, wo)
|
self.update_work_order_data(for_quantity, process_loss_qty, time_in_mins, wo)
|
||||||
|
|
||||||
def update_corrective_in_work_order(self, wo):
|
def update_corrective_in_work_order(self, wo):
|
||||||
wo.corrective_operation_cost = 0.0
|
wo.corrective_operation_cost = 0.0
|
||||||
@ -542,11 +562,11 @@ class JobCard(Document):
|
|||||||
wo.flags.ignore_validate_update_after_submit = True
|
wo.flags.ignore_validate_update_after_submit = True
|
||||||
wo.save()
|
wo.save()
|
||||||
|
|
||||||
def validate_produced_quantity(self, for_quantity, wo):
|
def validate_produced_quantity(self, for_quantity, process_loss_qty, wo):
|
||||||
if self.docstatus < 2:
|
if self.docstatus < 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
if wo.produced_qty > for_quantity:
|
if wo.produced_qty > for_quantity + process_loss_qty:
|
||||||
first_part_msg = _(
|
first_part_msg = _(
|
||||||
"The {0} {1} is used to calculate the valuation cost for the finished good {2}."
|
"The {0} {1} is used to calculate the valuation cost for the finished good {2}."
|
||||||
).format(
|
).format(
|
||||||
@ -561,7 +581,7 @@ class JobCard(Document):
|
|||||||
_("{0} {1}").format(first_part_msg, second_part_msg), JobCardCancelError, title=_("Error")
|
_("{0} {1}").format(first_part_msg, second_part_msg), JobCardCancelError, title=_("Error")
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_work_order_data(self, for_quantity, time_in_mins, wo):
|
def update_work_order_data(self, for_quantity, process_loss_qty, time_in_mins, wo):
|
||||||
workstation_hour_rate = frappe.get_value("Workstation", self.workstation, "hour_rate")
|
workstation_hour_rate = frappe.get_value("Workstation", self.workstation, "hour_rate")
|
||||||
jc = frappe.qb.DocType("Job Card")
|
jc = frappe.qb.DocType("Job Card")
|
||||||
jctl = frappe.qb.DocType("Job Card Time Log")
|
jctl = frappe.qb.DocType("Job Card Time Log")
|
||||||
@ -582,6 +602,7 @@ class JobCard(Document):
|
|||||||
for data in wo.operations:
|
for data in wo.operations:
|
||||||
if data.get("name") == self.operation_id:
|
if data.get("name") == self.operation_id:
|
||||||
data.completed_qty = for_quantity
|
data.completed_qty = for_quantity
|
||||||
|
data.process_loss_qty = process_loss_qty
|
||||||
data.actual_operation_time = time_in_mins
|
data.actual_operation_time = time_in_mins
|
||||||
data.actual_start_time = time_data[0].start_time if time_data else None
|
data.actual_start_time = time_data[0].start_time if time_data else None
|
||||||
data.actual_end_time = time_data[0].end_time if time_data else None
|
data.actual_end_time = time_data[0].end_time if time_data else None
|
||||||
@ -599,7 +620,11 @@ class JobCard(Document):
|
|||||||
def get_current_operation_data(self):
|
def get_current_operation_data(self):
|
||||||
return frappe.get_all(
|
return frappe.get_all(
|
||||||
"Job Card",
|
"Job Card",
|
||||||
fields=["sum(total_time_in_mins) as time_in_mins", "sum(total_completed_qty) as completed_qty"],
|
fields=[
|
||||||
|
"sum(total_time_in_mins) as time_in_mins",
|
||||||
|
"sum(total_completed_qty) as completed_qty",
|
||||||
|
"sum(process_loss_qty) as process_loss_qty",
|
||||||
|
],
|
||||||
filters={
|
filters={
|
||||||
"docstatus": 1,
|
"docstatus": 1,
|
||||||
"work_order": self.work_order,
|
"work_order": self.work_order,
|
||||||
@ -777,7 +802,7 @@ class JobCard(Document):
|
|||||||
|
|
||||||
data = frappe.get_all(
|
data = frappe.get_all(
|
||||||
"Work Order Operation",
|
"Work Order Operation",
|
||||||
fields=["operation", "status", "completed_qty"],
|
fields=["operation", "status", "completed_qty", "sequence_id"],
|
||||||
filters={"docstatus": 1, "parent": self.work_order, "sequence_id": ("<", self.sequence_id)},
|
filters={"docstatus": 1, "parent": self.work_order, "sequence_id": ("<", self.sequence_id)},
|
||||||
order_by="sequence_id, idx",
|
order_by="sequence_id, idx",
|
||||||
)
|
)
|
||||||
@ -795,6 +820,16 @@ class JobCard(Document):
|
|||||||
OperationSequenceError,
|
OperationSequenceError,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if row.completed_qty < current_operation_qty:
|
||||||
|
msg = f"""The completed quantity {bold(current_operation_qty)}
|
||||||
|
of an operation {bold(self.operation)} cannot be greater
|
||||||
|
than the completed quantity {bold(row.completed_qty)}
|
||||||
|
of a previous operation
|
||||||
|
{bold(row.operation)}.
|
||||||
|
"""
|
||||||
|
|
||||||
|
frappe.throw(_(msg))
|
||||||
|
|
||||||
def validate_work_order(self):
|
def validate_work_order(self):
|
||||||
if self.is_work_order_closed():
|
if self.is_work_order_closed():
|
||||||
frappe.throw(_("You can't make any changes to Job Card since Work Order is closed."))
|
frappe.throw(_("You can't make any changes to Job Card since Work Order is closed."))
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from frappe.test_runner import make_test_records
|
||||||
from frappe.tests.utils import FrappeTestCase, change_settings
|
from frappe.tests.utils import FrappeTestCase, change_settings
|
||||||
from frappe.utils import random_string
|
from frappe.utils import random_string
|
||||||
from frappe.utils.data import add_to_date, now, today
|
from frappe.utils.data import add_to_date, now, today
|
||||||
@ -469,6 +470,119 @@ class TestJobCard(FrappeTestCase):
|
|||||||
self.assertEqual(ste.from_bom, 1.0)
|
self.assertEqual(ste.from_bom, 1.0)
|
||||||
self.assertEqual(ste.bom_no, work_order.bom_no)
|
self.assertEqual(ste.bom_no, work_order.bom_no)
|
||||||
|
|
||||||
|
def test_job_card_proccess_qty_and_completed_qty(self):
|
||||||
|
from erpnext.manufacturing.doctype.routing.test_routing import (
|
||||||
|
create_routing,
|
||||||
|
setup_bom,
|
||||||
|
setup_operations,
|
||||||
|
)
|
||||||
|
from erpnext.manufacturing.doctype.work_order.work_order import (
|
||||||
|
make_stock_entry as make_stock_entry_for_wo,
|
||||||
|
)
|
||||||
|
from erpnext.stock.doctype.item.test_item import make_item
|
||||||
|
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
{"operation": "Test Operation A1", "workstation": "Test Workstation A", "time_in_mins": 30},
|
||||||
|
{"operation": "Test Operation B1", "workstation": "Test Workstation A", "time_in_mins": 20},
|
||||||
|
]
|
||||||
|
|
||||||
|
make_test_records("UOM")
|
||||||
|
|
||||||
|
warehouse = create_warehouse("Test Warehouse 123 for Job Card")
|
||||||
|
|
||||||
|
setup_operations(operations)
|
||||||
|
|
||||||
|
item_code = "Test Job Card Process Qty Item"
|
||||||
|
for item in [item_code, item_code + "RM 1", item_code + "RM 2"]:
|
||||||
|
if not frappe.db.exists("Item", item):
|
||||||
|
make_item(
|
||||||
|
item,
|
||||||
|
{
|
||||||
|
"item_name": item,
|
||||||
|
"stock_uom": "Nos",
|
||||||
|
"is_stock_item": 1,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
routing_doc = create_routing(routing_name="Testing Route", operations=operations)
|
||||||
|
bom_doc = setup_bom(
|
||||||
|
item_code=item_code,
|
||||||
|
routing=routing_doc.name,
|
||||||
|
raw_materials=[item_code + "RM 1", item_code + "RM 2"],
|
||||||
|
source_warehouse=warehouse,
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in bom_doc.items:
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=row.item_code,
|
||||||
|
target=row.source_warehouse,
|
||||||
|
qty=10,
|
||||||
|
basic_rate=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
wo_doc = make_wo_order_test_record(
|
||||||
|
production_item=item_code,
|
||||||
|
bom_no=bom_doc.name,
|
||||||
|
skip_transfer=1,
|
||||||
|
wip_warehouse=warehouse,
|
||||||
|
source_warehouse=warehouse,
|
||||||
|
)
|
||||||
|
|
||||||
|
for row in routing_doc.operations:
|
||||||
|
self.assertEqual(row.sequence_id, row.idx)
|
||||||
|
|
||||||
|
first_job_card = frappe.get_all(
|
||||||
|
"Job Card",
|
||||||
|
filters={"work_order": wo_doc.name, "sequence_id": 1},
|
||||||
|
fields=["name"],
|
||||||
|
order_by="sequence_id",
|
||||||
|
limit=1,
|
||||||
|
)[0].name
|
||||||
|
|
||||||
|
jc = frappe.get_doc("Job Card", first_job_card)
|
||||||
|
jc.time_logs[0].completed_qty = 8
|
||||||
|
jc.save()
|
||||||
|
jc.submit()
|
||||||
|
|
||||||
|
self.assertEqual(jc.process_loss_qty, 2)
|
||||||
|
self.assertEqual(jc.for_quantity, 10)
|
||||||
|
|
||||||
|
second_job_card = frappe.get_all(
|
||||||
|
"Job Card",
|
||||||
|
filters={"work_order": wo_doc.name, "sequence_id": 2},
|
||||||
|
fields=["name"],
|
||||||
|
order_by="sequence_id",
|
||||||
|
limit=1,
|
||||||
|
)[0].name
|
||||||
|
|
||||||
|
jc2 = frappe.get_doc("Job Card", second_job_card)
|
||||||
|
jc2.time_logs[0].completed_qty = 10
|
||||||
|
|
||||||
|
self.assertRaises(frappe.ValidationError, jc2.save)
|
||||||
|
|
||||||
|
jc2.load_from_db()
|
||||||
|
jc2.time_logs[0].completed_qty = 8
|
||||||
|
jc2.save()
|
||||||
|
jc2.submit()
|
||||||
|
|
||||||
|
self.assertEqual(jc2.for_quantity, 10)
|
||||||
|
self.assertEqual(jc2.process_loss_qty, 2)
|
||||||
|
|
||||||
|
s = frappe.get_doc(make_stock_entry_for_wo(wo_doc.name, "Manufacture", 10))
|
||||||
|
s.submit()
|
||||||
|
|
||||||
|
self.assertEqual(s.process_loss_qty, 2)
|
||||||
|
|
||||||
|
wo_doc.reload()
|
||||||
|
for row in wo_doc.operations:
|
||||||
|
self.assertEqual(row.completed_qty, 8)
|
||||||
|
self.assertEqual(row.process_loss_qty, 2)
|
||||||
|
|
||||||
|
self.assertEqual(wo_doc.produced_qty, 8)
|
||||||
|
self.assertEqual(wo_doc.process_loss_qty, 2)
|
||||||
|
self.assertEqual(wo_doc.status, "Completed")
|
||||||
|
|
||||||
|
|
||||||
def create_bom_with_multiple_operations():
|
def create_bom_with_multiple_operations():
|
||||||
"Create a BOM with multiple operations and Material Transfer against Job Card"
|
"Create a BOM with multiple operations and Material Transfer against Job Card"
|
||||||
|
@ -141,6 +141,7 @@ def setup_bom(**args):
|
|||||||
routing=args.routing,
|
routing=args.routing,
|
||||||
with_operations=1,
|
with_operations=1,
|
||||||
currency=args.currency,
|
currency=args.currency,
|
||||||
|
source_warehouse=args.source_warehouse,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
bom_doc = frappe.get_doc("BOM", name)
|
bom_doc = frappe.get_doc("BOM", name)
|
||||||
|
@ -503,10 +503,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
stock_entry.cancel()
|
stock_entry.cancel()
|
||||||
|
|
||||||
def test_capcity_planning(self):
|
def test_capcity_planning(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings", {"disable_capacity_planning": 0, "capacity_planning_for_days": 1}
|
||||||
None,
|
|
||||||
{"disable_capacity_planning": 0, "capacity_planning_for_days": 1},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data = frappe.get_cached_value(
|
data = frappe.get_cached_value(
|
||||||
@ -529,7 +527,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertRaises(CapacityError, work_order1.submit)
|
self.assertRaises(CapacityError, work_order1.submit)
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, {"capacity_planning_for_days": 30})
|
frappe.db.set_single_value("Manufacturing Settings", {"capacity_planning_for_days": 30})
|
||||||
|
|
||||||
work_order1.reload()
|
work_order1.reload()
|
||||||
work_order1.submit()
|
work_order1.submit()
|
||||||
@ -539,7 +537,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
work_order.cancel()
|
work_order.cancel()
|
||||||
|
|
||||||
def test_work_order_with_non_transfer_item(self):
|
def test_work_order_with_non_transfer_item(self):
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM")
|
frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
|
||||||
|
|
||||||
items = {"Finished Good Transfer Item": 1, "_Test FG Item": 1, "_Test FG Item 1": 0}
|
items = {"Finished Good Transfer Item": 1, "_Test FG Item": 1, "_Test FG Item 1": 0}
|
||||||
for item, allow_transfer in items.items():
|
for item, allow_transfer in items.items():
|
||||||
@ -619,7 +617,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
fg_item = "Test Batch Size Item For BOM 3"
|
fg_item = "Test Batch Size Item For BOM 3"
|
||||||
rm1 = "Test Batch Size Item RM 1 For BOM 3"
|
rm1 = "Test Batch Size Item RM 1 For BOM 3"
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0)
|
frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 0)
|
||||||
for item in ["Test Batch Size Item For BOM 3", "Test Batch Size Item RM 1 For BOM 3"]:
|
for item in ["Test Batch Size Item For BOM 3", "Test Batch Size Item RM 1 For BOM 3"]:
|
||||||
item_args = {"include_item_in_manufacturing": 1, "is_stock_item": 1}
|
item_args = {"include_item_in_manufacturing": 1, "is_stock_item": 1}
|
||||||
|
|
||||||
@ -655,7 +653,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
work_order = make_wo_order_test_record(
|
work_order = make_wo_order_test_record(
|
||||||
item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1
|
item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1
|
||||||
)
|
)
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 1)
|
frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 1)
|
||||||
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1))
|
ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 1))
|
||||||
for row in ste1.get("items"):
|
for row in ste1.get("items"):
|
||||||
if row.is_finished_item:
|
if row.is_finished_item:
|
||||||
@ -699,10 +697,10 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
|
|
||||||
self.assertEqual(sorted(remaining_batches), sorted(batches))
|
self.assertEqual(sorted(remaining_batches), sorted(batches))
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0)
|
frappe.db.set_single_value("Manufacturing Settings", "make_serial_no_batch_from_work_order", 0)
|
||||||
|
|
||||||
def test_partial_material_consumption(self):
|
def test_partial_material_consumption(self):
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 1)
|
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 1)
|
||||||
wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4)
|
wo_order = make_wo_order_test_record(planned_start_date=now(), qty=4)
|
||||||
|
|
||||||
ste_cancel_list = []
|
ste_cancel_list = []
|
||||||
@ -736,13 +734,12 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
for ste_doc in ste_cancel_list:
|
for ste_doc in ste_cancel_list:
|
||||||
ste_doc.cancel()
|
ste_doc.cancel()
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0)
|
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0)
|
||||||
|
|
||||||
def test_extra_material_transfer(self):
|
def test_extra_material_transfer(self):
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "material_consumption", 0)
|
frappe.db.set_single_value("Manufacturing Settings", "material_consumption", 0)
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
@ -787,7 +784,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
for ste_doc in ste_cancel_list:
|
for ste_doc in ste_cancel_list:
|
||||||
ste_doc.cancel()
|
ste_doc.cancel()
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM")
|
frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
|
||||||
|
|
||||||
def test_make_stock_entry_for_customer_provided_item(self):
|
def test_make_stock_entry_for_customer_provided_item(self):
|
||||||
finished_item = "Test Item for Make Stock Entry 1"
|
finished_item = "Test Item for Make Stock Entry 1"
|
||||||
@ -903,7 +900,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertEqual(se.process_loss_qty, 1)
|
self.assertEqual(se.process_loss_qty, 1)
|
||||||
|
|
||||||
wo.load_from_db()
|
wo.load_from_db()
|
||||||
self.assertEqual(wo.status, "In Process")
|
self.assertEqual(wo.status, "Completed")
|
||||||
|
|
||||||
@timeout(seconds=60)
|
@timeout(seconds=60)
|
||||||
def test_job_card_scrap_item(self):
|
def test_job_card_scrap_item(self):
|
||||||
@ -1087,9 +1084,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
def test_partial_manufacture_entries(self):
|
def test_partial_manufacture_entries(self):
|
||||||
cancel_stock_entry = []
|
cancel_stock_entry = []
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
@ -1139,7 +1135,7 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
doc = frappe.get_doc("Stock Entry", ste)
|
doc = frappe.get_doc("Stock Entry", ste)
|
||||||
doc.cancel()
|
doc.cancel()
|
||||||
|
|
||||||
frappe.db.set_value("Manufacturing Settings", None, "backflush_raw_materials_based_on", "BOM")
|
frappe.db.set_single_value("Manufacturing Settings", "backflush_raw_materials_based_on", "BOM")
|
||||||
|
|
||||||
@change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1})
|
@change_settings("Manufacturing Settings", {"make_serial_no_batch_from_work_order": 1})
|
||||||
def test_auto_batch_creation(self):
|
def test_auto_batch_creation(self):
|
||||||
@ -1283,9 +1279,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertEqual(work_order.required_items[1].transferred_qty, 2)
|
self.assertEqual(work_order.required_items[1].transferred_qty, 2)
|
||||||
|
|
||||||
def test_backflushed_batch_raw_materials_based_on_transferred(self):
|
def test_backflushed_batch_raw_materials_based_on_transferred(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
@ -1356,9 +1351,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertEqual(abs(d.qty), 2)
|
self.assertEqual(abs(d.qty), 2)
|
||||||
|
|
||||||
def test_backflushed_serial_no_raw_materials_based_on_transferred(self):
|
def test_backflushed_serial_no_raw_materials_based_on_transferred(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
@ -1400,9 +1394,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertEqual(manufacture_ste_doc2.items[0].qty, 2)
|
self.assertEqual(manufacture_ste_doc2.items[0].qty, 2)
|
||||||
|
|
||||||
def test_backflushed_serial_no_batch_raw_materials_based_on_transferred(self):
|
def test_backflushed_serial_no_batch_raw_materials_based_on_transferred(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
@ -1486,9 +1479,8 @@ class TestWorkOrder(FrappeTestCase):
|
|||||||
self.assertFalse(serial_nos)
|
self.assertFalse(serial_nos)
|
||||||
|
|
||||||
def test_non_consumed_material_return_against_work_order(self):
|
def test_non_consumed_material_return_against_work_order(self):
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Manufacturing Settings",
|
"Manufacturing Settings",
|
||||||
None,
|
|
||||||
"backflush_raw_materials_based_on",
|
"backflush_raw_materials_based_on",
|
||||||
"Material Transferred for Manufacture",
|
"Material Transferred for Manufacture",
|
||||||
)
|
)
|
||||||
|
@ -139,7 +139,7 @@ frappe.ui.form.on("Work Order", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (frm.doc.status != "Closed") {
|
if (frm.doc.status != "Closed") {
|
||||||
if (frm.doc.docstatus === 1
|
if (frm.doc.docstatus === 1 && frm.doc.status !== "Completed"
|
||||||
&& frm.doc.operations && frm.doc.operations.length) {
|
&& frm.doc.operations && frm.doc.operations.length) {
|
||||||
|
|
||||||
const not_completed = frm.doc.operations.filter(d => {
|
const not_completed = frm.doc.operations.filter(d => {
|
||||||
@ -256,6 +256,12 @@ frappe.ui.form.on("Work Order", {
|
|||||||
label: __('Batch Size'),
|
label: __('Batch Size'),
|
||||||
read_only: 1
|
read_only: 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
fieldtype: 'Int',
|
||||||
|
fieldname: 'sequence_id',
|
||||||
|
label: __('Sequence Id'),
|
||||||
|
read_only: 1
|
||||||
|
},
|
||||||
],
|
],
|
||||||
data: operations_data,
|
data: operations_data,
|
||||||
in_place_edit: true,
|
in_place_edit: true,
|
||||||
@ -280,8 +286,8 @@ frappe.ui.form.on("Work Order", {
|
|||||||
|
|
||||||
var pending_qty = 0;
|
var pending_qty = 0;
|
||||||
frm.doc.operations.forEach(data => {
|
frm.doc.operations.forEach(data => {
|
||||||
if(data.completed_qty != frm.doc.qty) {
|
if(data.completed_qty + data.process_loss_qty != frm.doc.qty) {
|
||||||
pending_qty = frm.doc.qty - flt(data.completed_qty);
|
pending_qty = frm.doc.qty - flt(data.completed_qty) - flt(data.process_loss_qty);
|
||||||
|
|
||||||
if (pending_qty) {
|
if (pending_qty) {
|
||||||
dialog.fields_dict.operations.df.data.push({
|
dialog.fields_dict.operations.df.data.push({
|
||||||
@ -290,7 +296,8 @@ frappe.ui.form.on("Work Order", {
|
|||||||
'workstation': data.workstation,
|
'workstation': data.workstation,
|
||||||
'batch_size': data.batch_size,
|
'batch_size': data.batch_size,
|
||||||
'qty': pending_qty,
|
'qty': pending_qty,
|
||||||
'pending_qty': pending_qty
|
'pending_qty': pending_qty,
|
||||||
|
'sequence_id': data.sequence_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@
|
|||||||
"required_items_section",
|
"required_items_section",
|
||||||
"materials_and_operations_tab",
|
"materials_and_operations_tab",
|
||||||
"operations_section",
|
"operations_section",
|
||||||
"operations",
|
|
||||||
"transfer_material_against",
|
"transfer_material_against",
|
||||||
|
"operations",
|
||||||
"time",
|
"time",
|
||||||
"planned_start_date",
|
"planned_start_date",
|
||||||
"planned_end_date",
|
"planned_end_date",
|
||||||
@ -330,7 +330,6 @@
|
|||||||
"label": "Expected Delivery Date"
|
"label": "Expected Delivery Date"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"collapsible": 1,
|
|
||||||
"fieldname": "operations_section",
|
"fieldname": "operations_section",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Operations",
|
"label": "Operations",
|
||||||
@ -591,7 +590,7 @@
|
|||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-04-06 12:35:12.149827",
|
"modified": "2023-06-09 13:20:09.154362",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Work Order",
|
"name": "Work Order",
|
||||||
|
@ -245,7 +245,9 @@ class WorkOrder(Document):
|
|||||||
status = "Not Started"
|
status = "Not Started"
|
||||||
if flt(self.material_transferred_for_manufacturing) > 0:
|
if flt(self.material_transferred_for_manufacturing) > 0:
|
||||||
status = "In Process"
|
status = "In Process"
|
||||||
if flt(self.produced_qty) >= flt(self.qty):
|
|
||||||
|
total_qty = flt(self.produced_qty) + flt(self.process_loss_qty)
|
||||||
|
if flt(total_qty) >= flt(self.qty):
|
||||||
status = "Completed"
|
status = "Completed"
|
||||||
else:
|
else:
|
||||||
status = "Cancelled"
|
status = "Cancelled"
|
||||||
@ -761,13 +763,15 @@ class WorkOrder(Document):
|
|||||||
max_allowed_qty_for_wo = flt(self.qty) + (allowance_percentage / 100 * flt(self.qty))
|
max_allowed_qty_for_wo = flt(self.qty) + (allowance_percentage / 100 * flt(self.qty))
|
||||||
|
|
||||||
for d in self.get("operations"):
|
for d in self.get("operations"):
|
||||||
if not d.completed_qty:
|
precision = d.precision("completed_qty")
|
||||||
|
qty = flt(d.completed_qty, precision) + flt(d.process_loss_qty, precision)
|
||||||
|
if not qty:
|
||||||
d.status = "Pending"
|
d.status = "Pending"
|
||||||
elif flt(d.completed_qty) < flt(self.qty):
|
elif flt(qty) < flt(self.qty):
|
||||||
d.status = "Work in Progress"
|
d.status = "Work in Progress"
|
||||||
elif flt(d.completed_qty) == flt(self.qty):
|
elif flt(qty) == flt(self.qty):
|
||||||
d.status = "Completed"
|
d.status = "Completed"
|
||||||
elif flt(d.completed_qty) <= max_allowed_qty_for_wo:
|
elif flt(qty) <= max_allowed_qty_for_wo:
|
||||||
d.status = "Completed"
|
d.status = "Completed"
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Completed Qty cannot be greater than 'Qty to Manufacture'"))
|
frappe.throw(_("Completed Qty cannot be greater than 'Qty to Manufacture'"))
|
||||||
|
@ -2,12 +2,14 @@
|
|||||||
"actions": [],
|
"actions": [],
|
||||||
"creation": "2014-10-16 14:35:41.950175",
|
"creation": "2014-10-16 14:35:41.950175",
|
||||||
"doctype": "DocType",
|
"doctype": "DocType",
|
||||||
|
"editable_grid": 1,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"details",
|
"details",
|
||||||
"operation",
|
"operation",
|
||||||
"status",
|
"status",
|
||||||
"completed_qty",
|
"completed_qty",
|
||||||
|
"process_loss_qty",
|
||||||
"column_break_4",
|
"column_break_4",
|
||||||
"bom",
|
"bom",
|
||||||
"workstation_type",
|
"workstation_type",
|
||||||
@ -36,6 +38,7 @@
|
|||||||
"fieldtype": "Section Break"
|
"fieldtype": "Section Break"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"columns": 2,
|
||||||
"fieldname": "operation",
|
"fieldname": "operation",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -46,6 +49,7 @@
|
|||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"columns": 2,
|
||||||
"fieldname": "bom",
|
"fieldname": "bom",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -62,7 +66,7 @@
|
|||||||
"oldfieldtype": "Text"
|
"oldfieldtype": "Text"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"columns": 1,
|
"columns": 2,
|
||||||
"description": "Operation completed for how many finished goods?",
|
"description": "Operation completed for how many finished goods?",
|
||||||
"fieldname": "completed_qty",
|
"fieldname": "completed_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
@ -80,6 +84,7 @@
|
|||||||
"options": "Pending\nWork in Progress\nCompleted"
|
"options": "Pending\nWork in Progress\nCompleted"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"columns": 1,
|
||||||
"fieldname": "workstation",
|
"fieldname": "workstation",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
@ -115,7 +120,7 @@
|
|||||||
"fieldname": "time_in_mins",
|
"fieldname": "time_in_mins",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"label": "Operation Time",
|
"label": "Time",
|
||||||
"oldfieldname": "time_in_mins",
|
"oldfieldname": "time_in_mins",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
@ -203,12 +208,21 @@
|
|||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Workstation Type",
|
"label": "Workstation Type",
|
||||||
"options": "Workstation Type"
|
"options": "Workstation Type"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"columns": 2,
|
||||||
|
"fieldname": "process_loss_qty",
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Process Loss Qty",
|
||||||
|
"no_copy": 1,
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-11-09 01:37:56.563068",
|
"modified": "2023-06-09 14:03:01.612909",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Manufacturing",
|
"module": "Manufacturing",
|
||||||
"name": "Work Order Operation",
|
"name": "Work Order Operation",
|
||||||
|
@ -33,10 +33,9 @@ def get_data(filters: Filters) -> Data:
|
|||||||
wo.name,
|
wo.name,
|
||||||
wo.status,
|
wo.status,
|
||||||
wo.production_item,
|
wo.production_item,
|
||||||
wo.qty,
|
|
||||||
wo.produced_qty,
|
wo.produced_qty,
|
||||||
wo.process_loss_qty,
|
wo.process_loss_qty,
|
||||||
(wo.produced_qty - wo.process_loss_qty).as_("actual_produced_qty"),
|
wo.qty.as_("qty_to_manufacture"),
|
||||||
Sum(se.total_incoming_value).as_("total_fg_value"),
|
Sum(se.total_incoming_value).as_("total_fg_value"),
|
||||||
Sum(se.total_outgoing_value).as_("total_rm_value"),
|
Sum(se.total_outgoing_value).as_("total_rm_value"),
|
||||||
)
|
)
|
||||||
@ -44,6 +43,7 @@ def get_data(filters: Filters) -> Data:
|
|||||||
(wo.process_loss_qty > 0)
|
(wo.process_loss_qty > 0)
|
||||||
& (wo.company == filters.company)
|
& (wo.company == filters.company)
|
||||||
& (se.docstatus == 1)
|
& (se.docstatus == 1)
|
||||||
|
& (se.purpose == "Manufacture")
|
||||||
& (se.posting_date.between(filters.from_date, filters.to_date))
|
& (se.posting_date.between(filters.from_date, filters.to_date))
|
||||||
)
|
)
|
||||||
.groupby(se.work_order)
|
.groupby(se.work_order)
|
||||||
@ -79,20 +79,30 @@ def get_columns() -> Columns:
|
|||||||
"width": "100",
|
"width": "100",
|
||||||
},
|
},
|
||||||
{"label": _("Status"), "fieldname": "status", "fieldtype": "Data", "width": "100"},
|
{"label": _("Status"), "fieldname": "status", "fieldtype": "Data", "width": "100"},
|
||||||
|
{
|
||||||
|
"label": _("Qty To Manufacture"),
|
||||||
|
"fieldname": "qty_to_manufacture",
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "150",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": _("Manufactured Qty"),
|
"label": _("Manufactured Qty"),
|
||||||
"fieldname": "produced_qty",
|
"fieldname": "produced_qty",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"width": "150",
|
"width": "150",
|
||||||
},
|
},
|
||||||
{"label": _("Loss Qty"), "fieldname": "process_loss_qty", "fieldtype": "Float", "width": "150"},
|
|
||||||
{
|
{
|
||||||
"label": _("Actual Manufactured Qty"),
|
"label": _("Process Loss Qty"),
|
||||||
"fieldname": "actual_produced_qty",
|
"fieldname": "process_loss_qty",
|
||||||
|
"fieldtype": "Float",
|
||||||
|
"width": "150",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": _("Process Loss Value"),
|
||||||
|
"fieldname": "total_pl_value",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"width": "150",
|
"width": "150",
|
||||||
},
|
},
|
||||||
{"label": _("Loss Value"), "fieldname": "total_pl_value", "fieldtype": "Float", "width": "150"},
|
|
||||||
{"label": _("FG Value"), "fieldname": "total_fg_value", "fieldtype": "Float", "width": "150"},
|
{"label": _("FG Value"), "fieldname": "total_fg_value", "fieldtype": "Float", "width": "150"},
|
||||||
{
|
{
|
||||||
"label": _("Raw Material Value"),
|
"label": _("Raw Material Value"),
|
||||||
@ -105,5 +115,5 @@ def get_columns() -> Columns:
|
|||||||
|
|
||||||
def update_data_with_total_pl_value(data: Data) -> None:
|
def update_data_with_total_pl_value(data: Data) -> None:
|
||||||
for row in data:
|
for row in data:
|
||||||
value_per_unit_fg = row["total_fg_value"] / row["actual_produced_qty"]
|
value_per_unit_fg = row["total_fg_value"] / row["qty_to_manufacture"]
|
||||||
row["total_pl_value"] = row["process_loss_qty"] * value_per_unit_fg
|
row["total_pl_value"] = row["process_loss_qty"] * value_per_unit_fg
|
||||||
|
@ -7,8 +7,8 @@ import frappe
|
|||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc("buying", "doctype", "buying_settings")
|
frappe.reload_doc("buying", "doctype", "buying_settings")
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM"
|
"Buying Settings", "backflush_raw_materials_of_subcontract_based_on", "BOM"
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.reload_doc("stock", "doctype", "stock_entry_detail")
|
frappe.reload_doc("stock", "doctype", "stock_entry_detail")
|
||||||
|
@ -11,6 +11,6 @@ def execute():
|
|||||||
rename_field("Item", "tolerance", "over_delivery_receipt_allowance")
|
rename_field("Item", "tolerance", "over_delivery_receipt_allowance")
|
||||||
|
|
||||||
qty_allowance = frappe.db.get_single_value("Stock Settings", "over_delivery_receipt_allowance")
|
qty_allowance = frappe.db.get_single_value("Stock Settings", "over_delivery_receipt_allowance")
|
||||||
frappe.db.set_value("Accounts Settings", None, "over_delivery_receipt_allowance", qty_allowance)
|
frappe.db.set_single_value("Accounts Settings", "over_delivery_receipt_allowance", qty_allowance)
|
||||||
|
|
||||||
frappe.db.sql("update tabItem set over_billing_allowance=over_delivery_receipt_allowance")
|
frappe.db.sql("update tabItem set over_billing_allowance=over_delivery_receipt_allowance")
|
||||||
|
@ -4,6 +4,6 @@ import frappe
|
|||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc("accounts", "doctype", "accounts_settings")
|
frappe.reload_doc("accounts", "doctype", "accounts_settings")
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"Accounts Settings", None, "automatically_process_deferred_accounting_entry", 1
|
"Accounts Settings", "automatically_process_deferred_accounting_entry", 1
|
||||||
)
|
)
|
||||||
|
@ -2,4 +2,4 @@ import frappe
|
|||||||
|
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.db.set_value("Homepage", "Homepage", "hero_section_based_on", "Default")
|
frappe.db.set_single_value("Homepage", "hero_section_based_on", "Default")
|
||||||
|
@ -46,7 +46,7 @@ def set_priorities_service_level():
|
|||||||
|
|
||||||
frappe.reload_doc("support", "doctype", "service_level")
|
frappe.reload_doc("support", "doctype", "service_level")
|
||||||
frappe.reload_doc("support", "doctype", "support_settings")
|
frappe.reload_doc("support", "doctype", "support_settings")
|
||||||
frappe.db.set_value("Support Settings", None, "track_service_level_agreement", 1)
|
frappe.db.set_single_value("Support Settings", "track_service_level_agreement", 1)
|
||||||
|
|
||||||
for service_level in service_level_priorities:
|
for service_level in service_level_priorities:
|
||||||
if service_level:
|
if service_level:
|
||||||
|
@ -47,7 +47,7 @@ def execute():
|
|||||||
|
|
||||||
acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto")
|
acc_frozen_upto = frappe.db.get_value("Accounts Settings", None, "acc_frozen_upto")
|
||||||
if acc_frozen_upto:
|
if acc_frozen_upto:
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", None)
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", None)
|
||||||
|
|
||||||
for invoice in purchase_invoices + sales_invoices:
|
for invoice in purchase_invoices + sales_invoices:
|
||||||
try:
|
try:
|
||||||
@ -65,4 +65,4 @@ def execute():
|
|||||||
print(f"Failed to correct gl entries of {invoice.name}")
|
print(f"Failed to correct gl entries of {invoice.name}")
|
||||||
|
|
||||||
if acc_frozen_upto:
|
if acc_frozen_upto:
|
||||||
frappe.db.set_value("Accounts Settings", None, "acc_frozen_upto", acc_frozen_upto)
|
frappe.db.set_single_value("Accounts Settings", "acc_frozen_upto", acc_frozen_upto)
|
||||||
|
@ -8,4 +8,4 @@ def execute():
|
|||||||
discount_account = data and int(data[0][0]) or 0
|
discount_account = data and int(data[0][0]) or 0
|
||||||
if discount_account:
|
if discount_account:
|
||||||
for doctype in ["Buying Settings", "Selling Settings"]:
|
for doctype in ["Buying Settings", "Selling Settings"]:
|
||||||
frappe.db.set_value(doctype, doctype, "enable_discount_accounting", 1, update_modified=False)
|
frappe.db.set_single_value(doctype, "enable_discount_accounting", 1, update_modified=False)
|
||||||
|
@ -11,8 +11,7 @@ def execute():
|
|||||||
|
|
||||||
frappe.reload_doc("crm", "doctype", "crm_settings")
|
frappe.reload_doc("crm", "doctype", "crm_settings")
|
||||||
if settings:
|
if settings:
|
||||||
frappe.db.set_value(
|
frappe.db.set_single_value(
|
||||||
"CRM Settings",
|
|
||||||
"CRM Settings",
|
"CRM Settings",
|
||||||
{
|
{
|
||||||
"campaign_naming_by": settings.campaign_naming_by,
|
"campaign_naming_by": settings.campaign_naming_by,
|
||||||
|
@ -304,6 +304,7 @@ def set_tasks_as_overdue():
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def make_timesheet(source_name, target_doc=None, ignore_permissions=False):
|
def make_timesheet(source_name, target_doc=None, ignore_permissions=False):
|
||||||
def set_missing_values(source, target):
|
def set_missing_values(source, target):
|
||||||
|
target.parent_project = source.project
|
||||||
target.append(
|
target.append(
|
||||||
"time_logs",
|
"time_logs",
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
"css/erpnext.css": [
|
"css/erpnext.css": [
|
||||||
"public/less/erpnext.less",
|
"public/less/erpnext.less",
|
||||||
"public/scss/call_popup.scss",
|
"public/scss/call_popup.scss",
|
||||||
"public/scss/point-of-sale.scss",
|
"public/scss/point-of-sale.scss"
|
||||||
"public/scss/hierarchy_chart.scss"
|
|
||||||
],
|
],
|
||||||
"js/erpnext-web.min.js": [
|
"js/erpnext-web.min.js": [
|
||||||
"public/js/website_utils.js",
|
"public/js/website_utils.js",
|
||||||
@ -37,7 +36,6 @@
|
|||||||
"public/js/utils/dimension_tree_filter.js",
|
"public/js/utils/dimension_tree_filter.js",
|
||||||
"public/js/telephony.js",
|
"public/js/telephony.js",
|
||||||
"public/js/templates/call_link.html",
|
"public/js/templates/call_link.html",
|
||||||
"public/js/templates/node_card.html",
|
|
||||||
"public/js/bulk_transaction_processing.js"
|
"public/js/bulk_transaction_processing.js"
|
||||||
],
|
],
|
||||||
"js/item-dashboard.min.js": [
|
"js/item-dashboard.min.js": [
|
||||||
@ -62,10 +60,6 @@
|
|||||||
"public/js/bank_reconciliation_tool/number_card.js",
|
"public/js/bank_reconciliation_tool/number_card.js",
|
||||||
"public/js/bank_reconciliation_tool/dialog_manager.js"
|
"public/js/bank_reconciliation_tool/dialog_manager.js"
|
||||||
],
|
],
|
||||||
"js/hierarchy-chart.min.js": [
|
|
||||||
"public/js/hierarchy_chart/hierarchy_chart_desktop.js",
|
|
||||||
"public/js/hierarchy_chart/hierarchy_chart_mobile.js"
|
|
||||||
],
|
|
||||||
"js/e-commerce.min.js": [
|
"js/e-commerce.min.js": [
|
||||||
"e_commerce/product_ui/views.js",
|
"e_commerce/product_ui/views.js",
|
||||||
"e_commerce/product_ui/grid.js",
|
"e_commerce/product_ui/grid.js",
|
||||||
|
@ -40,8 +40,8 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
|
|||||||
name: __("Date"),
|
name: __("Date"),
|
||||||
editable: false,
|
editable: false,
|
||||||
width: 100,
|
width: 100,
|
||||||
|
format: frappe.form.formatters.Date,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: __("Party Type"),
|
name: __("Party Type"),
|
||||||
editable: false,
|
editable: false,
|
||||||
@ -117,17 +117,13 @@ erpnext.accounts.bank_reconciliation.DataTableManager = class DataTableManager {
|
|||||||
return [
|
return [
|
||||||
row["date"],
|
row["date"],
|
||||||
row["party_type"],
|
row["party_type"],
|
||||||
row["party"],
|
frappe.form.formatters.Link(row["party"], {options: row["party_type"]}),
|
||||||
row["description"],
|
row["description"],
|
||||||
row["deposit"],
|
row["deposit"],
|
||||||
row["withdrawal"],
|
row["withdrawal"],
|
||||||
row["unallocated_amount"],
|
row["unallocated_amount"],
|
||||||
row["reference_number"],
|
row["reference_number"],
|
||||||
`
|
`<button class="btn btn-primary btn-xs center" data-name="${row["name"]}">${__("Actions")}</button>`
|
||||||
<Button class="btn btn-primary btn-xs center" data-name = ${row["name"]} >
|
|
||||||
${__("Actions")}
|
|
||||||
</a>
|
|
||||||
`,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,30 +76,17 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
|||||||
callback: (result) => {
|
callback: (result) => {
|
||||||
const data = result.message;
|
const data = result.message;
|
||||||
|
|
||||||
|
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper;
|
const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper;
|
||||||
proposals_wrapper.show();
|
proposals_wrapper.show();
|
||||||
this.dialog.fields_dict.no_matching_vouchers.$wrapper.hide();
|
this.dialog.fields_dict.no_matching_vouchers.$wrapper.hide();
|
||||||
this.data = [];
|
this.data = data.map((row) => this.format_row(row));
|
||||||
data.forEach((row) => {
|
|
||||||
const reference_date = row[5] ? row[5] : row[8];
|
|
||||||
this.data.push([
|
|
||||||
row[1],
|
|
||||||
row[2],
|
|
||||||
reference_date,
|
|
||||||
format_currency(row[3], row[9]),
|
|
||||||
row[4],
|
|
||||||
row[6],
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
this.get_dt_columns();
|
this.get_dt_columns();
|
||||||
this.get_datatable(proposals_wrapper);
|
this.get_datatable(proposals_wrapper);
|
||||||
} else {
|
} else {
|
||||||
const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper;
|
const proposals_wrapper = this.dialog.fields_dict.payment_proposals.$wrapper;
|
||||||
proposals_wrapper.hide();
|
proposals_wrapper.hide();
|
||||||
this.dialog.fields_dict.no_matching_vouchers.$wrapper.show();
|
this.dialog.fields_dict.no_matching_vouchers.$wrapper.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
this.dialog.show();
|
this.dialog.show();
|
||||||
},
|
},
|
||||||
@ -122,6 +109,7 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
|||||||
name: __("Reference Date"),
|
name: __("Reference Date"),
|
||||||
editable: false,
|
editable: false,
|
||||||
width: 120,
|
width: 120,
|
||||||
|
format: frappe.form.formatters.Date,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: __("Remaining"),
|
name: __("Remaining"),
|
||||||
@ -141,6 +129,17 @@ erpnext.accounts.bank_reconciliation.DialogManager = class DialogManager {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
format_row(row) {
|
||||||
|
return [
|
||||||
|
row[1], // Document Type
|
||||||
|
frappe.form.formatters.Link(row[2], {options: row[1]}), // Document Name
|
||||||
|
row[5] || row[8], // Reference Date
|
||||||
|
format_currency(row[3], row[9]), // Remaining
|
||||||
|
row[4], // Reference Number
|
||||||
|
row[6], // Party
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
get_datatable(proposals_wrapper) {
|
get_datatable(proposals_wrapper) {
|
||||||
if (!this.datatable) {
|
if (!this.datatable) {
|
||||||
const datatable_options = {
|
const datatable_options = {
|
||||||
|
@ -805,11 +805,13 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.frm.doc.payments.find(pay => {
|
if(!this.frm.doc.is_return){
|
||||||
if (pay.default) {
|
this.frm.doc.payments.find(payment => {
|
||||||
pay.amount = total_amount_to_pay;
|
if (payment.default) {
|
||||||
}
|
payment.amount = total_amount_to_pay;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.frm.refresh_fields();
|
this.frm.refresh_fields();
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
'item_code': item_row.item_code,
|
'item_code': item_row.item_code,
|
||||||
'voucher_type': doc.doctype,
|
'voucher_type': doc.doctype,
|
||||||
'voucher_no': ["in", [doc.name, ""]],
|
'voucher_no': ["in", [doc.name, ""]],
|
||||||
|
'is_cancelled': 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2339,14 +2340,11 @@ erpnext.show_serial_batch_selector = function (frm, item_row, callback, on_close
|
|||||||
|
|
||||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
|
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
|
||||||
if (in_list(["Sales Invoice", "Delivery Note"], frm.doc.doctype)) {
|
if (in_list(["Sales Invoice", "Delivery Note"], frm.doc.doctype)) {
|
||||||
item_row.outward = frm.doc.is_return ? 0 : 1;
|
item_row.type_of_transaction = frm.doc.is_return ? "Inward" : "Outward";
|
||||||
} else {
|
} else {
|
||||||
item_row.outward = frm.doc.is_return ? 1 : 0;
|
item_row.type_of_transaction = frm.doc.is_return ? "Outward" : "Inward";
|
||||||
}
|
}
|
||||||
|
|
||||||
item_row.type_of_transaction = (item_row.outward === 1
|
|
||||||
? "Outward":"Inward");
|
|
||||||
|
|
||||||
new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => {
|
new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => {
|
||||||
if (r) {
|
if (r) {
|
||||||
let update_values = {
|
let update_values = {
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
import "./hierarchy_chart/hierarchy_chart_desktop.js";
|
|
||||||
import "./hierarchy_chart/hierarchy_chart_mobile.js";
|
|
||||||
import "./templates/node_card.html";
|
|
@ -1,608 +0,0 @@
|
|||||||
import html2canvas from 'html2canvas';
|
|
||||||
erpnext.HierarchyChart = class {
|
|
||||||
/* Options:
|
|
||||||
- doctype
|
|
||||||
- wrapper: wrapper for the hierarchy view
|
|
||||||
- method:
|
|
||||||
- to get the data for each node
|
|
||||||
- this method should return id, name, title, image, and connections for each node
|
|
||||||
*/
|
|
||||||
constructor(doctype, wrapper, method) {
|
|
||||||
this.page = wrapper.page;
|
|
||||||
this.method = method;
|
|
||||||
this.doctype = doctype;
|
|
||||||
|
|
||||||
this.setup_page_style();
|
|
||||||
this.page.main.addClass('frappe-card');
|
|
||||||
|
|
||||||
this.nodes = {};
|
|
||||||
this.setup_node_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_page_style() {
|
|
||||||
this.page.main.css({
|
|
||||||
'min-height': '300px',
|
|
||||||
'max-height': '600px',
|
|
||||||
'overflow': 'auto',
|
|
||||||
'position': 'relative'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_node_class() {
|
|
||||||
let me = this;
|
|
||||||
this.Node = class {
|
|
||||||
constructor({
|
|
||||||
id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line
|
|
||||||
}) {
|
|
||||||
// to setup values passed via constructor
|
|
||||||
$.extend(this, arguments[0]);
|
|
||||||
|
|
||||||
this.expanded = 0;
|
|
||||||
|
|
||||||
me.nodes[this.id] = this;
|
|
||||||
me.make_node_element(this);
|
|
||||||
|
|
||||||
if (!me.all_nodes_expanded) {
|
|
||||||
me.setup_node_click_action(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
me.setup_edit_node_action(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
make_node_element(node) {
|
|
||||||
let node_card = frappe.render_template('node_card', {
|
|
||||||
id: node.id,
|
|
||||||
name: node.name,
|
|
||||||
title: node.title,
|
|
||||||
image: node.image,
|
|
||||||
parent: node.parent_id,
|
|
||||||
connections: node.connections,
|
|
||||||
is_mobile: false
|
|
||||||
});
|
|
||||||
|
|
||||||
node.parent.append(node_card);
|
|
||||||
node.$link = $(`[id="${node.id}"]`);
|
|
||||||
}
|
|
||||||
|
|
||||||
show() {
|
|
||||||
this.setup_actions();
|
|
||||||
if ($(`[data-fieldname="company"]`).length) return;
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
let company = this.page.add_field({
|
|
||||||
fieldtype: 'Link',
|
|
||||||
options: 'Company',
|
|
||||||
fieldname: 'company',
|
|
||||||
placeholder: __('Select Company'),
|
|
||||||
default: frappe.defaults.get_default('company'),
|
|
||||||
only_select: true,
|
|
||||||
reqd: 1,
|
|
||||||
change: () => {
|
|
||||||
me.company = undefined;
|
|
||||||
$('#hierarchy-chart-wrapper').remove();
|
|
||||||
|
|
||||||
if (company.get_value()) {
|
|
||||||
me.company = company.get_value();
|
|
||||||
|
|
||||||
// svg for connectors
|
|
||||||
me.make_svg_markers();
|
|
||||||
me.setup_hierarchy();
|
|
||||||
me.render_root_nodes();
|
|
||||||
me.all_nodes_expanded = false;
|
|
||||||
} else {
|
|
||||||
frappe.throw(__('Please select a company first.'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
company.refresh();
|
|
||||||
$(`[data-fieldname="company"]`).trigger('change');
|
|
||||||
$(`[data-fieldname="company"] .link-field`).css('z-index', 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_actions() {
|
|
||||||
let me = this;
|
|
||||||
this.page.clear_inner_toolbar();
|
|
||||||
this.page.add_inner_button(__('Export'), function() {
|
|
||||||
me.export_chart();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.page.add_inner_button(__('Expand All'), function() {
|
|
||||||
me.load_children(me.root_node, true);
|
|
||||||
me.all_nodes_expanded = true;
|
|
||||||
|
|
||||||
me.page.remove_inner_button(__('Expand All'));
|
|
||||||
me.page.add_inner_button(__('Collapse All'), function() {
|
|
||||||
me.setup_hierarchy();
|
|
||||||
me.render_root_nodes();
|
|
||||||
me.all_nodes_expanded = false;
|
|
||||||
|
|
||||||
me.page.remove_inner_button(__('Collapse All'));
|
|
||||||
me.setup_actions();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export_chart() {
|
|
||||||
frappe.dom.freeze(__('Exporting...'));
|
|
||||||
this.page.main.css({
|
|
||||||
'min-height': '',
|
|
||||||
'max-height': '',
|
|
||||||
'overflow': 'visible',
|
|
||||||
'position': 'fixed',
|
|
||||||
'left': '0',
|
|
||||||
'top': '0'
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.node-card').addClass('exported');
|
|
||||||
|
|
||||||
html2canvas(document.querySelector('#hierarchy-chart-wrapper'), {
|
|
||||||
scrollY: -window.scrollY,
|
|
||||||
scrollX: 0
|
|
||||||
}).then(function(canvas) {
|
|
||||||
// Export the canvas to its data URI representation
|
|
||||||
let dataURL = canvas.toDataURL('image/png');
|
|
||||||
|
|
||||||
// download the image
|
|
||||||
let a = document.createElement('a');
|
|
||||||
a.href = dataURL;
|
|
||||||
a.download = 'hierarchy_chart';
|
|
||||||
a.click();
|
|
||||||
}).finally(() => {
|
|
||||||
frappe.dom.unfreeze();
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setup_page_style();
|
|
||||||
$('.node-card').removeClass('exported');
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_hierarchy() {
|
|
||||||
if (this.$hierarchy)
|
|
||||||
this.$hierarchy.remove();
|
|
||||||
|
|
||||||
$(`#connectors`).empty();
|
|
||||||
|
|
||||||
// setup hierarchy
|
|
||||||
this.$hierarchy = $(
|
|
||||||
`<ul class="hierarchy">
|
|
||||||
<li class="root-level level">
|
|
||||||
<ul class="node-children"></ul>
|
|
||||||
</li>
|
|
||||||
</ul>`);
|
|
||||||
|
|
||||||
this.page.main
|
|
||||||
.find('#hierarchy-chart')
|
|
||||||
.empty()
|
|
||||||
.append(this.$hierarchy);
|
|
||||||
|
|
||||||
this.nodes = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
make_svg_markers() {
|
|
||||||
$('#hierarchy-chart-wrapper').remove();
|
|
||||||
|
|
||||||
this.page.main.append(`
|
|
||||||
<div id="hierarchy-chart-wrapper">
|
|
||||||
<svg id="arrows" width="100%" height="100%">
|
|
||||||
<defs>
|
|
||||||
<marker id="arrowhead-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-500)">
|
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
|
||||||
</marker>
|
|
||||||
<marker id="arrowhead-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-300)">
|
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
|
||||||
</marker>
|
|
||||||
|
|
||||||
<marker id="arrowstart-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-500)">
|
|
||||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-500)"/>
|
|
||||||
</marker>
|
|
||||||
<marker id="arrowstart-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-300)">
|
|
||||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-300)"/>
|
|
||||||
</marker>
|
|
||||||
</defs>
|
|
||||||
<g id="connectors" fill="none">
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
<div id="hierarchy-chart">
|
|
||||||
</div>
|
|
||||||
</div>`);
|
|
||||||
}
|
|
||||||
|
|
||||||
render_root_nodes(expanded_view=false) {
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
return frappe.call({
|
|
||||||
method: me.method,
|
|
||||||
args: {
|
|
||||||
company: me.company
|
|
||||||
}
|
|
||||||
}).then(r => {
|
|
||||||
if (r.message.length) {
|
|
||||||
let expand_node = undefined;
|
|
||||||
let node = undefined;
|
|
||||||
|
|
||||||
$.each(r.message, (_i, data) => {
|
|
||||||
if ($(`[id="${data.id}"]`).length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
node = new me.Node({
|
|
||||||
id: data.id,
|
|
||||||
parent: $('<li class="child-node"></li>').appendTo(me.$hierarchy.find('.node-children')),
|
|
||||||
parent_id: undefined,
|
|
||||||
image: data.image,
|
|
||||||
name: data.name,
|
|
||||||
title: data.title,
|
|
||||||
expandable: true,
|
|
||||||
connections: data.connections,
|
|
||||||
is_root: true
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!expand_node && data.connections)
|
|
||||||
expand_node = node;
|
|
||||||
});
|
|
||||||
|
|
||||||
me.root_node = expand_node;
|
|
||||||
if (!expanded_view) {
|
|
||||||
me.expand_node(expand_node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_node(node) {
|
|
||||||
const is_sibling = this.selected_node && this.selected_node.parent_id === node.parent_id;
|
|
||||||
this.set_selected_node(node);
|
|
||||||
this.show_active_path(node);
|
|
||||||
this.collapse_previous_level_nodes(node);
|
|
||||||
|
|
||||||
// since the previous node collapses, all connections to that node need to be rebuilt
|
|
||||||
// if a sibling node is clicked, connections don't need to be rebuilt
|
|
||||||
if (!is_sibling) {
|
|
||||||
// rebuild outgoing connections
|
|
||||||
this.refresh_connectors(node.parent_id);
|
|
||||||
|
|
||||||
// rebuild incoming connections
|
|
||||||
let grandparent = $(`[id="${node.parent_id}"]`).attr('data-parent');
|
|
||||||
this.refresh_connectors(grandparent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.expandable && !node.expanded) {
|
|
||||||
return this.load_children(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_node() {
|
|
||||||
if (this.selected_node.expandable) {
|
|
||||||
this.selected_node.$children.hide();
|
|
||||||
$(`path[data-parent="${this.selected_node.id}"]`).hide();
|
|
||||||
this.selected_node.expanded = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
show_active_path(node) {
|
|
||||||
// mark node parent on active path
|
|
||||||
$(`[id="${node.parent_id}"]`).addClass('active-path');
|
|
||||||
}
|
|
||||||
|
|
||||||
load_children(node, deep=false) {
|
|
||||||
if (!deep) {
|
|
||||||
frappe.run_serially([
|
|
||||||
() => this.get_child_nodes(node.id),
|
|
||||||
(child_nodes) => this.render_child_nodes(node, child_nodes)
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
frappe.run_serially([
|
|
||||||
() => frappe.dom.freeze(),
|
|
||||||
() => this.setup_hierarchy(),
|
|
||||||
() => this.render_root_nodes(true),
|
|
||||||
() => this.get_all_nodes(),
|
|
||||||
(data_list) => this.render_children_of_all_nodes(data_list),
|
|
||||||
() => frappe.dom.unfreeze()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get_child_nodes(node_id) {
|
|
||||||
let me = this;
|
|
||||||
return new Promise(resolve => {
|
|
||||||
frappe.call({
|
|
||||||
method: me.method,
|
|
||||||
args: {
|
|
||||||
parent: node_id,
|
|
||||||
company: me.company
|
|
||||||
}
|
|
||||||
}).then(r => resolve(r.message));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render_child_nodes(node, child_nodes) {
|
|
||||||
const last_level = this.$hierarchy.find('.level:last').index();
|
|
||||||
const current_level = $(`[id="${node.id}"]`).parent().parent().parent().index();
|
|
||||||
|
|
||||||
if (last_level === current_level) {
|
|
||||||
this.$hierarchy.append(`
|
|
||||||
<li class="level"></li>
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!node.$children) {
|
|
||||||
node.$children = $('<ul class="node-children"></ul>')
|
|
||||||
.hide()
|
|
||||||
.appendTo(this.$hierarchy.find('.level:last'));
|
|
||||||
|
|
||||||
node.$children.empty();
|
|
||||||
|
|
||||||
if (child_nodes) {
|
|
||||||
$.each(child_nodes, (_i, data) => {
|
|
||||||
if (!$(`[id="${data.id}"]`).length) {
|
|
||||||
this.add_node(node, data);
|
|
||||||
setTimeout(() => {
|
|
||||||
this.add_connector(node.id, data.id);
|
|
||||||
}, 250);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.$children.show();
|
|
||||||
$(`path[data-parent="${node.id}"]`).show();
|
|
||||||
node.expanded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_all_nodes() {
|
|
||||||
let me = this;
|
|
||||||
return new Promise(resolve => {
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.utilities.hierarchy_chart.get_all_nodes',
|
|
||||||
args: {
|
|
||||||
method: me.method,
|
|
||||||
company: me.company
|
|
||||||
},
|
|
||||||
callback: (r) => {
|
|
||||||
resolve(r.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render_children_of_all_nodes(data_list) {
|
|
||||||
let entry = undefined;
|
|
||||||
let node = undefined;
|
|
||||||
|
|
||||||
while (data_list.length) {
|
|
||||||
// to avoid overlapping connectors
|
|
||||||
entry = data_list.shift();
|
|
||||||
node = this.nodes[entry.parent];
|
|
||||||
if (node) {
|
|
||||||
this.render_child_nodes_for_expanded_view(node, entry.data);
|
|
||||||
} else if (data_list.length) {
|
|
||||||
data_list.push(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
render_child_nodes_for_expanded_view(node, child_nodes) {
|
|
||||||
node.$children = $('<ul class="node-children"></ul>');
|
|
||||||
|
|
||||||
const last_level = this.$hierarchy.find('.level:last').index();
|
|
||||||
const node_level = $(`[id="${node.id}"]`).parent().parent().parent().index();
|
|
||||||
|
|
||||||
if (last_level === node_level) {
|
|
||||||
this.$hierarchy.append(`
|
|
||||||
<li class="level"></li>
|
|
||||||
`);
|
|
||||||
node.$children.appendTo(this.$hierarchy.find('.level:last'));
|
|
||||||
} else {
|
|
||||||
node.$children.appendTo(this.$hierarchy.find('.level:eq(' + (node_level + 1) + ')'));
|
|
||||||
}
|
|
||||||
|
|
||||||
node.$children.hide().empty();
|
|
||||||
|
|
||||||
if (child_nodes) {
|
|
||||||
$.each(child_nodes, (_i, data) => {
|
|
||||||
this.add_node(node, data);
|
|
||||||
setTimeout(() => {
|
|
||||||
this.add_connector(node.id, data.id);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
node.$children.show();
|
|
||||||
$(`path[data-parent="${node.id}"]`).show();
|
|
||||||
node.expanded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_node(node, data) {
|
|
||||||
return new this.Node({
|
|
||||||
id: data.id,
|
|
||||||
parent: $('<li class="child-node"></li>').appendTo(node.$children),
|
|
||||||
parent_id: node.id,
|
|
||||||
image: data.image,
|
|
||||||
name: data.name,
|
|
||||||
title: data.title,
|
|
||||||
expandable: data.expandable,
|
|
||||||
connections: data.connections,
|
|
||||||
children: undefined
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
add_connector(parent_id, child_id) {
|
|
||||||
// using pure javascript for better performance
|
|
||||||
const parent_node = document.getElementById(`${parent_id}`);
|
|
||||||
const child_node = document.getElementById(`${child_id}`);
|
|
||||||
|
|
||||||
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
||||||
|
|
||||||
// we need to connect right side of the parent to the left side of the child node
|
|
||||||
const pos_parent_right = {
|
|
||||||
x: parent_node.offsetLeft + parent_node.offsetWidth,
|
|
||||||
y: parent_node.offsetTop + parent_node.offsetHeight / 2
|
|
||||||
};
|
|
||||||
const pos_child_left = {
|
|
||||||
x: child_node.offsetLeft - 5,
|
|
||||||
y: child_node.offsetTop + child_node.offsetHeight / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
const connector = this.get_connector(pos_parent_right, pos_child_left);
|
|
||||||
|
|
||||||
path.setAttribute('d', connector);
|
|
||||||
this.set_path_attributes(path, parent_id, child_id);
|
|
||||||
|
|
||||||
document.getElementById('connectors').appendChild(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
get_connector(pos_parent_right, pos_child_left) {
|
|
||||||
if (pos_parent_right.y === pos_child_left.y) {
|
|
||||||
// don't add arcs if it's a straight line
|
|
||||||
return "M" +
|
|
||||||
(pos_parent_right.x) + "," + (pos_parent_right.y) + " " +
|
|
||||||
"L"+
|
|
||||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
|
||||||
} else {
|
|
||||||
let arc_1 = "";
|
|
||||||
let arc_2 = "";
|
|
||||||
let offset = 0;
|
|
||||||
|
|
||||||
if (pos_parent_right.y > pos_child_left.y) {
|
|
||||||
// if child is above parent on Y axis 1st arc is anticlocwise
|
|
||||||
// second arc is clockwise
|
|
||||||
arc_1 = "a10,10 1 0 0 10,-10 ";
|
|
||||||
arc_2 = "a10,10 0 0 1 10,-10 ";
|
|
||||||
offset = 10;
|
|
||||||
} else {
|
|
||||||
// if child is below parent on Y axis 1st arc is clockwise
|
|
||||||
// second arc is anticlockwise
|
|
||||||
arc_1 = "a10,10 0 0 1 10,10 ";
|
|
||||||
arc_2 = "a10,10 1 0 0 10,10 ";
|
|
||||||
offset = -10;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "M" + (pos_parent_right.x) + "," + (pos_parent_right.y) + " " +
|
|
||||||
"L" +
|
|
||||||
(pos_parent_right.x + 40) + "," + (pos_parent_right.y) + " " +
|
|
||||||
arc_1 +
|
|
||||||
"L" +
|
|
||||||
(pos_parent_right.x + 50) + "," + (pos_child_left.y + offset) + " " +
|
|
||||||
arc_2 +
|
|
||||||
"L"+
|
|
||||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_path_attributes(path, parent_id, child_id) {
|
|
||||||
path.setAttribute("data-parent", parent_id);
|
|
||||||
path.setAttribute("data-child", child_id);
|
|
||||||
const parent = $(`[id="${parent_id}"]`);
|
|
||||||
|
|
||||||
if (parent.hasClass('active')) {
|
|
||||||
path.setAttribute("class", "active-connector");
|
|
||||||
path.setAttribute("marker-start", "url(#arrowstart-active)");
|
|
||||||
path.setAttribute("marker-end", "url(#arrowhead-active)");
|
|
||||||
} else {
|
|
||||||
path.setAttribute("class", "collapsed-connector");
|
|
||||||
path.setAttribute("marker-start", "url(#arrowstart-collapsed)");
|
|
||||||
path.setAttribute("marker-end", "url(#arrowhead-collapsed)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_selected_node(node) {
|
|
||||||
// remove active class from the current node
|
|
||||||
if (this.selected_node)
|
|
||||||
this.selected_node.$link.removeClass('active');
|
|
||||||
|
|
||||||
// add active class to the newly selected node
|
|
||||||
this.selected_node = node;
|
|
||||||
node.$link.addClass('active');
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_previous_level_nodes(node) {
|
|
||||||
let node_parent = $(`[id="${node.parent_id}"]`);
|
|
||||||
let previous_level_nodes = node_parent.parent().parent().children('li');
|
|
||||||
let node_card = undefined;
|
|
||||||
|
|
||||||
previous_level_nodes.each(function() {
|
|
||||||
node_card = $(this).find('.node-card');
|
|
||||||
|
|
||||||
if (!node_card.hasClass('active-path')) {
|
|
||||||
node_card.addClass('collapsed');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh_connectors(node_parent) {
|
|
||||||
if (!node_parent) return;
|
|
||||||
|
|
||||||
$(`path[data-parent="${node_parent}"]`).remove();
|
|
||||||
|
|
||||||
frappe.run_serially([
|
|
||||||
() => this.get_child_nodes(node_parent),
|
|
||||||
(child_nodes) => {
|
|
||||||
if (child_nodes) {
|
|
||||||
$.each(child_nodes, (_i, data) => {
|
|
||||||
this.add_connector(node_parent, data.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_node_click_action(node) {
|
|
||||||
let me = this;
|
|
||||||
let node_element = $(`[id="${node.id}"]`);
|
|
||||||
|
|
||||||
node_element.click(function() {
|
|
||||||
const is_sibling = me.selected_node.parent_id === node.parent_id;
|
|
||||||
|
|
||||||
if (is_sibling) {
|
|
||||||
me.collapse_node();
|
|
||||||
} else if (node_element.is(':visible')
|
|
||||||
&& (node_element.hasClass('collapsed') || node_element.hasClass('active-path'))) {
|
|
||||||
me.remove_levels_after_node(node);
|
|
||||||
me.remove_orphaned_connectors();
|
|
||||||
}
|
|
||||||
|
|
||||||
me.expand_node(node);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_edit_node_action(node) {
|
|
||||||
let node_element = $(`[id="${node.id}"]`);
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
node_element.find('.btn-edit-node').click(function() {
|
|
||||||
frappe.set_route('Form', me.doctype, node.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_levels_after_node(node) {
|
|
||||||
let level = $(`[id="${node.id}"]`).parent().parent().parent().index();
|
|
||||||
|
|
||||||
level = $('.hierarchy > li:eq('+ level + ')');
|
|
||||||
level.nextAll('li').remove();
|
|
||||||
|
|
||||||
let nodes = level.find('.node-card');
|
|
||||||
let node_object = undefined;
|
|
||||||
|
|
||||||
$.each(nodes, (_i, element) => {
|
|
||||||
node_object = this.nodes[element.id];
|
|
||||||
node_object.expanded = 0;
|
|
||||||
node_object.$children = undefined;
|
|
||||||
});
|
|
||||||
|
|
||||||
nodes.removeClass('collapsed active-path');
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_orphaned_connectors() {
|
|
||||||
let paths = $('#connectors > path');
|
|
||||||
$.each(paths, (_i, path) => {
|
|
||||||
const parent = $(path).data('parent');
|
|
||||||
const child = $(path).data('child');
|
|
||||||
|
|
||||||
if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$(path).remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,550 +0,0 @@
|
|||||||
erpnext.HierarchyChartMobile = class {
|
|
||||||
/* Options:
|
|
||||||
- doctype
|
|
||||||
- wrapper: wrapper for the hierarchy view
|
|
||||||
- method:
|
|
||||||
- to get the data for each node
|
|
||||||
- this method should return id, name, title, image, and connections for each node
|
|
||||||
*/
|
|
||||||
constructor(doctype, wrapper, method) {
|
|
||||||
this.page = wrapper.page;
|
|
||||||
this.method = method;
|
|
||||||
this.doctype = doctype;
|
|
||||||
|
|
||||||
this.page.main.css({
|
|
||||||
'min-height': '300px',
|
|
||||||
'max-height': '600px',
|
|
||||||
'overflow': 'auto',
|
|
||||||
'position': 'relative'
|
|
||||||
});
|
|
||||||
this.page.main.addClass('frappe-card');
|
|
||||||
|
|
||||||
this.nodes = {};
|
|
||||||
this.setup_node_class();
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_node_class() {
|
|
||||||
let me = this;
|
|
||||||
this.Node = class {
|
|
||||||
constructor({
|
|
||||||
id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line
|
|
||||||
}) {
|
|
||||||
// to setup values passed via constructor
|
|
||||||
$.extend(this, arguments[0]);
|
|
||||||
|
|
||||||
this.expanded = 0;
|
|
||||||
|
|
||||||
me.nodes[this.id] = this;
|
|
||||||
me.make_node_element(this);
|
|
||||||
me.setup_node_click_action(this);
|
|
||||||
me.setup_edit_node_action(this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
make_node_element(node) {
|
|
||||||
let node_card = frappe.render_template('node_card', {
|
|
||||||
id: node.id,
|
|
||||||
name: node.name,
|
|
||||||
title: node.title,
|
|
||||||
image: node.image,
|
|
||||||
parent: node.parent_id,
|
|
||||||
connections: node.connections,
|
|
||||||
is_mobile: true
|
|
||||||
});
|
|
||||||
|
|
||||||
node.parent.append(node_card);
|
|
||||||
node.$link = $(`[id="${node.id}"]`);
|
|
||||||
node.$link.addClass('mobile-node');
|
|
||||||
}
|
|
||||||
|
|
||||||
show() {
|
|
||||||
let me = this;
|
|
||||||
if ($(`[data-fieldname="company"]`).length) return;
|
|
||||||
|
|
||||||
let company = this.page.add_field({
|
|
||||||
fieldtype: 'Link',
|
|
||||||
options: 'Company',
|
|
||||||
fieldname: 'company',
|
|
||||||
placeholder: __('Select Company'),
|
|
||||||
default: frappe.defaults.get_default('company'),
|
|
||||||
only_select: true,
|
|
||||||
reqd: 1,
|
|
||||||
change: () => {
|
|
||||||
me.company = undefined;
|
|
||||||
|
|
||||||
if (company.get_value() && me.company != company.get_value()) {
|
|
||||||
me.company = company.get_value();
|
|
||||||
|
|
||||||
// svg for connectors
|
|
||||||
me.make_svg_markers();
|
|
||||||
|
|
||||||
if (me.$sibling_group)
|
|
||||||
me.$sibling_group.remove();
|
|
||||||
|
|
||||||
// setup sibling group wrapper
|
|
||||||
me.$sibling_group = $(`<div class="sibling-group mt-4 mb-4"></div>`);
|
|
||||||
me.page.main.append(me.$sibling_group);
|
|
||||||
|
|
||||||
me.setup_hierarchy();
|
|
||||||
me.render_root_nodes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
company.refresh();
|
|
||||||
$(`[data-fieldname="company"]`).trigger('change');
|
|
||||||
}
|
|
||||||
|
|
||||||
make_svg_markers() {
|
|
||||||
$('#arrows').remove();
|
|
||||||
|
|
||||||
this.page.main.prepend(`
|
|
||||||
<svg id="arrows" width="100%" height="100%">
|
|
||||||
<defs>
|
|
||||||
<marker id="arrowhead-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-500)">
|
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
|
||||||
</marker>
|
|
||||||
<marker id="arrowhead-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-300)">
|
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
|
||||||
</marker>
|
|
||||||
|
|
||||||
<marker id="arrowstart-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-500)">
|
|
||||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-500)"/>
|
|
||||||
</marker>
|
|
||||||
<marker id="arrowstart-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-300)">
|
|
||||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-300)"/>
|
|
||||||
</marker>
|
|
||||||
</defs>
|
|
||||||
<g id="connectors" fill="none">
|
|
||||||
</g>
|
|
||||||
</svg>`);
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_hierarchy() {
|
|
||||||
$(`#connectors`).empty();
|
|
||||||
if (this.$hierarchy)
|
|
||||||
this.$hierarchy.remove();
|
|
||||||
|
|
||||||
if (this.$sibling_group)
|
|
||||||
this.$sibling_group.empty();
|
|
||||||
|
|
||||||
this.$hierarchy = $(
|
|
||||||
`<ul class="hierarchy-mobile">
|
|
||||||
<li class="root-level level"></li>
|
|
||||||
</ul>`);
|
|
||||||
|
|
||||||
this.page.main.append(this.$hierarchy);
|
|
||||||
}
|
|
||||||
|
|
||||||
render_root_nodes() {
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
frappe.call({
|
|
||||||
method: me.method,
|
|
||||||
args: {
|
|
||||||
company: me.company
|
|
||||||
},
|
|
||||||
}).then(r => {
|
|
||||||
if (r.message.length) {
|
|
||||||
let root_level = me.$hierarchy.find('.root-level');
|
|
||||||
root_level.empty();
|
|
||||||
|
|
||||||
$.each(r.message, (_i, data) => {
|
|
||||||
return new me.Node({
|
|
||||||
id: data.id,
|
|
||||||
parent: root_level,
|
|
||||||
parent_id: undefined,
|
|
||||||
image: data.image,
|
|
||||||
name: data.name,
|
|
||||||
title: data.title,
|
|
||||||
expandable: true,
|
|
||||||
connections: data.connections,
|
|
||||||
is_root: true
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_node(node) {
|
|
||||||
const is_same_node = (this.selected_node && this.selected_node.id === node.id);
|
|
||||||
this.set_selected_node(node);
|
|
||||||
this.show_active_path(node);
|
|
||||||
|
|
||||||
if (this.$sibling_group) {
|
|
||||||
const sibling_parent = this.$sibling_group.find('.node-group').attr('data-parent');
|
|
||||||
if (node.parent_id !== undefined && node.parent_id != sibling_parent)
|
|
||||||
this.$sibling_group.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_same_node) {
|
|
||||||
// since the previous/parent node collapses, all connections to that node need to be rebuilt
|
|
||||||
// rebuild outgoing connections of parent
|
|
||||||
this.refresh_connectors(node.parent_id, node.id);
|
|
||||||
|
|
||||||
// rebuild incoming connections of parent
|
|
||||||
let grandparent = $(`[id="${node.parent_id}"]`).attr('data-parent');
|
|
||||||
this.refresh_connectors(grandparent, node.parent_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.expandable && !node.expanded) {
|
|
||||||
return this.load_children(node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
collapse_node() {
|
|
||||||
let node = this.selected_node;
|
|
||||||
if (node.expandable && node.$children) {
|
|
||||||
node.$children.hide();
|
|
||||||
node.expanded = 0;
|
|
||||||
|
|
||||||
// add a collapsed level to show the collapsed parent
|
|
||||||
// and a button beside it to move to that level
|
|
||||||
let node_parent = node.$link.parent();
|
|
||||||
node_parent.prepend(
|
|
||||||
`<div class="collapsed-level d-flex flex-row"></div>`
|
|
||||||
);
|
|
||||||
|
|
||||||
node_parent
|
|
||||||
.find('.collapsed-level')
|
|
||||||
.append(node.$link);
|
|
||||||
|
|
||||||
frappe.run_serially([
|
|
||||||
() => this.get_child_nodes(node.parent_id, node.id),
|
|
||||||
(child_nodes) => this.get_node_group(child_nodes, node.parent_id),
|
|
||||||
(node_group) => node_parent.find('.collapsed-level').append(node_group),
|
|
||||||
() => this.setup_node_group_action()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
show_active_path(node) {
|
|
||||||
// mark node parent on active path
|
|
||||||
$(`[id="${node.parent_id}"]`).addClass('active-path');
|
|
||||||
}
|
|
||||||
|
|
||||||
load_children(node) {
|
|
||||||
frappe.run_serially([
|
|
||||||
() => this.get_child_nodes(node.id),
|
|
||||||
(child_nodes) => this.render_child_nodes(node, child_nodes)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
get_child_nodes(node_id, exclude_node=null) {
|
|
||||||
let me = this;
|
|
||||||
return new Promise(resolve => {
|
|
||||||
frappe.call({
|
|
||||||
method: me.method,
|
|
||||||
args: {
|
|
||||||
parent: node_id,
|
|
||||||
company: me.company,
|
|
||||||
exclude_node: exclude_node
|
|
||||||
}
|
|
||||||
}).then(r => resolve(r.message));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render_child_nodes(node, child_nodes) {
|
|
||||||
if (!node.$children) {
|
|
||||||
node.$children = $('<ul class="node-children"></ul>')
|
|
||||||
.hide()
|
|
||||||
.appendTo(node.$link.parent());
|
|
||||||
|
|
||||||
node.$children.empty();
|
|
||||||
|
|
||||||
if (child_nodes) {
|
|
||||||
$.each(child_nodes, (_i, data) => {
|
|
||||||
this.add_node(node, data);
|
|
||||||
$(`[id="${data.id}"]`).addClass('active-child');
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.add_connector(node.id, data.id);
|
|
||||||
}, 250);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
node.$children.show();
|
|
||||||
node.expanded = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
add_node(node, data) {
|
|
||||||
var $li = $('<li class="child-node"></li>');
|
|
||||||
|
|
||||||
return new this.Node({
|
|
||||||
id: data.id,
|
|
||||||
parent: $li.appendTo(node.$children),
|
|
||||||
parent_id: node.id,
|
|
||||||
image: data.image,
|
|
||||||
name: data.name,
|
|
||||||
title: data.title,
|
|
||||||
expandable: data.expandable,
|
|
||||||
connections: data.connections,
|
|
||||||
children: undefined
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
add_connector(parent_id, child_id) {
|
|
||||||
const parent_node = document.getElementById(`${parent_id}`);
|
|
||||||
const child_node = document.getElementById(`${child_id}`);
|
|
||||||
|
|
||||||
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
||||||
|
|
||||||
let connector = undefined;
|
|
||||||
|
|
||||||
if ($(`[id="${parent_id}"]`).hasClass('active')) {
|
|
||||||
connector = this.get_connector_for_active_node(parent_node, child_node);
|
|
||||||
} else if ($(`[id="${parent_id}"]`).hasClass('active-path')) {
|
|
||||||
connector = this.get_connector_for_collapsed_node(parent_node, child_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
path.setAttribute('d', connector);
|
|
||||||
this.set_path_attributes(path, parent_id, child_id);
|
|
||||||
|
|
||||||
document.getElementById('connectors').appendChild(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
get_connector_for_active_node(parent_node, child_node) {
|
|
||||||
// we need to connect the bottom left of the parent to the left side of the child node
|
|
||||||
let pos_parent_bottom = {
|
|
||||||
x: parent_node.offsetLeft + 20,
|
|
||||||
y: parent_node.offsetTop + parent_node.offsetHeight
|
|
||||||
};
|
|
||||||
let pos_child_left = {
|
|
||||||
x: child_node.offsetLeft - 5,
|
|
||||||
y: child_node.offsetTop + child_node.offsetHeight / 2
|
|
||||||
};
|
|
||||||
|
|
||||||
let connector =
|
|
||||||
"M" +
|
|
||||||
(pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " +
|
|
||||||
"L" +
|
|
||||||
(pos_parent_bottom.x) + "," + (pos_child_left.y - 10) + " " +
|
|
||||||
"a10,10 1 0 0 10,10 " +
|
|
||||||
"L" +
|
|
||||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
|
||||||
|
|
||||||
return connector;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_connector_for_collapsed_node(parent_node, child_node) {
|
|
||||||
// we need to connect the bottom left of the parent to the top left of the child node
|
|
||||||
let pos_parent_bottom = {
|
|
||||||
x: parent_node.offsetLeft + 20,
|
|
||||||
y: parent_node.offsetTop + parent_node.offsetHeight
|
|
||||||
};
|
|
||||||
let pos_child_top = {
|
|
||||||
x: child_node.offsetLeft + 20,
|
|
||||||
y: child_node.offsetTop
|
|
||||||
};
|
|
||||||
|
|
||||||
let connector =
|
|
||||||
"M" +
|
|
||||||
(pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " +
|
|
||||||
"L" +
|
|
||||||
(pos_child_top.x) + "," + (pos_child_top.y);
|
|
||||||
|
|
||||||
return connector;
|
|
||||||
}
|
|
||||||
|
|
||||||
set_path_attributes(path, parent_id, child_id) {
|
|
||||||
path.setAttribute("data-parent", parent_id);
|
|
||||||
path.setAttribute("data-child", child_id);
|
|
||||||
const parent = $(`[id="${parent_id}"]`);
|
|
||||||
|
|
||||||
if (parent.hasClass('active')) {
|
|
||||||
path.setAttribute("class", "active-connector");
|
|
||||||
path.setAttribute("marker-start", "url(#arrowstart-active)");
|
|
||||||
path.setAttribute("marker-end", "url(#arrowhead-active)");
|
|
||||||
} else if (parent.hasClass('active-path')) {
|
|
||||||
path.setAttribute("class", "collapsed-connector");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
set_selected_node(node) {
|
|
||||||
// remove .active class from the current node
|
|
||||||
if (this.selected_node)
|
|
||||||
this.selected_node.$link.removeClass('active');
|
|
||||||
|
|
||||||
// add active class to the newly selected node
|
|
||||||
this.selected_node = node;
|
|
||||||
node.$link.addClass('active');
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_node_click_action(node) {
|
|
||||||
let me = this;
|
|
||||||
let node_element = $(`[id="${node.id}"]`);
|
|
||||||
|
|
||||||
node_element.click(function() {
|
|
||||||
let el = undefined;
|
|
||||||
|
|
||||||
if (node.is_root) {
|
|
||||||
el = $(this).detach();
|
|
||||||
me.$hierarchy.empty();
|
|
||||||
$(`#connectors`).empty();
|
|
||||||
me.add_node_to_hierarchy(el, node);
|
|
||||||
} else if (node_element.is(':visible') && node_element.hasClass('active-path')) {
|
|
||||||
me.remove_levels_after_node(node);
|
|
||||||
me.remove_orphaned_connectors();
|
|
||||||
} else {
|
|
||||||
el = $(this).detach();
|
|
||||||
me.add_node_to_hierarchy(el, node);
|
|
||||||
me.collapse_node();
|
|
||||||
}
|
|
||||||
|
|
||||||
me.expand_node(node);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_edit_node_action(node) {
|
|
||||||
let node_element = $(`[id="${node.id}"]`);
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
node_element.find('.btn-edit-node').click(function() {
|
|
||||||
frappe.set_route('Form', me.doctype, node.id);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_node_group_action() {
|
|
||||||
let me = this;
|
|
||||||
|
|
||||||
$('.node-group').on('click', function() {
|
|
||||||
let parent = $(this).attr('data-parent');
|
|
||||||
if (parent === 'undefined') {
|
|
||||||
me.setup_hierarchy();
|
|
||||||
me.render_root_nodes();
|
|
||||||
} else {
|
|
||||||
me.expand_sibling_group_node(parent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
add_node_to_hierarchy(node_element, node) {
|
|
||||||
this.$hierarchy.append(`<li class="level"></li>`);
|
|
||||||
node_element.removeClass('active-child active-path');
|
|
||||||
this.$hierarchy.find('.level:last').append(node_element);
|
|
||||||
|
|
||||||
let node_object = this.nodes[node.id];
|
|
||||||
node_object.expanded = 0;
|
|
||||||
node_object.$children = undefined;
|
|
||||||
this.nodes[node.id] = node_object;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_node_group(nodes, parent, collapsed=true) {
|
|
||||||
let limit = 2;
|
|
||||||
const display_nodes = nodes.slice(0, limit);
|
|
||||||
const extra_nodes = nodes.slice(limit);
|
|
||||||
|
|
||||||
let html = display_nodes.map(node =>
|
|
||||||
this.get_avatar(node)
|
|
||||||
).join('');
|
|
||||||
|
|
||||||
if (extra_nodes.length === 1) {
|
|
||||||
let node = extra_nodes[0];
|
|
||||||
html += this.get_avatar(node);
|
|
||||||
} else if (extra_nodes.length > 1) {
|
|
||||||
html = `
|
|
||||||
${html}
|
|
||||||
<span class="avatar avatar-small">
|
|
||||||
<div class="avatar-frame standard-image avatar-extra-count"
|
|
||||||
title="${extra_nodes.map(node => node.name).join(', ')}">
|
|
||||||
+${extra_nodes.length}
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (html) {
|
|
||||||
const $node_group =
|
|
||||||
$(`<div class="node-group card cursor-pointer" data-parent=${parent}>
|
|
||||||
<div class="avatar-group right overlap">
|
|
||||||
${html}
|
|
||||||
</div>
|
|
||||||
</div>`);
|
|
||||||
|
|
||||||
if (collapsed)
|
|
||||||
$node_group.addClass('collapsed');
|
|
||||||
|
|
||||||
return $node_group;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_avatar(node) {
|
|
||||||
return `<span class="avatar avatar-small" title="${node.name}">
|
|
||||||
<span class="avatar-frame" src=${node.image} style="background-image: url(${node.image})"></span>
|
|
||||||
</span>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
expand_sibling_group_node(parent) {
|
|
||||||
let node_object = this.nodes[parent];
|
|
||||||
let node = node_object.$link;
|
|
||||||
|
|
||||||
node.removeClass('active-child active-path');
|
|
||||||
node_object.expanded = 0;
|
|
||||||
node_object.$children = undefined;
|
|
||||||
this.nodes[node.id] = node_object;
|
|
||||||
|
|
||||||
// show parent's siblings and expand parent node
|
|
||||||
frappe.run_serially([
|
|
||||||
() => this.get_child_nodes(node_object.parent_id, node_object.id),
|
|
||||||
(child_nodes) => this.get_node_group(child_nodes, node_object.parent_id, false),
|
|
||||||
(node_group) => {
|
|
||||||
if (node_group)
|
|
||||||
this.$sibling_group.empty().append(node_group);
|
|
||||||
},
|
|
||||||
() => this.setup_node_group_action(),
|
|
||||||
() => this.reattach_and_expand_node(node, node_object)
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
reattach_and_expand_node(node, node_object) {
|
|
||||||
var el = node.detach();
|
|
||||||
|
|
||||||
this.$hierarchy.empty().append(`
|
|
||||||
<li class="level"></li>
|
|
||||||
`);
|
|
||||||
this.$hierarchy.find('.level').append(el);
|
|
||||||
$(`#connectors`).empty();
|
|
||||||
this.expand_node(node_object);
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_levels_after_node(node) {
|
|
||||||
let level = $(`[id="${node.id}"]`).parent().parent().index();
|
|
||||||
|
|
||||||
level = $('.hierarchy-mobile > li:eq('+ level + ')');
|
|
||||||
level.nextAll('li').remove();
|
|
||||||
|
|
||||||
let node_object = this.nodes[node.id];
|
|
||||||
let current_node = level.find(`[id="${node.id}"]`).detach();
|
|
||||||
|
|
||||||
current_node.removeClass('active-child active-path');
|
|
||||||
|
|
||||||
node_object.expanded = 0;
|
|
||||||
node_object.$children = undefined;
|
|
||||||
|
|
||||||
level.empty().append(current_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
remove_orphaned_connectors() {
|
|
||||||
let paths = $('#connectors > path');
|
|
||||||
$.each(paths, (_i, path) => {
|
|
||||||
const parent = $(path).data('parent');
|
|
||||||
const child = $(path).data('child');
|
|
||||||
|
|
||||||
if ($(`[id="${parent}"]`).length && $(`[id="${child}"]`).length)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$(path).remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh_connectors(node_parent, node_id) {
|
|
||||||
if (!node_parent) return;
|
|
||||||
|
|
||||||
$(`path[data-parent="${node_parent}"]`).remove();
|
|
||||||
this.add_connector(node_parent, node_id);
|
|
||||||
}
|
|
||||||
};
|
|
@ -8,7 +8,7 @@ frappe.ui.form.ControlData = class ControlData extends frappe.ui.form.ControlDat
|
|||||||
Object.values(this.frm.fields_dict).forEach(function(field) {
|
Object.values(this.frm.fields_dict).forEach(function(field) {
|
||||||
if (field.df.read_only === 1 && field.df.options === 'Phone'
|
if (field.df.read_only === 1 && field.df.options === 'Phone'
|
||||||
&& field.disp_area.style[0] != 'display' && !field.has_icon) {
|
&& field.disp_area.style[0] != 'display' && !field.has_icon) {
|
||||||
field.setup_phone();
|
field.setup_phone && field.setup_phone();
|
||||||
field.has_icon = true;
|
field.has_icon = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
<div class="node-card card cursor-pointer" id="{%= id %}" data-parent="{%= parent %}">
|
|
||||||
<div class="node-meta d-flex flex-row">
|
|
||||||
<div class="mr-3">
|
|
||||||
<span class="avatar node-image" title="{{ name }}">
|
|
||||||
<span class="avatar-frame" src={{image}} style="background-image: url(\'{%= image %}\')"></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div class="node-name d-flex flex-row mb-1">
|
|
||||||
<span class="ellipsis">{{ name }}</span>
|
|
||||||
<div class="btn-xs btn-edit-node d-flex flex-row">
|
|
||||||
<a class="node-edit-icon">{{ frappe.utils.icon("edit", "xs") }}</a>
|
|
||||||
<span class="edit-chart-node text-xs">{{ __("Edit") }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="node-info d-flex flex-row mb-1">
|
|
||||||
<div class="node-title text-muted ellipsis">{{ title }}</div>
|
|
||||||
|
|
||||||
{% if is_mobile %}
|
|
||||||
<div class="node-connections text-muted ml-2 ellipsis">
|
|
||||||
· {{ connections }} <span class="fa fa-level-down"></span>
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
{% if connections == 1 %}
|
|
||||||
<div class="node-connections text-muted ml-2 ellipsis">· {{ connections }} Connection</div>
|
|
||||||
{% else %}
|
|
||||||
<div class="node-connections text-muted ml-2 ellipsis">· {{ connections }} Connections</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -350,6 +350,38 @@ $.extend(erpnext.utils, {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
pick_serial_and_batch_bundle(frm, cdt, cdn, type_of_transaction, warehouse_field) {
|
||||||
|
let item_row = frappe.get_doc(cdt, cdn);
|
||||||
|
item_row.type_of_transaction = type_of_transaction;
|
||||||
|
|
||||||
|
frappe.db.get_value("Item", item_row.item_code, ["has_batch_no", "has_serial_no"])
|
||||||
|
.then((r) => {
|
||||||
|
item_row.has_batch_no = r.message.has_batch_no;
|
||||||
|
item_row.has_serial_no = r.message.has_serial_no;
|
||||||
|
|
||||||
|
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
|
||||||
|
new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => {
|
||||||
|
if (r) {
|
||||||
|
let update_values = {
|
||||||
|
"serial_and_batch_bundle": r.name,
|
||||||
|
"qty": Math.abs(r.total_qty)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!warehouse_field) {
|
||||||
|
warehouse_field = "warehouse";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r.warehouse) {
|
||||||
|
update_values[warehouse_field] = r.warehouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
frappe.model.set_value(item_row.doctype, item_row.name, update_values);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
erpnext.utils.select_alternate_items = function(opts) {
|
erpnext.utils.select_alternate_items = function(opts) {
|
||||||
|
@ -16,8 +16,8 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) {
|
|||||||
|| (frm.doc.party_name && in_list(['Quotation', 'Opportunity'], frm.doc.doctype))) {
|
|| (frm.doc.party_name && in_list(['Quotation', 'Opportunity'], frm.doc.doctype))) {
|
||||||
|
|
||||||
let party_type = "Customer";
|
let party_type = "Customer";
|
||||||
if (frm.doc.quotation_to && frm.doc.quotation_to === "Lead") {
|
if (frm.doc.quotation_to && in_list(["Lead", "Prospect"], frm.doc.quotation_to)) {
|
||||||
party_type = "Lead";
|
party_type = frm.doc.quotation_to;
|
||||||
}
|
}
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
|
@ -26,7 +26,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
title: this.item?.title || primary_label,
|
title: this.item?.title || primary_label,
|
||||||
fields: this.get_dialog_fields(),
|
fields: this.get_dialog_fields(),
|
||||||
primary_action_label: primary_label,
|
primary_action_label: primary_label,
|
||||||
primary_action: () => this.update_ledgers(),
|
primary_action: () => this.update_bundle_entries(),
|
||||||
secondary_action_label: __('Edit Full Form'),
|
secondary_action_label: __('Edit Full Form'),
|
||||||
secondary_action: () => this.edit_full_form(),
|
secondary_action: () => this.edit_full_form(),
|
||||||
});
|
});
|
||||||
@ -36,7 +36,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_serial_no_filters() {
|
get_serial_no_filters() {
|
||||||
let warehouse = this.item?.outward ?
|
let warehouse = this.item?.type_of_transaction === "Outward" ?
|
||||||
(this.item.warehouse || this.item.s_warehouse) : "";
|
(this.item.warehouse || this.item.s_warehouse) : "";
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -121,7 +121,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.item?.outward) {
|
if (this.item?.type_of_transaction === "Outward") {
|
||||||
fields = [...this.get_filter_fields(), ...fields];
|
fields = [...this.get_filter_fields(), ...fields];
|
||||||
} else {
|
} else {
|
||||||
fields = [...fields, ...this.get_attach_field()];
|
fields = [...fields, ...this.get_attach_field()];
|
||||||
@ -267,7 +267,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
label: __('Batch No'),
|
label: __('Batch No'),
|
||||||
in_list_view: 1,
|
in_list_view: 1,
|
||||||
get_query: () => {
|
get_query: () => {
|
||||||
if (!this.item.outward) {
|
if (this.item.type_of_transaction !== "Outward") {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
'item': this.item.item_code,
|
'item': this.item.item_code,
|
||||||
@ -356,7 +356,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
this.dialog.fields_dict.entries.grid.refresh();
|
this.dialog.fields_dict.entries.grid.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
update_ledgers() {
|
update_bundle_entries() {
|
||||||
let entries = this.dialog.get_values().entries;
|
let entries = this.dialog.get_values().entries;
|
||||||
let warehouse = this.dialog.get_value('warehouse');
|
let warehouse = this.dialog.get_value('warehouse');
|
||||||
|
|
||||||
@ -390,7 +390,7 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
_new.warehouse = this.get_warehouse();
|
_new.warehouse = this.get_warehouse();
|
||||||
_new.has_serial_no = this.item.has_serial_no;
|
_new.has_serial_no = this.item.has_serial_no;
|
||||||
_new.has_batch_no = this.item.has_batch_no;
|
_new.has_batch_no = this.item.has_batch_no;
|
||||||
_new.type_of_transaction = this.get_type_of_transaction();
|
_new.type_of_transaction = this.item.type_of_transaction;
|
||||||
_new.company = this.frm.doc.company;
|
_new.company = this.frm.doc.company;
|
||||||
_new.voucher_type = this.frm.doc.doctype;
|
_new.voucher_type = this.frm.doc.doctype;
|
||||||
bundle_id = _new.name;
|
bundle_id = _new.name;
|
||||||
@ -401,15 +401,11 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_warehouse() {
|
get_warehouse() {
|
||||||
return (this.item?.outward ?
|
return (this.item?.type_of_transaction === "Outward" ?
|
||||||
(this.item.warehouse || this.item.s_warehouse)
|
(this.item.warehouse || this.item.s_warehouse)
|
||||||
: (this.item.warehouse || this.item.t_warehouse));
|
: (this.item.warehouse || this.item.t_warehouse));
|
||||||
}
|
}
|
||||||
|
|
||||||
get_type_of_transaction() {
|
|
||||||
return (this.item?.outward ? 'Outward' : 'Inward');
|
|
||||||
}
|
|
||||||
|
|
||||||
render_data() {
|
render_data() {
|
||||||
if (!this.frm.is_new() && this.bundle) {
|
if (!this.frm.is_new() && this.bundle) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
@import "./erpnext";
|
@import "./erpnext";
|
||||||
@import "./call_popup";
|
@import "./call_popup";
|
||||||
@import "./point-of-sale";
|
@import "./point-of-sale";
|
||||||
@import "./hierarchy_chart";
|
|
||||||
|
@ -1,313 +0,0 @@
|
|||||||
.node-card {
|
|
||||||
background: white;
|
|
||||||
stroke: 1px solid var(--gray-200);
|
|
||||||
box-shadow: var(--shadow-base);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
padding: 0.75rem;
|
|
||||||
margin-left: 3rem;
|
|
||||||
width: 18rem;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
.btn-edit-node {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-chart-node {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-edit-icon {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card.exported {
|
|
||||||
box-shadow: none
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-image {
|
|
||||||
width: 3.0rem;
|
|
||||||
height: 3.0rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-name {
|
|
||||||
font-size: 1rem;
|
|
||||||
line-height: 1.72;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-title {
|
|
||||||
font-size: 0.75rem;
|
|
||||||
line-height: 1.35;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-info {
|
|
||||||
width: 12.7rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-connections {
|
|
||||||
font-size: 0.75rem;
|
|
||||||
line-height: 1.35;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card.active {
|
|
||||||
background: var(--blue-50);
|
|
||||||
border: 1px solid var(--blue-500);
|
|
||||||
box-shadow: var(--shadow-md);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
padding: 0.75rem;
|
|
||||||
width: 18rem;
|
|
||||||
|
|
||||||
.btn-edit-node {
|
|
||||||
display: flex;
|
|
||||||
background: var(--blue-100);
|
|
||||||
color: var(--blue-500);
|
|
||||||
padding: .25rem .5rem;
|
|
||||||
font-size: .75rem;
|
|
||||||
justify-content: center;
|
|
||||||
box-shadow: var(--shadow-sm);
|
|
||||||
margin-left: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-chart-node {
|
|
||||||
display: block;
|
|
||||||
margin-right: 0.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-edit-icon {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-edit-icon > .icon{
|
|
||||||
stroke: var(--blue-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-name {
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
margin-bottom: 2px;
|
|
||||||
width: 12.2rem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card.active-path {
|
|
||||||
background: var(--blue-100);
|
|
||||||
border: 1px solid var(--blue-300);
|
|
||||||
box-shadow: var(--shadow-sm);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
padding: 0.75rem;
|
|
||||||
width: 15rem;
|
|
||||||
height: 3.0rem;
|
|
||||||
|
|
||||||
.btn-edit-node {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-chart-node {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-edit-icon {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-info {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-title {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-connections {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-name {
|
|
||||||
font-size: 0.85rem;
|
|
||||||
line-height: 1.35;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-image {
|
|
||||||
width: 1.5rem;
|
|
||||||
height: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-meta {
|
|
||||||
align-items: baseline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card.collapsed {
|
|
||||||
background: white;
|
|
||||||
stroke: 1px solid var(--gray-200);
|
|
||||||
box-shadow: var(--shadow-sm);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
padding: 0.75rem;
|
|
||||||
width: 15rem;
|
|
||||||
height: 3.0rem;
|
|
||||||
|
|
||||||
.btn-edit-node {
|
|
||||||
display: none !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.edit-chart-node {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-edit-icon {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-info {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-title {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-connections {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-name {
|
|
||||||
font-size: 0.85rem;
|
|
||||||
line-height: 1.35;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-image {
|
|
||||||
width: 1.5rem;
|
|
||||||
height: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-meta {
|
|
||||||
align-items: baseline;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// horizontal hierarchy tree view
|
|
||||||
#hierarchy-chart-wrapper {
|
|
||||||
padding-top: 30px;
|
|
||||||
|
|
||||||
#arrows {
|
|
||||||
margin-top: -80px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.hierarchy {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hierarchy li {
|
|
||||||
list-style-type: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.child-node {
|
|
||||||
margin: 0px 0px 16px 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hierarchy, .hierarchy-mobile {
|
|
||||||
.level {
|
|
||||||
margin-right: 8px;
|
|
||||||
align-items: flex-start;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#arrows {
|
|
||||||
position: absolute;
|
|
||||||
overflow: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.active-connector {
|
|
||||||
stroke: var(--blue-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
.collapsed-connector {
|
|
||||||
stroke: var(--blue-300);
|
|
||||||
}
|
|
||||||
|
|
||||||
// mobile
|
|
||||||
|
|
||||||
.hierarchy-mobile {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
padding-top: 10px;
|
|
||||||
padding-left: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hierarchy-mobile li {
|
|
||||||
list-style-type: none;
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: flex-end;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-node {
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-node.active-path {
|
|
||||||
width: 12.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.active-child {
|
|
||||||
width: 15.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.mobile-node .node-connections {
|
|
||||||
max-width: 80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hierarchy-mobile .node-children {
|
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.root-level .node-card {
|
|
||||||
margin: 0 0 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
// node group
|
|
||||||
|
|
||||||
.collapsed-level {
|
|
||||||
margin-bottom: 16px;
|
|
||||||
width: 18rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-group {
|
|
||||||
background: white;
|
|
||||||
border: 1px solid var(--gray-300);
|
|
||||||
box-shadow: var(--shadow-sm);
|
|
||||||
border-radius: 0.5rem;
|
|
||||||
padding: 0.75rem;
|
|
||||||
width: 18rem;
|
|
||||||
height: 3rem;
|
|
||||||
overflow: hidden;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-group .avatar-group {
|
|
||||||
margin-left: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-group .avatar-extra-count {
|
|
||||||
background-color: var(--blue-100);
|
|
||||||
color: var(--blue-500);
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-group .avatar-frame {
|
|
||||||
width: 1.5rem;
|
|
||||||
height: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-group.collapsed {
|
|
||||||
width: 5rem;
|
|
||||||
margin-left: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sibling-group {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
@ -10,7 +10,7 @@ from frappe.utils.data import fmt_money
|
|||||||
from frappe.utils.jinja import render_template
|
from frappe.utils.jinja import render_template
|
||||||
from frappe.utils.pdf import get_pdf
|
from frappe.utils.pdf import get_pdf
|
||||||
from frappe.utils.print_format import read_multi_pdf
|
from frappe.utils.print_format import read_multi_pdf
|
||||||
from PyPDF2 import PdfWriter
|
from pypdf import PdfWriter
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_fiscal_year
|
from erpnext.accounts.utils import get_fiscal_year
|
||||||
|
|
||||||
|
@ -454,12 +454,12 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False,
|
|||||||
customer_outstanding += flt(extra_amount)
|
customer_outstanding += flt(extra_amount)
|
||||||
|
|
||||||
if credit_limit > 0 and flt(customer_outstanding) > credit_limit:
|
if credit_limit > 0 and flt(customer_outstanding) > credit_limit:
|
||||||
msgprint(
|
message = _("Credit limit has been crossed for customer {0} ({1}/{2})").format(
|
||||||
_("Credit limit has been crossed for customer {0} ({1}/{2})").format(
|
customer, customer_outstanding, credit_limit
|
||||||
customer, customer_outstanding, credit_limit
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
message += "<br><br>"
|
||||||
|
|
||||||
# If not authorized person raise exception
|
# If not authorized person raise exception
|
||||||
credit_controller_role = frappe.db.get_single_value("Accounts Settings", "credit_controller")
|
credit_controller_role = frappe.db.get_single_value("Accounts Settings", "credit_controller")
|
||||||
if not credit_controller_role or credit_controller_role not in frappe.get_roles():
|
if not credit_controller_role or credit_controller_role not in frappe.get_roles():
|
||||||
@ -480,7 +480,7 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False,
|
|||||||
"<li>".join(credit_controller_users_formatted)
|
"<li>".join(credit_controller_users_formatted)
|
||||||
)
|
)
|
||||||
|
|
||||||
message = _(
|
message += _(
|
||||||
"Please contact any of the following users to extend the credit limits for {0}: {1}"
|
"Please contact any of the following users to extend the credit limits for {0}: {1}"
|
||||||
).format(customer, user_list)
|
).format(customer, user_list)
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ def check_credit_limit(customer, company, ignore_outstanding_sales_order=False,
|
|||||||
# prompt them to send out an email to the controller users
|
# prompt them to send out an email to the controller users
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
message,
|
message,
|
||||||
title="Notify",
|
title=_("Credit Limit Crossed"),
|
||||||
raise_exception=1,
|
raise_exception=1,
|
||||||
primary_action={
|
primary_action={
|
||||||
"label": "Send Email",
|
"label": "Send Email",
|
||||||
@ -519,7 +519,6 @@ def get_customer_outstanding(
|
|||||||
customer, company, ignore_outstanding_sales_order=False, cost_center=None
|
customer, company, ignore_outstanding_sales_order=False, cost_center=None
|
||||||
):
|
):
|
||||||
# Outstanding based on GL Entries
|
# Outstanding based on GL Entries
|
||||||
|
|
||||||
cond = ""
|
cond = ""
|
||||||
if cost_center:
|
if cost_center:
|
||||||
lft, rgt = frappe.get_cached_value("Cost Center", cost_center, ["lft", "rgt"])
|
lft, rgt = frappe.get_cached_value("Cost Center", cost_center, ["lft", "rgt"])
|
||||||
|
@ -345,7 +345,7 @@ class TestCustomer(FrappeTestCase):
|
|||||||
def test_serach_fields_for_customer(self):
|
def test_serach_fields_for_customer(self):
|
||||||
from erpnext.controllers.queries import customer_query
|
from erpnext.controllers.queries import customer_query
|
||||||
|
|
||||||
frappe.db.set_value("Selling Settings", None, "cust_master_name", "Naming Series")
|
frappe.db.set_single_value("Selling Settings", "cust_master_name", "Naming Series")
|
||||||
|
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
"Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype"
|
"Customer", None, "search_fields", "customer_group", "Data", for_doctype="Doctype"
|
||||||
@ -371,7 +371,7 @@ class TestCustomer(FrappeTestCase):
|
|||||||
self.assertEqual(data[0].territory, "_Test Territory")
|
self.assertEqual(data[0].territory, "_Test Territory")
|
||||||
self.assertTrue("territory" in data[0])
|
self.assertTrue("territory" in data[0])
|
||||||
|
|
||||||
frappe.db.set_value("Selling Settings", None, "cust_master_name", "Customer Name")
|
frappe.db.set_single_value("Selling Settings", "cust_master_name", "Customer Name")
|
||||||
|
|
||||||
|
|
||||||
def get_customer_dict(customer_name):
|
def get_customer_dict(customer_name):
|
||||||
|
@ -7,6 +7,17 @@ frappe.ui.form.on('Installation Note', {
|
|||||||
frm.set_query('customer_address', erpnext.queries.address_query);
|
frm.set_query('customer_address', erpnext.queries.address_query);
|
||||||
frm.set_query('contact_person', erpnext.queries.contact_query);
|
frm.set_query('contact_person', erpnext.queries.contact_query);
|
||||||
frm.set_query('customer', erpnext.queries.customer);
|
frm.set_query('customer', erpnext.queries.customer);
|
||||||
|
frm.set_query("serial_and_batch_bundle", "items", (doc, cdt, cdn) => {
|
||||||
|
let row = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
'item_code': row.item_code,
|
||||||
|
'voucher_type': doc.doctype,
|
||||||
|
'voucher_no': ["in", [doc.name, ""]],
|
||||||
|
'is_cancelled': 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
onload: function(frm) {
|
onload: function(frm) {
|
||||||
if(!frm.doc.status) {
|
if(!frm.doc.status) {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user