@ -1,3 +1,8 @@
/* Copyright (C) 2019-TODAY Cybrosys Technologies(<https:/ / www . cybrosys . com > ) .
Copyright 2021 Binovo IT Human Project SL
License AGPL - 3.0 or later ( https : //www.gnu.org/licenses/agpl).
* /
odoo . define ( 'pos_quotation_order.models' , function ( require ) {
"use strict" ;
@ -43,68 +48,15 @@ models.load_models({
var posmodel_super = models . PosModel . prototype ;
models . PosModel = models . PosModel . extend ( {
_ save_to_server : function ( orders , options ) {
if ( ! orders || ! orders . length ) {
var result = $ . Deferred ( ) ;
result . resolve ( [ ] ) ;
return result ;
}
options = options || { } ;
var self = this ;
var fields = _ . find ( this . models , function ( model ) { return model . model === 'pos.quotation' ; } ) . fields ;
var timeout = typeof options . timeout === 'number' ? options . timeout : 7500 * orders . length ;
var order_ids_to_sync = _ . pluck ( orders , 'id' ) ;
var args = [ _ . map ( orders , function ( order ) {
order . to_invoice = options . to_invoice || false ;
return order ;
} ) ] ;
return rpc . query ( {
model : 'pos.order' ,
method : 'create_from_ui' ,
args : args ,
kwargs : { context : session . user_context } ,
} , {
timeout : timeout ,
shadow : ! options . to_invoice
} )
. then ( function ( server_ids ) {
console . log ( server_ids )
if ( server_ids [ 1 ] . length != 0 ) {
console . log ( "dddddddddddddd" )
for ( var item in server_ids [ 1 ] ) {
rpc . query ( {
model : 'pos.quotation' ,
method : 'search_read' ,
args : [ [ [ 'id' , '=' , server_ids [ 1 ] [ item ] ] ] , fields ] ,
limit : 1 ,
} ) . then ( function ( quotation ) {
console . log ( quotation )
var index = self . quotations . indexOf ( quotation [ 0 ] ) ;
console . log ( index )
return posmodel_super . _ save_to_server . apply ( this , arguments ) . then ( function ( server_ids ) {
_ . each ( orders , function ( o ) {
if ( o . data . quotation_ref ) {
var index = self . quotations . indexOf ( o . data . quotation_ref ) ;
self . quotations . splice ( index , 1 ) ;
} ) ;
}
}
_ . each ( order_ids_to_sync , function ( order_id ) {
self . db . remove_order ( order_id ) ;
} ) ;
self . set ( 'failed' , false ) ;
return server_ids [ 0 ] ;
} ) . fail ( function ( type , error ) {
if ( error . code === 200 ) {
if ( error . data . exception_type == 'warning' ) {
delete error . data . debug ;
}
if ( ( ! self . get ( 'failed' ) || options . show_error ) && ! options . to_invoice ) {
self . gui . show_popup ( 'error-traceback' , {
'title' : error . data . message ,
'body' : error . data . debug
} ) ;
}
self . set ( 'failed' , error ) ;
}
console . error ( 'Failed to send orders:' , orders ) ;
} ) ;
}
} ) ;
} ) ;