@ -1,40 +1,45 @@
/* 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 ) {
odoo . define ( 'pos_quotation_order.models' , function ( require ) {
"use strict" ;
"use strict" ;
var screens = require ( 'point_of_sale.screens' ) ;
var screens = require ( 'point_of_sale.screens' ) ;
var gui = require ( 'point_of_sale.gui' ) ;
var gui = require ( 'point_of_sale.gui' ) ;
var core = require ( 'web.core' ) ;
var core = require ( 'web.core' ) ;
var rpc = require ( 'web.rpc' ) ;
var rpc = require ( 'web.rpc' ) ;
var models = require ( 'point_of_sale.models' ) ;
var models = require ( 'point_of_sale.models' ) ;
var session = require ( 'web.session' ) ;
var session = require ( 'web.session' ) ;
var QWeb = core . qweb ;
var QWeb = core . qweb ;
var _ t = core . _ t ;
var _ t = core . _ t ;
models . load_models ( {
models . load_models ( {
model : 'pos.quotation' ,
model : 'pos.quotation' ,
fields : [ 'name' , 'partner_id' , 'date_order' , 'amount_total' , 'lines' , 'state' ] ,
fields : [ 'name' , 'partner_id' , 'date_order' , 'amount_total' , 'lines' , 'state' ] ,
domain : [ [ 'state' , '=' , 'draft' ] ] ,
domain : [ [ 'state' , '=' , 'draft' ] ] ,
loaded : function ( self , quotations ) {
loaded : function ( self , quotations ) {
self . quotations = quotations ;
self . quotations = quotations ;
}
}
} ) ;
} ) ;
models . load_models ( {
models . load_models ( {
model : 'pos.quotation.line' ,
model : 'pos.quotation.line' ,
fields : [ 'product_id' , 'qty' ] ,
fields : [ 'product_id' , 'qty' ] ,
loaded : function ( self , quotation_lines ) {
loaded : function ( self , quotation_lines ) {
self . quotation_lines = quotation_lines ;
self . quotation_lines = quotation_lines ;
}
}
} ) ;
} ) ;
var _ super_order = models . Order . prototype ;
var _ super_order = models . Order . prototype ;
models . Order = models . Order . extend ( {
models . Order = models . Order . extend ( {
export_as_JSON : function ( ) {
export_as_JSON : function ( ) {
var data = _ super_order . export_as_JSON . apply ( this , arguments ) ;
var data = _ super_order . export_as_JSON . apply ( this , arguments ) ;
data . quotation_ref = this . quotation_ref ;
data . quotation_ref = this . quotation_ref ;
return data ;
return data ;
} ,
} ,
init_from_JSON : function ( json ) {
init_from_JSON : function ( json ) {
this . quotation_ref = json . quotation_ref ;
this . quotation_ref = json . quotation_ref ;
_ super_order . init_from_JSON . call ( this , json ) ;
_ super_order . init_from_JSON . call ( this , json ) ;
} ,
} ,
@ -43,68 +48,15 @@ models.load_models({
var posmodel_super = models . PosModel . prototype ;
var posmodel_super = models . PosModel . prototype ;
models . PosModel = models . PosModel . extend ( {
models . PosModel = models . PosModel . extend ( {
_ save_to_server : function ( orders , options ) {
_ save_to_server : function ( orders , options ) {
if ( ! orders || ! orders . length ) {
var result = $ . Deferred ( ) ;
result . resolve ( [ ] ) ;
return result ;
}
options = options || { } ;
var self = this ;
var self = this ;
var fields = _ . find ( this . models , function ( model ) { return model . model === 'pos.quotation' ; } ) . fields ;
return posmodel_super . _ save_to_server . apply ( this , arguments ) . then ( function ( server_ids ) {
var timeout = typeof options . timeout === 'number' ? options . timeout : 7500 * orders . length ;
_ . each ( orders , function ( o ) {
var order_ids_to_sync = _ . pluck ( orders , 'id' ) ;
if ( o . data . quotation_ref ) {
var args = [ _ . map ( orders , function ( order ) {
var index = self . quotations . indexOf ( o . data . quotation_ref ) ;
order . to_invoice = options . to_invoice || false ;
self . quotations . splice ( index , 1 ) ;
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 )
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 ) ;
} ) ;
} ) ;
} ) ;
}
}
} ) ;
} ) ;
} ) ;
} ) ;