mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
Merge branch 'develop' into SCR-SCRAP-ITEMS
This commit is contained in:
@@ -10,14 +10,91 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
frm.ignore_doctypes_on_cancel_all = ['Serial and Batch Bundle'];
|
||||
frm.get_field('supplied_items').grid.cannot_add_rows = true;
|
||||
frm.get_field('supplied_items').grid.only_sortable();
|
||||
frm.trigger('set_queries');
|
||||
},
|
||||
|
||||
refresh: (frm) => {
|
||||
if (frm.doc.docstatus > 0) {
|
||||
frm.add_custom_button(__('Stock Ledger'), () => {
|
||||
frappe.route_options = {
|
||||
voucher_no: frm.doc.name,
|
||||
from_date: frm.doc.posting_date,
|
||||
to_date: moment(frm.doc.modified).format('YYYY-MM-DD'),
|
||||
company: frm.doc.company,
|
||||
show_cancelled_entries: frm.doc.docstatus === 2
|
||||
}
|
||||
frappe.set_route('query-report', 'Stock Ledger');
|
||||
}, __('View'));
|
||||
|
||||
frm.add_custom_button(__('Accounting Ledger'), () => {
|
||||
frappe.route_options = {
|
||||
voucher_no: frm.doc.name,
|
||||
from_date: frm.doc.posting_date,
|
||||
to_date: moment(frm.doc.modified).format('YYYY-MM-DD'),
|
||||
company: frm.doc.company,
|
||||
group_by: 'Group by Voucher (Consolidated)',
|
||||
show_cancelled_entries: frm.doc.docstatus === 2
|
||||
}
|
||||
frappe.set_route('query-report', 'General Ledger');
|
||||
}, __('View'));
|
||||
}
|
||||
|
||||
if (!frm.doc.is_return && frm.doc.docstatus === 1 && frm.doc.per_returned < 100) {
|
||||
frm.add_custom_button(__('Subcontract Return'), () => {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_subcontract_return',
|
||||
frm: frm
|
||||
});
|
||||
}, __('Create'));
|
||||
frm.page.set_inner_btn_group_as_primary(__('Create'));
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus === 0) {
|
||||
frm.add_custom_button(__('Subcontracting Order'), () => {
|
||||
if (!frm.doc.supplier) {
|
||||
frappe.throw({
|
||||
title: __('Mandatory'),
|
||||
message: __('Please Select a Supplier')
|
||||
});
|
||||
}
|
||||
|
||||
erpnext.utils.map_current_doc({
|
||||
method: 'erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order.make_subcontracting_receipt',
|
||||
source_doctype: 'Subcontracting Order',
|
||||
target: frm,
|
||||
setters: {
|
||||
supplier: frm.doc.supplier,
|
||||
},
|
||||
get_query_filters: {
|
||||
docstatus: 1,
|
||||
per_received: ['<', 100],
|
||||
company: frm.doc.company
|
||||
}
|
||||
});
|
||||
}, __('Get Items From'));
|
||||
|
||||
frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', 'read_only', frm.doc.__onload && frm.doc.__onload.backflush_based_on === 'BOM');
|
||||
}
|
||||
|
||||
frm.trigger('setup_quality_inspection');
|
||||
},
|
||||
|
||||
set_warehouse: (frm) => {
|
||||
set_warehouse_in_children(frm.doc.items, 'warehouse', frm.doc.set_warehouse);
|
||||
},
|
||||
|
||||
rejected_warehouse: (frm) => {
|
||||
set_warehouse_in_children(frm.doc.items, 'rejected_warehouse', frm.doc.rejected_warehouse);
|
||||
},
|
||||
|
||||
set_queries: (frm) => {
|
||||
frm.set_query('set_warehouse', () => {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query('rejected_warehouse', () => {
|
||||
@@ -26,7 +103,7 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query('supplier_warehouse', () => {
|
||||
@@ -35,7 +112,7 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
company: frm.doc.company,
|
||||
is_group: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query('warehouse', 'items', () => ({
|
||||
@@ -56,7 +133,7 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
return {
|
||||
query: 'erpnext.controllers.queries.get_expense_account',
|
||||
filters: { 'company': frm.doc.company }
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
frm.set_query('batch_no', 'items', (doc, cdt, cdn) => {
|
||||
@@ -96,7 +173,7 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
'item_code': row.doc.rm_item_code,
|
||||
'voucher_type': frm.doc.doctype,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let batch_no_field = frm.get_docfield('items', 'batch_no');
|
||||
@@ -105,80 +182,15 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
||||
return {
|
||||
'item': row.doc.item_code
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
refresh: (frm) => {
|
||||
if (frm.doc.docstatus > 0) {
|
||||
frm.add_custom_button(__('Stock Ledger'), () => {
|
||||
frappe.route_options = {
|
||||
voucher_no: frm.doc.name,
|
||||
from_date: frm.doc.posting_date,
|
||||
to_date: moment(frm.doc.modified).format('YYYY-MM-DD'),
|
||||
company: frm.doc.company,
|
||||
show_cancelled_entries: frm.doc.docstatus === 2
|
||||
};
|
||||
frappe.set_route('query-report', 'Stock Ledger');
|
||||
}, __('View'));
|
||||
|
||||
frm.add_custom_button(__('Accounting Ledger'), () => {
|
||||
frappe.route_options = {
|
||||
voucher_no: frm.doc.name,
|
||||
from_date: frm.doc.posting_date,
|
||||
to_date: moment(frm.doc.modified).format('YYYY-MM-DD'),
|
||||
company: frm.doc.company,
|
||||
group_by: 'Group by Voucher (Consolidated)',
|
||||
show_cancelled_entries: frm.doc.docstatus === 2
|
||||
};
|
||||
frappe.set_route('query-report', 'General Ledger');
|
||||
}, __('View'));
|
||||
setup_quality_inspection: (frm) => {
|
||||
if (!frm.is_new() && frm.doc.docstatus === 0 && !frm.doc.is_return) {
|
||||
let transaction_controller = new erpnext.TransactionController({ frm: frm });
|
||||
transaction_controller.setup_quality_inspection();
|
||||
}
|
||||
|
||||
if (!frm.doc.is_return && frm.doc.docstatus == 1 && frm.doc.per_returned < 100) {
|
||||
frm.add_custom_button(__('Subcontract Return'), () => {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: 'erpnext.subcontracting.doctype.subcontracting_receipt.subcontracting_receipt.make_subcontract_return',
|
||||
frm: frm
|
||||
});
|
||||
}, __('Create'));
|
||||
frm.page.set_inner_btn_group_as_primary(__('Create'));
|
||||
}
|
||||
|
||||
if (frm.doc.docstatus == 0) {
|
||||
frm.add_custom_button(__('Subcontracting Order'), () => {
|
||||
if (!frm.doc.supplier) {
|
||||
frappe.throw({
|
||||
title: __('Mandatory'),
|
||||
message: __('Please Select a Supplier')
|
||||
});
|
||||
}
|
||||
|
||||
erpnext.utils.map_current_doc({
|
||||
method: 'erpnext.subcontracting.doctype.subcontracting_order.subcontracting_order.make_subcontracting_receipt',
|
||||
source_doctype: 'Subcontracting Order',
|
||||
target: frm,
|
||||
setters: {
|
||||
supplier: frm.doc.supplier,
|
||||
},
|
||||
get_query_filters: {
|
||||
docstatus: 1,
|
||||
per_received: ['<', 100],
|
||||
company: frm.doc.company
|
||||
}
|
||||
});
|
||||
}, __('Get Items From'));
|
||||
|
||||
frm.fields_dict.supplied_items.grid.update_docfield_property('consumed_qty', 'read_only', frm.doc.__onload && frm.doc.__onload.backflush_based_on === 'BOM');
|
||||
}
|
||||
},
|
||||
|
||||
set_warehouse: (frm) => {
|
||||
set_warehouse_in_children(frm.doc.items, 'warehouse', frm.doc.set_warehouse);
|
||||
},
|
||||
|
||||
rejected_warehouse: (frm) => {
|
||||
set_warehouse_in_children(frm.doc.items, 'rejected_warehouse', frm.doc.rejected_warehouse);
|
||||
},
|
||||
|
||||
get_scrap_items: (frm) => {
|
||||
@@ -235,7 +247,7 @@ frappe.ui.form.on('Subcontracting Receipt Item', {
|
||||
|
||||
items_remove: (frm) => {
|
||||
set_missing_values(frm);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Subcontracting Receipt Supplied Item', {
|
||||
@@ -247,7 +259,7 @@ frappe.ui.form.on('Subcontracting Receipt Supplied Item', {
|
||||
let set_warehouse_in_children = (child_table, warehouse_field, warehouse) => {
|
||||
let transaction_controller = new erpnext.TransactionController();
|
||||
transaction_controller.autofill_warehouse(child_table, warehouse_field, warehouse);
|
||||
};
|
||||
}
|
||||
|
||||
let set_missing_values = (frm) => {
|
||||
frappe.call({
|
||||
@@ -257,4 +269,4 @@ let set_missing_values = (frm) => {
|
||||
if (!r.exc) frm.refresh();
|
||||
},
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -47,6 +47,9 @@ class SubcontractingReceipt(SubcontractingController):
|
||||
self.reset_supplied_items()
|
||||
self.validate_posting_time()
|
||||
|
||||
if not self.get("is_return"):
|
||||
self.validate_inspection()
|
||||
|
||||
if getdate(self.posting_date) > getdate(nowdate()):
|
||||
frappe.throw(_("Posting Date cannot be future date"))
|
||||
|
||||
|
||||
@@ -567,6 +567,64 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
||||
self.assertEqual(rm_item.rate, 100)
|
||||
self.assertEqual(rm_item.amount, rm_item.consumed_qty * rm_item.rate)
|
||||
|
||||
def test_quality_inspection_for_subcontracting_receipt(self):
|
||||
from erpnext.stock.doctype.quality_inspection.test_quality_inspection import (
|
||||
create_quality_inspection,
|
||||
)
|
||||
|
||||
set_backflush_based_on("BOM")
|
||||
fg_item = "Subcontracted Item SA1"
|
||||
service_items = [
|
||||
{
|
||||
"warehouse": "_Test Warehouse - _TC",
|
||||
"item_code": "Subcontracted Service Item 1",
|
||||
"qty": 5,
|
||||
"rate": 100,
|
||||
"fg_item": fg_item,
|
||||
"fg_item_qty": 5,
|
||||
},
|
||||
]
|
||||
sco = get_subcontracting_order(service_items=service_items)
|
||||
rm_items = get_rm_items(sco.supplied_items)
|
||||
itemwise_details = make_stock_in_entry(rm_items=rm_items)
|
||||
make_stock_transfer_entry(
|
||||
sco_no=sco.name,
|
||||
rm_items=rm_items,
|
||||
itemwise_details=copy.deepcopy(itemwise_details),
|
||||
)
|
||||
scr1 = make_subcontracting_receipt(sco.name)
|
||||
scr1.save()
|
||||
|
||||
# Enable `Inspection Required before Purchase` in Item Master
|
||||
frappe.db.set_value("Item", fg_item, "inspection_required_before_purchase", 1)
|
||||
|
||||
# ValidationError should be raised as Quality Inspection is not created/linked
|
||||
self.assertRaises(frappe.ValidationError, scr1.submit)
|
||||
|
||||
qa = create_quality_inspection(
|
||||
reference_type="Subcontracting Receipt",
|
||||
reference_name=scr1.name,
|
||||
inspection_type="Incoming",
|
||||
item_code=fg_item,
|
||||
)
|
||||
scr1.reload()
|
||||
self.assertEqual(scr1.items[0].quality_inspection, qa.name)
|
||||
|
||||
# SCR should be submitted successfully as Quality Inspection is set
|
||||
scr1.submit()
|
||||
qa.cancel()
|
||||
scr1.reload()
|
||||
scr1.cancel()
|
||||
|
||||
scr2 = make_subcontracting_receipt(sco.name)
|
||||
scr2.save()
|
||||
|
||||
# Disable `Inspection Required before Purchase` in Item Master
|
||||
frappe.db.set_value("Item", fg_item, "inspection_required_before_purchase", 0)
|
||||
|
||||
# ValidationError should not be raised as `Inspection Required before Purchase` is disabled
|
||||
scr2.submit()
|
||||
|
||||
|
||||
def make_return_subcontracting_receipt(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
Reference in New Issue
Block a user