@ -1,157 +1,207 @@
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Copyright ( C ) 2017 - Today : GRAP ( http : //www.grap.coop)
Copyright ( C ) 2017 - Today : GRAP ( http : //www.grap.coop)
@ author : Sylvain LE GAL ( https : //twitter.com/legalsylvain)
@ author : Sylvain LE GAL ( https : //twitter.com/legalsylvain)
License AGPL - 3.0 or later ( http : //www.gnu.org/licenses/agpl.html).
License AGPL - 3.0 or later ( http : //www.gnu.org/licenses/agpl.html).
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
openerp . pos_order_to_sale_order = function ( instance , local ) {
openerp . pos_order_to_sale_order = function ( instance ) {
"use strict" ;
"use strict" ;
var module = instance . point_of_sale ;
var module = instance . point_of_sale ;
var _t = instance . web . _t ;
var _t = instance . web . _t ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
New Widget CreateSaleOrderButtonWidget :
* On click , check if there is a customer defined ,
ask confirmation call server to create sale order , and delete
the current order .
* /
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
New Widget CreateSaleOrderButtonWidget
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
module . CreateSaleOrderButtonWidget = module . PosBaseWidget . extend ( {
module . CreateSaleOrderButtonWidget = module . PosBaseWidget . extend ( {
template : 'CreateSaleOrderButtonWidget' ,
template : 'CreateSaleOrderButtonWidget' ,
init : function ( parent , options ) {
/ * *
* Define all the confirmation messages .
* /
init : function ( parent , options ) {
this . _super ( parent , options ) ;
this . _super ( parent , options ) ;
this . sale_order_state = options . sale_order_state ;
this . sale_order_state = options . sale_order_state ;
if ( this . sale_order_state == 'draft' ) {
if ( this . sale_order_state === 'draft' ) {
this . display_text = _t ( "Create Draft Order" ) ;
this . display_text = _t ( "Create Draft Order" ) ;
this . confirmation_message = _t ( 'Create Draft Sale Order and discard the current PoS Order?' ) ;
this . confirmation_comment = _t ( "This operation will permanently discard the current PoS Order and create a draft Sale Order, based on the current order lines." ) ;
console . log ( this ) ;
}
else if ( options . sale_order_state == 'confirmed' ) {
this . confirmation_message = _t (
'Create Draft Sale Order and discard the current' +
' PoS Order?' ) ;
this . confirmation_comment = _t (
"This operation will permanently discard the current PoS" +
" Order and create a draft Sale Order, based on the" +
" current order lines." ) ;
} else if ( options . sale_order_state === 'confirmed' ) {
this . display_text = _t ( "Create Confirmed Order" ) ;
this . display_text = _t ( "Create Confirmed Order" ) ;
this . confirmation_message = _t ( 'Create Confirmed Sale Order and discard the current PoS Order?' ) ;
this . confirmation_comment = _t ( "This operation will permanently discard the current PoS Order and create a confirmed Sale Order, based on the current order lines." ) ;
}
else if ( options . sale_order_state == 'delivered' ) {
this . confirmation_message = _t (
'Create Confirmed Sale Order and discard the current' +
' PoS Order?' ) ;
this . confirmation_comment = _t (
"This operation will permanently discard the current PoS" +
" Order and create a confirmed Sale Order, based on the" +
" current order lines." ) ;
} else if ( options . sale_order_state === 'delivered' ) {
this . display_text = _t ( "Create Delivered Order" ) ;
this . display_text = _t ( "Create Delivered Order" ) ;
this . confirmation_message = _t ( 'Create Delivered Sale Order and discard the current PoS Order?' ) ;
this . confirmation_comment = _t ( "This operation will permanently discard the current PoS Order and create a confirmed Sale Order, based on the current order lines. The according picking will be marked as delivered." ) ;
this . confirmation_message = _t (
'Create Delivered Sale Order and discard the current' +
' PoS Order?' ) ;
this . confirmation_comment = _t (
"This operation will permanently discard the current PoS" +
" Order and create a confirmed Sale Order, based on the" +
" current order lines. The according picking will be" +
" marked as delivered." ) ;
}
}
if ( ! this . pos . pricelist_engine ) {
this . confirmation_comment += _t ( "\nNote if you have manually changed unit prices for some products, this changes will not been taken into account in the sale order." )
if ( ! this . pos . pricelist_engine ) {
this . confirmation_comment += _t (
"\nNote if you have manually changed unit prices for" +
" some products, this changes will not been taken into" +
" account in the sale order." )
}
}
} ,
} ,
renderElement : function ( ) {
/ * *
* Define onclick function when the button to create sale order is
* clicked .
* - On click , check if there is a customer defined ,
* - ask confirmation call server to create sale order , and delete
* the current order .
* /
renderElement : function ( ) {
var self = this ;
var self = this ;
this . _super ( ) ;
this . _super ( ) ;
this . $el . click ( function ( ) {
this . $el . click ( function ( ) {
var current_order = self . pos . get ( 'selectedOrder' ) ;
var current_order = self . pos . get ( 'selectedOrder' ) ;
// Prevent empty delivery order
// Prevent empty delivery order
if ( current_order . get ( 'orderLines' ) . length == 0 ) {
self . pos_widget . screen_selector . show_popup ( 'error' , {
if ( current_order . get ( 'orderLines' ) . length === 0 ) {
self . pos_widget . screen_selector . show_popup ( 'error' , {
'message' : _t ( 'Empty Order' ) ,
'message' : _t ( 'Empty Order' ) ,
'comment' : _t ( 'There must be at least one product in your order to create Sale Order.' ) ,
'comment' : _t (
'There must be at least one product in your' +
' order to create Sale Order.' ) ,
} ) ;
} ) ;
return ;
return ;
}
}
// Check Customer
// Check Customer
if ( ! current_order . get ( 'client' ) ) {
self . pos_widget . screen_selector . show_popup ( 'error' , {
if ( ! current_order . get ( 'client' ) ) {
self . pos_widget . screen_selector . show_popup ( 'error' , {
'message' : _t ( 'No customer defined' ) ,
'message' : _t ( 'No customer defined' ) ,
'comment' : _t ( 'You should select a customer in order to create a Sale Order. Please select one by clicking the order tab.' ) ,
'comment' : _t (
'You should select a customer in order to create' +
' a Sale Order. Please select one by clicking' +
' the order tab.' ) ,
} ) ;
} ) ;
return ;
return ;
}
}
self . pos . pos_widget . screen_selector . show_popup ( 'confirm' , {
self . pos . pos_widget . screen_selector . show_popup ( 'confirm' , {
message : self . confirmation_message ,
message : self . confirmation_message ,
comment : self . confirmation_comment ,
comment : self . confirmation_comment ,
confirm : function ( ) {
var SaleOrderModel = new instance . web . Model ( 'sale.order' ) ;
confirm : function ( ) {
var SaleOrderModel =
new instance . web . Model ( 'sale.order' ) ;
current_order . sale_order_state = self . sale_order_state ;
current_order . sale_order_state = self . sale_order_state ;
SaleOrderModel . call ( 'create_order_from_pos' , [ self . prepare_create_sale_order ( current_order ) ]
instance . web . blockUI ( ) ;
SaleOrderModel . call ( 'create_order_from_pos' , [
self . prepare_create_sale_order ( current_order ) ]
) . then ( function ( result ) {
) . then ( function ( result ) {
instance . web . unblockUI ( ) ;
self . hook_create_sale_order_success ( result ) ;
self . hook_create_sale_order_success ( result ) ;
} ) . fail ( function ( error , event ) {
} ) . fail ( function ( error , event ) {
instance . web . unblockUI ( ) ;
self . hook_create_sale_order_error ( error , event ) ;
self . hook_create_sale_order_error ( error , event ) ;
} ) ;
} ) ;
} ,
} ,
} ) ;
} ) ;
} ) ;
} ) ;
} ,
} ,
// Overload This function to send custom sale order data to server
prepare_create_sale_order : function ( order ) {
/ * *
* Overloadable function to send custom sale order data to server
* /
prepare_create_sale_order : function ( order ) {
var res = order . export_as_JSON ( ) ;
var res = order . export_as_JSON ( ) ;
res . sale_order_state = this . sale_order_state ;
res . sale_order_state = this . sale_order_state ;
return res ;
return res ;
} ,
} ,
// Overload this function to make custom action after Sale order
// Creation success
hook_create_sale_order_success : function ( result ) {
/ * *
* Overloadable function to make custom action after Sale order
* Creation succeeded
* /
hook_create_sale_order_success : function ( result ) {
this . pos . get ( 'selectedOrder' ) . destroy ( ) ;
this . pos . get ( 'selectedOrder' ) . destroy ( ) ;
} ,
} ,
// Overload this function to make custom action after Sale order
// Creation fail
hook_create_sale_order_error : function ( error , event ) {
/ * *
* Overloadable function to make custom action after Sale order
* Creation failed
* /
hook_create_sale_order_error : function ( error , event ) {
event . preventDefault ( ) ;
event . preventDefault ( ) ;
if ( error . code === 200 ) {
if ( error . code === 200 ) {
// Business Logic Error, not a connection problem
// Business Logic Error, not a connection problem
this . pos_widget . screen_selector . show_popup ( 'error-traceback' , {
this . pos_widget . screen_selector . show_popup ( 'error-traceback' , {
message : error . data . message ,
message : error . data . message ,
comment : error . data . debug ,
comment : error . data . debug ,
} ) ;
} ) ;
}
else {
// connexion problem
this . pos_widget . screen_selector . show_popup ( 'error' , {
} else {
// Connexion problem
this . pos_widget . screen_selector . show_popup ( 'error' , {
message : _t ( 'The order could not be sent' ) ,
message : _t ( 'The order could not be sent' ) ,
comment : _t ( 'Check your internet connection and try again.' ) ,
comment : _t (
'Check your internet connection and try again.' ) ,
} ) ;
} ) ;
}
}
} ,
} ,
} ) ;
} ) ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extend PosWidget :
Extend PosWidget :
* Create new buttons , depending of the configuration
* /
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
module . PosWidget = module . PosWidget . extend ( {
module . PosWidget = module . PosWidget . extend ( {
build_widgets : function ( ) {
/ * *
* Overload build_widgets ( ) , to create new buttons , depending of the
* configuration
* /
build_widgets : function ( ) {
this . _super ( ) ;
this . _super ( ) ;
if ( this . pos . config . iface_create_draft_sale_order ) {
this . create_draft_sale_order_button = new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'draft' } ) ;
this . create_draft_sale_order_button . appendTo ( this . pos_widget . $ ( 'ul.orderlines' ) ) ;
if ( this . pos . config . iface_create_draft_sale_order ) {
this . create_draft_sale_order_button =
new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'draft' } ) ;
this . create_draft_sale_order_button . appendTo (
this . pos_widget . $ ( 'ul.orderlines' ) ) ;
}
}
if ( this . pos . config . iface_create_confirmed_sale_order ) {
this . create_confirmed_sale_order_button = new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'confirmed' } ) ;
this . create_confirmed_sale_order_button . appendTo ( this . pos_widget . $ ( 'ul.orderlines' ) ) ;
if ( this . pos . config . iface_create_confirmed_sale_order ) {
this . create_confirmed_sale_order_button =
new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'confirmed' } ) ;
this . create_confirmed_sale_order_button . appendTo (
this . pos_widget . $ ( 'ul.orderlines' ) ) ;
}
}
if ( this . pos . config . iface_create_delivered_sale_order ) {
this . create_delivered_sale_order_button = new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'delivered' } ) ;
this . create_delivered_sale_order_button . appendTo ( this . pos_widget . $ ( 'ul.orderlines' ) ) ;
if ( this . pos . config . iface_create_delivered_sale_order ) {
this . create_delivered_sale_order_button =
new module . CreateSaleOrderButtonWidget (
this , { 'sale_order_state' : 'delivered' } ) ;
this . create_delivered_sale_order_button . appendTo (
this . pos_widget . $ ( 'ul.orderlines' ) ) ;
}
}
} ,
} ,
} ) ;
} ) ;
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extend OrderWidget :
Overload renderElement , to display buttons when the order change .
* /
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Extend OrderWidget
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
module . OrderWidget = module . OrderWidget . extend ( {
module . OrderWidget = module . OrderWidget . extend ( {
renderElement : function ( scrollbottom ) {
/ * *
* Overload renderElement ( ) , to display buttons when the order change .
* /
renderElement : function ( scrollbottom ) {
this . _super ( scrollbottom ) ;
this . _super ( scrollbottom ) ;
if ( this . pos_widget . create_draft_sale_order_button ) {
if ( this . pos_widget . create_draft_sale_order_button ) {
this . pos_widget . create_draft_sale_order_button . appendTo (
this . pos_widget . create_draft_sale_order_button . appendTo (
@ -169,7 +219,7 @@ openerp.pos_order_to_sale_order = function(instance, local) {
) ;
) ;
}
}
}
} ,
} ) ;
} ) ;
} ;
} ;