diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index bfeeb75a642..e8fba1e26b4 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -69,6 +69,7 @@ class AssetCapitalization(StockController): def on_submit(self): self.update_stock_ledger() self.make_gl_entries() + self.repost_future_sle_and_gle() self.update_target_asset() def on_cancel(self): @@ -82,6 +83,7 @@ class AssetCapitalization(StockController): self.cancel_target_asset() self.update_stock_ledger() self.make_gl_entries() + self.repost_future_sle_and_gle() self.restore_consumed_asset_items() def on_trash(self): diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index aa7dfbd90d6..521149215da 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -174,7 +174,7 @@ erpnext.buying.BuyingController = class BuyingController extends erpnext.Transac } qty(doc, cdt, cdn) { - if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && (doc.update_stock || doc.is_return))) { + if ((doc.doctype == "Purchase Receipt") || (doc.doctype == "Purchase Invoice" && doc.update_stock)) { this.calculate_received_qty(doc, cdt, cdn) } super.qty(doc, cdt, cdn); diff --git a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py index 2b4d0754759..5919c21fcbf 100644 --- a/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py +++ b/erpnext/setup/doctype/transaction_deletion_record/transaction_deletion_record.py @@ -190,35 +190,42 @@ class TransactionDeletionRecord(Document): """Delete addresses to which leads are linked""" self.validate_doc_status() if not self.delete_leads_and_addresses: - leads = frappe.get_all("Lead", filters={"company": self.company}) - leads = ["'%s'" % row.get("name") for row in leads] + leads = frappe.db.get_all("Lead", filters={"company": self.company}, pluck="name") addresses = [] if leads: - addresses = frappe.db.sql_list( - """select parent from `tabDynamic Link` where link_name - in ({leads})""".format(leads=",".join(leads)) + addresses = frappe.db.get_all( + "Dynamic Link", filters={"link_name": ("in", leads)}, pluck="parent" ) - if addresses: addresses = ["%s" % frappe.db.escape(addr) for addr in addresses] - frappe.db.sql( - """delete from `tabAddress` where name in ({addresses}) and - name not in (select distinct dl1.parent from `tabDynamic Link` dl1 - inner join `tabDynamic Link` dl2 on dl1.parent=dl2.parent - and dl1.link_doctype<>dl2.link_doctype)""".format(addresses=",".join(addresses)) - ) + address = qb.DocType("Address") + dl1 = qb.DocType("Dynamic Link") + dl2 = qb.DocType("Dynamic Link") - frappe.db.sql( - """delete from `tabDynamic Link` where link_doctype='Lead' - and parenttype='Address' and link_name in ({leads})""".format(leads=",".join(leads)) - ) + qb.from_(address).delete().where( + (address.name.isin(addresses)) + & ( + address.name.notin( + qb.from_(dl1) + .join(dl2) + .on((dl1.parent == dl2.parent) & (dl1.link_doctype != dl2.link_doctype)) + .select(dl1.parent) + .distinct() + ) + ) + ).run() + + dynamic_link = qb.DocType("Dynamic Link") + qb.from_(dynamic_link).delete().where( + (dynamic_link.link_doctype == "Lead") + & (dynamic_link.parenttype == "Address") + & (dynamic_link.link_name.isin(leads)) + ).run() + + customer = qb.DocType("Customer") + qb.update(customer).set(customer.lead_name, None).where(customer.lead_name.isin(leads)).run() - frappe.db.sql( - """update `tabCustomer` set lead_name=NULL where lead_name in ({leads})""".format( - leads=",".join(leads) - ) - ) self.db_set("delete_leads_and_addresses", 1) self.enqueue_task(task="Reset Company Values") diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index feb2844aec0..7213b86b405 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -49,6 +49,9 @@ class QualityInspection(Document): child = self.append("readings", {}) child.update(d) child.status = "Accepted" + child.parameter_group = frappe.get_value( + "Quality Inspection Parameter", d.specification, "parameter_group" + ) @frappe.whitelist() def get_quality_inspection_template(self): diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 90d5c3201e6..9dfd12acc2c 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -209,7 +209,7 @@ class SerialNo(StockController): OR serial_no like %s ) ORDER BY - posting_date desc, posting_time desc, creation desc""", + posting_datetime desc, creation desc""", ( self.item_code, self.company, diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 78599572759..3366309f38c 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1314,17 +1314,38 @@ class StockEntry(StockController): @frappe.whitelist() def get_item_details(self, args=None, for_update=False): - item = frappe.db.sql( - """select i.name, i.stock_uom, i.description, i.image, i.item_name, i.item_group, - i.has_batch_no, i.sample_quantity, i.has_serial_no, i.allow_alternative_item, - id.expense_account, id.buying_cost_center - from `tabItem` i LEFT JOIN `tabItem Default` id ON i.name=id.parent and id.company=%s - where i.name=%s - and i.disabled=0 - and (i.end_of_life is null or i.end_of_life<'1900-01-01' or i.end_of_life > %s)""", - (self.company, args.get("item_code"), nowdate()), - as_dict=1, + item = frappe.qb.DocType("Item") + item_default = frappe.qb.DocType("Item Default") + + query = ( + frappe.qb.from_(item) + .left_join(item_default) + .on((item.name == item_default.parent) & (item_default.company == self.company)) + .select( + item.name, + item.stock_uom, + item.description, + item.image, + item.item_name, + item.item_group, + item.has_batch_no, + item.sample_quantity, + item.has_serial_no, + item.allow_alternative_item, + item_default.expense_account, + item_default.buying_cost_center, + ) + .where( + (item.name == args.get("item_code")) + & (item.disabled == 0) + & ( + (item.end_of_life.isnull()) + | (item.end_of_life < "1900-01-01") + | (item.end_of_life > nowdate()) + ) + ) ) + item = query.run(as_dict=True) if not item: frappe.throw( @@ -1369,6 +1390,11 @@ class StockEntry(StockController): if self.purpose == "Material Issue": ret["expense_account"] = item.get("expense_account") or item_group_defaults.get("expense_account") + if self.purpose == "Manufacture": + ret["expense_account"] = frappe.get_cached_value( + "Company", self.company, "stock_adjustment_account" + ) + for company_field, field in { "stock_adjustment_account": "expense_account", "cost_center": "cost_center",