diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 3a2e3fcdb41e..24d95ae563e3 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -7,7 +7,7 @@ from erpnext.hooks import regional_overrides -__version__ = '13.14.1' +__version__ = '13.16.1' def get_default_company(user=None): '''Get default company for user''' diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js index a43ece8b9b22..48384071be8a 100644 --- a/erpnext/accounts/doctype/account/account_tree.js +++ b/erpnext/accounts/doctype/account/account_tree.js @@ -78,6 +78,7 @@ frappe.treeview_settings["Account"] = { const format = (value, currency) => format_currency(Math.abs(value), currency); if (account.balance!==undefined) { + node.parent && node.parent.find('.balance-area').remove(); $('' + (account.balance_in_account_currency ? (format(account.balance_in_account_currency, account.account_currency) + " / ") : "") diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index f54473351a2f..3a2d77ca9ef2 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -20,6 +20,9 @@ def validate(self): frappe.db.set_default("add_taxes_from_item_tax_template", self.get("add_taxes_from_item_tax_template", 0)) + frappe.db.set_default("enable_common_party_accounting", + self.get("enable_common_party_accounting", 0)) + self.validate_stale_days() self.enable_payment_schedule_in_print() self.toggle_discount_accounting_fields() diff --git a/erpnext/accounts/doctype/party_link/party_link.py b/erpnext/accounts/doctype/party_link/party_link.py index fe9d8c6592c7..174ac14e05c4 100644 --- a/erpnext/accounts/doctype/party_link/party_link.py +++ b/erpnext/accounts/doctype/party_link/party_link.py @@ -23,3 +23,16 @@ def validate(self): if existing_party_link: frappe.throw(_('{} {} is already linked with another {}') .format(self.primary_role, self.primary_party, existing_party_link[0])) + + +@frappe.whitelist() +def create_party_link(primary_role, primary_party, secondary_party): + party_link = frappe.new_doc('Party Link') + party_link.primary_role = primary_role + party_link.primary_party = primary_party + party_link.secondary_role = 'Customer' if primary_role == 'Supplier' else 'Supplier' + party_link.secondary_party = secondary_party + + party_link.save(ignore_permissions=True) + + return party_link \ No newline at end of file diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py index 9f30dc00c1e8..a5f33dd48cb5 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py @@ -89,9 +89,10 @@ def get_pnl_gl_entry(self, pl_accounts): for acc in pl_accounts: if flt(acc.bal_in_company_currency): + cost_center = acc.cost_center if self.cost_center_wise_pnl else company_cost_center gl_entry = self.get_gl_dict({ "account": self.closing_account_head, - "cost_center": acc.cost_center or company_cost_center, + "cost_center": cost_center, "finance_book": acc.finance_book, "account_currency": acc.account_currency, "debit_in_account_currency": abs(flt(acc.bal_in_account_currency)) if flt(acc.bal_in_account_currency) > 0 else 0, diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py index 2d417a4cfba0..b209fedbb8c3 100644 --- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py +++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py @@ -67,8 +67,8 @@ def test_cost_center_wise_posting(self): company = create_company() surplus_account = create_account() - cost_center1 = create_cost_center("Test Cost Center 1") - cost_center2 = create_cost_center("Test Cost Center 2") + cost_center1 = create_cost_center("Main") + cost_center2 = create_cost_center("Western Branch") create_sales_invoice( company=company, @@ -87,7 +87,10 @@ def test_cost_center_wise_posting(self): debit_to="Debtors - TPC" ) - pcv = self.make_period_closing_voucher() + pcv = self.make_period_closing_voucher(submit=False) + pcv.cost_center_wise_pnl = 1 + pcv.save() + pcv.submit() surplus_account = pcv.closing_account_head expected_gle = ( @@ -150,7 +153,7 @@ def test_period_closing_with_finance_book_entries(self): self.assertEqual(pcv_gle, expected_gle) - def make_period_closing_voucher(self): + def make_period_closing_voucher(self, submit=True): surplus_account = create_account() cost_center = create_cost_center("Test Cost Center 1") pcv = frappe.get_doc({ @@ -164,7 +167,8 @@ def make_period_closing_voucher(self): "remarks": "test" }) pcv.insert() - pcv.submit() + if submit: + pcv.submit() return pcv diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 64aa9bc962ae..06f1867a76f2 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -14,6 +14,7 @@ from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry from erpnext.buying.doctype.supplier.test_supplier import create_supplier from erpnext.controllers.accounts_controller import get_payment_terms +from erpnext.controllers.buying_controller import QtyMismatchError from erpnext.exceptions import InvalidCurrency from erpnext.projects.doctype.project.test_project import make_project from erpnext.stock.doctype.item.test_item import create_item @@ -36,6 +37,27 @@ def setUpClass(self): def tearDownClass(self): unlink_payment_on_cancel_of_invoice(0) + def test_purchase_invoice_received_qty(self): + """ + 1. Test if received qty is validated against accepted + rejected + 2. Test if received qty is auto set on save + """ + pi = make_purchase_invoice( + qty=1, + rejected_qty=1, + received_qty=3, + item_code="_Test Item Home Desktop 200", + rejected_warehouse = "_Test Rejected Warehouse - _TC", + update_stock=True, do_not_save=True) + self.assertRaises(QtyMismatchError, pi.save) + + pi.items[0].received_qty = 0 + pi.save() + self.assertEqual(pi.items[0].received_qty, 2) + + # teardown + pi.delete() + def test_gl_entries_without_perpetual_inventory(self): frappe.db.set_value("Company", "_Test Company", "round_off_account", "Round Off - _TC") pi = frappe.copy_doc(test_records[0]) @@ -789,29 +811,12 @@ def test_purchase_invoice_with_shipping_rule(self): pi.shipping_rule = shipping_rule.name pi.insert() - - shipping_amount = 0.0 - for condition in shipping_rule.get("conditions"): - if not condition.to_value or (flt(condition.from_value) <= pi.net_total <= flt(condition.to_value)): - shipping_amount = condition.shipping_amount - - shipping_charge = { - "doctype": "Purchase Taxes and Charges", - "category": "Valuation and Total", - "charge_type": "Actual", - "account_head": shipping_rule.account, - "cost_center": shipping_rule.cost_center, - "tax_amount": shipping_amount, - "description": shipping_rule.name, - "add_deduct_tax": "Add" - } - pi.append("taxes", shipping_charge) pi.save() self.assertEqual(pi.net_total, 1250) - self.assertEqual(pi.total_taxes_and_charges, 462.3) - self.assertEqual(pi.grand_total, 1712.3) + self.assertEqual(pi.total_taxes_and_charges, 354.1) + self.assertEqual(pi.grand_total, 1604.1) def test_make_pi_without_terms(self): pi = make_purchase_invoice(do_not_save=1) diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index eab98a7e3fd5..4b12f9954e8d 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -22,10 +22,10 @@ "received_qty", "qty", "rejected_qty", - "stock_uom", "col_break2", "uom", "conversion_factor", + "stock_uom", "stock_qty", "sec_break1", "price_list_rate", @@ -175,7 +175,8 @@ { "fieldname": "received_qty", "fieldtype": "Float", - "label": "Received Qty" + "label": "Received Qty", + "read_only": 1 }, { "bold": 1, @@ -223,7 +224,7 @@ { "fieldname": "stock_qty", "fieldtype": "Float", - "label": "Stock Qty", + "label": "Accepted Qty in Stock UOM", "print_hide": 1, "read_only": 1, "reqd": 1 @@ -870,10 +871,11 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-09-01 16:04:03.538643", + "modified": "2021-11-15 17:04:07.191013", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 67465c51acda..4513e32ef2d7 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1626,28 +1626,12 @@ def test_sales_invoice_with_shipping_rule(self): si.shipping_rule = shipping_rule.name si.insert() - - shipping_amount = 0.0 - for condition in shipping_rule.get("conditions"): - if not condition.to_value or (flt(condition.from_value) <= si.net_total <= flt(condition.to_value)): - shipping_amount = condition.shipping_amount - - shipping_charge = { - "doctype": "Sales Taxes and Charges", - "category": "Valuation and Total", - "charge_type": "Actual", - "account_head": shipping_rule.account, - "cost_center": shipping_rule.cost_center, - "tax_amount": shipping_amount, - "description": shipping_rule.name - } - si.append("taxes", shipping_charge) si.save() self.assertEqual(si.net_total, 1250) - self.assertEqual(si.total_taxes_and_charges, 577.05) - self.assertEqual(si.grand_total, 1827.05) + self.assertEqual(si.total_taxes_and_charges, 468.85) + self.assertEqual(si.grand_total, 1718.85) @@ -2251,6 +2235,7 @@ def test_sales_invoice_against_supplier(self): from erpnext.accounts.doctype.opening_invoice_creation_tool.test_opening_invoice_creation_tool import ( make_customer, ) + from erpnext.accounts.doctype.party_link.party_link import create_party_link from erpnext.buying.doctype.supplier.test_supplier import create_supplier # create a customer @@ -2260,12 +2245,7 @@ def test_sales_invoice_against_supplier(self): # create a party link between customer & supplier # set primary role as supplier - party_link = frappe.new_doc("Party Link") - party_link.primary_role = "Supplier" - party_link.primary_party = supplier - party_link.secondary_role = "Customer" - party_link.secondary_party = customer - party_link.save() + party_link = create_party_link("Supplier", supplier, customer) # enable common party accounting frappe.db.set_value('Accounts Settings', None, 'enable_common_party_accounting', 1) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index ecc8783df2c2..6f9e61c5da70 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -70,10 +70,12 @@ def _get_party_details(party=None, account=None, party_type="Customer", company= party_details["tax_category"] = get_address_tax_category(party.get("tax_category"), party_address, shipping_address if party_type != "Supplier" else party_address) - if not party_details.get("taxes_and_charges"): - party_details["taxes_and_charges"] = set_taxes(party.name, party_type, posting_date, company, - customer_group=party_details.customer_group, supplier_group=party_details.supplier_group, tax_category=party_details.tax_category, - billing_address=party_address, shipping_address=shipping_address) + tax_template = set_taxes(party.name, party_type, posting_date, company, + customer_group=party_details.customer_group, supplier_group=party_details.supplier_group, tax_category=party_details.tax_category, + billing_address=party_address, shipping_address=shipping_address) + + if tax_template: + party_details['taxes_and_charges'] = tax_template if cint(fetch_payment_terms_template): party_details["payment_terms_template"] = get_payment_terms_template(party.name, party_type, company) diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js index 79c8861bcdc1..36f510b18ee3 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.js @@ -14,6 +14,14 @@ frappe.ui.form.on('Asset Value Adjustment', { } } }); + frm.set_query('asset', function() { + return { + filters: { + calculate_depreciation: 1, + docstatus: 1 + } + }; + }); }, onload: function(frm) { diff --git a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py index 2c11018caa9d..55226e788e21 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/asset_value_adjustment.py @@ -13,7 +13,9 @@ get_checks_for_pl_and_bs_accounts, ) from erpnext.assets.doctype.asset.depreciation import get_depreciation_accounts - +from erpnext.regional.india.utils import ( + get_depreciation_amount as get_depreciation_amount_for_india, +) class AssetValueAdjustment(Document): def validate(self): @@ -92,6 +94,7 @@ def make_depreciation_entry(self): def reschedule_depreciations(self, asset_value): asset = frappe.get_doc('Asset', self.asset) + country = frappe.get_value('Company', self.company, 'country') for d in asset.finance_books: d.value_after_depreciation = asset_value @@ -113,8 +116,10 @@ def reschedule_depreciations(self, asset_value): depreciation_amount = days * rate_per_day from_date = data.schedule_date else: - depreciation_amount = asset.get_depreciation_amount(value_after_depreciation, - no_of_depreciations, d) + if country == "India": + depreciation_amount = get_depreciation_amount_for_india(asset, value_after_depreciation, d) + else: + depreciation_amount = get_depreciation_amount(asset, value_after_depreciation, d) if depreciation_amount: value_after_depreciation -= flt(depreciation_amount) diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js index 7ee91961ca5f..c81f2535c32b 100644 --- a/erpnext/buying/doctype/supplier/supplier.js +++ b/erpnext/buying/doctype/supplier/supplier.js @@ -83,6 +83,12 @@ frappe.ui.form.on("Supplier", { frm.trigger("get_supplier_group_details"); }, __('Actions')); + if (cint(frappe.defaults.get_default("enable_common_party_accounting"))) { + frm.add_custom_button(__('Link with Customer'), function () { + frm.trigger('show_party_link_dialog'); + }, __('Actions')); + } + // indicators erpnext.utils.set_party_dashboard_indicators(frm); } @@ -128,5 +134,43 @@ frappe.ui.form.on("Supplier", { else { frm.toggle_reqd("represents_company", false); } + }, + + show_party_link_dialog: function(frm) { + const dialog = new frappe.ui.Dialog({ + title: __('Select a Customer'), + fields: [{ + fieldtype: 'Link', label: __('Customer'), + options: 'Customer', fieldname: 'customer', reqd: 1 + }], + primary_action: function({ customer }) { + frappe.call({ + method: 'erpnext.accounts.doctype.party_link.party_link.create_party_link', + args: { + primary_role: 'Supplier', + primary_party: frm.doc.name, + secondary_party: customer + }, + freeze: true, + callback: function() { + dialog.hide(); + frappe.msgprint({ + message: __('Successfully linked to Customer'), + alert: true + }); + }, + error: function() { + dialog.hide(); + frappe.msgprint({ + message: __('Linking to Customer Failed. Please try again.'), + title: __('Linking Failed'), + indicator: 'red' + }); + } + }); + }, + primary_action_label: __('Create Link') + }); + dialog.show(); } }); diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index de67fbaae051..0366a182ed24 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -12,7 +12,11 @@ ) from frappe.model.naming import set_name_by_naming_series, set_name_from_naming_options -from erpnext.accounts.party import get_dashboard_info, validate_party_accounts +from erpnext.accounts.party import ( # noqa + get_dashboard_info, + get_timeline_data, + validate_party_accounts, +) from erpnext.utilities.transaction_base import TransactionBase diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index e0b3ad801ec4..6ea06aeae1fb 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe -from frappe import _, msgprint +from frappe import ValidationError, _, msgprint from frappe.contacts.doctype.address.address import get_address_display from frappe.utils import cint, cstr, flt, getdate @@ -18,6 +18,9 @@ from erpnext.stock.utils import get_incoming_rate +class QtyMismatchError(ValidationError): + pass + class BuyingController(StockController, Subcontracting): def get_feed(self): @@ -361,19 +364,15 @@ def validate_rejected_warehouse(self): def validate_accepted_rejected_qty(self): for d in self.get("items"): self.validate_negative_quantity(d, ["received_qty","qty", "rejected_qty"]) - if not flt(d.received_qty) and flt(d.qty): - d.received_qty = flt(d.qty) - flt(d.rejected_qty) - - elif not flt(d.qty) and flt(d.rejected_qty): - d.qty = flt(d.received_qty) - flt(d.rejected_qty) - elif not flt(d.rejected_qty): - d.rejected_qty = flt(d.received_qty) - flt(d.qty) + if not flt(d.received_qty) and (flt(d.qty) or flt(d.rejected_qty)): + d.received_qty = flt(d.qty) + flt(d.rejected_qty) - val = flt(d.qty) + flt(d.rejected_qty) # Check Received Qty = Accepted Qty + Rejected Qty + val = flt(d.qty) + flt(d.rejected_qty) if (flt(val, d.precision("received_qty")) != flt(d.received_qty, d.precision("received_qty"))): - frappe.throw(_("Accepted + Rejected Qty must be equal to Received quantity for Item {0}").format(d.item_code)) + message = _("Row #{0}: Received Qty must be equal to Accepted + Rejected Qty for Item {1}").format(d.idx, d.item_code) + frappe.throw(msg=message, title=_("Mismatch"), exc=QtyMismatchError) def validate_negative_quantity(self, item_row, field_list): if self.is_return: diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 4697205d72df..d70821bcb28b 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -17,7 +17,7 @@ from erpnext.accounts.utils import get_fiscal_year from erpnext.controllers.accounts_controller import AccountsController from erpnext.stock import get_warehouse_account_map -from erpnext.stock.stock_ledger import get_valuation_rate +from erpnext.stock.stock_ledger import get_items_to_be_repost, get_valuation_rate class QualityInspectionRequiredError(frappe.ValidationError): pass @@ -537,7 +537,12 @@ def repost_future_sle_and_gle(self): "company": self.company }) if future_sle_exists(args): - create_repost_item_valuation_entry(args) + item_based_reposting = cint(frappe.db.get_single_value("Stock Reposting Settings", "item_based_reposting")) + if item_based_reposting: + create_item_wise_repost_entries(voucher_type=self.doctype, voucher_no=self.name) + else: + create_repost_item_valuation_entry(args) + @frappe.whitelist() def make_quality_inspections(doctype, docname, items): @@ -671,3 +676,35 @@ def create_repost_item_valuation_entry(args): repost_entry.flags.ignore_links = True repost_entry.save() repost_entry.submit() + + +def create_item_wise_repost_entries(voucher_type, voucher_no, allow_zero_rate=False): + """Using a voucher create repost item valuation records for all item-warehouse pairs.""" + + stock_ledger_entries = get_items_to_be_repost(voucher_type, voucher_no) + + distinct_item_warehouses = set() + repost_entries = [] + + for sle in stock_ledger_entries: + item_wh = (sle.item_code, sle.warehouse) + if item_wh in distinct_item_warehouses: + continue + distinct_item_warehouses.add(item_wh) + + repost_entry = frappe.new_doc("Repost Item Valuation") + repost_entry.based_on = "Item and Warehouse" + repost_entry.voucher_type = voucher_type + repost_entry.voucher_no = voucher_no + + repost_entry.item_code = sle.item_code + repost_entry.warehouse = sle.warehouse + repost_entry.posting_date = sle.posting_date + repost_entry.posting_time = sle.posting_time + repost_entry.allow_zero_rate = allow_zero_rate + repost_entry.flags.ignore_links = True + repost_entry.flags.ignore_permissions = True + repost_entry.submit() + repost_entries.append(repost_entry) + + return repost_entries diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index fbfdfdfac89c..4e63f9d65734 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -51,6 +51,7 @@ def _calculate(self): self.initialize_taxes() self.determine_exclusive_rate() self.calculate_net_total() + self.calculate_shipping_charges() self.calculate_taxes() self.manipulate_grand_total_for_inclusive_tax() self.calculate_totals() @@ -259,6 +260,11 @@ def calculate_net_total(self): self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"]) + def calculate_shipping_charges(self): + if hasattr(self.doc, "shipping_rule") and self.doc.shipping_rule: + shipping_rule = frappe.get_doc("Shipping Rule", self.doc.shipping_rule) + shipping_rule.apply(self.doc) + def calculate_taxes(self): self.doc.rounding_adjustment = 0 # maintain actual tax rate based on idx diff --git a/erpnext/hr/doctype/employee_advance/employee_advance.py b/erpnext/hr/doctype/employee_advance/employee_advance.py index 8d90bccd2daa..dbcfe71c4685 100644 --- a/erpnext/hr/doctype/employee_advance/employee_advance.py +++ b/erpnext/hr/doctype/employee_advance/employee_advance.py @@ -7,6 +7,7 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.query_builder.functions import Sum from frappe.utils import flt, nowdate import erpnext @@ -43,24 +44,34 @@ def set_status(self): self.status = "Cancelled" def set_total_advance_paid(self): - paid_amount = frappe.db.sql(""" - select ifnull(sum(debit), 0) as paid_amount - from `tabGL Entry` - where against_voucher_type = 'Employee Advance' - and against_voucher = %s - and party_type = 'Employee' - and party = %s - """, (self.name, self.employee), as_dict=1)[0].paid_amount - - return_amount = frappe.db.sql(""" - select ifnull(sum(credit), 0) as return_amount - from `tabGL Entry` - where against_voucher_type = 'Employee Advance' - and voucher_type != 'Expense Claim' - and against_voucher = %s - and party_type = 'Employee' - and party = %s - """, (self.name, self.employee), as_dict=1)[0].return_amount + gle = frappe.qb.DocType("GL Entry") + + paid_amount = ( + frappe.qb.from_(gle) + .select(Sum(gle.debit).as_("paid_amount")) + .where( + (gle.against_voucher_type == 'Employee Advance') + & (gle.against_voucher == self.name) + & (gle.party_type == 'Employee') + & (gle.party == self.employee) + & (gle.docstatus == 1) + & (gle.is_cancelled == 0) + ) + ).run(as_dict=True)[0].paid_amount or 0 + + return_amount = ( + frappe.qb.from_(gle) + .select(Sum(gle.credit).as_("return_amount")) + .where( + (gle.against_voucher_type == 'Employee Advance') + & (gle.voucher_type != 'Expense Claim') + & (gle.against_voucher == self.name) + & (gle.party_type == 'Employee') + & (gle.party == self.employee) + & (gle.docstatus == 1) + & (gle.is_cancelled == 0) + ) + ).run(as_dict=True)[0].return_amount or 0 if paid_amount != 0: paid_amount = flt(paid_amount) / flt(self.exchange_rate) diff --git a/erpnext/hr/doctype/employee_advance/test_employee_advance.py b/erpnext/hr/doctype/employee_advance/test_employee_advance.py index c439d45b55c2..653db50f8eaa 100644 --- a/erpnext/hr/doctype/employee_advance/test_employee_advance.py +++ b/erpnext/hr/doctype/employee_advance/test_employee_advance.py @@ -36,6 +36,24 @@ def test_paid_amount_and_status(self): journal_entry1 = make_payment_entry(advance) self.assertRaises(EmployeeAdvanceOverPayment, journal_entry1.submit) + def test_paid_amount_on_pe_cancellation(self): + employee_name = make_employee("_T@employe.advance") + advance = make_employee_advance(employee_name) + + pe = make_payment_entry(advance) + pe.submit() + + advance.reload() + + self.assertEqual(advance.paid_amount, 1000) + self.assertEqual(advance.status, "Paid") + + pe.cancel() + advance.reload() + + self.assertEqual(advance.paid_amount, 0) + self.assertEqual(advance.status, "Unpaid") + def test_repay_unclaimed_amount_from_salary(self): employee_name = make_employee("_T@employe.advance") advance = make_employee_advance(employee_name, {"repay_unclaimed_amount_from_salary": 1}) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 3c4c672816c9..315e0884beeb 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -369,6 +369,7 @@ frappe.ui.form.on("Expense Claim Detail", { sanctioned_amount: function(frm, cdt, cdn) { cur_frm.cscript.calculate_total(frm.doc, cdt, cdn); frm.trigger("get_taxes"); + frm.trigger("calculate_grand_total"); }, cost_center: function(frm, cdt, cdn) { erpnext.utils.copy_value_in_all_rows(frm.doc, cdt, cdn, "expenses", "cost_center"); diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json index c62258fbcb69..7b525ab7dba7 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.json +++ b/erpnext/hr/doctype/expense_claim/expense_claim.json @@ -379,11 +379,12 @@ "idx": 1, "is_submittable": 1, "links": [], - "modified": "2021-05-12 20:02:00.064379", + "modified": "2021-11-22 16:26:57.787838", "modified_by": "Administrator", "module": "HR", "name": "Expense Claim", "name_case": "Title Case", + "naming_rule": "By \"Naming Series\" field", "owner": "Administrator", "permissions": [ { diff --git a/erpnext/hr/doctype/shift_assignment/shift_assignment.py b/erpnext/hr/doctype/shift_assignment/shift_assignment.py index 69af5c54c3b6..f643414dd0c9 100644 --- a/erpnext/hr/doctype/shift_assignment/shift_assignment.py +++ b/erpnext/hr/doctype/shift_assignment/shift_assignment.py @@ -21,8 +21,8 @@ def validate(self): validate_active_employee(self.employee) self.validate_overlapping_dates() - if self.end_date and self.end_date <= self.start_date: - frappe.throw(_("End Date must not be lesser than Start Date")) + if self.end_date: + self.validate_from_to_dates('start_date', 'end_date') def validate_overlapping_dates(self): if not self.name: diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py index e1d79be81c4f..b3b94071f0b9 100644 --- a/erpnext/manufacturing/doctype/job_card/job_card.py +++ b/erpnext/manufacturing/doctype/job_card/job_card.py @@ -605,7 +605,8 @@ def set_missing_values(source, target): "doctype": "Material Request Item", "field_map": { "required_qty": "qty", - "uom": "stock_uom" + "uom": "stock_uom", + "name": "job_card_item" }, "postprocess": update_item, } diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 8bbb5fc88516..6a241b7695e4 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -238,6 +238,12 @@ frappe.ui.form.on('Production Plan', { method: "get_items", freeze: true, doc: frm.doc, + callback: function() { + frm.refresh_field("po_items"); + if (frm.doc.sub_assembly_items.length > 0) { + frm.trigger("get_sub_assembly_items"); + } + } }); }, diff --git a/erpnext/manufacturing/doctype/work_order/work_order.js b/erpnext/manufacturing/doctype/work_order/work_order.js index 512048512ed1..2611c03ea29c 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.js +++ b/erpnext/manufacturing/doctype/work_order/work_order.js @@ -440,7 +440,7 @@ frappe.ui.form.on("Work Order", { additional_operating_cost: function(frm) { erpnext.work_order.calculate_cost(frm.doc); erpnext.work_order.calculate_total_cost(frm); - } + }, }); frappe.ui.form.on("Work Order Item", { diff --git a/erpnext/manufacturing/doctype/work_order/work_order.json b/erpnext/manufacturing/doctype/work_order/work_order.json index c4f0e886ab2d..2f13a48a9a6e 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.json +++ b/erpnext/manufacturing/doctype/work_order/work_order.json @@ -325,6 +325,7 @@ "label": "Expected Delivery Date" }, { + "collapsible": 1, "fieldname": "operations_section", "fieldtype": "Section Break", "label": "Operations", @@ -336,7 +337,7 @@ "fieldname": "transfer_material_against", "fieldtype": "Select", "label": "Transfer Material Against", - "options": "\nWork Order\nJob Card" + "options": "Work Order\nJob Card" }, { "fieldname": "operations", @@ -572,7 +573,7 @@ "image_field": "image", "is_submittable": 1, "links": [], - "modified": "2022-02-24 15:14:03.844937", + "modified": "2022-02-25 15:14:03.844937", "modified_by": "Administrator", "module": "Manufacturing", "restrict_to_domain": "Manufacturing", diff --git a/erpnext/manufacturing/doctype/work_order_operation/work_order_operation.json b/erpnext/manufacturing/doctype/work_order_operation/work_order_operation.json index f7b8787a0b37..fcb0de961ceb 100644 --- a/erpnext/manufacturing/doctype/work_order_operation/work_order_operation.json +++ b/erpnext/manufacturing/doctype/work_order_operation/work_order_operation.json @@ -6,27 +6,27 @@ "field_order": [ "details", "operation", - "bom", - "column_break_4", - "description", - "sequence_id", - "col_break1", - "completed_qty", "status", + "completed_qty", + "column_break_4", + "bom", "workstation", + "sequence_id", + "section_break_10", + "description", "estimated_time_and_cost", "planned_start_time", - "planned_end_time", - "column_break_10", - "time_in_mins", "hour_rate", + "time_in_mins", + "column_break_10", + "planned_end_time", "batch_size", "planned_operating_cost", "section_break_9", "actual_start_time", - "actual_end_time", - "column_break_11", "actual_operation_time", + "column_break_11", + "actual_end_time", "actual_operating_cost" ], "fields": [ @@ -42,7 +42,6 @@ "oldfieldname": "operation_no", "oldfieldtype": "Data", "options": "Operation", - "read_only": 1, "reqd": 1 }, { @@ -52,20 +51,14 @@ "label": "BOM", "no_copy": 1, "options": "BOM", - "print_hide": 1, - "read_only": 1 + "print_hide": 1 }, { "fieldname": "description", "fieldtype": "Text Editor", "label": "Operation Description", "oldfieldname": "opn_description", - "oldfieldtype": "Text", - "read_only": 1 - }, - { - "fieldname": "col_break1", - "fieldtype": "Column Break" + "oldfieldtype": "Text" }, { "columns": 1, @@ -74,19 +67,16 @@ "fieldtype": "Float", "in_list_view": 1, "label": "Completed Qty", - "no_copy": 1, - "read_only": 1 + "no_copy": 1 }, { "columns": 1, "default": "Pending", "fieldname": "status", "fieldtype": "Select", - "in_list_view": 1, "label": "Status", "no_copy": 1, - "options": "Pending\nWork in Progress\nCompleted", - "read_only": 1 + "options": "Pending\nWork in Progress\nCompleted" }, { "fieldname": "workstation", @@ -106,15 +96,13 @@ "fieldname": "planned_start_time", "fieldtype": "Datetime", "label": "Planned Start Time", - "no_copy": 1, - "read_only": 1 + "no_copy": 1 }, { "fieldname": "planned_end_time", "fieldtype": "Datetime", "label": "Planned End Time", - "no_copy": 1, - "read_only": 1 + "no_copy": 1 }, { "fieldname": "column_break_10", @@ -122,7 +110,7 @@ }, { "columns": 1, - "description": "in Minutes", + "description": "In Minutes", "fieldname": "time_in_mins", "fieldtype": "Float", "in_list_view": 1, @@ -152,6 +140,7 @@ "label": "Actual Time and Cost" }, { + "description": "Updated via 'Time Log' (In Minutes)", "fieldname": "actual_start_time", "fieldtype": "Datetime", "label": "Actual Start Time", @@ -159,7 +148,7 @@ "read_only": 1 }, { - "description": "Updated via 'Time Log'", + "description": "Updated via 'Time Log' (In Minutes)", "fieldname": "actual_end_time", "fieldtype": "Datetime", "label": "Actual End Time", @@ -171,7 +160,7 @@ "fieldtype": "Column Break" }, { - "description": "in Minutes\nUpdated via 'Time Log'", + "description": "Updated via 'Time Log' (In Minutes)", "fieldname": "actual_operation_time", "fieldtype": "Float", "label": "Actual Operation Time", @@ -190,25 +179,28 @@ { "fieldname": "batch_size", "fieldtype": "Int", - "label": "Batch Size", - "read_only": 1 + "label": "Batch Size" }, { "fieldname": "sequence_id", "fieldtype": "Int", + "hidden": 1, "label": "Sequence ID", - "print_hide": 1, - "read_only": 1 + "print_hide": 1 }, { "fieldname": "column_break_4", "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_10", + "fieldtype": "Section Break" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-06-24 14:36:12.835543", + "modified": "2021-11-25 04:52:54.295168", "modified_by": "Administrator", "module": "Manufacturing", "name": "Work Order Operation", @@ -217,4 +209,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.py b/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.py index 0dcad448d795..de4931a47ecf 100644 --- a/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.py +++ b/erpnext/manufacturing/report/cost_of_poor_quality_report/cost_of_poor_quality_report.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt from __future__ import unicode_literals @@ -31,7 +31,6 @@ def get_data(report_filters): for row in job_cards: row.operating_cost = flt(row.hour_rate) * (flt(row.total_time_in_mins) / 60.0) - update_raw_material_cost(row, report_filters) data.append(row) return data @@ -47,12 +46,6 @@ def get_filters(report_filters, operations): return filters -def update_raw_material_cost(row, filters): - row.rm_cost = 0.0 - for data in frappe.get_all("Job Card Item", fields = ["amount"], - filters={"parent": row.name, "docstatus": 1}): - row.rm_cost += data.amount - def get_columns(filters): return [ { @@ -60,7 +53,7 @@ def get_columns(filters): "fieldtype": "Link", "fieldname": "name", "options": "Job Card", - "width": "100" + "width": "120" }, { "label": _("Work Order"), @@ -112,18 +105,12 @@ def get_columns(filters): "label": _("Operating Cost"), "fieldtype": "Currency", "fieldname": "operating_cost", - "width": "100" - }, - { - "label": _("Raw Material Cost"), - "fieldtype": "Currency", - "fieldname": "rm_cost", - "width": "100" + "width": "150" }, { "label": _("Total Time (in Mins)"), "fieldtype": "Float", "fieldname": "total_time_in_mins", - "width": "100" + "width": "150" } ] diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 9c4851ebb0e1..613f93cc3f3f 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -164,44 +164,32 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ this.price_list_rate(doc, cdt, cdn); }, - qty: function(doc, cdt, cdn) { - var item = frappe.get_doc(cdt, cdn); + qty(doc, cdt, cdn) { if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) { - frappe.model.round_floats_in(item, ["qty", "received_qty"]); - - if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "received_qty"])){ return } - - if(!item.rejected_qty && item.qty) { - item.received_qty = item.qty; - } - - frappe.model.round_floats_in(item, ["qty", "received_qty"]); - item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item)); - item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty); + this.calculate_received_qty(doc, cdt, cdn) } this._super(doc, cdt, cdn); }, - batch_no: function(doc, cdt, cdn) { - this._super(doc, cdt, cdn); + rejected_qty(doc, cdt, cdn) { + this.calculate_received_qty(doc, cdt, cdn) }, - received_qty: function(doc, cdt, cdn) { - this.calculate_accepted_qty(doc, cdt, cdn) - }, + calculate_received_qty(doc, cdt, cdn){ + var item = frappe.get_doc(cdt, cdn); + frappe.model.round_floats_in(item, ["qty", "rejected_qty"]); - rejected_qty: function(doc, cdt, cdn) { - this.calculate_accepted_qty(doc, cdt, cdn) - }, + if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["qty", "rejected_qty"])){ return } - calculate_accepted_qty: function(doc, cdt, cdn){ - var item = frappe.get_doc(cdt, cdn); - frappe.model.round_floats_in(item, ["received_qty", "rejected_qty"]); + let received_qty = flt(item.qty + item.rejected_qty, precision("received_qty", item)); + let received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(received_qty); - if(!doc.is_return && this.validate_negative_quantity(cdt, cdn, item, ["received_qty", "rejected_qty"])){ return } + frappe.model.set_value(cdt, cdn, "received_qty", received_qty); + frappe.model.set_value(cdt, cdn, "received_stock_qty", received_stock_qty); + }, - item.qty = flt(item.received_qty - item.rejected_qty, precision("qty", item)); - this.qty(doc, cdt, cdn); + batch_no(doc, cdt, cdn) { + super.batch_no(doc, cdt, cdn); }, validate_negative_quantity: function(cdt, cdn, item, fieldnames){ diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 97f9c02894a7..871f8145220f 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -81,6 +81,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ this.initialize_taxes(); this.determine_exclusive_rate(); this.calculate_net_total(); + this.calculate_shipping_charges(); this.calculate_taxes(); this.calculate_item_commission(); this.manipulate_grand_total_for_inclusive_tax(); @@ -273,8 +274,13 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ me.frm.doc.net_total += item.net_amount; me.frm.doc.base_net_total += item.base_net_amount; }); + }, + calculate_shipping_charges: function() { frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]); + if (frappe.meta.get_docfield(this.frm.doc.doctype, "shipping_rule", this.frm.doc.name)) { + this.shipping_rule(); + } }, add_taxes_from_item_tax_template: function(item_tax_map) { diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index e14f74408c6c..9763afa68ed4 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1065,16 +1065,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ return this.frm.call({ doc: this.frm.doc, method: "apply_shipping_rule", - callback: function(r) { - if(!r.exc) { - me.calculate_taxes_and_totals(); - } - } }).fail(() => this.frm.set_value('shipping_rule', '')); } - else { - me.calculate_taxes_and_totals(); - } }, set_margin_amount_based_on_currency: function(exchange_rate) { diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index e1cef614a22c..d57a79f1df00 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -750,9 +750,13 @@ frappe.form.link_formatters['Item'] = function(value, doc) { } frappe.form.link_formatters['Employee'] = function(value, doc) { - if(doc && doc.employee_name && doc.employee_name !== value) { - return value? value + ': ' + doc.employee_name: doc.employee_name; + if (doc && value && doc.employee_name && doc.employee_name !== value && doc.employee === value) { + return value + ': ' + doc.employee_name; + } else if (!value && doc.doctype && doc.employee_name) { + // format blank value in child table + return doc.employee; } else { + // if value is blank in report view or project name and name are the same, return as is return value; } } diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 38e17705a6a5..f76cb88dfe05 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -202,28 +202,18 @@ def get_regional_address_details(party_details, doctype, company): if doctype in ("Sales Invoice", "Delivery Note", "Sales Order"): master_doctype = "Sales Taxes and Charges Template" - get_tax_template_based_on_category(master_doctype, company, party_details) - - if party_details.get('taxes_and_charges'): - return party_details - - if not party_details.company_gstin: - return party_details + tax_template_by_category = get_tax_template_based_on_category(master_doctype, company, party_details) elif doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt"): master_doctype = "Purchase Taxes and Charges Template" - get_tax_template_based_on_category(master_doctype, company, party_details) + tax_template_by_category = get_tax_template_based_on_category(master_doctype, company, party_details) - if party_details.get('taxes_and_charges'): - return party_details - - if not party_details.supplier_gstin: - return party_details + if tax_template_by_category: + party_details.get['taxes_and_charges'] = tax_template_by_category + return if not party_details.place_of_supply: return party_details - if not party_details.company_gstin: return party_details - if ((doctype in ("Sales Invoice", "Delivery Note", "Sales Order") and party_details.company_gstin and party_details.company_gstin[:2] != party_details.place_of_supply[:2]) or (doctype in ("Purchase Invoice", "Purchase Order", "Purchase Receipt") and party_details.supplier_gstin and party_details.supplier_gstin[:2] != party_details.place_of_supply[:2])): @@ -233,6 +223,7 @@ def get_regional_address_details(party_details, doctype, company): if not default_tax: return party_details + party_details["taxes_and_charges"] = default_tax party_details.taxes = get_taxes_and_charges(master_doctype, default_tax) @@ -264,9 +255,7 @@ def get_tax_template_based_on_category(master_doctype, company, party_details): default_tax = frappe.db.get_value(master_doctype, {'company': company, 'tax_category': party_details.get('tax_category')}, 'name') - if default_tax: - party_details["taxes_and_charges"] = default_tax - party_details.taxes = get_taxes_and_charges(master_doctype, default_tax) + return default_tax def get_tax_template(master_doctype, company, is_inter_state, state_code): tax_categories = frappe.get_all('Tax Category', fields = ['name', 'is_inter_state', 'gst_state'], diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index b33c6e5c6185..25ac327a2fa1 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -133,6 +133,12 @@ frappe.ui.form.on("Customer", { frm.trigger("get_customer_group_details"); }, __('Actions')); + if (cint(frappe.defaults.get_default("enable_common_party_accounting"))) { + frm.add_custom_button(__('Link with Supplier'), function () { + frm.trigger('show_party_link_dialog'); + }, __('Actions')); + } + // indicator erpnext.utils.set_party_dashboard_indicators(frm); @@ -157,6 +163,43 @@ frappe.ui.form.on("Customer", { } }); + }, + show_party_link_dialog: function(frm) { + const dialog = new frappe.ui.Dialog({ + title: __('Select a Supplier'), + fields: [{ + fieldtype: 'Link', label: __('Supplier'), + options: 'Supplier', fieldname: 'supplier', reqd: 1 + }], + primary_action: function({ supplier }) { + frappe.call({ + method: 'erpnext.accounts.doctype.party_link.party_link.create_party_link', + args: { + primary_role: 'Customer', + primary_party: frm.doc.name, + secondary_party: supplier + }, + freeze: true, + callback: function() { + dialog.hide(); + frappe.msgprint({ + message: __('Successfully linked to Supplier'), + alert: true + }); + }, + error: function() { + dialog.hide(); + frappe.msgprint({ + message: __('Linking to Supplier Failed. Please try again.'), + title: __('Linking Failed'), + indicator: 'red' + }); + } + }); + }, + primary_action_label: __('Create Link') + }); + dialog.show(); } }); diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index 46405fbaf789..ad4f6416dbaf 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -19,7 +19,11 @@ from frappe.utils import cint, cstr, flt, get_formatted_email, today from frappe.utils.user import get_users_with_role -from erpnext.accounts.party import get_dashboard_info, validate_party_accounts +from erpnext.accounts.party import ( # noqa + get_dashboard_info, + get_timeline_data, + validate_party_accounts, +) from erpnext.utilities.transaction_base import TransactionBase diff --git a/erpnext/selling/page/point_of_sale/pos_item_cart.js b/erpnext/selling/page/point_of_sale/pos_item_cart.js index 9d8338e5fed0..465297c41a23 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_cart.js +++ b/erpnext/selling/page/point_of_sale/pos_item_cart.js @@ -502,6 +502,7 @@ erpnext.PointOfSale.ItemCart = class { if (taxes.length) { const currency = this.events.get_frm().doc.currency; const taxes_html = taxes.map(t => { + if (t.tax_amount_after_discount_amount == 0.0) return; const description = /[0-9]+/.test(t.description) ? t.description : `${t.description} @ ${t.rate}%`; return `
${description}
diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 8f7e84063c02..527b953b8518 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -204,42 +204,6 @@ erpnext.company.set_chart_of_accounts_options = function(doc) { } } -cur_frm.cscript.change_abbr = function() { - var dialog = new frappe.ui.Dialog({ - title: "Replace Abbr", - fields: [ - {"fieldtype": "Data", "label": "New Abbreviation", "fieldname": "new_abbr", - "reqd": 1 }, - {"fieldtype": "Button", "label": "Update", "fieldname": "update"}, - ] - }); - - dialog.fields_dict.update.$input.click(function() { - var args = dialog.get_values(); - if(!args) return; - frappe.show_alert(__("Update in progress. It might take a while.")); - return frappe.call({ - method: "erpnext.setup.doctype.company.company.enqueue_replace_abbr", - args: { - "company": cur_frm.doc.name, - "old": cur_frm.doc.abbr, - "new": args.new_abbr - }, - callback: function(r) { - if(r.exc) { - frappe.msgprint(__("There were errors.")); - return; - } else { - cur_frm.set_value("abbr", args.new_abbr); - } - dialog.hide(); - cur_frm.refresh(); - }, - btn: this - }) - }); - dialog.show(); -} erpnext.company.setup_queries = function(frm) { $.each([ diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index e6ec496a65e7..e608ac5ddc5f 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -12,7 +12,6 @@ "details", "company_name", "abbr", - "change_abbr", "is_group", "cb0", "domain", @@ -125,13 +124,8 @@ "label": "Abbr", "oldfieldname": "abbr", "oldfieldtype": "Data", - "reqd": 1 - }, - { - "depends_on": "eval:!doc.__islocal && in_list(frappe.user_roles, \"System Manager\")", - "fieldname": "change_abbr", - "fieldtype": "Button", - "label": "Change Abbreviation" + "reqd": 1, + "set_only_once": 1 }, { "bold": 1, @@ -748,7 +742,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2021-05-12 16:51:08.187233", + "modified": "2021-05-14 16:51:08.187233", "modified_by": "Administrator", "module": "Setup", "name": "Company", diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 93f80db23cd9..1ad6dbda79bf 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -424,44 +424,6 @@ def validate_company_limit(self): frappe.throw('Lo sentimos, ha alcanzado el límite máximo de empresas para su suscripción. Puedes contactar a soporte para descubrir cómo añadir más empresas.', MaxCompaniesReachedError) -@frappe.whitelist() -def enqueue_replace_abbr(company, old, new): - kwargs = dict(queue="long", company=company, old=old, new=new) - frappe.enqueue('erpnext.setup.doctype.company.company.replace_abbr', **kwargs) - - -@frappe.whitelist() -def replace_abbr(company, old, new): - new = new.strip() - if not new: - frappe.throw(_("Abbr can not be blank or space")) - - frappe.only_for("System Manager") - - def _rename_record(doc): - parts = doc[0].rsplit(" - ", 1) - if len(parts) == 1 or parts[1].lower() == old.lower(): - frappe.rename_doc(dt, doc[0], parts[0] + " - " + new, force=True) - - def _rename_records(dt): - # rename is expensive so let's be economical with memory usage - doc = (d for d in frappe.db.sql("select name from `tab%s` where company=%s" % (dt, '%s'), company)) - for d in doc: - _rename_record(d) - try: - frappe.db.auto_commit_on_many_writes = 1 - frappe.db.set_value("Company", company, "abbr", new) - for dt in ["Warehouse", "Account", "Cost Center", "Department", - "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template"]: - _rename_records(dt) - frappe.db.commit() - - except Exception: - frappe.log_error(title=_('Abbreviation Rename Error')) - finally: - frappe.db.auto_commit_on_many_writes = 0 - - def get_name_with_abbr(name, company): company_abbr = frappe.get_cached_value('Company', company, "abbr") parts = name.split(" - ") diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 26d448b8285c..8bd6b34e45a7 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -503,7 +503,8 @@ def set_missing_values(source, target): "field_map": { "name": "material_request_item", "parent": "material_request", - "uom": "stock_uom" + "uom": "stock_uom", + "job_card_item": "job_card_item" }, "postprocess": update_item, "condition": lambda doc: doc.ordered_qty < doc.stock_qty diff --git a/erpnext/stock/doctype/material_request_item/material_request_item.json b/erpnext/stock/doctype/material_request_item/material_request_item.json index 25bbbbd4b3ed..2bad42a0ebb9 100644 --- a/erpnext/stock/doctype/material_request_item/material_request_item.json +++ b/erpnext/stock/doctype/material_request_item/material_request_item.json @@ -52,6 +52,7 @@ "sales_order_item", "production_plan", "material_request_plan_item", + "job_card_item", "col_break4", "expense_account", "section_break_46", @@ -444,16 +445,25 @@ { "fieldname": "qty_info_col_break", "fieldtype": "Column Break" + }, + { + "fieldname": "job_card_item", + "fieldtype": "Data", + "hidden": 1, + "no_copy": 1, + "print_hide": 1, + "label": "Job Card Item" } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-10-02 11:44:36.553064", + "modified": "2021-11-03 14:40:24.409826", "modified_by": "Administrator", "module": "Stock", "name": "Material Request Item", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index c61304098f4b..9a9cb360e105 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -12,31 +12,67 @@ import erpnext from erpnext.accounts.doctype.account.test_account import get_inventory_account +from erpnext.controllers.buying_controller import QtyMismatchError from erpnext.stock.doctype.item.test_item import create_item, make_item from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice from erpnext.stock.doctype.serial_no.serial_no import SerialNoDuplicateError, get_serial_nos from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.stock_ledger import SerialNoExistsInFutureTransaction +from erpnext.tests.utils import ERPNextTestCase class TestPurchaseReceipt(unittest.TestCase): def setUp(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) + def test_purchase_receipt_received_qty(self): + """ + 1. Test if received qty is validated against accepted + rejected + 2. Test if received qty is auto set on save + """ + pr = make_purchase_receipt( + qty=1, + rejected_qty=1, + received_qty=3, + item_code="_Test Item Home Desktop 200", + do_not_save=True + ) + self.assertRaises(QtyMismatchError, pr.save) + + pr.items[0].received_qty = 0 + pr.save() + self.assertEqual(pr.items[0].received_qty, 2) + + # teardown + pr.delete() + def test_reverse_purchase_receipt_sle(self): pr = make_purchase_receipt(qty=0.5, item_code="_Test Item Home Desktop 200") - sl_entry = frappe.db.get_all("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", - "voucher_no": pr.name}, ['actual_qty']) + sl_entry = frappe.db.get_all( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name + }, + ['actual_qty'] + ) self.assertEqual(len(sl_entry), 1) self.assertEqual(sl_entry[0].actual_qty, 0.5) pr.cancel() - sl_entry_cancelled = frappe.db.get_all("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", - "voucher_no": pr.name}, ['actual_qty'], order_by='creation') + sl_entry_cancelled = frappe.db.get_all( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name + }, + ['actual_qty'], + order_by='creation' + ) self.assertEqual(len(sl_entry_cancelled), 2) self.assertEqual(sl_entry_cancelled[1].actual_qty, -0.5) @@ -62,8 +98,15 @@ def test_make_purchase_invoice(self): }] }).insert() - template = frappe.db.get_value('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice') - old_template_in_supplier = frappe.db.get_value("Supplier", "_Test Supplier", "payment_terms") + template = frappe.db.get_value( + "Payment Terms Template", + "_Test Payment Terms Template For Purchase Invoice" + ) + old_template_in_supplier = frappe.db.get_value( + "Supplier", + "_Test Supplier", + "payment_terms" + ) frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", template) pr = make_purchase_receipt(do_not_save=True) @@ -89,30 +132,59 @@ def test_make_purchase_invoice(self): # teardown pi.delete() # draft PI pr.cancel() - frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", old_template_in_supplier) - frappe.get_doc('Payment Terms Template', '_Test Payment Terms Template For Purchase Invoice').delete() + frappe.db.set_value( + "Supplier", + "_Test Supplier", + "payment_terms", + old_template_in_supplier + ) + frappe.get_doc( + "Payment Terms Template", + "_Test Payment Terms Template For Purchase Invoice" + ).delete() def test_purchase_receipt_no_gl_entry(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') - - existing_bin_qty, existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item", - "warehouse": "_Test Warehouse - _TC"}, ["actual_qty", "stock_value"]) + existing_bin_qty, existing_bin_stock_value = frappe.db.get_value( + "Bin", + { + "item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC" + }, + ["actual_qty", "stock_value"] + ) if existing_bin_qty < 0: - make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=abs(existing_bin_qty)) + make_stock_entry( + item_code="_Test Item", + target="_Test Warehouse - _TC", + qty=abs(existing_bin_qty) + ) pr = make_purchase_receipt() - stock_value_difference = frappe.db.get_value("Stock Ledger Entry", - {"voucher_type": "Purchase Receipt", "voucher_no": pr.name, - "item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}, "stock_value_difference") + stock_value_difference = frappe.db.get_value( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name, + "item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC" + }, + "stock_value_difference" + ) self.assertEqual(stock_value_difference, 250) - current_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item", - "warehouse": "_Test Warehouse - _TC"}, "stock_value") + current_bin_stock_value = frappe.db.get_value( + "Bin", + { + "item_code": "_Test Item", + "warehouse": "_Test Warehouse - _TC" + }, + "stock_value" + ) self.assertEqual(current_bin_stock_value, existing_bin_stock_value + 250) self.assertFalse(get_gl_entries("Purchase Receipt", pr.name)) @@ -134,13 +206,17 @@ def test_batched_serial_no_purchase(self): pr = make_purchase_receipt(item_code=item.name, qty=5, rate=500) - self.assertTrue(frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name})) + self.assertTrue( + frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name}) + ) pr.load_from_db() batch_no = pr.items[0].batch_no pr.cancel() - self.assertFalse(frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name})) + self.assertFalse( + frappe.db.get_value('Batch', {'item': item.name, 'reference_name': pr.name}) + ) self.assertFalse(frappe.db.get_all('Serial No', {'batch_no': batch_no})) def test_duplicate_serial_nos(self): @@ -159,42 +235,78 @@ def test_duplicate_serial_nos(self): pr = make_purchase_receipt(item_code=item.name, qty=2, rate=500) pr.load_from_db() - serial_nos = frappe.db.get_value('Stock Ledger Entry', - {'voucher_type': 'Purchase Receipt', 'voucher_no': pr.name, 'item_code': item.name}, 'serial_no') + serial_nos = frappe.db.get_value( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": pr.name, + "item_code": item.name + }, + "serial_no" + ) serial_nos = get_serial_nos(serial_nos) self.assertEquals(get_serial_nos(pr.items[0].serial_no), serial_nos) # Then tried to receive same serial nos in difference company - pr_different_company = make_purchase_receipt(item_code=item.name, qty=2, rate=500, - serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True, - warehouse = 'Stores - _TC1') + pr_different_company = make_purchase_receipt( + item_code=item.name, + qty=2, + rate=500, + serial_no='\n'.join(serial_nos), + company='_Test Company 1', + do_not_submit=True, + warehouse = 'Stores - _TC1' + ) self.assertRaises(SerialNoDuplicateError, pr_different_company.submit) # Then made delivery note to remove the serial nos from stock - dn = create_delivery_note(item_code=item.name, qty=2, rate = 1500, serial_no='\n'.join(serial_nos)) + dn = create_delivery_note( + item_code=item.name, + qty=2, + rate=1500, + serial_no='\n'.join(serial_nos) + ) dn.load_from_db() self.assertEquals(get_serial_nos(dn.items[0].serial_no), serial_nos) posting_date = add_days(today(), -3) # Try to receive same serial nos again in the same company with backdated. - pr1 = make_purchase_receipt(item_code=item.name, qty=2, rate=500, - posting_date=posting_date, serial_no='\n'.join(serial_nos), do_not_submit=True) + pr1 = make_purchase_receipt( + item_code=item.name, + qty=2, + rate=500, + posting_date=posting_date, + serial_no='\n'.join(serial_nos), + do_not_submit=True + ) self.assertRaises(SerialNoExistsInFutureTransaction, pr1.submit) # Try to receive same serial nos with different company with backdated. - pr2 = make_purchase_receipt(item_code=item.name, qty=2, rate=500, - posting_date=posting_date, serial_no='\n'.join(serial_nos), company='_Test Company 1', do_not_submit=True, - warehouse = 'Stores - _TC1') + pr2 = make_purchase_receipt( + item_code=item.name, + qty=2, + rate=500, + posting_date=posting_date, + serial_no='\n'.join(serial_nos), + company="_Test Company 1", + do_not_submit=True, + warehouse="Stores - _TC1" + ) self.assertRaises(SerialNoExistsInFutureTransaction, pr2.submit) # Receive the same serial nos after the delivery note posting date and time - make_purchase_receipt(item_code=item.name, qty=2, rate=500, serial_no='\n'.join(serial_nos)) + make_purchase_receipt( + item_code=item.name, + qty=2, + rate=500, + serial_no='\n'.join(serial_nos) + ) # Raise the error for backdated deliver note entry cancel self.assertRaises(SerialNoExistsInFutureTransaction, dn.cancel) @@ -237,11 +349,23 @@ def test_purchase_receipt_gl_entry(self): def test_subcontracting(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") - make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100) - make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC", - qty=100, basic_rate=100) - pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=500, is_subcontracted="Yes") + frappe.db.set_value( + "Buying Settings", None, + "backflush_raw_materials_of_subcontract_based_on", "BOM" + ) + + make_stock_entry( + item_code="_Test Item", qty=100, + target="_Test Warehouse 1 - _TC", basic_rate=100 + ) + make_stock_entry( + item_code="_Test Item Home Desktop 100", qty=100, + target="_Test Warehouse 1 - _TC", basic_rate=100 + ) + pr = make_purchase_receipt( + item_code="_Test FG Item", qty=10, + rate=500, is_subcontracted="Yes" + ) self.assertEqual(len(pr.get("supplied_items")), 2) rm_supp_cost = sum(d.amount for d in pr.get("supplied_items")) @@ -251,17 +375,33 @@ def test_subcontracting(self): def test_subcontracting_gle_fg_item_rate_zero(self): from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry - frappe.db.set_value("Buying Settings", None, "backflush_raw_materials_of_subcontract_based_on", "BOM") + frappe.db.set_value( + "Buying Settings", None, + "backflush_raw_materials_of_subcontract_based_on", "BOM" + ) - se1 = make_stock_entry(item_code="_Test Item", target="Work In Progress - TCP1", - qty=100, basic_rate=100, company="_Test Company with perpetual inventory") + se1 = make_stock_entry( + item_code="_Test Item", + target="Work In Progress - TCP1", + qty=100, basic_rate=100, + company="_Test Company with perpetual inventory" + ) - se2 = make_stock_entry(item_code="_Test Item Home Desktop 100", target="Work In Progress - TCP1", - qty=100, basic_rate=100, company="_Test Company with perpetual inventory") + se2 = make_stock_entry( + item_code="_Test Item Home Desktop 100", + target="Work In Progress - TCP1", + qty=100, basic_rate=100, + company="_Test Company with perpetual inventory" + ) - pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=0, is_subcontracted="Yes", - company="_Test Company with perpetual inventory", warehouse='Stores - TCP1', - supplier_warehouse='Work In Progress - TCP1') + pr = make_purchase_receipt( + item_code="_Test FG Item", + qty=10, rate=0, + is_subcontracted="Yes", + company="_Test Company with perpetual inventory", + warehouse="Stores - TCP1", + supplier_warehouse="Work In Progress - TCP1" + ) gl_entries = get_gl_entries("Purchase Receipt", pr.name) @@ -292,16 +432,30 @@ def test_subcontracting_over_receipt(self): item_code = "_Test Subcontracted FG Item 1" make_subcontracted_item(item_code=item_code) - po = create_purchase_order(item_code=item_code, qty=1, include_exploded_items=0, - is_subcontracted="Yes", supplier_warehouse="_Test Warehouse 1 - _TC") + po = create_purchase_order( + item_code=item_code, + qty=1, include_exploded_items=0, + is_subcontracted="Yes", + supplier_warehouse="_Test Warehouse 1 - _TC" + ) + + # stock raw materials in a warehouse before transfer + se1 = make_stock_entry( + target="_Test Warehouse - _TC", + item_code="Test Extra Item 1", + qty=10, basic_rate=100 + ) + se2 = make_stock_entry( + target="_Test Warehouse - _TC", + item_code="_Test FG Item", + qty=1, basic_rate=100 + ) + se3 = make_stock_entry( + target="_Test Warehouse - _TC", + item_code="Test Extra Item 2", + qty=1, basic_rate=100 + ) - #stock raw materials in a warehouse before transfer - se1 = make_stock_entry(target="_Test Warehouse - _TC", - item_code = "Test Extra Item 1", qty=10, basic_rate=100) - se2 = make_stock_entry(target="_Test Warehouse - _TC", - item_code = "_Test FG Item", qty=1, basic_rate=100) - se3 = make_stock_entry(target="_Test Warehouse - _TC", - item_code = "Test Extra Item 2", qty=1, basic_rate=100) rm_items = [ { "item_code": item_code, @@ -335,11 +489,17 @@ def test_subcontracting_over_receipt(self): def test_serial_no_supplier(self): pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1) - self.assertEqual(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"), - pr.supplier) + pr_row_1_serial_no = pr.get("items")[0].serial_no + + self.assertEqual( + frappe.db.get_value("Serial No", pr_row_1_serial_no, "supplier"), + pr.supplier + ) pr.cancel() - self.assertFalse(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "warehouse")) + self.assertFalse( + frappe.db.get_value("Serial No", pr_row_1_serial_no, "warehouse") + ) def test_rejected_serial_no(self): pr = frappe.copy_doc(test_records[0]) @@ -366,18 +526,33 @@ def test_rejected_serial_no(self): pr.cancel() def test_purchase_return_partial(self): - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", - warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1" + ) - return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", - warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", - is_return=1, return_against=pr.name, qty=-2, do_not_submit=1) + return_pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1", + is_return=1, + return_against=pr.name, + qty=-2, + do_not_submit=1 + ) return_pr.items[0].purchase_receipt_item = pr.items[0].name return_pr.submit() # check sle - outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", - "voucher_no": return_pr.name}, "outgoing_rate") + outgoing_rate = frappe.db.get_value( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": return_pr.name + }, + "outgoing_rate" + ) self.assertEqual(outgoing_rate, 50) @@ -441,11 +616,21 @@ def test_purchase_return_partial(self): pr.cancel() def test_purchase_return_full(self): - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", - supplier_warehouse = "Work in Progress - TCP1") + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1" + ) - return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", - supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, qty=-5, do_not_submit=1) + return_pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1", + is_return=1, + return_against=pr.name, + qty=-5, + do_not_submit=1 + ) return_pr.items[0].purchase_receipt_item = pr.items[0].name return_pr.submit() @@ -467,15 +652,41 @@ def test_purchase_return_for_rejected_qty(self): rejected_warehouse="_Test Rejected Warehouse - TCP1" if not frappe.db.exists("Warehouse", rejected_warehouse): - get_warehouse(company = "_Test Company with perpetual inventory", - abbr = " - TCP1", warehouse_name = "_Test Rejected Warehouse").name + get_warehouse( + company = "_Test Company with perpetual inventory", + abbr = " - TCP1", + warehouse_name = "_Test Rejected Warehouse" + ).name - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", received_qty=4, qty=2, rejected_warehouse=rejected_warehouse) + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1", + qty=2, + rejected_qty=2, + rejected_warehouse=rejected_warehouse + ) - return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, received_qty = -4, qty=-2, rejected_warehouse=rejected_warehouse) + return_pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1", + is_return=1, + return_against=pr.name, + qty=-2, + rejected_qty = -2, + rejected_warehouse=rejected_warehouse + ) - actual_qty = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", - "voucher_no": return_pr.name, 'warehouse': return_pr.items[0].rejected_warehouse}, "actual_qty") + actual_qty = frappe.db.get_value( + "Stock Ledger Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": return_pr.name, + "warehouse": return_pr.items[0].rejected_warehouse + }, + "actual_qty" + ) self.assertEqual(actual_qty, -2) @@ -500,8 +711,13 @@ def _check_serial_no_values(serial_no, field_values): "purchase_document_no": pr.name }) - return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1, - is_return=1, return_against=pr.name, serial_no=serial_no) + return_pr = make_purchase_receipt( + item_code="_Test Serialized Item With Series", + qty=-1, + is_return=1, + return_against=pr.name, + serial_no=serial_no + ) _check_serial_no_values(serial_no, { "warehouse": "", @@ -523,9 +739,21 @@ def test_purchase_return_for_multi_uom(self): }) row.db_update() - pr = make_purchase_receipt(item_code=item_code, qty=1, uom="Box", conversion_factor=1.0) - return_pr = make_purchase_receipt(item_code=item_code, qty=-10, uom="Unit", - stock_uom="Box", conversion_factor=0.1, is_return=1, return_against=pr.name) + pr = make_purchase_receipt( + item_code=item_code, + qty=1, + uom="Box", + conversion_factor=1.0 + ) + return_pr = make_purchase_receipt( + item_code=item_code, + qty=-10, + uom="Unit", + stock_uom="Box", + conversion_factor=0.1, + is_return=1, + return_against=pr.name + ) self.assertEqual(abs(return_pr.items[0].stock_qty), 1.0) @@ -541,13 +769,19 @@ def test_closed_purchase_receipt(self): pr.submit() update_purchase_receipt_status(pr.name, "Closed") - self.assertEqual(frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed") + self.assertEqual( + frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed" + ) pr.reload() pr.cancel() def test_pr_billing_status(self): - # PO -> PR1 -> PI and PO -> PI and PO -> PR2 + """Flow: + 1. PO -> PR1 -> PI + 2. PO -> PI + 3. PO -> PR2. + """ from erpnext.buying.doctype.purchase_order.purchase_order import ( make_purchase_invoice as make_purchase_invoice_from_po, ) @@ -611,21 +845,39 @@ def test_serial_no_against_purchase_receipt(self): pr_doc = make_purchase_receipt(item_code=item_code, qty=1, serial_no = serial_no) - self.assertEqual(serial_no, frappe.db.get_value("Serial No", - {"purchase_document_type": "Purchase Receipt", "purchase_document_no": pr_doc.name}, "name")) + self.assertEqual( + serial_no, + frappe.db.get_value( + "Serial No", + { + "purchase_document_type": "Purchase Receipt", + "purchase_document_no": pr_doc.name + }, + "name" + ) + ) pr_doc.cancel() - #check for the auto created serial nos + # check for the auto created serial nos item_code = "Test Auto Created Serial No" if not frappe.db.exists("Item", item_code): - item = make_item(item_code, dict(has_serial_no=1, serial_no_series="KLJL.###")) + make_item(item_code, dict(has_serial_no=1, serial_no_series="KLJL.###")) new_pr_doc = make_purchase_receipt(item_code=item_code, qty=1) serial_no = get_serial_nos(new_pr_doc.items[0].serial_no)[0] - self.assertEqual(serial_no, frappe.db.get_value("Serial No", - {"purchase_document_type": "Purchase Receipt", "purchase_document_no": new_pr_doc.name}, "name")) + self.assertEqual( + serial_no, + frappe.db.get_value( + "Serial No", + { + "purchase_document_type": "Purchase Receipt", + "purchase_document_no": new_pr_doc.name + }, + "name" + ) + ) new_pr_doc.cancel() @@ -701,8 +953,12 @@ def test_purchase_return_with_submitted_asset(self): def test_purchase_receipt_cost_center(self): from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center + cost_center = "_Test Cost Center for BS Account - TCP1" - create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company with perpetual inventory") + create_cost_center( + cost_center_name="_Test Cost Center for BS Account", + company="_Test Company with perpetual inventory" + ) if not frappe.db.exists('Location', 'Test Location'): frappe.get_doc({ @@ -710,10 +966,16 @@ def test_purchase_receipt_cost_center(self): 'location_name': 'Test Location' }).insert() - pr = make_purchase_receipt(cost_center=cost_center, company="_Test Company with perpetual inventory", - warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") + pr = make_purchase_receipt( + cost_center=cost_center, + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1" + ) - stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse) + stock_in_hand_account = get_inventory_account( + pr.company, pr.get("items")[0].warehouse + ) gl_entries = get_gl_entries("Purchase Receipt", pr.name) self.assertTrue(gl_entries) @@ -737,9 +999,16 @@ def test_purchase_receipt_cost_center_with_balance_sheet_account(self): 'doctype': 'Location', 'location_name': 'Test Location' }).insert() - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") - stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse) + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + supplier_warehouse = "Work in Progress - TCP1" + ) + + stock_in_hand_account = get_inventory_account( + pr.company, pr.get("items")[0].warehouse + ) gl_entries = get_gl_entries("Purchase Receipt", pr.name) self.assertTrue(gl_entries) @@ -767,7 +1036,11 @@ def test_make_purchase_invoice_from_pr_for_returned_qty(self): po = create_purchase_order() pr = create_pr_against_po(po.name) - pr1 = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-1, do_not_submit=True) + pr1 = make_purchase_receipt( + qty=-1, + is_return=1, return_against=pr.name, + do_not_submit=True + ) pr1.items[0].purchase_order = po.name pr1.items[0].purchase_order_item = po.items[0].name pr1.items[0].purchase_receipt_item = pr.items[0].name @@ -800,7 +1073,11 @@ def test_make_purchase_invoice_from_pr_with_returned_qty_duplicate_items(self): pi1.save() pi1.submit() - pr2 = make_purchase_receipt(is_return=1, return_against=pr1.name, qty=-2, do_not_submit=True) + pr2 = make_purchase_receipt( + qty=-2, + is_return=1, return_against=pr1.name, + do_not_submit=True + ) pr2.items[0].purchase_receipt_item = pr1.items[0].name pr2.submit() @@ -842,14 +1119,22 @@ def test_stock_transfer_from_purchase_receipt(self): pr1.cancel() def test_stock_transfer_from_purchase_receipt_with_valuation(self): - create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory", - properties={"account": '_Test Account Stock In Hand - TCP1'}) + create_warehouse( + "_Test Warehouse for Valuation", + company="_Test Company with perpetual inventory", + properties={"account": '_Test Account Stock In Hand - TCP1'} + ) - pr1 = make_purchase_receipt(warehouse = '_Test Warehouse for Valuation - TCP1', - company="_Test Company with perpetual inventory") + pr1 = make_purchase_receipt( + warehouse = '_Test Warehouse for Valuation - TCP1', + company="_Test Company with perpetual inventory" + ) - pr = make_purchase_receipt(company="_Test Company with perpetual inventory", - warehouse = "Stores - TCP1", do_not_save=1) + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse = "Stores - TCP1", + do_not_save=1 + ) pr.items[0].from_warehouse = '_Test Warehouse for Valuation - TCP1' pr.supplier_warehouse = '' @@ -931,10 +1216,24 @@ def test_subcontracted_pr_for_multi_transfer_batches(self): } rm_items = [ - {"item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 3","item_name":"_Test Item", - "qty":300,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[0].name}, - {"item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 3","item_name":"_Test Item", - "qty":200,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[0].name} + { + "item_code":item_code, + "rm_item_code":"Sub Contracted Raw Material 3", + "item_name":"_Test Item", + "qty":300, + "warehouse":"_Test Warehouse - _TC", + "stock_uom":"Nos", + "name": po.supplied_items[0].name + }, + { + "item_code":item_code, + "rm_item_code":"Sub Contracted Raw Material 3", + "item_name":"_Test Item", + "qty":200, + "warehouse":"_Test Warehouse - _TC", + "stock_uom":"Nos", + "name": po.supplied_items[0].name + } ] rm_item_string = json.dumps(rm_items) @@ -944,8 +1243,14 @@ def test_subcontracted_pr_for_multi_transfer_batches(self): se.items[1].batch_no = ste2.items[0].batch_no se.submit() - supplied_qty = frappe.db.get_value("Purchase Order Item Supplied", - {"parent": po.name, "rm_item_code": "Sub Contracted Raw Material 3"}, "supplied_qty") + supplied_qty = frappe.db.get_value( + "Purchase Order Item Supplied", + { + "parent": po.name, + "rm_item_code": "Sub Contracted Raw Material 3" + }, + "supplied_qty" + ) self.assertEqual(supplied_qty, 500.00) @@ -1017,10 +1322,18 @@ def test_service_item_purchase_with_perpetual_inventory(self): company = '_Test Company with perpetual inventory' service_item = '_Test Non Stock Item' - before_test_value = frappe.db.get_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items') - frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', 1) + before_test_value = frappe.db.get_value( + 'Company', company, 'enable_perpetual_inventory_for_non_stock_items' + ) + frappe.db.set_value( + 'Company', company, + 'enable_perpetual_inventory_for_non_stock_items', 1 + ) srbnb_account = 'Stock Received But Not Billed - TCP1' - frappe.db.set_value('Company', company, 'service_received_but_not_billed', srbnb_account) + frappe.db.set_value( + 'Company', company, + 'service_received_but_not_billed', srbnb_account + ) pr = make_purchase_receipt( company=company, item=service_item, @@ -1052,7 +1365,10 @@ def test_service_item_purchase_with_perpetual_inventory(self): self.assertEqual(len(item_one_gl_entry), 1) self.assertEqual(len(item_two_gl_entry), 1) - frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value) + frappe.db.set_value( + 'Company', company, + 'enable_perpetual_inventory_for_non_stock_items', before_test_value + ) def test_payment_terms_are_fetched_when_creating_purchase_invoice(self): from erpnext.accounts.doctype.payment_entry.test_payment_entry import ( @@ -1195,8 +1511,8 @@ def make_purchase_receipt(**args): pr.return_against = args.return_against pr.apply_putaway_rule = args.apply_putaway_rule qty = args.qty or 5 - received_qty = args.received_qty or qty - rejected_qty = args.rejected_qty or flt(received_qty) - flt(qty) + rejected_qty = args.rejected_qty or 0 + received_qty = args.received_qty or flt(rejected_qty) + flt(qty) item_code = args.item or args.item_code or "_Test Item" uom = args.uom or frappe.db.get_value("Item", item_code, "stock_uom") or "_Test UOM" @@ -1219,9 +1535,12 @@ def make_purchase_receipt(**args): if args.get_multiple_items: pr.items = [] - for item in get_items(warehouse= args.warehouse, cost_center = args.cost_center or frappe.get_cached_value('Company', pr.company, 'cost_center')): - pr.append("items", item) + company_cost_center = frappe.get_cached_value('Company', pr.company, 'cost_center') + cost_center = args.cost_center or company_cost_center + + for item in get_items(warehouse=args.warehouse, cost_center=cost_center): + pr.append("items", item) if args.get_taxes_and_charges: for tax in get_taxes(): diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 3efa66e02ed4..30ea1c3cadc2 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -197,6 +197,7 @@ }, { "bold": 1, + "default": "0", "fieldname": "received_qty", "fieldtype": "Float", "label": "Received Quantity", @@ -204,6 +205,7 @@ "oldfieldtype": "Currency", "print_hide": 1, "print_width": "100px", + "read_only": 1, "reqd": 1, "width": "100px" }, @@ -219,8 +221,10 @@ "width": "100px" }, { + "columns": 1, "fieldname": "rejected_qty", "fieldtype": "Float", + "in_list_view": 1, "label": "Rejected Quantity", "oldfieldname": "rejected_qty", "oldfieldtype": "Currency", @@ -327,7 +331,7 @@ }, { "bold": 1, - "columns": 3, + "columns": 2, "fieldname": "rate", "fieldtype": "Currency", "in_list_view": 1, @@ -543,6 +547,7 @@ "fieldname": "stock_qty", "fieldtype": "Float", "label": "Accepted Qty in Stock UOM", + "no_copy": 1, "oldfieldname": "stock_qty", "oldfieldtype": "Currency", "print_hide": 1, @@ -882,7 +887,9 @@ "fieldname": "received_stock_qty", "fieldtype": "Float", "label": "Received Qty in Stock UOM", - "print_hide": 1 + "no_copy": 1, + "print_hide": 1, + "read_only": 1 }, { "depends_on": "eval: doc.uom != doc.stock_uom", @@ -969,10 +976,11 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-09-01 16:02:40.338597", + "modified": "2021-11-15 15:46:10.591600", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "quick_entry": 1, diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json index a800bf870130..f1ef96a2dbad 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json @@ -64,7 +64,7 @@ "in_standard_filter": 1, "label": "Status", "no_copy": 1, - "options": "Queued\nIn Progress\nCompleted\nFailed", + "options": "Queued\nIn Progress\nCompleted\nSkipped\nFailed", "read_only": 1 }, { @@ -177,7 +177,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-07-22 18:59:43.057878", + "modified": "2021-11-24 02:18:10.524560", "modified_by": "Administrator", "module": "Stock", "name": "Repost Item Valuation", @@ -242,4 +242,4 @@ ], "sort_field": "modified", "sort_order": "DESC" -} \ No newline at end of file +} diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 8f3ae23dcefc..4faf308243ba 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -2,8 +2,6 @@ # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -from __future__ import unicode_literals - import frappe from frappe import _ from frappe.model.document import Document @@ -21,7 +19,7 @@ class RepostItemValuation(Document): def validate(self): - self.set_status() + self.set_status(write=False) self.reset_field_values() self.set_company() @@ -29,23 +27,24 @@ def reset_field_values(self): if self.based_on == 'Transaction': self.item_code = None self.warehouse = None - else: - self.voucher_type = None - self.voucher_no = None def set_company(self): - if self.voucher_type and self.voucher_no: + if self.based_on == "Transaction": self.company = frappe.get_cached_value(self.voucher_type, self.voucher_no, "company") elif self.warehouse: self.company = frappe.get_cached_value("Warehouse", self.warehouse, "company") - def set_status(self, status=None): + def set_status(self, status=None, write=True): + status = status or self.status if not status: - status = 'Queued' - self.db_set('status', status) + self.status = 'Queued' + else: + self.status = status + if write: + self.db_set('status', self.status) def on_submit(self): - if not frappe.flags.in_test: + if not frappe.flags.in_test or self.flags.dont_run_in_test: return frappe.enqueue(repost, timeout=1800, queue='long', @@ -53,9 +52,42 @@ def on_submit(self): @frappe.whitelist() def restart_reposting(self): - self.set_status('Queued') - frappe.enqueue(repost, timeout=1800, queue='long', - job_name='repost_sle', now=True, doc=self) + self.set_status('Queued', write=False) + self.current_index = 0 + self.distinct_item_and_warehouse = None + self.items_to_be_repost = None + self.db_update() + + def deduplicate_similar_repost(self): + """ Deduplicate similar reposts based on item-warehouse-posting combination.""" + if self.based_on != "Item and Warehouse": + return + + filters = { + "item_code": self.item_code, + "warehouse": self.warehouse, + "name": self.name, + "posting_date": self.posting_date, + "posting_time": self.posting_time, + } + + frappe.db.sql(""" + update `tabRepost Item Valuation` + set status = 'Skipped' + WHERE item_code = %(item_code)s + and warehouse = %(warehouse)s + and name != %(name)s + and TIMESTAMP(posting_date, posting_time) > TIMESTAMP(%(posting_date)s, %(posting_time)s) + and docstatus = 1 + and status = 'Queued' + and based_on = 'Item and Warehouse' + """, + filters + ) + +def on_doctype_update(): + frappe.db.add_index("Repost Item Valuation", ["warehouse", "item_code"], "item_warehouse") + def repost(doc): try: @@ -132,8 +164,10 @@ def repost_entries(): riv_entries = get_repost_item_valuation_entries() for row in riv_entries: - doc = frappe.get_cached_doc('Repost Item Valuation', row.name) - repost(doc) + doc = frappe.get_doc('Repost Item Valuation', row.name) + if doc.status in ('Queued', 'In Progress'): + doc.deduplicate_similar_repost() + repost(doc) riv_entries = get_repost_item_valuation_entries() if riv_entries: diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py index c086f938b5d4..de793163fdbb 100644 --- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -5,6 +5,8 @@ import frappe +from erpnext.controllers.stock_controller import create_item_wise_repost_entries +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import ( in_configured_timeslot, ) @@ -70,3 +72,69 @@ def test_repost_time_slot(self): in_configured_timeslot(repost_settings, case.get("current_time")), msg=f"Exepcted false from : {case}", ) + + def test_create_item_wise_repost_item_valuation_entries(self): + pr = make_purchase_receipt( + company="_Test Company with perpetual inventory", + warehouse="Stores - TCP1", + get_multiple_items=True, + ) + + rivs = create_item_wise_repost_entries(pr.doctype, pr.name) + self.assertGreaterEqual(len(rivs), 2) + self.assertIn("_Test Item", [d.item_code for d in rivs]) + + for riv in rivs: + self.assertEqual(riv.company, "_Test Company with perpetual inventory") + self.assertEqual(riv.warehouse, "Stores - TCP1") + + def test_deduplication(self): + def _assert_status(doc, status): + doc.load_from_db() + self.assertEqual(doc.status, status) + + riv_args = frappe._dict( + doctype="Repost Item Valuation", + item_code="_Test Item", + warehouse="_Test Warehouse - _TC", + based_on="Item and Warehouse", + voucher_type="Sales Invoice", + voucher_no="SI-1", + posting_date="2021-01-02", + posting_time="00:01:00", + ) + + # new repost without any duplicates + riv1 = frappe.get_doc(riv_args) + riv1.flags.dont_run_in_test = True + riv1.submit() + _assert_status(riv1, "Queued") + self.assertEqual(riv1.voucher_type, "Sales Invoice") # traceability + self.assertEqual(riv1.voucher_no, "SI-1") + + # newer than existing duplicate - riv1 + riv2 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-03"})) + riv2.flags.dont_run_in_test = True + riv2.submit() + riv1.deduplicate_similar_repost() + _assert_status(riv2, "Skipped") + + # older than exisitng duplicate - riv1 + riv3 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-01"})) + riv3.flags.dont_run_in_test = True + riv3.submit() + riv3.deduplicate_similar_repost() + _assert_status(riv3, "Queued") + _assert_status(riv1, "Skipped") + + # unrelated reposts, shouldn't do anything to others. + riv4 = frappe.get_doc(riv_args.update({"warehouse": "Stores - _TC"})) + riv4.flags.dont_run_in_test = True + riv4.submit() + riv4.deduplicate_similar_repost() + _assert_status(riv4, "Queued") + _assert_status(riv3, "Queued") + + # to avoid breaking other tests accidentaly + riv4.set_status("Skipped") + riv3.set_status("Skipped") diff --git a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json index 24740590037a..0facae8d3b88 100644 --- a/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json +++ b/erpnext/stock/doctype/stock_reposting_settings/stock_reposting_settings.json @@ -1,6 +1,7 @@ { "actions": [], "allow_rename": 1, + "beta": 1, "creation": "2021-10-01 10:56:30.814787", "doctype": "DocType", "editable_grid": 1, @@ -10,7 +11,8 @@ "limit_reposting_timeslot", "start_time", "end_time", - "limits_dont_apply_on" + "limits_dont_apply_on", + "item_based_reposting" ], "fields": [ { @@ -44,12 +46,18 @@ "fieldname": "limit_reposting_timeslot", "fieldtype": "Check", "label": "Limit timeslot for Stock Reposting" + }, + { + "default": "0", + "fieldname": "item_based_reposting", + "fieldtype": "Check", + "label": "Use Item based reposting" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-10-01 11:27:28.981594", + "modified": "2021-11-02 01:22:45.155841", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reposting Settings", diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 6c6f3f6e0b3c..1ab8cce517c9 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -306,7 +306,7 @@ def get_basic_details(args, item, overwrite_warehouse=True): "warehouse": warehouse, "income_account": get_default_income_account(args, item_defaults, item_group_defaults, brand_defaults), "expense_account": expense_account or get_default_expense_account(args, item_defaults, item_group_defaults, brand_defaults) , - "discount_account": None or get_default_discount_account(args, item_defaults), + "discount_account": get_default_discount_account(args, item_defaults), "cost_center": get_default_cost_center(args, item_defaults, item_group_defaults, brand_defaults), 'has_serial_no': item.has_serial_no, 'has_batch_no': item.has_batch_no, @@ -324,6 +324,7 @@ def get_basic_details(args, item, overwrite_warehouse=True): "net_rate": 0.0, "net_amount": 0.0, "discount_percentage": 0.0, + "discount_amount": 0.0, "supplier": get_default_supplier(args, item_defaults, item_group_defaults, brand_defaults), "update_stock": args.get("update_stock") if args.get('doctype') in ['Sales Invoice', 'Purchase Invoice'] else 0, "delivered_by_supplier": item.delivered_by_supplier if args.get("doctype") in ["Sales Order", "Sales Invoice"] else 0, diff --git a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.html b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.html index de7e38e7d3e0..adab47864038 100644 --- a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.html +++ b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.html @@ -1,19 +1,19 @@ {% for d in data %}
-
+ -
+ -
+
{{ d.stock_capacity }}
-
+
{{ d.actual_qty }}
-
+
-
+
{{ d.percent_occupied }}%
{% if can_write %} -
-
{% endif %}
diff --git a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js index 47ae86b9e213..6a5906299bc1 100644 --- a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js +++ b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary.js @@ -4,7 +4,7 @@ frappe.pages['warehouse-capacity-summary'].on_page_load = function(wrapper) { title: 'Warehouse Capacity Summary', single_column: true }); - page.set_secondary_action('Refresh', () => page.capacity_dashboard.refresh(), 'octicon octicon-sync'); + page.set_secondary_action('Refresh', () => page.capacity_dashboard.refresh(), 'refresh'); page.start = 0; page.company_field = page.add_field({ diff --git a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary_header.html b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary_header.html index 7ac5e6403022..1183ad4496e7 100644 --- a/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary_header.html +++ b/erpnext/stock/page/warehouse_capacity_summary/warehouse_capacity_summary_header.html @@ -1,18 +1,18 @@
-
+
Warehouse
-
+
Item
-
+
Stock Capacity
-
+
Balance Stock Qty
-
+
% Occupied
diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.js b/erpnext/stock/report/total_stock_summary/total_stock_summary.js index 90648f1b2499..88054aaea736 100644 --- a/erpnext/stock/report/total_stock_summary/total_stock_summary.js +++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.js @@ -10,23 +10,8 @@ frappe.query_reports["Total Stock Summary"] = { "fieldtype": "Select", "width": "80", "reqd": 1, - "options": ["", "Warehouse", "Company"], - "change": function() { - let group_by = frappe.query_report.get_filter_value("group_by") - let company_filter = frappe.query_report.get_filter("company") - if (group_by == "Company") { - company_filter.df.reqd = 0; - company_filter.df.hidden = 1; - frappe.query_report.set_filter_value("company", ""); - company_filter.refresh(); - } - else { - company_filter.df.reqd = 1; - company_filter.df.hidden = 0; - company_filter.refresh(); - frappe.query_report.refresh(); - } - } + "options": ["Warehouse", "Company"], + "default": "Warehouse", }, { "fieldname": "company", @@ -34,8 +19,9 @@ frappe.query_reports["Total Stock Summary"] = { "fieldtype": "Link", "width": "80", "options": "Company", + "reqd": 1, "default": frappe.defaults.get_user_default("Company"), - "reqd": 1 + "depends_on": "eval: doc.group_by != 'Company'", }, ] } diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.py b/erpnext/stock/report/total_stock_summary/total_stock_summary.py index 779b5aabdbc8..f6c450c13b9d 100644 --- a/erpnext/stock/report/total_stock_summary/total_stock_summary.py +++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.py @@ -8,8 +8,8 @@ def execute(filters=None): - if not filters: filters = {} - validate_filters(filters) + if not filters: + filters = {} columns = get_columns() stock = get_total_stock(filters) @@ -54,9 +54,3 @@ def get_total_stock(filters): ON warehouse.name = ledger.warehouse WHERE ledger.actual_qty != 0 %s""" % (columns, conditions)) - -def validate_filters(filters): - if filters.get("group_by") == 'Company' and \ - filters.get("company"): - - frappe.throw(_("Please set Company filter blank if Group By is 'Company'")) diff --git a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py index 6cb375136661..cf08d5797604 100644 --- a/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py +++ b/erpnext/stock/report/warehouse_wise_item_balance_age_and_value/warehouse_wise_item_balance_age_and_value.py @@ -48,8 +48,8 @@ def execute(filters=None): item_balance.setdefault((item, item_map[item]["item_group"]), []) total_stock_value = 0.00 for wh in warehouse_list: - row += [qty_dict.bal_qty] if wh.name in warehouse else [0.00] - total_stock_value += qty_dict.bal_val if wh.name in warehouse else 0.00 + row += [qty_dict.bal_qty] if wh.name == warehouse else [0.00] + total_stock_value += qty_dict.bal_val if wh.name == warehouse else 0.00 item_balance[(item, item_map[item]["item_group"])].append(row) item_value.setdefault((item, item_map[item]["item_group"]),[]) diff --git a/erpnext/translations/es.csv b/erpnext/translations/es.csv index 8e178fe1689f..1a5fb32aec27 100644 --- a/erpnext/translations/es.csv +++ b/erpnext/translations/es.csv @@ -10885,6 +10885,17 @@ Scheduling,Programación, Limit timeslot for Stock Reposting,Limitar la franja horaria para el traspaso de acciones, Limits don't apply on,Los límites no se aplican el, Note: This Training Event is mandatory,Nota: Esta capacitación es obligatoria, +Link with Customer,Vincular con cliente, +Select a Customer,Seleccione un cliente, +Successfully linked to Customer,Vinculado con éxito al cliente, +Linking to Customer Failed. Please try again.,La vinculación con el cliente ha fallado. Inténtelo de nuevo., +Linking Failed,Fallo en la vinculación, +Create Link,Crear vínculo, +Link with Supplier,Vincular con proveedor, +Select a Supplier,Seleccione un proveedor, +Successfully linked to Supplier,Vinculado con éxito al proveedor, +Linking to Supplier Failed. Please try again.,La vinculación con el proveedor ha fallado. Inténtelo de nuevo., +Payment Terms Status for Sales Order,Estado de pago de ordenes de venta, Notes:,Notas:, Quotations:,Cotizaciones:, Grand Total,Total, @@ -10892,4 +10903,4 @@ Transfer Asset,Transferir Activo, Scrap Asset,Desechar Activo, Sell Asset,Vender Activo, Restore Asset,Restaurar Activo, -View General Ledger,Ver Balance General, +View General Ledger,Ver Balance General, \ No newline at end of file