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 = erpnext . TransactionController . extend ( {
2016-05-19 12:52:49 +00:00
setup : function ( ) {
this . _super ( ) ;
2018-09-25 13:38:16 +00:00
this . frm . add _fetch ( "sales_partner" , "commission_rate" , "commission_rate" ) ;
this . frm . add _fetch ( "sales_person" , "commission_rate" , "commission_rate" ) ;
2016-05-19 12:52:49 +00:00
} ,
2013-07-11 13:43:58 +00:00
onload : function ( ) {
this . _super ( ) ;
this . setup _queries ( ) ;
2017-11-17 09:01:09 +00:00
this . frm . set _query ( 'shipping_rule' , function ( ) {
return {
filters : {
"shipping_rule_type" : "Selling"
}
} ;
} ) ;
2013-07-11 13:43:58 +00:00
} ,
2014-04-11 11:21:27 +00:00
2013-07-11 13:43:58 +00:00
setup _queries : function ( ) {
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 ) ;
2014-01-29 11:01:38 +00:00
if ( this . frm . fields _dict . taxes _and _charges ) {
this . frm . set _query ( "taxes_and_charges" , function ( ) {
2013-07-10 07:37:49 +00:00
return {
filters : [
2015-05-08 05:38:48 +00:00
[ 'Sales Taxes and Charges Template' , 'company' , '=' , me . frm . doc . company ] ,
[ 'Sales Taxes and Charges Template' , 'docstatus' , '!=' , 2 ]
2013-07-10 07:37:49 +00:00
]
}
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" ,
filters : { 'is_sales_item' : 1 }
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 )
} ) ;
}
} ,
2013-08-01 12:49:51 +00:00
refresh : function ( ) {
this . _super ( ) ;
2017-01-13 13:23:11 +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 ) ) ;
2014-12-25 10:31:55 +00:00
if ( this . frm . fields _dict . packed _items ) {
var packing _list _exists = ( this . frm . doc . packed _items || [ ] ) . length ;
2013-08-01 12:49:51 +00:00
this . frm . toggle _display ( "packing_list" , packing _list _exists ? true : false ) ;
}
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 : function ( ) {
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 : function ( ) {
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 : function ( ) {
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
2014-05-28 07:19:20 +00:00
sales _partner : function ( ) {
this . apply _pricing _rule ( ) ;
} ,
campaign : function ( ) {
this . apply _pricing _rule ( ) ;
} ,
2013-08-09 12:41:35 +00:00
selling _price _list : function ( ) {
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
price _list _rate : function ( doc , cdt , cdn ) {
2014-03-27 08:47:33 +00:00
var item = frappe . get _doc ( cdt , cdn ) ;
2014-02-14 10:17:51 +00:00
frappe . model . round _floats _in ( item , [ "price_list_rate" , "discount_percentage" ] ) ;
2014-04-11 11:21:27 +00:00
2016-03-05 09:40:25 +00:00
// check if child doctype is Sales Order Item/Qutation Item and calculate the rate
if ( in _list ( [ "Quotation Item" , "Sales Order Item" , "Delivery Note Item" , "Sales Invoice Item" ] ) , cdt )
2016-04-09 09:01:09 +00:00
this . apply _pricing _rule _on _item ( item ) ;
2016-03-05 09:40:25 +00:00
else
item . rate = flt ( item . price _list _rate * ( 1 - item . discount _percentage / 100.0 ) ,
precision ( "rate" , item ) ) ;
2013-05-21 14:05:06 +00:00
this . calculate _taxes _and _totals ( ) ;
} ,
2014-04-11 11:21:27 +00:00
2014-02-10 12:24:04 +00:00
discount _percentage : function ( 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 : function ( 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 : function ( 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 : function ( ) {
this . calculate _commission ( ) ;
refresh _field ( "total_commission" ) ;
} ,
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
total _commission : function ( ) {
2015-02-12 10:39:11 +00:00
if ( this . frm . doc . base _net _total ) {
frappe . model . round _floats _in ( this . frm . doc , [ "base_net_total" , "total_commission" ] ) ;
2014-04-11 11:21:27 +00:00
2015-02-12 10:39:11 +00:00
if ( this . frm . doc . base _net _total < this . frm . doc . total _commission ) {
2014-04-14 10:55:30 +00:00
var msg = ( _ _ ( "[Error]" ) + " " +
_ _ ( frappe . meta . get _label ( this . frm . doc . doctype , "total_commission" ,
2014-04-11 11:21:27 +00:00
this . frm . doc . name ) ) + " > " +
2015-02-12 10:39:11 +00:00
_ _ ( frappe . meta . get _label ( this . frm . doc . doctype , "base_net_total" , this . frm . doc . name ) ) ) ;
2017-05-30 07:24:42 +00:00
frappe . msgprint ( msg ) ;
2013-05-21 14:05:06 +00:00
throw msg ;
}
2014-04-11 11:21:27 +00:00
this . frm . set _value ( "commission_rate" ,
2015-02-12 10:39:11 +00:00
flt ( this . frm . doc . total _commission * 100.0 / this . frm . doc . base _net _total ) ) ;
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 : function ( 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
2015-02-12 10:39:11 +00:00
sales _person . allocated _amount = flt ( this . frm . doc . base _net _total *
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 : function ( 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 : function ( 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 ) ;
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
}
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 ;
2018-04-13 06:33:42 +00:00
me . set _batch _number ( cdt , cdn ) ;
me . batch _no ( doc , cdt , cdn ) ;
}
}
} ) ;
}
} )
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 : function ( ) {
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 ) {
df . read _only = 0 ;
}
} ,
2014-04-11 11:21:27 +00:00
2013-05-21 14:05:06 +00:00
calculate _commission : function ( ) {
2013-05-28 11:53:36 +00:00
if ( this . frm . fields _dict . commission _rate ) {
if ( this . frm . doc . commission _rate > 100 ) {
2014-04-14 10:55:30 +00:00
var msg = _ _ ( frappe . meta . get _label ( this . frm . doc . doctype , "commission_rate" , this . frm . doc . name ) ) +
" " + _ _ ( "cannot be greater than 100" ) ;
2017-05-30 07:24:42 +00:00
frappe . msgprint ( msg ) ;
2013-05-28 11:53:36 +00:00
throw msg ;
}
2014-04-11 11:21:27 +00:00
2015-02-12 10:39:11 +00:00
this . frm . doc . total _commission = flt ( this . frm . doc . base _net _total * this . frm . doc . commission _rate / 100.0 ,
2013-05-28 11:53:36 +00:00
precision ( "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 : function ( ) {
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 ) ;
if ( sales _person . allocated _percentage ) {
sales _person . allocated _amount = flt (
me . frm . doc . base _net _total * sales _person . allocated _percentage / 100.0 ,
precision ( "allocated_amount" , sales _person ) ) ;
}
} ) ;
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 : function ( 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 : function ( doc , cdt , cdn ) {
var me = this ;
var item = frappe . get _doc ( cdt , cdn ) ;
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 : function ( ) {
2013-06-21 12:25:31 +00:00
this . _super ( ) ;
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 : function ( 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
2016-03-05 09:40:25 +00:00
margin _rate _or _amount : function ( doc , cdt , cdn ) {
2016-01-18 10:51:25 +00:00
// calculated the revised total margin and rate on margin rate changes
2017-05-30 07:24:42 +00:00
var item = locals [ cdt ] [ cdn ] ;
2016-04-09 09:01:09 +00:00
this . apply _pricing _rule _on _item ( item )
2016-03-05 09:40:25 +00:00
this . calculate _taxes _and _totals ( ) ;
2016-01-18 10:51:25 +00:00
cur _frm . refresh _fields ( ) ;
} ,
2016-01-19 14:22:22 +00:00
2016-03-05 09:40:25 +00:00
margin _type : function ( doc , cdt , cdn ) {
2016-01-18 10:51:25 +00:00
// calculate the revised total margin and rate on margin type changes
2017-05-30 07:24:42 +00:00
var item = locals [ cdt ] [ cdn ] ;
2017-05-24 03:31:44 +00:00
if ( ! item . margin _type ) {
frappe . model . set _value ( cdt , cdn , "margin_rate_or_amount" , 0 ) ;
} else {
this . apply _pricing _rule _on _item ( item , doc , cdt , cdn )
this . calculate _taxes _and _totals ( ) ;
cur _frm . refresh _fields ( ) ;
}
2017-08-21 02:58:55 +00:00
} ,
company _address : function ( ) {
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 : function ( doc , cdt , cdn , dont _fetch _price _list _rate ) {
this . _super ( 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
} ,
qty : function ( doc , cdt , cdn ) {
2018-04-13 06:33:42 +00:00
this . _super ( 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 : function ( cdt , cdn ) {
const doc = frappe . get _doc ( cdt , cdn ) ;
2017-11-24 05:16:27 +00:00
if ( doc && doc . has _batch _no ) {
2017-11-23 07:35:15 +00:00
this . _set _batch _number ( doc ) ;
}
} ,
_set _batch _number : function ( doc ) {
return frappe . call ( {
method : 'erpnext.stock.doctype.batch.batch.get_batch_no' ,
args : { 'item_code' : doc . item _code , 'warehouse' : doc . warehouse , 'qty' : flt ( doc . qty ) * flt ( doc . conversion _factor ) } ,
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 : function ( 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 ) ;
2017-05-30 07:24:42 +00:00
frappe . msgprint ( _ _ ( "Cost Center For Item with Item Code '" + row . item _name + "' has been Changed to " + 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 : [
{ "fieldtype" : "Table MultiSelect" ,
"label" : _ _ ( "Lost Reasons" ) ,
"fieldname" : "lost_reason" ,
"options" : "Lost Reason Detail" ,
"reqd" : 1 } ,
{ "fieldtype" : "Text" , "label" : _ _ ( "Detailed Reason" ) , "fieldname" : "detailed_reason" } ,
] ,
primary _action : function ( ) {
var values = dialog . get _values ( ) ;
var reasons = values [ "lost_reason" ] ;
var detailed _reason = values [ "detailed_reason" ] ;
frm . call ( {
doc : frm . doc ,
method : 'declare_enquiry_lost' ,
args : {
'lost_reasons_list' : reasons ,
'detailed_reason' : detailed _reason
} ,
callback : function ( r ) {
dialog . hide ( ) ;
frm . reload _doc ( ) ;
} ,
} ) ;
refresh _field ( "lost_reason" ) ;
} ,
primary _action _label : _ _ ( 'Declare Lost' )
} ) ;
dialog . show ( ) ;
}
} )