diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/verified/ae_uae_chart_template_standard.json b/erpnext/accounts/doctype/account/chart_of_accounts/verified/ae_uae_chart_template_standard.json index a8afb55df6..3a3b6e399e 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/verified/ae_uae_chart_template_standard.json +++ b/erpnext/accounts/doctype/account/chart_of_accounts/verified/ae_uae_chart_template_standard.json @@ -437,12 +437,20 @@ }, "Sales": { "Sales from Other Regions": { - "Sales from Other Region": {} + "Sales from Other Region": { + "account_type": "Income Account" + } }, "Sales of same region": { - "Management Consultancy Fees 1": {}, - "Sales Account": {}, - "Sales of I/C": {} + "Management Consultancy Fees 1": { + "account_type": "Income Account" + }, + "Sales Account": { + "account_type": "Income Account" + }, + "Sales of I/C": { + "account_type": "Income Account" + } } }, "root_type": "Income" diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/verified/id_chart_of_accounts.json b/erpnext/accounts/doctype/account/chart_of_accounts/verified/id_chart_of_accounts.json index d1a0defba9..fb974765db 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/verified/id_chart_of_accounts.json +++ b/erpnext/accounts/doctype/account/chart_of_accounts/verified/id_chart_of_accounts.json @@ -69,8 +69,7 @@ "Persediaan Barang": { "Persediaan Barang": { "account_number": "1141.000", - "account_type": "Stock", - "is_group": 1 + "account_type": "Stock" }, "Uang Muka Pembelian": { "Uang Muka Pembelian": { @@ -670,7 +669,8 @@ }, "Penjualan Barang Dagangan": { "Penjualan": { - "account_number": "4110.000" + "account_number": "4110.000", + "account_type": "Income Account" }, "Potongan Penjualan": { "account_number": "4130.000" diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 954b4e7957..de2f9e7e0d 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -271,9 +271,9 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N net_total, limit_consumed, ldc.certificate_limit, ldc.rate, tax_details ) else: - tax_amount = net_total * tax_details.rate / 100 if net_total > 0 else 0 + tax_amount = net_total * tax_details.rate / 100 else: - tax_amount = net_total * tax_details.rate / 100 if net_total > 0 else 0 + tax_amount = net_total * tax_details.rate / 100 # once tds is deducted, not need to add vouchers in the invoice voucher_wise_amount = {} diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 3803836ef7..d4967785ba 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -539,6 +539,10 @@ def get_round_off_account_and_cost_center( "Company", company, ["round_off_account", "round_off_cost_center"] ) or [None, None] + # Use expense account as fallback + if not round_off_account: + round_off_account = frappe.get_cached_value("Company", company, "default_expense_account") + meta = frappe.get_meta(voucher_type) # Give first preference to parent cost center for round off GLE diff --git a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py index 6f1889b34e..0c7d931d2d 100644 --- a/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/test_accounts_receivable.py @@ -8,20 +8,17 @@ from erpnext import get_default_cost_center from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.report.accounts_receivable.accounts_receivable import execute +from erpnext.accounts.test.accounts_mixin import AccountsTestMixin from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order -class TestAccountsReceivable(FrappeTestCase): +class TestAccountsReceivable(AccountsTestMixin, FrappeTestCase): def setUp(self): - frappe.db.sql("delete from `tabSales Invoice` where company='_Test Company 2'") - frappe.db.sql("delete from `tabSales Order` where company='_Test Company 2'") - frappe.db.sql("delete from `tabPayment Entry` where company='_Test Company 2'") - frappe.db.sql("delete from `tabGL Entry` where company='_Test Company 2'") - frappe.db.sql("delete from `tabPayment Ledger Entry` where company='_Test Company 2'") - frappe.db.sql("delete from `tabJournal Entry` where company='_Test Company 2'") - frappe.db.sql("delete from `tabExchange Rate Revaluation` where company='_Test Company 2'") - - self.create_usd_account() + self.create_company() + self.create_customer() + self.create_item() + self.create_usd_receivable_account() + self.clear_old_entries() def tearDown(self): frappe.db.rollback() @@ -49,29 +46,84 @@ class TestAccountsReceivable(FrappeTestCase): debtors_usd.account_type = debtors.account_type self.debtors_usd = debtors_usd.save().name + def create_sales_invoice(self, no_payment_schedule=False, do_not_submit=False): + frappe.set_user("Administrator") + si = create_sales_invoice( + item=self.item, + company=self.company, + customer=self.customer, + debit_to=self.debit_to, + posting_date=today(), + parent_cost_center=self.cost_center, + cost_center=self.cost_center, + rate=100, + price_list_rate=100, + do_not_save=1, + ) + if not no_payment_schedule: + si.append( + "payment_schedule", + dict(due_date=getdate(add_days(today(), 30)), invoice_portion=30.00, payment_amount=30), + ) + si.append( + "payment_schedule", + dict(due_date=getdate(add_days(today(), 60)), invoice_portion=50.00, payment_amount=50), + ) + si.append( + "payment_schedule", + dict(due_date=getdate(add_days(today(), 90)), invoice_portion=20.00, payment_amount=20), + ) + si = si.save() + if not do_not_submit: + si = si.submit() + return si + + def create_payment_entry(self, docname): + pe = get_payment_entry("Sales Invoice", docname, bank_account=self.cash, party_amount=40) + pe.paid_from = self.debit_to + pe.insert() + pe.submit() + + def create_credit_note(self, docname): + credit_note = create_sales_invoice( + company=self.company, + customer=self.customer, + item=self.item, + qty=-1, + debit_to=self.debit_to, + cost_center=self.cost_center, + is_return=1, + return_against=docname, + ) + + return credit_note + def test_accounts_receivable(self): filters = { - "company": "_Test Company 2", + "company": self.company, "based_on_payment_terms": 1, "report_date": today(), "range1": 30, "range2": 60, "range3": 90, "range4": 120, + "show_remarks": True, } # check invoice grand total and invoiced column's value for 3 payment terms - name = make_sales_invoice().name + si = self.create_sales_invoice() + name = si.name + report = execute(filters) - expected_data = [[100, 30], [100, 50], [100, 20]] + expected_data = [[100, 30, "No Remarks"], [100, 50, "No Remarks"], [100, 20, "No Remarks"]] for i in range(3): row = report[1][i - 1] - self.assertEqual(expected_data[i - 1], [row.invoice_grand_total, row.invoiced]) + self.assertEqual(expected_data[i - 1], [row.invoice_grand_total, row.invoiced, row.remarks]) # check invoice grand total, invoiced, paid and outstanding column's value after payment - make_payment(name) + self.create_payment_entry(si.name) report = execute(filters) expected_data_after_payment = [[100, 50, 10, 40], [100, 20, 0, 20]] @@ -84,10 +136,10 @@ class TestAccountsReceivable(FrappeTestCase): ) # check invoice grand total, invoiced, paid and outstanding column's value after credit note - make_credit_note(name) + self.create_credit_note(si.name) report = execute(filters) - expected_data_after_credit_note = [100, 0, 0, 40, -40, "Debtors - _TC2"] + expected_data_after_credit_note = [100, 0, 0, 40, -40, self.debit_to] row = report[1][0] self.assertEqual( @@ -108,21 +160,20 @@ class TestAccountsReceivable(FrappeTestCase): """ so = make_sales_order( - company="_Test Company 2", - customer="_Test Customer 2", - warehouse="Finished Goods - _TC2", - currency="EUR", - debit_to="Debtors - _TC2", - income_account="Sales - _TC2", - expense_account="Cost of Goods Sold - _TC2", - cost_center="Main - _TC2", + company=self.company, + customer=self.customer, + warehouse=self.warehouse, + debit_to=self.debit_to, + income_account=self.income_account, + expense_account=self.expense_account, + cost_center=self.cost_center, ) pe = get_payment_entry(so.doctype, so.name) pe = pe.save().submit() filters = { - "company": "_Test Company 2", + "company": self.company, "based_on_payment_terms": 0, "report_date": today(), "range1": 30, @@ -147,34 +198,32 @@ class TestAccountsReceivable(FrappeTestCase): ) @change_settings( - "Accounts Settings", {"allow_multi_currency_invoices_against_single_party_account": 1} + "Accounts Settings", + {"allow_multi_currency_invoices_against_single_party_account": 1, "allow_stale": 0}, ) def test_exchange_revaluation_for_party(self): """ - Exchange Revaluation for party on Receivable/Payable shoule be included + Exchange Revaluation for party on Receivable/Payable should be included """ - company = "_Test Company 2" - customer = "_Test Customer 2" - # Using Exchange Gain/Loss account for unrealized as well. - company_doc = frappe.get_doc("Company", company) + company_doc = frappe.get_doc("Company", self.company) company_doc.unrealized_exchange_gain_loss_account = company_doc.exchange_gain_loss_account company_doc.save() - si = make_sales_invoice(no_payment_schedule=True, do_not_submit=True) + si = self.create_sales_invoice(no_payment_schedule=True, do_not_submit=True) si.currency = "USD" - si.conversion_rate = 0.90 + si.conversion_rate = 80 si.debit_to = self.debtors_usd si = si.save().submit() # Exchange Revaluation err = frappe.new_doc("Exchange Rate Revaluation") - err.company = company + err.company = self.company err.posting_date = today() accounts = err.get_accounts_data() err.extend("accounts", accounts) - err.accounts[0].new_exchange_rate = 0.95 + err.accounts[0].new_exchange_rate = 85 row = err.accounts[0] row.new_balance_in_base_currency = flt( row.new_exchange_rate * flt(row.balance_in_account_currency) @@ -189,7 +238,7 @@ class TestAccountsReceivable(FrappeTestCase): je = je.submit() filters = { - "company": company, + "company": self.company, "report_date": today(), "range1": 30, "range2": 60, @@ -198,7 +247,7 @@ class TestAccountsReceivable(FrappeTestCase): } report = execute(filters) - expected_data_for_err = [0, -5, 0, 5] + expected_data_for_err = [0, -500, 0, 500] row = [x for x in report[1] if x.voucher_type == je.doctype and x.voucher_no == je.name][0] self.assertEqual( expected_data_for_err, @@ -214,46 +263,43 @@ class TestAccountsReceivable(FrappeTestCase): """ Payment against credit/debit note should be considered against the parent invoice """ - company = "_Test Company 2" - customer = "_Test Customer 2" - si1 = make_sales_invoice() + si1 = self.create_sales_invoice() - pe = get_payment_entry("Sales Invoice", si1.name, bank_account="Cash - _TC2") - pe.paid_from = "Debtors - _TC2" + pe = get_payment_entry(si1.doctype, si1.name, bank_account=self.cash) + pe.paid_from = self.debit_to pe.insert() pe.submit() - cr_note = make_credit_note(si1.name) + cr_note = self.create_credit_note(si1.name) - si2 = make_sales_invoice() + si2 = self.create_sales_invoice() # manually link cr_note with si2 using journal entry je = frappe.new_doc("Journal Entry") - je.company = company + je.company = self.company je.voucher_type = "Credit Note" je.posting_date = today() - debit_account = "Debtors - _TC2" debit_entry = { - "account": debit_account, + "account": self.debit_to, "party_type": "Customer", - "party": customer, + "party": self.customer, "debit": 100, "debit_in_account_currency": 100, "reference_type": cr_note.doctype, "reference_name": cr_note.name, - "cost_center": "Main - _TC2", + "cost_center": self.cost_center, } credit_entry = { - "account": debit_account, + "account": self.debit_to, "party_type": "Customer", - "party": customer, + "party": self.customer, "credit": 100, "credit_in_account_currency": 100, "reference_type": si2.doctype, "reference_name": si2.name, - "cost_center": "Main - _TC2", + "cost_center": self.cost_center, } je.append("accounts", debit_entry) @@ -261,7 +307,7 @@ class TestAccountsReceivable(FrappeTestCase): je = je.save().submit() filters = { - "company": company, + "company": self.company, "report_date": today(), "range1": 30, "range2": 60, @@ -271,64 +317,254 @@ class TestAccountsReceivable(FrappeTestCase): report = execute(filters) self.assertEqual(report[1], []) + def test_group_by_party(self): + si1 = self.create_sales_invoice(do_not_submit=True) + si1.posting_date = add_days(today(), -1) + si1.save().submit() + si2 = self.create_sales_invoice(do_not_submit=True) + si2.items[0].rate = 85 + si2.save().submit() -def make_sales_invoice(no_payment_schedule=False, do_not_submit=False): - frappe.set_user("Administrator") + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "group_by_party": True, + } + report = execute(filters)[1] + self.assertEqual(len(report), 5) - si = create_sales_invoice( - company="_Test Company 2", - customer="_Test Customer 2", - currency="EUR", - warehouse="Finished Goods - _TC2", - debit_to="Debtors - _TC2", - income_account="Sales - _TC2", - expense_account="Cost of Goods Sold - _TC2", - cost_center="Main - _TC2", - do_not_save=1, - ) + # assert voucher rows + expected_voucher_rows = [ + [100.0, 100.0, 100.0, 100.0], + [85.0, 85.0, 85.0, 85.0], + ] + voucher_rows = [] + for x in report[0:2]: + voucher_rows.append( + [x.invoiced, x.outstanding, x.invoiced_in_account_currency, x.outstanding_in_account_currency] + ) + self.assertEqual(expected_voucher_rows, voucher_rows) - if not no_payment_schedule: - si.append( - "payment_schedule", - dict(due_date=getdate(add_days(today(), 30)), invoice_portion=30.00, payment_amount=30), + # assert total rows + expected_total_rows = [ + [self.customer, 185.0, 185.0], # party total + {}, # empty row for padding + ["Total", 185.0, 185.0], # grand total + ] + party_total_row = report[2] + self.assertEqual( + expected_total_rows[0], + [ + party_total_row.get("party"), + party_total_row.get("invoiced"), + party_total_row.get("outstanding"), + ], ) - si.append( - "payment_schedule", - dict(due_date=getdate(add_days(today(), 60)), invoice_portion=50.00, payment_amount=50), - ) - si.append( - "payment_schedule", - dict(due_date=getdate(add_days(today(), 90)), invoice_portion=20.00, payment_amount=20), + empty_row = report[3] + self.assertEqual(expected_total_rows[1], empty_row) + grand_total_row = report[4] + self.assertEqual( + expected_total_rows[2], + [ + grand_total_row.get("party"), + grand_total_row.get("invoiced"), + grand_total_row.get("outstanding"), + ], ) - si = si.save() + def test_future_payments(self): + si = self.create_sales_invoice() + pe = get_payment_entry(si.doctype, si.name) + pe.posting_date = add_days(today(), 1) + pe.paid_amount = 90.0 + pe.references[0].allocated_amount = 90.0 + pe.save().submit() + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "show_future_payments": True, + } + report = execute(filters)[1] + self.assertEqual(len(report), 1) - if not do_not_submit: - si = si.submit() + expected_data = [100.0, 100.0, 10.0, 90.0] - return si + row = report[0] + self.assertEqual( + expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount] + ) + pe.cancel() + # full payment in future date + pe = get_payment_entry(si.doctype, si.name) + pe.posting_date = add_days(today(), 1) + pe.save().submit() + report = execute(filters)[1] + self.assertEqual(len(report), 1) + expected_data = [100.0, 100.0, 0.0, 100.0] + row = report[0] + self.assertEqual( + expected_data, [row.invoiced, row.outstanding, row.remaining_balance, row.future_amount] + ) -def make_payment(docname): - pe = get_payment_entry("Sales Invoice", docname, bank_account="Cash - _TC2", party_amount=40) - pe.paid_from = "Debtors - _TC2" - pe.insert() - pe.submit() + pe.cancel() + # over payment in future date + pe = get_payment_entry(si.doctype, si.name) + pe.posting_date = add_days(today(), 1) + pe.paid_amount = 110 + pe.save().submit() + report = execute(filters)[1] + self.assertEqual(len(report), 2) + expected_data = [[100.0, 0.0, 100.0, 0.0, 100.0], [0.0, 10.0, -10.0, -10.0, 0.0]] + for idx, row in enumerate(report): + self.assertEqual( + expected_data[idx], + [row.invoiced, row.paid, row.outstanding, row.remaining_balance, row.future_amount], + ) + def test_sales_person(self): + sales_person = ( + frappe.get_doc({"doctype": "Sales Person", "sales_person_name": "John Clark", "enabled": True}) + .insert() + .submit() + ) + si = self.create_sales_invoice(do_not_submit=True) + si.append("sales_team", {"sales_person": sales_person.name, "allocated_percentage": 100}) + si.save().submit() -def make_credit_note(docname): - credit_note = create_sales_invoice( - company="_Test Company 2", - customer="_Test Customer 2", - currency="EUR", - qty=-1, - warehouse="Finished Goods - _TC2", - debit_to="Debtors - _TC2", - income_account="Sales - _TC2", - expense_account="Cost of Goods Sold - _TC2", - cost_center="Main - _TC2", - is_return=1, - return_against=docname, - ) + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "sales_person": sales_person.name, + "show_sales_person": True, + } + report = execute(filters)[1] + self.assertEqual(len(report), 1) - return credit_note + expected_data = [100.0, 100.0, sales_person.name] + + row = report[0] + self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.sales_person]) + + def test_cost_center_filter(self): + si = self.create_sales_invoice() + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "cost_center": self.cost_center, + } + report = execute(filters)[1] + self.assertEqual(len(report), 1) + expected_data = [100.0, 100.0, self.cost_center] + row = report[0] + self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.cost_center]) + + def test_customer_group_filter(self): + si = self.create_sales_invoice() + cus_group = frappe.db.get_value("Customer", self.customer, "customer_group") + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "customer_group": cus_group, + } + report = execute(filters)[1] + self.assertEqual(len(report), 1) + expected_data = [100.0, 100.0, cus_group] + row = report[0] + self.assertEqual(expected_data, [row.invoiced, row.outstanding, row.customer_group]) + + filters.update({"customer_group": "Individual"}) + report = execute(filters)[1] + self.assertEqual(len(report), 0) + + def test_party_account_filter(self): + si1 = self.create_sales_invoice() + self.customer2 = ( + frappe.get_doc( + { + "doctype": "Customer", + "customer_name": "Jane Doe", + "type": "Individual", + "default_currency": "USD", + } + ) + .insert() + .submit() + ) + + si2 = self.create_sales_invoice(do_not_submit=True) + si2.posting_date = add_days(today(), -1) + si2.customer = self.customer2 + si2.currency = "USD" + si2.conversion_rate = 80 + si2.debit_to = self.debtors_usd + si2.save().submit() + + # Filter on company currency receivable account + filters = { + "company": self.company, + "report_date": today(), + "range1": 30, + "range2": 60, + "range3": 90, + "range4": 120, + "party_account": self.debit_to, + } + report = execute(filters)[1] + self.assertEqual(len(report), 1) + expected_data = [100.0, 100.0, self.debit_to, si1.currency] + row = report[0] + self.assertEqual( + expected_data, [row.invoiced, row.outstanding, row.party_account, row.account_currency] + ) + + # Filter on USD receivable account + filters.update({"party_account": self.debtors_usd}) + report = execute(filters)[1] + self.assertEqual(len(report), 1) + expected_data = [8000.0, 8000.0, self.debtors_usd, si2.currency] + row = report[0] + self.assertEqual( + expected_data, [row.invoiced, row.outstanding, row.party_account, row.account_currency] + ) + + # without filter on party account + filters.pop("party_account") + report = execute(filters)[1] + self.assertEqual(len(report), 2) + expected_data = [ + [8000.0, 8000.0, 100.0, 100.0, self.debtors_usd, si2.currency], + [100.0, 100.0, 100.0, 100.0, self.debit_to, si1.currency], + ] + for idx, row in enumerate(report): + self.assertEqual( + expected_data[idx], + [ + row.invoiced, + row.outstanding, + row.invoiced_in_account_currency, + row.outstanding_in_account_currency, + row.party_account, + row.account_currency, + ], + ) diff --git a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py index d67eee3552..bdc8d8504f 100644 --- a/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py +++ b/erpnext/accounts/report/asset_depreciations_and_balances/asset_depreciations_and_balances.py @@ -58,6 +58,9 @@ def get_data(filters): def get_asset_categories(filters): + condition = "" + if filters.get("asset_category"): + condition += " and asset_category = %(asset_category)s" return frappe.db.sql( """ SELECT asset_category, @@ -98,15 +101,25 @@ def get_asset_categories(filters): 0 end), 0) as cost_of_scrapped_asset from `tabAsset` - where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s + where docstatus=1 and company=%(company)s and purchase_date <= %(to_date)s {} group by asset_category - """, - {"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company}, + """.format( + condition + ), + { + "to_date": filters.to_date, + "from_date": filters.from_date, + "company": filters.company, + "asset_category": filters.get("asset_category"), + }, as_dict=1, ) def get_assets(filters): + condition = "" + if filters.get("asset_category"): + condition = " and a.asset_category = '{}'".format(filters.get("asset_category")) return frappe.db.sql( """ SELECT results.asset_category, @@ -138,7 +151,7 @@ def get_assets(filters): aca.parent = a.asset_category and aca.company_name = %(company)s join `tabCompany` company on company.name = %(company)s - where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) + where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s and gle.debit != 0 and gle.is_cancelled = 0 and gle.account = ifnull(aca.depreciation_expense_account, company.depreciation_expense_account) {0} group by a.asset_category union SELECT a.asset_category, @@ -154,10 +167,12 @@ def get_assets(filters): end), 0) as depreciation_eliminated_during_the_period, 0 as depreciation_amount_during_the_period from `tabAsset` a - where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s + where a.docstatus=1 and a.company=%(company)s and a.purchase_date <= %(to_date)s {0} group by a.asset_category) as results group by results.asset_category - """, + """.format( + condition + ), {"to_date": filters.to_date, "from_date": filters.from_date, "company": filters.company}, as_dict=1, ) diff --git a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py index 7d16661472..7191720c57 100644 --- a/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py +++ b/erpnext/accounts/report/tax_withholding_details/tax_withholding_details.py @@ -257,7 +257,7 @@ def get_tds_docs(filters): } party = frappe.get_all(filters.get("party_type"), pluck="name") - query_filters.update({"against": ("in", party)}) + or_filters.update({"against": ("in", party), "voucher_type": "Journal Entry"}) if filters.get("party"): del query_filters["account"] @@ -294,7 +294,7 @@ def get_tds_docs(filters): if journal_entries: journal_entry_party_map = get_journal_entry_party_map(journal_entries) - get_doc_info(journal_entries, "Journal Entry", tax_category_map) + get_doc_info(journal_entries, "Journal Entry", tax_category_map, net_total_map) return ( tds_documents, @@ -309,7 +309,11 @@ def get_journal_entry_party_map(journal_entries): journal_entry_party_map = {} for d in frappe.db.get_all( "Journal Entry Account", - {"parent": ("in", journal_entries), "party_type": "Supplier", "party": ("is", "set")}, + { + "parent": ("in", journal_entries), + "party_type": ("in", ("Supplier", "Customer")), + "party": ("is", "set"), + }, ["parent", "party"], ): if d.parent not in journal_entry_party_map: @@ -320,41 +324,29 @@ def get_journal_entry_party_map(journal_entries): def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None): - if doctype == "Purchase Invoice": - fields = [ - "name", - "tax_withholding_category", - "base_tax_withholding_net_total", - "grand_total", - "base_total", - ] - elif doctype == "Sales Invoice": - fields = ["name", "base_net_total", "grand_total", "base_total"] - elif doctype == "Payment Entry": - fields = [ - "name", - "tax_withholding_category", - "paid_amount", - "paid_amount_after_tax", - "base_paid_amount", - ] - else: - fields = ["name", "tax_withholding_category"] + common_fields = ["name", "tax_withholding_category"] + fields_dict = { + "Purchase Invoice": ["base_tax_withholding_net_total", "grand_total", "base_total"], + "Sales Invoice": ["base_net_total", "grand_total", "base_total"], + "Payment Entry": ["paid_amount", "paid_amount_after_tax", "base_paid_amount"], + "Journal Entry": ["total_amount"], + } - entries = frappe.get_all(doctype, filters={"name": ("in", vouchers)}, fields=fields) + entries = frappe.get_all( + doctype, filters={"name": ("in", vouchers)}, fields=common_fields + fields_dict[doctype] + ) for entry in entries: tax_category_map.update({entry.name: entry.tax_withholding_category}) if doctype == "Purchase Invoice": - net_total_map.update( - {entry.name: [entry.base_tax_withholding_net_total, entry.grand_total, entry.base_total]} - ) + value = [entry.base_tax_withholding_net_total, entry.grand_total, entry.base_total] elif doctype == "Sales Invoice": - net_total_map.update({entry.name: [entry.base_net_total, entry.grand_total, entry.base_total]}) + value = [entry.base_net_total, entry.grand_total, entry.base_total] elif doctype == "Payment Entry": - net_total_map.update( - {entry.name: [entry.paid_amount, entry.paid_amount_after_tax, entry.base_paid_amount]} - ) + value = [entry.paid_amount, entry.paid_amount_after_tax, entry.base_paid_amount] + else: + value = [entry.total_amount] * 3 + net_total_map.update({entry.name: value}) def get_tax_rate_map(filters): diff --git a/erpnext/accounts/test/accounts_mixin.py b/erpnext/accounts/test/accounts_mixin.py index debfffdcbb..bf01362c97 100644 --- a/erpnext/accounts/test/accounts_mixin.py +++ b/erpnext/accounts/test/accounts_mixin.py @@ -60,7 +60,6 @@ class AccountsTestMixin: self.income_account = "Sales - " + abbr self.expense_account = "Cost of Goods Sold - " + abbr self.debit_to = "Debtors - " + abbr - self.debit_usd = "Debtors USD - " + abbr self.cash = "Cash - " + abbr self.creditors = "Creditors - " + abbr self.retained_earnings = "Retained Earnings - " + abbr @@ -105,6 +104,28 @@ class AccountsTestMixin: new_acc.save() setattr(self, acc.attribute_name, new_acc.name) + def create_usd_receivable_account(self): + account_name = "Debtors USD" + if not frappe.db.get_value( + "Account", filters={"account_name": account_name, "company": self.company} + ): + acc = frappe.new_doc("Account") + acc.account_name = account_name + acc.parent_account = "Accounts Receivable - " + self.company_abbr + acc.company = self.company + acc.account_currency = "USD" + acc.account_type = "Receivable" + acc.insert() + else: + name = frappe.db.get_value( + "Account", + filters={"account_name": account_name, "company": self.company}, + fieldname="name", + pluck=True, + ) + acc = frappe.get_doc("Account", name) + self.debtors_usd = acc.name + def clear_old_entries(self): doctype_list = [ "GL Entry", @@ -113,6 +134,8 @@ class AccountsTestMixin: "Purchase Invoice", "Payment Entry", "Journal Entry", + "Sales Order", + "Exchange Rate Revaluation", ] for doctype in doctype_list: qb.from_(qb.DocType(doctype)).delete().where(qb.DocType(doctype).company == self.company).run() diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 9d6d0f91fb..1aefeaacf7 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -908,9 +908,9 @@ def get_outstanding_invoices( min_outstanding=None, max_outstanding=None, accounting_dimensions=None, - vouchers=None, # list of dicts [{'voucher_type': '', 'voucher_no': ''}] for filtering - limit=None, # passed by reconciliation tool - voucher_no=None, # filter passed by reconciliation tool + vouchers=None, # list of dicts [{'voucher_type': '', 'voucher_no': ''}] for filtering + limit=None, # passed by reconciliation tool + voucher_no=None, # filter passed by reconciliation tool ): ple = qb.DocType("Payment Ledger Entry") diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 173e812dbd..165e17b2d7 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -345,6 +345,8 @@ def make_return_doc( elif doctype == "Purchase Invoice": # look for Print Heading "Debit Note" doc.select_print_heading = frappe.get_cached_value("Print Heading", _("Debit Note")) + if source.tax_withholding_category: + doc.set_onload("supplier_tds", source.tax_withholding_category) for tax in doc.get("taxes") or []: if tax.charge_type == "Actual": diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index d669abe910..ae54b801f1 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -599,6 +599,7 @@ class StockController(AccountsController): inspection_fieldname_map = { "Purchase Receipt": "inspection_required_before_purchase", "Purchase Invoice": "inspection_required_before_purchase", + "Subcontracting Receipt": "inspection_required_before_purchase", "Sales Invoice": "inspection_required_before_delivery", "Delivery Note": "inspection_required_before_delivery", } diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 7eaa146db6..41db6b3a72 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -198,7 +198,7 @@ website_route_rules = [ ] standard_portal_menu_items = [ - {"title": "Projects", "route": "/project", "reference_doctype": "Project"}, + {"title": "Projects", "route": "/project", "reference_doctype": "Project", "role": "Customer"}, { "title": "Request for Quotations", "route": "/rfq", @@ -290,6 +290,7 @@ has_website_permission = { "Delivery Note": "erpnext.controllers.website_list_for_contact.has_website_permission", "Issue": "erpnext.support.doctype.issue.issue.has_website_permission", "Timesheet": "erpnext.controllers.website_list_for_contact.has_website_permission", + "Project": "erpnext.controllers.website_list_for_contact.has_website_permission", } before_tests = "erpnext.setup.utils.before_tests" diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json index d02402299e..e8d3542835 100644 --- a/erpnext/manufacturing/doctype/bom/bom.json +++ b/erpnext/manufacturing/doctype/bom/bom.json @@ -78,6 +78,10 @@ "show_items", "show_operations", "web_long_description", + "reference_section", + "bom_creator", + "bom_creator_item", + "column_break_oxbz", "amended_from", "connections_tab" ], @@ -233,7 +237,7 @@ "fieldname": "rm_cost_as_per", "fieldtype": "Select", "label": "Rate Of Materials Based On", - "options": "Valuation Rate\nLast Purchase Rate\nPrice List" + "options": "Valuation Rate\nLast Purchase Rate\nPrice List\nManual" }, { "allow_on_submit": 1, @@ -599,6 +603,32 @@ "fieldname": "operating_cost_per_bom_quantity", "fieldtype": "Currency", "label": "Operating Cost Per BOM Quantity" + }, + { + "fieldname": "reference_section", + "fieldtype": "Section Break", + "label": "Reference" + }, + { + "fieldname": "bom_creator", + "fieldtype": "Link", + "label": "BOM Creator", + "no_copy": 1, + "options": "BOM Creator", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "bom_creator_item", + "fieldtype": "Data", + "label": "BOM Creator Item", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_oxbz", + "fieldtype": "Column Break" } ], "icon": "fa fa-sitemap", @@ -606,7 +636,7 @@ "image_field": "image", "is_submittable": 1, "links": [], - "modified": "2023-04-06 12:47:58.514795", + "modified": "2023-08-07 11:38:08.152294", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM", diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 8058a5f8b7..023166849d 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -206,6 +206,7 @@ class BOM(WebsiteGenerator): def on_submit(self): self.manage_default_bom() + self.update_bom_creator_status() def on_cancel(self): self.db_set("is_active", 0) @@ -214,6 +215,23 @@ class BOM(WebsiteGenerator): # check if used in any other bom self.validate_bom_links() self.manage_default_bom() + self.update_bom_creator_status() + + def update_bom_creator_status(self): + if not self.bom_creator: + return + + if self.bom_creator_item: + frappe.db.set_value( + "BOM Creator Item", + self.bom_creator_item, + "bom_created", + 1 if self.docstatus == 1 else 0, + update_modified=False, + ) + + doc = frappe.get_doc("BOM Creator", self.bom_creator) + doc.set_status(save=True) def on_update_after_submit(self): self.validate_bom_links() @@ -662,18 +680,19 @@ class BOM(WebsiteGenerator): for d in self.get("items"): old_rate = d.rate - d.rate = self.get_rm_rate( - { - "company": self.company, - "item_code": d.item_code, - "bom_no": d.bom_no, - "qty": d.qty, - "uom": d.uom, - "stock_uom": d.stock_uom, - "conversion_factor": d.conversion_factor, - "sourced_by_supplier": d.sourced_by_supplier, - } - ) + if self.rm_cost_as_per != "Manual": + d.rate = self.get_rm_rate( + { + "company": self.company, + "item_code": d.item_code, + "bom_no": d.bom_no, + "qty": d.qty, + "uom": d.uom, + "stock_uom": d.stock_uom, + "conversion_factor": d.conversion_factor, + "sourced_by_supplier": d.sourced_by_supplier, + } + ) d.base_rate = flt(d.rate) * flt(self.conversion_rate) d.amount = flt(d.rate, d.precision("rate")) * flt(d.qty, d.precision("qty")) @@ -964,7 +983,12 @@ def get_valuation_rate(data): .as_("valuation_rate") ) .where((bin_table.item_code == item_code) & (wh_table.company == company)) - ).run(as_dict=True)[0] + ) + + if data.get("set_rate_based_on_warehouse") and data.get("warehouse"): + item_valuation = item_valuation.where(bin_table.warehouse == data.get("warehouse")) + + item_valuation = item_valuation.run(as_dict=True)[0] valuation_rate = item_valuation.get("valuation_rate") diff --git a/erpnext/manufacturing/doctype/bom_creator/__init__.py b/erpnext/manufacturing/doctype/bom_creator/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator.js b/erpnext/manufacturing/doctype/bom_creator/bom_creator.js new file mode 100644 index 0000000000..01dc89b080 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator.js @@ -0,0 +1,201 @@ +// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +frappe.provide("erpnext.bom"); + +frappe.ui.form.on("BOM Creator", { + setup(frm) { + frm.trigger("set_queries"); + }, + + setup_bom_creator(frm) { + frm.dashboard.clear_comment(); + + if (!frm.is_new()) { + if ((!frappe.bom_configurator + || frappe.bom_configurator.bom_configurator !== frm.doc.name)) { + frm.trigger("build_tree"); + } + } else { + let $parent = $(frm.fields_dict["bom_creator"].wrapper); + $parent.empty(); + frm.trigger("make_new_entry"); + } + }, + + build_tree(frm) { + let $parent = $(frm.fields_dict["bom_creator"].wrapper); + $parent.empty(); + frm.toggle_enable("item_code", false); + + frappe.require('bom_configurator.bundle.js').then(() => { + frappe.bom_configurator = new frappe.ui.BOMConfigurator({ + wrapper: $parent, + page: $parent, + frm: frm, + bom_configurator: frm.doc.name, + }); + }); + }, + + make_new_entry(frm) { + let dialog = new frappe.ui.Dialog({ + title: __("Multi-level BOM Creator"), + fields: [ + { + label: __("Name"), + fieldtype: "Data", + fieldname: "name", + reqd: 1 + }, + { fieldtype: "Column Break" }, + { + label: __("Company"), + fieldtype: "Link", + fieldname: "company", + options: "Company", + reqd: 1, + default: frappe.defaults.get_user_default("Company"), + }, + { fieldtype: "Section Break" }, + { + label: __("Item Code (Final Product)"), + fieldtype: "Link", + fieldname: "item_code", + options: "Item", + reqd: 1 + }, + { fieldtype: "Column Break" }, + { + label: __("Quantity"), + fieldtype: "Float", + fieldname: "qty", + reqd: 1, + default: 1.0 + }, + { fieldtype: "Section Break" }, + { + label: __("Currency"), + fieldtype: "Link", + fieldname: "currency", + options: "Currency", + reqd: 1, + default: frappe.defaults.get_global_default("currency") + }, + { fieldtype: "Column Break" }, + { + label: __("Conversion Rate"), + fieldtype: "Float", + fieldname: "conversion_rate", + reqd: 1, + default: 1.0 + }, + ], + primary_action_label: __("Create"), + primary_action: (values) => { + values.doctype = frm.doc.doctype; + frappe.db + .insert(values) + .then((doc) => { + frappe.set_route("Form", doc.doctype, doc.name); + }); + } + }) + + dialog.show(); + }, + + set_queries(frm) { + frm.set_query("bom_no", "items", function(doc, cdt, cdn) { + let item = frappe.get_doc(cdt, cdn); + return { + filters: { + item: item.item_code, + } + } + }); + }, + + refresh(frm) { + frm.trigger("setup_bom_creator"); + frm.trigger("set_root_item"); + frm.trigger("add_custom_buttons"); + }, + + set_root_item(frm) { + if (frm.is_new() && frm.doc.items?.length) { + frappe.model.set_value(frm.doc.items[0].doctype, + frm.doc.items[0].name, "is_root", 1); + } + }, + + add_custom_buttons(frm) { + if (!frm.is_new()) { + frm.add_custom_button(__("Rebuild Tree"), () => { + frm.trigger("build_tree"); + }); + } + } +}); + +frappe.ui.form.on("BOM Creator Item", { + item_code(frm, cdt, cdn) { + let item = frappe.get_doc(cdt, cdn); + if (item.item_code && item.is_root) { + frappe.model.set_value(cdt, cdn, "fg_item", item.item_code); + } + }, + + do_not_explode(frm, cdt, cdn) { + let item = frappe.get_doc(cdt, cdn); + if (!item.do_not_explode) { + frm.call({ + method: "get_default_bom", + doc: frm.doc, + args: { + item_code: item.item_code + }, + callback(r) { + if (r.message) { + frappe.model.set_value(cdt, cdn, "bom_no", r.message); + } + } + }) + } else { + frappe.model.set_value(cdt, cdn, "bom_no", ""); + } + } +}); + + +erpnext.bom.BomConfigurator = class BomConfigurator extends erpnext.TransactionController { + conversion_rate(doc) { + if(this.frm.doc.currency === this.get_company_currency()) { + this.frm.set_value("conversion_rate", 1.0); + } else { + erpnext.bom.update_cost(doc); + } + } + + buying_price_list(doc) { + this.apply_price_list(); + } + + plc_conversion_rate(doc) { + if (!this.in_apply_price_list) { + this.apply_price_list(null, true); + } + } + + conversion_factor(doc, cdt, cdn) { + if (frappe.meta.get_docfield(cdt, "stock_qty", cdn)) { + var item = frappe.get_doc(cdt, cdn); + frappe.model.round_floats_in(item, ["qty", "conversion_factor"]); + item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item)); + refresh_field("stock_qty", item.name, item.parentfield); + this.toggle_conversion_factor(item); + this.frm.events.update_cost(this.frm); + } + } +}; + +extend_cscript(cur_frm.cscript, new erpnext.bom.BomConfigurator({frm: cur_frm})); \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator.json b/erpnext/manufacturing/doctype/bom_creator/bom_creator.json new file mode 100644 index 0000000000..fb4c6c5c95 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator.json @@ -0,0 +1,330 @@ +{ + "actions": [], + "allow_import": 1, + "autoname": "prompt", + "creation": "2023-07-18 14:56:34.477800", + "default_view": "List", + "doctype": "DocType", + "document_type": "Setup", + "engine": "InnoDB", + "field_order": [ + "tab_2_tab", + "bom_creator", + "details_tab", + "section_break_ylsl", + "item_code", + "item_name", + "item_group", + "column_break_ikj7", + "qty", + "project", + "uom", + "raw_materials_tab", + "currency_detail", + "rm_cost_as_per", + "set_rate_based_on_warehouse", + "buying_price_list", + "price_list_currency", + "plc_conversion_rate", + "column_break_ivyw", + "currency", + "conversion_rate", + "section_break_zcfg", + "default_warehouse", + "column_break_tzot", + "company", + "materials_section", + "items", + "costing_detail", + "raw_material_cost", + "remarks_tab", + "remarks", + "section_break_yixm", + "status", + "column_break_irab", + "error_log", + "connections_tab", + "amended_from" + ], + "fields": [ + { + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "remember_last_selected_value": 1, + "reqd": 1 + }, + { + "fieldname": "currency_detail", + "fieldtype": "Section Break", + "label": "Costing" + }, + { + "allow_on_submit": 1, + "default": "Valuation Rate", + "fieldname": "rm_cost_as_per", + "fieldtype": "Select", + "label": "Rate Of Materials Based On", + "options": "Valuation Rate\nLast Purchase Rate\nPrice List\nManual", + "reqd": 1 + }, + { + "allow_on_submit": 1, + "depends_on": "eval:doc.rm_cost_as_per===\"Price List\"", + "fieldname": "buying_price_list", + "fieldtype": "Link", + "label": "Price List", + "options": "Price List" + }, + { + "allow_on_submit": 1, + "depends_on": "eval:doc.rm_cost_as_per=='Price List'", + "fieldname": "price_list_currency", + "fieldtype": "Link", + "label": "Price List Currency", + "options": "Currency", + "print_hide": 1, + "read_only": 1 + }, + { + "allow_on_submit": 1, + "depends_on": "eval:doc.rm_cost_as_per=='Price List'", + "fieldname": "plc_conversion_rate", + "fieldtype": "Float", + "label": "Price List Exchange Rate" + }, + { + "fieldname": "column_break_ivyw", + "fieldtype": "Column Break" + }, + { + "fieldname": "currency", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Currency", + "options": "Currency", + "reqd": 1 + }, + { + "default": "1", + "fieldname": "conversion_rate", + "fieldtype": "Float", + "label": "Conversion Rate", + "precision": "9" + }, + { + "fieldname": "materials_section", + "fieldtype": "Section Break", + "oldfieldtype": "Section Break" + }, + { + "allow_bulk_edit": 1, + "fieldname": "items", + "fieldtype": "Table", + "label": "Items", + "oldfieldname": "bom_materials", + "oldfieldtype": "Table", + "options": "BOM Creator Item" + }, + { + "fieldname": "costing_detail", + "fieldtype": "Section Break", + "label": "Costing Details" + }, + { + "fieldname": "raw_material_cost", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Total Cost", + "no_copy": 1, + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "remarks", + "fieldtype": "Text Editor", + "label": "Remarks" + }, + { + "fieldname": "column_break_ikj7", + "fieldtype": "Column Break" + }, + { + "fieldname": "project", + "fieldtype": "Link", + "label": "Project", + "options": "Project" + }, + { + "fieldname": "item_code", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Finished Good", + "options": "Item", + "reqd": 1 + }, + { + "fieldname": "qty", + "fieldtype": "Float", + "label": "Quantity", + "reqd": 1 + }, + { + "fetch_from": "item_code.item_name", + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name" + }, + { + "fetch_from": "item_code.stock_uom", + "fieldname": "uom", + "fieldtype": "Link", + "label": "UOM", + "options": "UOM" + }, + { + "fieldname": "tab_2_tab", + "fieldtype": "Tab Break", + "label": "BOM Tree" + }, + { + "fieldname": "details_tab", + "fieldtype": "Tab Break", + "label": "Final Product" + }, + { + "fieldname": "raw_materials_tab", + "fieldtype": "Tab Break", + "label": "Sub Assemblies & Raw Materials" + }, + { + "fieldname": "remarks_tab", + "fieldtype": "Tab Break", + "label": "Remarks" + }, + { + "fieldname": "connections_tab", + "fieldtype": "Tab Break", + "label": "Connections", + "show_dashboard": 1 + }, + { + "fetch_from": "item_code.item_group", + "fieldname": "item_group", + "fieldtype": "Link", + "label": "Item Group", + "options": "Item Group" + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "BOM Creator", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "section_break_zcfg", + "fieldtype": "Section Break", + "label": "Warehouse" + }, + { + "fieldname": "column_break_tzot", + "fieldtype": "Column Break" + }, + { + "fieldname": "default_warehouse", + "fieldtype": "Link", + "label": "Default Source Warehouse", + "options": "Warehouse" + }, + { + "fieldname": "bom_creator", + "fieldtype": "HTML" + }, + { + "fieldname": "section_break_ylsl", + "fieldtype": "Section Break" + }, + { + "default": "0", + "depends_on": "eval:doc.rm_cost_as_per === \"Valuation Rate\"", + "fieldname": "set_rate_based_on_warehouse", + "fieldtype": "Check", + "label": "Set Valuation Rate Based on Source Warehouse" + }, + { + "fieldname": "section_break_yixm", + "fieldtype": "Section Break" + }, + { + "default": "Draft", + "fieldname": "status", + "fieldtype": "Select", + "label": "Status", + "no_copy": 1, + "options": "Draft\nSubmitted\nIn Progress\nCompleted\nFailed\nCancelled", + "read_only": 1 + }, + { + "fieldname": "column_break_irab", + "fieldtype": "Column Break" + }, + { + "fieldname": "error_log", + "fieldtype": "Text", + "label": "Error Log", + "read_only": 1 + } + ], + "icon": "fa fa-sitemap", + "is_submittable": 1, + "links": [ + { + "link_doctype": "BOM", + "link_fieldname": "bom_creator" + } + ], + "modified": "2023-08-07 15:45:06.176313", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "BOM Creator", + "naming_rule": "Set by user", + "owner": "Administrator", + "permissions": [ + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Manufacturing Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Manufacturing User", + "share": 1, + "submit": 1, + "write": 1 + } + ], + "show_name_in_global_search": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator.py b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py new file mode 100644 index 0000000000..999d610dfa --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator.py @@ -0,0 +1,424 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from collections import OrderedDict + +import frappe +from frappe import _ +from frappe.model.document import Document +from frappe.utils import flt + +from erpnext.manufacturing.doctype.bom.bom import get_bom_item_rate + +BOM_FIELDS = [ + "company", + "rm_cost_as_per", + "project", + "currency", + "conversion_rate", + "buying_price_list", +] + +BOM_ITEM_FIELDS = [ + "item_code", + "qty", + "uom", + "rate", + "stock_qty", + "stock_uom", + "conversion_factor", + "do_not_explode", +] + + +class BOMCreator(Document): + def before_save(self): + self.set_status() + self.set_is_expandable() + self.set_conversion_factor() + self.set_reference_id() + self.set_rate_for_items() + + def validate(self): + self.validate_items() + + def validate_items(self): + for row in self.items: + if row.is_expandable and row.item_code == self.item_code: + frappe.throw(_("Item {0} cannot be added as a sub-assembly of itself").format(row.item_code)) + + def set_status(self, save=False): + self.status = { + 0: "Draft", + 1: "Submitted", + 2: "Cancelled", + }[self.docstatus] + + self.set_status_completed() + if save: + self.db_set("status", self.status) + + def set_status_completed(self): + if self.docstatus != 1: + return + + has_completed = True + for row in self.items: + if row.is_expandable and not row.bom_created: + has_completed = False + break + + if not frappe.get_cached_value( + "BOM", {"bom_creator": self.name, "item": self.item_code}, "name" + ): + has_completed = False + + if has_completed: + self.status = "Completed" + + def on_cancel(self): + self.set_status(True) + + def set_conversion_factor(self): + for row in self.items: + row.conversion_factor = 1.0 + + def before_submit(self): + self.validate_fields() + self.set_status() + + def set_reference_id(self): + parent_reference = {row.idx: row.name for row in self.items} + + for row in self.items: + if row.fg_reference_id: + continue + + if row.parent_row_no: + row.fg_reference_id = parent_reference.get(row.parent_row_no) + + @frappe.whitelist() + def add_boms(self): + self.submit() + + def set_rate_for_items(self): + if self.rm_cost_as_per == "Manual": + return + + amount = self.get_raw_material_cost() + self.raw_material_cost = amount + + def get_raw_material_cost(self, fg_reference_id=None, amount=0): + if not fg_reference_id: + fg_reference_id = self.name + + for row in self.items: + if row.fg_reference_id != fg_reference_id: + continue + + if not row.is_expandable: + row.rate = get_bom_item_rate( + { + "company": self.company, + "item_code": row.item_code, + "bom_no": "", + "qty": row.qty, + "uom": row.uom, + "stock_uom": row.stock_uom, + "conversion_factor": row.conversion_factor, + "sourced_by_supplier": row.sourced_by_supplier, + }, + self, + ) + + row.amount = flt(row.rate) * flt(row.qty) + + else: + row.amount = 0.0 + row.amount = self.get_raw_material_cost(row.name, row.amount) + row.rate = flt(row.amount) / (flt(row.qty) * flt(row.conversion_factor)) + + amount += flt(row.amount) + + return amount + + def set_is_expandable(self): + fg_items = [row.fg_item for row in self.items if row.fg_item != self.item_code] + for row in self.items: + row.is_expandable = 0 + if row.item_code in fg_items: + row.is_expandable = 1 + + def validate_fields(self): + fields = { + "items": "Items", + } + + for field, label in fields.items(): + if not self.get(field): + frappe.throw(_("Please set {0} in BOM Creator {1}").format(label, self.name)) + + def on_submit(self): + self.enqueue_create_boms() + + def enqueue_create_boms(self): + frappe.enqueue( + self.create_boms, + queue="short", + timeout=600, + is_async=True, + ) + + frappe.msgprint( + _("BOMs creation has been enqueued, kindly check the status after some time"), alert=True + ) + + def create_boms(self): + """ + Sample data structure of production_item_wise_rm + production_item_wise_rm = { + (fg_item_code, name): { + "items": [], + "bom_no": "", + "fg_item_data": {} + } + } + """ + + self.db_set("status", "In Progress") + production_item_wise_rm = OrderedDict({}) + production_item_wise_rm.setdefault( + (self.item_code, self.name), frappe._dict({"items": [], "bom_no": "", "fg_item_data": self}) + ) + + for row in self.items: + if row.is_expandable: + if (row.item_code, row.name) not in production_item_wise_rm: + production_item_wise_rm.setdefault( + (row.item_code, row.name), frappe._dict({"items": [], "bom_no": "", "fg_item_data": row}) + ) + + production_item_wise_rm[(row.fg_item, row.fg_reference_id)]["items"].append(row) + + reverse_tree = OrderedDict(reversed(list(production_item_wise_rm.items()))) + + try: + for d in reverse_tree: + fg_item_data = production_item_wise_rm.get(d).fg_item_data + self.create_bom(fg_item_data, production_item_wise_rm) + + frappe.msgprint(_("BOMs created successfully")) + except Exception: + traceback = frappe.get_traceback() + self.db_set( + { + "status": "Failed", + "error_log": traceback, + } + ) + + frappe.msgprint(_("BOMs creation failed")) + + def create_bom(self, row, production_item_wise_rm): + bom = frappe.new_doc("BOM") + bom.update( + { + "item": row.item_code, + "bom_type": "Production", + "quantity": row.qty, + "allow_alternative_item": 1, + "bom_creator": self.name, + "bom_creator_item": row.name if row.name != self.name else "", + "rm_cost_as_per": "Manual", + } + ) + + for field in BOM_FIELDS: + if self.get(field): + bom.set(field, self.get(field)) + + for item in production_item_wise_rm[(row.item_code, row.name)]["items"]: + bom_no = "" + item.do_not_explode = 1 + if (item.item_code, item.name) in production_item_wise_rm: + bom_no = production_item_wise_rm.get((item.item_code, item.name)).bom_no + item.do_not_explode = 0 + + item_args = {} + for field in BOM_ITEM_FIELDS: + item_args[field] = item.get(field) + + item_args.update( + { + "bom_no": bom_no, + "allow_alternative_item": 1, + "allow_scrap_items": 1, + "include_item_in_manufacturing": 1, + } + ) + + bom.append("items", item_args) + + bom.save(ignore_permissions=True) + bom.submit() + + production_item_wise_rm[(row.item_code, row.name)].bom_no = bom.name + + @frappe.whitelist() + def get_default_bom(self, item_code) -> str: + return frappe.get_cached_value("Item", item_code, "default_bom") + + +@frappe.whitelist() +def get_children(doctype=None, parent=None, **kwargs): + if isinstance(kwargs, str): + kwargs = frappe.parse_json(kwargs) + + if isinstance(kwargs, dict): + kwargs = frappe._dict(kwargs) + + fields = [ + "item_code as value", + "is_expandable as expandable", + "parent as parent_id", + "qty", + "idx", + "'BOM Creator Item' as doctype", + "name", + "uom", + "rate", + "amount", + ] + + query_filters = { + "fg_item": parent, + "parent": kwargs.parent_id, + } + + if kwargs.name: + query_filters["name"] = kwargs.name + + return frappe.get_all("BOM Creator Item", fields=fields, filters=query_filters, order_by="idx") + + +@frappe.whitelist() +def add_item(**kwargs): + if isinstance(kwargs, str): + kwargs = frappe.parse_json(kwargs) + + if isinstance(kwargs, dict): + kwargs = frappe._dict(kwargs) + + doc = frappe.get_doc("BOM Creator", kwargs.parent) + item_info = get_item_details(kwargs.item_code) + kwargs.update( + { + "uom": item_info.stock_uom, + "stock_uom": item_info.stock_uom, + "conversion_factor": 1, + } + ) + + doc.append("items", kwargs) + doc.save() + + return doc + + +@frappe.whitelist() +def add_sub_assembly(**kwargs): + if isinstance(kwargs, str): + kwargs = frappe.parse_json(kwargs) + + if isinstance(kwargs, dict): + kwargs = frappe._dict(kwargs) + + doc = frappe.get_doc("BOM Creator", kwargs.parent) + bom_item = frappe.parse_json(kwargs.bom_item) + + name = kwargs.fg_reference_id + parent_row_no = "" + if not kwargs.convert_to_sub_assembly: + item_info = get_item_details(bom_item.item_code) + item_row = doc.append( + "items", + { + "item_code": bom_item.item_code, + "qty": bom_item.qty, + "uom": item_info.stock_uom, + "fg_item": kwargs.fg_item, + "conversion_factor": 1, + "fg_reference_id": name, + "stock_qty": bom_item.qty, + "fg_reference_id": name, + "do_not_explode": 1, + "is_expandable": 1, + "stock_uom": item_info.stock_uom, + }, + ) + + parent_row_no = item_row.idx + name = "" + + for row in bom_item.get("items"): + row = frappe._dict(row) + item_info = get_item_details(row.item_code) + doc.append( + "items", + { + "item_code": row.item_code, + "qty": row.qty, + "fg_item": bom_item.item_code, + "uom": item_info.stock_uom, + "fg_reference_id": name, + "parent_row_no": parent_row_no, + "conversion_factor": 1, + "do_not_explode": 1, + "stock_qty": row.qty, + "stock_uom": item_info.stock_uom, + }, + ) + + doc.save() + + return doc + + +def get_item_details(item_code): + return frappe.get_cached_value( + "Item", item_code, ["item_name", "description", "image", "stock_uom", "default_bom"], as_dict=1 + ) + + +@frappe.whitelist() +def delete_node(**kwargs): + if isinstance(kwargs, str): + kwargs = frappe.parse_json(kwargs) + + if isinstance(kwargs, dict): + kwargs = frappe._dict(kwargs) + + items = get_children(parent=kwargs.fg_item, parent_id=kwargs.parent) + if kwargs.docname: + frappe.delete_doc("BOM Creator Item", kwargs.docname) + + for item in items: + frappe.delete_doc("BOM Creator Item", item.name) + if item.expandable: + delete_node(fg_item=item.value, parent=item.parent_id) + + doc = frappe.get_doc("BOM Creator", kwargs.parent) + doc.set_rate_for_items() + doc.save() + + return doc + + +@frappe.whitelist() +def edit_qty(doctype, docname, qty, parent): + frappe.db.set_value(doctype, docname, "qty", qty) + doc = frappe.get_doc("BOM Creator", parent) + doc.set_rate_for_items() + doc.save() + + return doc diff --git a/erpnext/manufacturing/doctype/bom_creator/bom_creator_list.js b/erpnext/manufacturing/doctype/bom_creator/bom_creator_list.js new file mode 100644 index 0000000000..423b721e04 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator/bom_creator_list.js @@ -0,0 +1,18 @@ +frappe.listview_settings['BOM Creator'] = { + add_fields: ["status"], + get_indicator: function (doc) { + if (doc.status === "Draft") { + return [__("Draft"), "red", "status,=,Draft"]; + } else if (doc.status === "In Progress") { + return [__("In Progress"), "orange", "status,=,In Progress"]; + } else if (doc.status === "Completed") { + return [__("Completed"), "green", "status,=,Completed"]; + } else if (doc.status === "Cancelled") { + return [__("Cancelled"), "red", "status,=,Cancelled"]; + } else if (doc.status === "Failed") { + return [__("Failed"), "red", "status,=,Failed"]; + } else if (doc.status === "Submitted") { + return [__("Submitted"), "blue", "status,=,Submitted"]; + } + }, +}; diff --git a/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py b/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py new file mode 100644 index 0000000000..d239d58131 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator/test_bom_creator.py @@ -0,0 +1,240 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +import random + +import frappe +from frappe.tests.utils import FrappeTestCase + +from erpnext.manufacturing.doctype.bom_creator.bom_creator import ( + add_item, + add_sub_assembly, + delete_node, + edit_qty, +) +from erpnext.stock.doctype.item.test_item import make_item + + +class TestBOMCreator(FrappeTestCase): + def setUp(self) -> None: + create_items() + + def test_bom_sub_assembly(self): + final_product = "Bicycle" + make_item( + final_product, + { + "item_group": "Raw Material", + "stock_uom": "Nos", + }, + ) + + doc = make_bom_creator( + name="Bicycle BOM with Sub Assembly", + company="_Test Company", + item_code=final_product, + qty=1, + rm_cosy_as_per="Valuation Rate", + currency="INR", + plc_conversion_rate=1, + conversion_rate=1, + ) + + add_sub_assembly( + parent=doc.name, + fg_item=final_product, + fg_reference_id=doc.name, + bom_item={ + "item_code": "Frame Assembly", + "qty": 1, + "items": [ + { + "item_code": "Frame", + "qty": 1, + }, + { + "item_code": "Fork", + "qty": 1, + }, + ], + }, + ) + + doc.reload() + self.assertEqual(doc.items[0].item_code, "Frame Assembly") + + fg_valuation_rate = 0 + for row in doc.items: + if not row.is_expandable: + fg_valuation_rate += row.amount + self.assertEqual(row.fg_item, "Frame Assembly") + self.assertEqual(row.fg_reference_id, doc.items[0].name) + + self.assertEqual(doc.items[0].amount, fg_valuation_rate) + + def test_bom_raw_material(self): + final_product = "Bicycle" + make_item( + final_product, + { + "item_group": "Raw Material", + "stock_uom": "Nos", + }, + ) + + doc = make_bom_creator( + name="Bicycle BOM with Raw Material", + company="_Test Company", + item_code=final_product, + qty=1, + rm_cosy_as_per="Valuation Rate", + currency="INR", + plc_conversion_rate=1, + conversion_rate=1, + ) + + add_item( + parent=doc.name, + fg_item=final_product, + fg_reference_id=doc.name, + item_code="Pedal Assembly", + qty=2, + ) + + doc.reload() + self.assertEqual(doc.items[0].item_code, "Pedal Assembly") + self.assertEqual(doc.items[0].qty, 2) + + fg_valuation_rate = 0 + for row in doc.items: + if not row.is_expandable: + fg_valuation_rate += row.amount + self.assertEqual(row.fg_item, "Bicycle") + self.assertEqual(row.fg_reference_id, doc.name) + + self.assertEqual(doc.raw_material_cost, fg_valuation_rate) + + def test_convert_to_sub_assembly(self): + final_product = "Bicycle" + make_item( + final_product, + { + "item_group": "Raw Material", + "stock_uom": "Nos", + }, + ) + + doc = make_bom_creator( + name="Bicycle BOM", + company="_Test Company", + item_code=final_product, + qty=1, + rm_cosy_as_per="Valuation Rate", + currency="INR", + plc_conversion_rate=1, + conversion_rate=1, + ) + + add_item( + parent=doc.name, + fg_item=final_product, + fg_reference_id=doc.name, + item_code="Pedal Assembly", + qty=2, + ) + + doc.reload() + self.assertEqual(doc.items[0].is_expandable, 0) + + add_sub_assembly( + convert_to_sub_assembly=1, + parent=doc.name, + fg_item=final_product, + fg_reference_id=doc.items[0].name, + bom_item={ + "item_code": "Pedal Assembly", + "qty": 2, + "items": [ + { + "item_code": "Pedal Body", + "qty": 2, + }, + { + "item_code": "Pedal Axle", + "qty": 2, + }, + ], + }, + ) + + doc.reload() + self.assertEqual(doc.items[0].is_expandable, 1) + + fg_valuation_rate = 0 + for row in doc.items: + if not row.is_expandable: + fg_valuation_rate += row.amount + self.assertEqual(row.fg_item, "Pedal Assembly") + self.assertEqual(row.qty, 2.0) + self.assertEqual(row.fg_reference_id, doc.items[0].name) + + self.assertEqual(doc.raw_material_cost, fg_valuation_rate) + + +def create_items(): + raw_materials = [ + "Frame", + "Fork", + "Rim", + "Spokes", + "Hub", + "Tube", + "Tire", + "Pedal Body", + "Pedal Axle", + "Ball Bearings", + "Chain Links", + "Chain Pins", + "Seat", + "Seat Post", + "Seat Clamp", + ] + + for item in raw_materials: + valuation_rate = random.choice([100, 200, 300, 500, 333, 222, 44, 20, 10]) + make_item( + item, + { + "item_group": "Raw Material", + "stock_uom": "Nos", + "valuation_rate": valuation_rate, + }, + ) + + sub_assemblies = [ + "Frame Assembly", + "Wheel Assembly", + "Pedal Assembly", + "Chain Assembly", + "Seat Assembly", + ] + + for item in sub_assemblies: + make_item( + item, + { + "item_group": "Raw Material", + "stock_uom": "Nos", + }, + ) + + +def make_bom_creator(**kwargs): + if isinstance(kwargs, str) or isinstance(kwargs, dict): + kwargs = frappe.parse_json(kwargs) + + doc = frappe.new_doc("BOM Creator") + doc.update(kwargs) + doc.save() + + return doc diff --git a/erpnext/manufacturing/doctype/bom_creator_item/__init__.py b/erpnext/manufacturing/doctype/bom_creator_item/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.json b/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.json new file mode 100644 index 0000000000..fdb5d3ad33 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.json @@ -0,0 +1,243 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-07-18 14:35:50.307386", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "item_code", + "item_name", + "item_group", + "column_break_f63f", + "fg_item", + "source_warehouse", + "is_expandable", + "sourced_by_supplier", + "bom_created", + "description_section", + "description", + "quantity_and_rate_section", + "qty", + "rate", + "uom", + "column_break_bgnb", + "stock_qty", + "conversion_factor", + "stock_uom", + "amount_section", + "amount", + "column_break_yuca", + "base_rate", + "base_amount", + "section_break_wtld", + "do_not_explode", + "parent_row_no", + "fg_reference_id", + "column_break_sulm", + "instruction" + ], + "fields": [ + { + "columns": 2, + "fieldname": "item_code", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item Code", + "options": "Item", + "reqd": 1 + }, + { + "fetch_from": "item_code.item_name", + "fetch_if_empty": 1, + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name" + }, + { + "fetch_from": "item_code.item_group", + "fieldname": "item_group", + "fieldtype": "Link", + "label": "Item Group", + "options": "Item Group" + }, + { + "fieldname": "column_break_f63f", + "fieldtype": "Column Break" + }, + { + "columns": 2, + "fieldname": "fg_item", + "fieldtype": "Link", + "in_list_view": 1, + "label": "FG Item", + "options": "Item", + "reqd": 1 + }, + { + "fieldname": "source_warehouse", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Source Warehouse", + "options": "Warehouse" + }, + { + "default": "0", + "fieldname": "is_expandable", + "fieldtype": "Check", + "label": "Is Expandable", + "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "description_section", + "fieldtype": "Section Break", + "label": "Description" + }, + { + "fetch_from": "item_code.description", + "fetch_if_empty": 1, + "fieldname": "description", + "fieldtype": "Small Text" + }, + { + "fieldname": "quantity_and_rate_section", + "fieldtype": "Section Break", + "label": "Quantity and Rate" + }, + { + "columns": 1, + "fieldname": "qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Qty" + }, + { + "columns": 2, + "fieldname": "rate", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Rate" + }, + { + "columns": 1, + "fieldname": "uom", + "fieldtype": "Link", + "in_list_view": 1, + "label": "UOM", + "options": "UOM" + }, + { + "fieldname": "column_break_bgnb", + "fieldtype": "Column Break" + }, + { + "fieldname": "stock_qty", + "fieldtype": "Float", + "label": "Stock Qty", + "read_only": 1 + }, + { + "fieldname": "conversion_factor", + "fieldtype": "Float", + "label": "Conversion Factor" + }, + { + "fetch_from": "item_code.stock_uom", + "fieldname": "stock_uom", + "fieldtype": "Link", + "label": "Stock UOM", + "no_copy": 1, + "options": "UOM", + "read_only": 1 + }, + { + "fieldname": "amount_section", + "fieldtype": "Section Break", + "label": "Amount" + }, + { + "fieldname": "amount", + "fieldtype": "Currency", + "label": "Amount", + "read_only": 1 + }, + { + "fieldname": "column_break_yuca", + "fieldtype": "Column Break" + }, + { + "default": "1", + "fieldname": "do_not_explode", + "fieldtype": "Check", + "hidden": 1, + "label": "Do Not Explode" + }, + { + "fieldname": "instruction", + "fieldtype": "Small Text", + "label": "Instruction" + }, + { + "fieldname": "base_amount", + "fieldtype": "Currency", + "hidden": 1, + "label": "Base Amount" + }, + { + "fieldname": "base_rate", + "fieldtype": "Currency", + "hidden": 1, + "label": "Base Rate" + }, + { + "default": "0", + "fieldname": "sourced_by_supplier", + "fieldtype": "Check", + "label": "Sourced by Supplier" + }, + { + "fieldname": "section_break_wtld", + "fieldtype": "Section Break" + }, + { + "fieldname": "fg_reference_id", + "fieldtype": "Data", + "label": "FG Reference", + "no_copy": 1, + "read_only": 1 + }, + { + "fieldname": "column_break_sulm", + "fieldtype": "Column Break" + }, + { + "fieldname": "parent_row_no", + "fieldtype": "Data", + "label": "Parent Row No", + "no_copy": 1, + "print_hide": 1 + }, + { + "default": "0", + "fieldname": "bom_created", + "fieldtype": "Check", + "hidden": 1, + "label": "BOM Created", + "no_copy": 1, + "print_hide": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2023-08-07 11:52:30.492233", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "BOM Creator Item", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.py b/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.py new file mode 100644 index 0000000000..350c9180b9 --- /dev/null +++ b/erpnext/manufacturing/doctype/bom_creator_item/bom_creator_item.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class BOMCreatorItem(Document): + pass diff --git a/erpnext/manufacturing/workspace/manufacturing/manufacturing.json b/erpnext/manufacturing/workspace/manufacturing/manufacturing.json index 518ae14659..8e0785074f 100644 --- a/erpnext/manufacturing/workspace/manufacturing/manufacturing.json +++ b/erpnext/manufacturing/workspace/manufacturing/manufacturing.json @@ -1,6 +1,6 @@ { "charts": [], - "content": "[{\"id\":\"csBCiDglCE\",\"type\":\"header\",\"data\":{\"text\":\"Your Shortcuts\",\"col\":12}},{\"id\":\"xit0dg7KvY\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"BOM\",\"col\":3}},{\"id\":\"LRhGV9GAov\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Production Plan\",\"col\":3}},{\"id\":\"69KKosI6Hg\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Work Order\",\"col\":3}},{\"id\":\"PwndxuIpB3\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Job Card\",\"col\":3}},{\"id\":\"OaiDqTT03Y\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Forecasting\",\"col\":3}},{\"id\":\"OtMcArFRa5\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"BOM Stock Report\",\"col\":3}},{\"id\":\"76yYsI5imF\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Production Planning Report\",\"col\":3}},{\"id\":\"PIQJYZOMnD\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Learn Manufacturing\",\"col\":3}},{\"id\":\"bN_6tHS-Ct\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"yVEFZMqVwd\",\"type\":\"header\",\"data\":{\"text\":\"Reports & Masters\",\"col\":12}},{\"id\":\"rwrmsTI58-\",\"type\":\"card\",\"data\":{\"card_name\":\"Production\",\"col\":4}},{\"id\":\"6dnsyX-siZ\",\"type\":\"card\",\"data\":{\"card_name\":\"Bill of Materials\",\"col\":4}},{\"id\":\"CIq-v5f5KC\",\"type\":\"card\",\"data\":{\"card_name\":\"Reports\",\"col\":4}},{\"id\":\"8RRiQeYr0G\",\"type\":\"card\",\"data\":{\"card_name\":\"Tools\",\"col\":4}},{\"id\":\"Pu8z7-82rT\",\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}}]", + "content": "[{\"id\":\"csBCiDglCE\",\"type\":\"header\",\"data\":{\"text\":\"Your Shortcuts\",\"col\":12}},{\"id\":\"YHCQG3wAGv\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"BOM Creator\",\"col\":3}},{\"id\":\"xit0dg7KvY\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"BOM\",\"col\":3}},{\"id\":\"LRhGV9GAov\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Production Plan\",\"col\":3}},{\"id\":\"69KKosI6Hg\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Work Order\",\"col\":3}},{\"id\":\"PwndxuIpB3\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Job Card\",\"col\":3}},{\"id\":\"OaiDqTT03Y\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Forecasting\",\"col\":3}},{\"id\":\"OtMcArFRa5\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"BOM Stock Report\",\"col\":3}},{\"id\":\"76yYsI5imF\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Production Planning Report\",\"col\":3}},{\"id\":\"PIQJYZOMnD\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Learn Manufacturing\",\"col\":3}},{\"id\":\"bN_6tHS-Ct\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"yVEFZMqVwd\",\"type\":\"header\",\"data\":{\"text\":\"Reports & Masters\",\"col\":12}},{\"id\":\"rwrmsTI58-\",\"type\":\"card\",\"data\":{\"card_name\":\"Production\",\"col\":4}},{\"id\":\"6dnsyX-siZ\",\"type\":\"card\",\"data\":{\"card_name\":\"Bill of Materials\",\"col\":4}},{\"id\":\"CIq-v5f5KC\",\"type\":\"card\",\"data\":{\"card_name\":\"Reports\",\"col\":4}},{\"id\":\"8RRiQeYr0G\",\"type\":\"card\",\"data\":{\"card_name\":\"Tools\",\"col\":4}},{\"id\":\"Pu8z7-82rT\",\"type\":\"card\",\"data\":{\"card_name\":\"Settings\",\"col\":4}}]", "creation": "2020-03-02 17:11:37.032604", "custom_blocks": [], "docstatus": 0, @@ -316,7 +316,7 @@ "type": "Link" } ], - "modified": "2023-07-04 14:40:47.281125", + "modified": "2023-08-08 22:28:39.633891", "modified_by": "Administrator", "module": "Manufacturing", "name": "Manufacturing", @@ -336,6 +336,13 @@ "type": "URL", "url": "https://frappe.school/courses/manufacturing?utm_source=in_app" }, + { + "color": "Grey", + "doc_view": "List", + "label": "BOM Creator", + "link_to": "BOM Creator", + "type": "DocType" + }, { "color": "Grey", "doc_view": "List", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index a25c7c22ad..c8cf7bc6be 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -263,6 +263,7 @@ erpnext.patches.v15_0.saudi_depreciation_warning erpnext.patches.v15_0.delete_saudi_doctypes erpnext.patches.v14_0.show_loan_management_deprecation_warning execute:frappe.rename_doc("Report", "TDS Payable Monthly", "Tax Withholding Details", force=True) +erpnext.patches.v14_0.delete_education_module_portal_menu_items [post_model_sync] execute:frappe.delete_doc_if_exists('Workspace', 'ERPNext Integrations Settings') diff --git a/erpnext/patches/v14_0/delete_education_doctypes.py b/erpnext/patches/v14_0/delete_education_doctypes.py index 76b2300fd2..56a596a02e 100644 --- a/erpnext/patches/v14_0/delete_education_doctypes.py +++ b/erpnext/patches/v14_0/delete_education_doctypes.py @@ -43,9 +43,18 @@ def execute(): frappe.delete_doc("Number Card", card, ignore_missing=True, force=True) doctypes = frappe.get_all("DocType", {"module": "education", "custom": 0}, pluck="name") + for doctype in doctypes: frappe.delete_doc("DocType", doctype, ignore_missing=True) + portal_settings = frappe.get_doc("Portal Settings") + + for row in portal_settings.get("menu"): + if row.reference_doctype in doctypes: + row.delete() + + portal_settings.save() + frappe.delete_doc("Module Def", "Education", ignore_missing=True, force=True) click.secho( diff --git a/erpnext/patches/v14_0/delete_education_module_portal_menu_items.py b/erpnext/patches/v14_0/delete_education_module_portal_menu_items.py new file mode 100644 index 0000000000..d964f14944 --- /dev/null +++ b/erpnext/patches/v14_0/delete_education_module_portal_menu_items.py @@ -0,0 +1,13 @@ +# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors +# License: MIT. See LICENSE + +import frappe + + +def execute(): + doctypes = frappe.get_all("DocType", {"module": "education", "custom": 0}, pluck="name") + items = frappe.get_all( + "Portal Menu Item", filters={"reference_doctype": ("in", doctypes)}, pluck="name" + ) + for item in items: + frappe.delete_doc("Portal Menu Item", item, ignore_missing=True, force=True) diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 7d80ac1cb7..c2ed579e73 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -10,9 +10,11 @@ from frappe.model.document import Document from frappe.query_builder import Interval from frappe.query_builder.functions import Count, CurDate, Date, UnixTimestamp from frappe.utils import add_days, flt, get_datetime, get_time, get_url, nowtime, today +from frappe.utils.user import is_website_user from erpnext import get_default_company from erpnext.controllers.queries import get_filters_cond +from erpnext.controllers.website_list_for_contact import get_customers_suppliers from erpnext.setup.doctype.holiday_list.holiday_list import is_holiday @@ -318,9 +320,20 @@ def get_timeline_data(doctype: str, name: str) -> dict[int, int]: def get_project_list( doctype, txt, filters, limit_start, limit_page_length=20, order_by="modified" ): + user = frappe.session.user + customers, suppliers = get_customers_suppliers("Project", frappe.session.user) + + ignore_permissions = False + if is_website_user(): + if not filters: + filters = [] + + if customers: + filters.append([doctype, "customer", "in", customers]) + + ignore_permissions = True + meta = frappe.get_meta(doctype) - if not filters: - filters = [] fields = "distinct *" @@ -351,18 +364,26 @@ def get_project_list( limit_start=limit_start, limit_page_length=limit_page_length, order_by=order_by, + ignore_permissions=ignore_permissions, ) def get_list_context(context=None): - return { - "show_sidebar": True, - "show_search": True, - "no_breadcrumbs": True, - "title": _("Projects"), - "get_list": get_project_list, - "row_template": "templates/includes/projects/project_row.html", - } + from erpnext.controllers.website_list_for_contact import get_list_context + + list_context = get_list_context(context) + list_context.update( + { + "show_sidebar": True, + "show_search": True, + "no_breadcrumbs": True, + "title": _("Projects"), + "get_list": get_project_list, + "row_template": "templates/includes/projects/project_row.html", + } + ) + + return list_context @frappe.whitelist() diff --git a/erpnext/public/js/bom_configurator/bom_configurator.bundle.js b/erpnext/public/js/bom_configurator/bom_configurator.bundle.js new file mode 100644 index 0000000000..b3b2e9f9b8 --- /dev/null +++ b/erpnext/public/js/bom_configurator/bom_configurator.bundle.js @@ -0,0 +1,416 @@ +class BOMConfigurator { + constructor({ wrapper, page, frm, bom_configurator }) { + this.$wrapper = $(wrapper); + this.page = page; + this.bom_configurator = bom_configurator; + this.frm = frm; + + this.make(); + this.prepare_layout(); + this.bind_events(); + } + + add_boms() { + this.frm.call({ + method: "add_boms", + freeze: true, + doc: this.frm.doc, + }); + } + + make() { + let options = { + ...this.tree_options(), + ...this.tree_methods(), + }; + + frappe.views.trees["BOM Configurator"] = new frappe.views.TreeView(options); + this.tree_view = frappe.views.trees["BOM Configurator"]; + } + + bind_events() { + frappe.views.trees["BOM Configurator"].events = { + frm: this.frm, + add_item: this.add_item, + add_sub_assembly: this.add_sub_assembly, + get_sub_assembly_modal_fields: this.get_sub_assembly_modal_fields, + convert_to_sub_assembly: this.convert_to_sub_assembly, + delete_node: this.delete_node, + edit_qty: this.edit_qty, + load_tree: this.load_tree, + set_default_qty: this.set_default_qty, + } + } + + tree_options() { + return { + parent: this.$wrapper.get(0), + body: this.$wrapper.get(0), + doctype: 'BOM Configurator', + page: this.page, + expandable: true, + title: __("Configure Product Assembly"), + breadcrumb: "Manufacturing", + get_tree_nodes: "erpnext.manufacturing.doctype.bom_creator.bom_creator.get_children", + root_label: this.frm.doc.item_code, + disable_add_node: true, + get_tree_root: false, + show_expand_all: false, + extend_toolbar: false, + do_not_make_page: true, + do_not_setup_menu: true, + } + } + + tree_methods() { + let frm_obj = this; + let view = frappe.views.trees["BOM Configurator"]; + + return { + onload: function(me) { + me.args["parent_id"] = frm_obj.frm.doc.name; + me.args["parent"] = frm_obj.frm.doc.item_code; + me.parent = frm_obj.$wrapper.get(0); + me.body = frm_obj.$wrapper.get(0); + me.make_tree(); + }, + onrender(node) { + const qty = node.data.qty || frm_obj.frm.doc.qty; + const uom = node.data.uom || frm_obj.frm.doc.uom; + const docname = node.data.name || frm_obj.frm.doc.name; + let amount = node.data.amount; + if (node.data.value === frm_obj.frm.doc.item_code) { + amount = frm_obj.frm.doc.raw_material_cost; + } + + amount = frappe.format(amount, { fieldtype: "Currency", currency: frm_obj.frm.doc.currency }); + + $(` +