2015-03-03 09:25:30 +00:00
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2013-08-05 09:29:54 +00:00
// License: GNU General Public License v3. See license.txt
2012-02-23 07:05:32 +00:00
2011-06-08 09:07:15 +00:00
2015-02-23 06:28:15 +00:00
cur _frm . cscript . tax _table = "Sales Taxes and Charges" ;
2016-04-21 13:30:34 +00:00
{ % include 'erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.js' % }
2015-02-23 06:28:15 +00:00
2014-01-02 06:17:23 +00:00
2014-09-12 07:39:41 +00:00
cur _frm . email _field = "contact_email" ;
2016-04-29 11:52:42 +00:00
frappe . provide ( "erpnext.selling" ) ;
2013-05-24 13:55:01 +00:00
erpnext . selling . SellingController = class SellingController extends erpnext . TransactionController {
2016-05-19 12:52:49 +00:00
setup ( ) {
super . setup ( ) ;
}
2013-07-11 13:43:58 +00:00
onload ( ) {
super . onload ( ) ;
this . setup _queries ( ) ;
2017-11-17 09:01:09 +00:00
this . frm . set _query ( 'shipping_rule' , function ( ) {
return {
filters : {
"shipping_rule_type" : "Selling"
}
} ;
} ) ;
2021-07-13 09:28:17 +00:00
}
2014-04-11 11:21:27 +00:00
2013-07-11 13:43:58 +00:00
setup _queries ( ) {
2013-07-04 11:43:53 +00:00
var me = this ;
2014-04-11 11:21:27 +00:00
2017-01-13 13:23:11 +00:00
$ . each ( [ [ "customer" , "customer" ] ,
2014-04-11 11:21:27 +00:00
[ "lead" , "lead" ] ] ,
2013-07-29 07:58:37 +00:00
function ( i , opts ) {
2014-04-11 11:21:27 +00:00
if ( me . frm . fields _dict [ opts [ 0 ] ] )
2013-07-29 07:58:37 +00:00
me . frm . set _query ( opts [ 0 ] , erpnext . queries [ opts [ 1 ] ] ) ;
} ) ;
2014-04-11 11:21:27 +00:00
2017-01-13 13:23:11 +00:00
me . frm . set _query ( 'contact_person' , erpnext . queries . contact _query ) ;
me . frm . set _query ( 'customer_address' , erpnext . queries . address _query ) ;
me . frm . set _query ( 'shipping_address_name' , erpnext . queries . address _query ) ;
2021-12-21 07:05:44 +00:00
me . frm . set _query ( 'dispatch_address_name' , erpnext . queries . dispatch _address _query ) ;
2017-01-13 13:23:11 +00:00
2022-06-02 08:27:54 +00:00
erpnext . accounts . dimensions . setup _dimension _filters ( me . frm , me . frm . doctype ) ;
2013-07-04 11:43:53 +00:00
2013-08-09 12:41:35 +00:00
if ( this . frm . fields _dict . selling _price _list ) {
this . frm . set _query ( "selling_price_list" , function ( ) {
2014-01-07 13:07:38 +00:00
return { filters : { selling : 1 } } ;
2013-07-26 06:02:02 +00:00
} ) ;
}
2014-04-11 11:21:27 +00:00
2019-07-04 17:16:16 +00:00
if ( this . frm . fields _dict . tc _name ) {
this . frm . set _query ( "tc_name" , function ( ) {
return { filters : { selling : 1 } } ;
} ) ;
}
2014-12-26 07:45:21 +00:00
if ( ! this . frm . fields _dict [ "items" ] ) {
2013-07-04 11:43:53 +00:00
return ;
}
2014-04-11 11:21:27 +00:00
2014-12-26 07:45:21 +00:00
if ( this . frm . fields _dict [ "items" ] . grid . get _field ( 'item_code' ) ) {
this . frm . set _query ( "item_code" , "items" , function ( ) {
2013-07-11 13:43:58 +00:00
return {
2016-08-16 06:02:08 +00:00
query : "erpnext.controllers.queries.item_query" ,
2022-05-16 06:44:07 +00:00
filters : { 'is_sales_item' : 1 , 'customer' : cur _frm . doc . customer , 'has_variants' : 0 }
2013-07-11 13:43:58 +00:00
}
2013-07-04 11:43:53 +00:00
} ) ;
}
2014-04-11 11:21:27 +00:00
2016-11-22 17:46:40 +00:00
if ( this . frm . fields _dict [ "packed_items" ] &&
this . frm . fields _dict [ "packed_items" ] . grid . get _field ( 'batch_no' ) ) {
2016-11-18 06:46:22 +00:00
this . frm . set _query ( "batch_no" , "packed_items" , function ( doc , cdt , cdn ) {
return me . set _query _for _batch ( doc , cdt , cdn )
} ) ;
}
2020-01-06 10:04:15 +00:00
if ( this . frm . fields _dict [ "items" ] . grid . get _field ( 'item_code' ) ) {
this . frm . set _query ( "item_tax_template" , "items" , function ( doc , cdt , cdn ) {
return me . set _query _for _item _tax _template ( doc , cdt , cdn )
} ) ;
}
2016-11-18 06:46:22 +00:00
}
2013-08-01 12:49:51 +00:00
refresh ( ) {
super . refresh ( ) ;
2021-08-19 08:11:10 +00:00
2017-01-16 07:36:07 +00:00
frappe . dynamic _link = { doc : this . frm . doc , fieldname : 'customer' , doctype : 'Customer' }
2017-01-13 13:23:11 +00:00
2014-04-11 11:21:27 +00:00
this . frm . toggle _display ( "customer_name" ,
2013-12-09 10:59:04 +00:00
( this . frm . doc . customer _name && this . frm . doc . customer _name !== this . frm . doc . customer ) ) ;
2021-09-02 11:14:59 +00:00
2015-04-16 12:25:35 +00:00
this . toggle _editable _price _list _rate ( ) ;
2013-07-04 07:20:52 +00:00
}
2014-04-11 11:21:27 +00:00
2013-05-24 13:55:01 +00:00
customer ( ) {
2014-05-28 07:19:20 +00:00
var me = this ;
2018-08-01 12:14:34 +00:00
erpnext . utils . get _party _details ( this . frm , null , null , function ( ) {
me . apply _price _list ( ) ;
} ) ;
2013-05-24 13:55:01 +00:00
}
2014-04-11 11:21:27 +00:00
2013-07-15 07:34:33 +00:00
customer _address ( ) {
2014-01-02 06:17:23 +00:00
erpnext . utils . get _address _display ( this . frm , "customer_address" ) ;
2018-12-28 20:49:11 +00:00
erpnext . utils . set _taxes _from _address ( this . frm , "customer_address" , "customer_address" , "shipping_address_name" ) ;
2013-07-15 07:34:33 +00:00
}
2014-04-11 11:21:27 +00:00
2014-02-19 12:13:24 +00:00
shipping _address _name ( ) {
erpnext . utils . get _address _display ( this . frm , "shipping_address_name" , "shipping_address" ) ;
2018-12-28 20:49:11 +00:00
erpnext . utils . set _taxes _from _address ( this . frm , "shipping_address_name" , "customer_address" , "shipping_address_name" ) ;
2014-02-19 12:13:24 +00:00
}
2014-04-11 11:21:27 +00:00
2021-07-13 09:28:17 +00:00
dispatch _address _name ( ) {
erpnext . utils . get _address _display ( this . frm , "dispatch_address_name" , "dispatch_address" ) ;
}
2014-05-28 07:19:20 +00:00
sales _partner ( ) {
this . apply _pricing _rule ( ) ;
}
campaign ( ) {
this . apply _pricing _rule ( ) ;
}
2013-08-09 12:41:35 +00:00
selling _price _list ( ) {
2014-07-01 12:15:15 +00:00
this . apply _price _list ( ) ;
2018-02-13 11:41:06 +00:00
this . set _dynamic _labels ( ) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2014-02-10 12:24:04 +00:00
discount _percentage ( doc , cdt , cdn ) {
2019-03-18 09:04:19 +00:00
var item = frappe . get _doc ( cdt , cdn ) ;
item . discount _amount = 0.0 ;
this . apply _discount _on _item ( doc , cdt , cdn , 'discount_percentage' ) ;
}
discount _amount ( doc , cdt , cdn ) {
2019-07-04 10:26:34 +00:00
if ( doc . name === cdn ) {
return ;
}
2019-04-05 14:05:02 +00:00
var item = frappe . get _doc ( cdt , cdn ) ;
item . discount _percentage = 0.0 ;
2019-03-18 09:04:19 +00:00
this . apply _discount _on _item ( doc , cdt , cdn , 'discount_amount' ) ;
}
apply _discount _on _item ( doc , cdt , cdn , field ) {
2014-03-27 08:47:33 +00:00
var item = frappe . get _doc ( cdt , cdn ) ;
2014-02-10 12:24:04 +00:00
if ( ! item . price _list _rate ) {
2019-03-18 09:04:19 +00:00
item [ field ] = 0.0 ;
2013-05-28 11:53:36 +00:00
} else {
2014-02-10 12:24:04 +00:00
this . price _list _rate ( doc , cdt , cdn ) ;
2013-05-28 11:53:36 +00:00
}
2016-02-26 12:32:55 +00:00
this . set _gross _profit ( item ) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
commission _rate ( ) {
this . calculate _commission ( ) ;
}
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
total _commission ( ) {
2021-11-30 12:24:18 +00:00
frappe . model . round _floats _in ( this . frm . doc , [ "amount_eligible_for_commission" , "total_commission" ] ) ;
2014-04-11 11:21:27 +00:00
2021-11-30 12:24:18 +00:00
const { amount _eligible _for _commission } = this . frm . doc ;
if ( ! amount _eligible _for _commission ) return ;
this . frm . set _value (
"commission_rate" , flt (
this . frm . doc . total _commission * 100.0 / amount _eligible _for _commission
)
) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
allocated _percentage ( doc , cdt , cdn ) {
2014-03-27 08:47:33 +00:00
var sales _person = frappe . get _doc ( cdt , cdn ) ;
2013-05-21 14:05:06 +00:00
if ( sales _person . allocated _percentage ) {
2018-09-25 13:38:16 +00:00
2013-05-21 14:05:06 +00:00
sales _person . allocated _percentage = flt ( sales _person . allocated _percentage ,
precision ( "allocated_percentage" , sales _person ) ) ;
2018-09-25 13:38:16 +00:00
2021-11-30 12:24:18 +00:00
sales _person . allocated _amount = flt ( this . frm . doc . amount _eligible _for _commission *
2014-04-11 11:21:27 +00:00
sales _person . allocated _percentage / 100.0 ,
2013-05-21 14:05:06 +00:00
precision ( "allocated_amount" , sales _person ) ) ;
2018-09-25 13:38:16 +00:00
refresh _field ( [ "allocated_amount" ] , sales _person ) ;
2013-05-21 14:05:06 +00:00
2018-09-25 13:38:16 +00:00
this . calculate _incentive ( sales _person ) ;
refresh _field ( [ "allocated_percentage" , "allocated_amount" , "commission_rate" , "incentives" ] , sales _person . name ,
2013-05-21 14:05:06 +00:00
sales _person . parentfield ) ;
2018-12-29 14:03:44 +00:00
}
2018-09-25 13:38:16 +00:00
}
sales _person ( doc , cdt , cdn ) {
var row = frappe . get _doc ( cdt , cdn ) ;
this . calculate _incentive ( row ) ;
refresh _field ( "incentives" , row . name , row . parentfield ) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2013-05-27 13:59:07 +00:00
warehouse ( doc , cdt , cdn ) {
2015-03-10 09:34:28 +00:00
var me = this ;
2014-03-27 08:47:33 +00:00
var item = frappe . get _doc ( cdt , cdn ) ;
2020-04-16 10:51:35 +00:00
2021-11-02 13:04:55 +00:00
// check if serial nos entered are as much as qty in row
if ( item . serial _no ) {
let serial _nos = item . serial _no . split ( ` \n ` ) . filter ( sn => sn . trim ( ) ) ; // filter out whitespaces
if ( item . qty === serial _nos . length ) return ;
2020-04-16 10:51:35 +00:00
}
2018-04-13 06:33:42 +00:00
if ( item . serial _no && ! item . batch _no ) {
item . serial _no = null ;
2013-05-27 13:59:07 +00:00
}
2020-04-16 10:51:35 +00:00
2018-04-13 06:33:42 +00:00
var has _batch _no ;
frappe . db . get _value ( 'Item' , { 'item_code' : item . item _code } , 'has_batch_no' , ( r ) => {
has _batch _no = r && r . has _batch _no ;
if ( item . item _code && item . warehouse ) {
return this . frm . call ( {
method : "erpnext.stock.get_item_details.get_bin_details_and_serial_nos" ,
child : item ,
args : {
item _code : item . item _code ,
warehouse : item . warehouse ,
2019-09-19 11:31:26 +00:00
has _batch _no : has _batch _no || 0 ,
2018-04-13 06:33:42 +00:00
stock _qty : item . stock _qty ,
serial _no : item . serial _no || "" ,
} ,
callback : function ( r ) {
if ( in _list ( [ 'Delivery Note' , 'Sales Invoice' ] , doc . doctype ) ) {
2019-06-28 08:38:08 +00:00
if ( doc . doctype === 'Sales Invoice' && ( ! doc . update _stock ) ) return ;
2022-02-15 10:40:35 +00:00
if ( has _batch _no ) {
me . set _batch _number ( cdt , cdn ) ;
me . batch _no ( doc , cdt , cdn ) ;
}
2018-04-13 06:33:42 +00:00
}
}
} ) ;
}
} )
2013-05-27 13:59:07 +00:00
}
2014-04-11 11:21:27 +00:00
2013-08-02 07:09:10 +00:00
toggle _editable _price _list _rate ( ) {
2014-12-26 07:45:21 +00:00
var df = frappe . meta . get _docfield ( this . frm . doc . doctype + " Item" , "price_list_rate" , this . frm . doc . name ) ;
2014-02-14 10:17:51 +00:00
var editable _price _list _rate = cint ( frappe . defaults . get _default ( "editable_price_list_rate" ) ) ;
2014-04-11 11:21:27 +00:00
2013-08-02 07:09:10 +00:00
if ( df && editable _price _list _rate ) {
2021-09-13 10:20:20 +00:00
const parent _field = frappe . meta . get _parentfield ( this . frm . doc . doctype , this . frm . doc . doctype + " Item" ) ;
if ( ! this . frm . fields _dict [ parent _field ] ) return ;
this . frm . fields _dict [ parent _field ] . grid . update _docfield _property (
'price_list_rate' , 'read_only' , 0
) ;
2013-08-02 07:09:10 +00:00
}
}
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
calculate _commission ( ) {
2021-11-30 12:24:18 +00:00
if ( ! this . frm . fields _dict . commission _rate ) return ;
2014-04-11 11:21:27 +00:00
2021-11-30 12:24:18 +00:00
if ( this . frm . doc . commission _rate > 100 ) {
this . frm . set _value ( "commission_rate" , 100 ) ;
frappe . throw ( ` ${ _ _ ( frappe . meta . get _label (
this . frm . doc . doctype , "commission_rate" , this . frm . doc . name
) ) } $ { _ _ ( "cannot be greater than 100" ) } ` );
2013-05-28 11:53:36 +00:00
}
2021-11-30 12:24:18 +00:00
this . frm . doc . amount _eligible _for _commission = this . frm . doc . items . reduce (
( sum , item ) => item . grant _commission ? sum + item . base _net _amount : sum , 0
)
this . frm . doc . total _commission = flt (
this . frm . doc . amount _eligible _for _commission * this . frm . doc . commission _rate / 100.0 ,
precision ( "total_commission" )
) ;
refresh _field ( [ "amount_eligible_for_commission" , "total_commission" ] ) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
calculate _contribution ( ) {
2013-05-23 13:55:08 +00:00
var me = this ;
2014-03-26 12:54:30 +00:00
$ . each ( this . frm . doc . doctype . sales _team || [ ] , function ( i , sales _person ) {
2017-05-30 07:24:42 +00:00
frappe . model . round _floats _in ( sales _person ) ;
2021-11-30 12:24:18 +00:00
if ( ! sales _person . allocated _percentage ) return ;
sales _person . allocated _amount = flt (
me . frm . doc . amount _eligible _for _commission
* sales _person . allocated _percentage
/ 1 0 0 . 0 ,
precision ( "allocated_amount" , sales _person )
) ;
2017-05-30 07:24:42 +00:00
} ) ;
2013-05-21 14:05:06 +00:00
}
2014-04-11 11:21:27 +00:00
2018-09-25 13:38:16 +00:00
calculate _incentive ( row ) {
if ( row . allocated _amount )
{
row . incentives = flt (
row . allocated _amount * row . commission _rate / 100.0 ,
2018-09-26 10:25:43 +00:00
precision ( "incentives" , row ) ) ;
2018-09-25 13:38:16 +00:00
}
}
2015-03-10 09:34:28 +00:00
batch _no ( doc , cdt , cdn ) {
var me = this ;
var item = frappe . get _doc ( cdt , cdn ) ;
2020-07-23 13:21:26 +00:00
if ( item . serial _no ) {
return ;
}
2018-04-13 06:33:42 +00:00
item . serial _no = null ;
var has _serial _no ;
frappe . db . get _value ( 'Item' , { 'item_code' : item . item _code } , 'has_serial_no' , ( r ) => {
has _serial _no = r && r . has _serial _no ;
if ( item . warehouse && item . item _code && item . batch _no ) {
return this . frm . call ( {
method : "erpnext.stock.get_item_details.get_batch_qty_and_serial_no" ,
child : item ,
args : {
"batch_no" : item . batch _no ,
2019-11-27 10:19:41 +00:00
"stock_qty" : item . stock _qty || item . qty , //if stock_qty field is not available fetch qty (in case of Packed Items table)
2018-04-13 06:33:42 +00:00
"warehouse" : item . warehouse ,
"item_code" : item . item _code ,
"has_serial_no" : has _serial _no
} ,
"fieldname" : "actual_batch_qty"
} ) ;
}
} )
2015-03-10 09:34:28 +00:00
}
2013-05-23 13:55:08 +00:00
set _dynamic _labels ( ) {
2013-06-21 12:25:31 +00:00
super . set _dynamic _labels ( ) ;
2015-07-07 08:29:23 +00:00
this . set _product _bundle _help ( this . frm . doc ) ;
2014-06-24 11:32:45 +00:00
}
2015-07-07 08:29:23 +00:00
set _product _bundle _help ( doc ) {
2014-06-24 11:32:45 +00:00
if ( ! cur _frm . fields _dict . packing _list ) return ;
2014-12-25 10:31:55 +00:00
if ( ( doc . packed _items || [ ] ) . length ) {
2014-06-24 11:32:45 +00:00
$ ( cur _frm . fields _dict . packing _list . row . wrapper ) . toggle ( true ) ;
2017-05-30 07:24:42 +00:00
if ( in _list ( [ 'Delivery Note' , 'Sales Invoice' ] , doc . doctype ) ) {
var help _msg = "<div class='alert alert-warning'>" +
2015-07-07 08:29:23 +00:00
_ _ ( "For 'Product Bundle' items, Warehouse, Serial No and Batch No will be considered from the 'Packing List' table. If Warehouse and Batch No are same for all packing items for any 'Product Bundle' item, those values can be entered in the main Item table, values will be copied to 'Packing List' table." ) +
2014-06-24 11:32:45 +00:00
"</div>" ;
2015-07-07 08:29:23 +00:00
frappe . meta . get _docfield ( doc . doctype , 'product_bundle_help' , doc . name ) . options = help _msg ;
2014-06-24 11:32:45 +00:00
}
} else {
$ ( cur _frm . fields _dict . packing _list . row . wrapper ) . toggle ( false ) ;
2017-05-30 07:24:42 +00:00
if ( in _list ( [ 'Delivery Note' , 'Sales Invoice' ] , doc . doctype ) ) {
2015-07-07 08:29:23 +00:00
frappe . meta . get _docfield ( doc . doctype , 'product_bundle_help' , doc . name ) . options = '' ;
2014-06-24 11:32:45 +00:00
}
}
2015-07-07 08:29:23 +00:00
refresh _field ( 'product_bundle_help' ) ;
2015-12-16 04:27:59 +00:00
}
2016-01-26 10:52:50 +00:00
2017-08-21 02:58:55 +00:00
company _address ( ) {
var me = this ;
if ( this . frm . doc . company _address ) {
frappe . call ( {
method : "frappe.contacts.doctype.address.address.get_address_display" ,
args : { "address_dict" : this . frm . doc . company _address } ,
callback : function ( r ) {
if ( r . message ) {
me . frm . set _value ( "company_address_display" , r . message )
}
}
} )
} else {
this . frm . set _value ( "company_address_display" , "" ) ;
}
2017-11-23 07:35:15 +00:00
}
conversion _factor ( doc , cdt , cdn , dont _fetch _price _list _rate ) {
super . conversion _factor ( doc , cdt , cdn , dont _fetch _price _list _rate ) ;
2018-01-25 18:21:05 +00:00
if ( frappe . meta . get _docfield ( cdt , "stock_qty" , cdn ) &&
in _list ( [ 'Delivery Note' , 'Sales Invoice' ] , doc . doctype ) ) {
2019-06-28 08:38:08 +00:00
if ( doc . doctype === 'Sales Invoice' && ( ! doc . update _stock ) ) return ;
this . set _batch _number ( cdt , cdn ) ;
}
2017-11-23 07:35:15 +00:00
}
2021-01-28 06:35:57 +00:00
batch _no ( doc , cdt , cdn ) {
super . batch _no ( doc , cdt , cdn ) ;
}
2017-11-23 07:35:15 +00:00
qty ( doc , cdt , cdn ) {
2018-04-13 06:33:42 +00:00
super . qty ( doc , cdt , cdn ) ;
2019-06-28 08:38:08 +00:00
if ( in _list ( [ 'Delivery Note' , 'Sales Invoice' ] , doc . doctype ) ) {
if ( doc . doctype === 'Sales Invoice' && ( ! doc . update _stock ) ) return ;
this . set _batch _number ( cdt , cdn ) ;
}
2017-11-23 07:35:15 +00:00
}
/ * D e t e r m i n e a p p r o p r i a t e b a t c h n u m b e r a n d s e t i t i n t h e f o r m .
* @ param { string } cdt - Document Doctype
* @ param { string } cdn - Document name
* /
set _batch _number ( cdt , cdn ) {
const doc = frappe . get _doc ( cdt , cdn ) ;
2020-03-26 07:48:57 +00:00
if ( doc && doc . has _batch _no && doc . warehouse ) {
2017-11-23 07:35:15 +00:00
this . _set _batch _number ( doc ) ;
}
}
_set _batch _number ( doc ) {
2021-08-23 08:57:55 +00:00
if ( doc . batch _no ) {
return
}
2020-03-26 07:48:57 +00:00
let args = { 'item_code' : doc . item _code , 'warehouse' : doc . warehouse , 'qty' : flt ( doc . qty ) * flt ( doc . conversion _factor ) } ;
if ( doc . has _serial _no && doc . serial _no ) {
args [ 'serial_no' ] = doc . serial _no
}
2020-04-22 18:48:21 +00:00
2017-11-23 07:35:15 +00:00
return frappe . call ( {
method : 'erpnext.stock.doctype.batch.batch.get_batch_no' ,
2020-03-26 07:48:57 +00:00
args : args ,
2017-11-23 07:35:15 +00:00
callback : function ( r ) {
if ( r . message ) {
frappe . model . set _value ( doc . doctype , doc . name , 'batch_no' , r . message ) ;
2017-11-30 06:07:21 +00:00
} else {
frappe . model . set _value ( doc . doctype , doc . name , 'batch_no' , r . message ) ;
2017-11-23 07:35:15 +00:00
}
}
} ) ;
}
2018-06-28 08:57:58 +00:00
update _auto _repeat _reference ( doc ) {
if ( doc . auto _repeat ) {
frappe . call ( {
2019-07-17 08:20:32 +00:00
method : "frappe.automation.doctype.auto_repeat.auto_repeat.update_reference" ,
2018-12-29 14:03:44 +00:00
args : {
2018-06-28 08:57:58 +00:00
docname : doc . auto _repeat ,
reference : doc . name
} ,
callback : function ( r ) {
if ( r . message == "success" ) {
frappe . show _alert ( { message : _ _ ( "Auto repeat document updated" ) , indicator : 'green' } ) ;
} else {
frappe . show _alert ( { message : _ _ ( "An error occurred during the update process" ) , indicator : 'red' } ) ;
}
}
} )
}
}
2014-06-24 11:32:45 +00:00
} ;
2014-08-26 08:55:53 +00:00
2016-03-09 11:32:59 +00:00
frappe . ui . form . on ( cur _frm . doctype , "project" , function ( frm ) {
2014-10-23 07:48:59 +00:00
if ( in _list ( [ "Delivery Note" , "Sales Invoice" ] , frm . doc . doctype ) ) {
2016-05-19 12:52:49 +00:00
if ( frm . doc . project ) {
frappe . call ( {
method : 'erpnext.projects.doctype.project.project.get_cost_center_name' ,
args : { project : frm . doc . project } ,
callback : function ( r , rt ) {
if ( ! r . exc ) {
$ . each ( frm . doc [ "items" ] || [ ] , function ( i , row ) {
if ( r . message ) {
frappe . model . set _value ( row . doctype , row . name , "cost_center" , r . message ) ;
2020-11-25 10:06:41 +00:00
frappe . msgprint ( _ _ ( "Cost Center For Item with Item Code {0} has been Changed to {1}" , [ row . item _name , r . message ] ) ) ;
2016-05-19 12:52:49 +00:00
}
} )
}
2014-10-23 07:48:59 +00:00
}
2016-05-19 12:52:49 +00:00
} )
}
2014-10-23 07:48:59 +00:00
}
2018-08-01 12:14:34 +00:00
} )
2018-12-29 14:03:44 +00:00
frappe . ui . form . on ( cur _frm . doctype , {
set _as _lost _dialog : function ( frm ) {
var dialog = new frappe . ui . Dialog ( {
title : _ _ ( "Set as Lost" ) ,
fields : [
2020-08-13 03:50:36 +00:00
{
"fieldtype" : "Table MultiSelect" ,
"label" : _ _ ( "Lost Reasons" ) ,
"fieldname" : "lost_reason" ,
"options" : frm . doctype === 'Opportunity' ? 'Opportunity Lost Reason Detail' : 'Quotation Lost Reason Detail' ,
"reqd" : 1
} ,
2021-11-09 14:06:27 +00:00
{
"fieldtype" : "Table MultiSelect" ,
"label" : _ _ ( "Competitors" ) ,
"fieldname" : "competitors" ,
"options" : "Competitor Detail"
} ,
2020-08-13 03:50:36 +00:00
{
2022-01-29 17:02:03 +00:00
"fieldtype" : "Small Text" ,
2020-08-13 03:50:36 +00:00
"label" : _ _ ( "Detailed Reason" ) ,
"fieldname" : "detailed_reason"
} ,
2018-12-29 14:03:44 +00:00
] ,
primary _action : function ( ) {
2021-11-09 14:06:27 +00:00
let values = dialog . get _values ( ) ;
2018-12-29 14:03:44 +00:00
frm . call ( {
doc : frm . doc ,
method : 'declare_enquiry_lost' ,
args : {
2021-11-09 14:06:27 +00:00
'lost_reasons_list' : values . lost _reason ,
2022-01-31 06:39:54 +00:00
'competitors' : values . competitors ? values . competitors : [ ] ,
2021-11-09 14:06:27 +00:00
'detailed_reason' : values . detailed _reason
2018-12-29 14:03:44 +00:00
} ,
callback : function ( r ) {
dialog . hide ( ) ;
frm . reload _doc ( ) ;
} ,
} ) ;
} ,
primary _action _label : _ _ ( 'Declare Lost' )
} ) ;
dialog . show ( ) ;
}
2022-06-10 08:22:17 +00:00
} )