@@ -255,20 +255,90 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends (
255255 }
256256
257257 toggle_get_items ( ) {
258- // Show buttons only when pos view is inactive and not is_return
259- if (
260- cint ( this . frm . doc . docstatus == 0 ) &&
261- this . frm . page . current_view_name !== "pos" &&
262- ! this . frm . doc . is_return
263- ) {
258+ const buttons = [ "Sales Order" , "Quotation" , "Timesheet" , "Delivery Note" ] ;
259+
260+ buttons . forEach ( ( label ) => {
261+ this . frm . remove_custom_button ( label , "Get Items From" ) ;
262+ } ) ;
263+
264+ if ( cint ( this . frm . doc . docstatus ) !== 0 || this . frm . page . current_view_name === "pos" ) {
265+ return ;
266+ }
267+
268+ if ( ! this . frm . doc . is_return ) {
264269 this . frm . cscript . sales_order_btn ( ) ;
265- this . frm . cscript . delivery_note_btn ( ) ;
266270 this . frm . cscript . quotation_btn ( ) ;
267- } else {
268- [ "Sales Order" , "Quotation" , "Timesheet" ] . forEach ( ( label ) => {
269- this . frm . remove_custom_button ( label , "Get Items From" ) ;
270- } ) ;
271+ this . frm . cscript . timesheet_btn ( ) ;
271272 }
273+
274+ this . frm . cscript . delivery_note_btn ( ) ;
275+ }
276+
277+ timesheet_btn ( ) {
278+ var me = this ;
279+
280+ me . frm . add_custom_button (
281+ __ ( "Timesheet" ) ,
282+ function ( ) {
283+ let d = new frappe . ui . Dialog ( {
284+ title : __ ( "Fetch Timesheet" ) ,
285+ fields : [
286+ {
287+ label : __ ( "From" ) ,
288+ fieldname : "from_time" ,
289+ fieldtype : "Date" ,
290+ reqd : 1 ,
291+ } ,
292+ {
293+ label : __ ( "Item Code" ) ,
294+ fieldname : "item_code" ,
295+ fieldtype : "Link" ,
296+ options : "Item" ,
297+ get_query : ( ) => {
298+ return {
299+ query : "erpnext.controllers.queries.item_query" ,
300+ filters : {
301+ is_sales_item : 1 ,
302+ customer : me . frm . doc . customer ,
303+ has_variants : 0 ,
304+ } ,
305+ } ;
306+ } ,
307+ } ,
308+ {
309+ fieldtype : "Column Break" ,
310+ fieldname : "col_break_1" ,
311+ } ,
312+ {
313+ label : __ ( "To" ) ,
314+ fieldname : "to_time" ,
315+ fieldtype : "Date" ,
316+ reqd : 1 ,
317+ } ,
318+ {
319+ label : __ ( "Project" ) ,
320+ fieldname : "project" ,
321+ fieldtype : "Link" ,
322+ options : "Project" ,
323+ default : me . frm . doc . project ,
324+ } ,
325+ ] ,
326+ primary_action : function ( ) {
327+ const data = d . get_values ( ) ;
328+ me . frm . events . add_timesheet_data ( me . frm , {
329+ from_time : data . from_time ,
330+ to_time : data . to_time ,
331+ project : data . project ,
332+ item_code : data . item_code ,
333+ } ) ;
334+ d . hide ( ) ;
335+ } ,
336+ primary_action_label : __ ( "Get Timesheets" ) ,
337+ } ) ;
338+ d . show ( ) ;
339+ } ,
340+ __ ( "Get Items From" )
341+ ) ;
272342 }
273343
274344 sales_order_btn ( ) {
@@ -1082,71 +1152,6 @@ frappe.ui.form.on("Sales Invoice", {
10821152 } ,
10831153
10841154 refresh : function ( frm ) {
1085- if ( frm . doc . docstatus === 0 && ! frm . doc . is_return ) {
1086- frm . add_custom_button (
1087- __ ( "Timesheet" ) ,
1088- function ( ) {
1089- let d = new frappe . ui . Dialog ( {
1090- title : __ ( "Fetch Timesheet" ) ,
1091- fields : [
1092- {
1093- label : __ ( "From" ) ,
1094- fieldname : "from_time" ,
1095- fieldtype : "Date" ,
1096- reqd : 1 ,
1097- } ,
1098- {
1099- label : __ ( "Item Code" ) ,
1100- fieldname : "item_code" ,
1101- fieldtype : "Link" ,
1102- options : "Item" ,
1103- get_query : ( ) => {
1104- return {
1105- query : "erpnext.controllers.queries.item_query" ,
1106- filters : {
1107- is_sales_item : 1 ,
1108- customer : frm . doc . customer ,
1109- has_variants : 0 ,
1110- } ,
1111- } ;
1112- } ,
1113- } ,
1114- {
1115- fieldtype : "Column Break" ,
1116- fieldname : "col_break_1" ,
1117- } ,
1118- {
1119- label : __ ( "To" ) ,
1120- fieldname : "to_time" ,
1121- fieldtype : "Date" ,
1122- reqd : 1 ,
1123- } ,
1124- {
1125- label : __ ( "Project" ) ,
1126- fieldname : "project" ,
1127- fieldtype : "Link" ,
1128- options : "Project" ,
1129- default : frm . doc . project ,
1130- } ,
1131- ] ,
1132- primary_action : function ( ) {
1133- const data = d . get_values ( ) ;
1134- frm . events . add_timesheet_data ( frm , {
1135- from_time : data . from_time ,
1136- to_time : data . to_time ,
1137- project : data . project ,
1138- item_code : data . item_code ,
1139- } ) ;
1140- d . hide ( ) ;
1141- } ,
1142- primary_action_label : __ ( "Get Timesheets" ) ,
1143- } ) ;
1144- d . show ( ) ;
1145- } ,
1146- __ ( "Get Items From" )
1147- ) ;
1148- }
1149-
11501155 if ( frm . doc . is_debit_note ) {
11511156 frm . set_df_property ( "return_against" , "label" , __ ( "Adjustment Against" ) ) ;
11521157 }
0 commit comments