@@ -24,6 +24,7 @@ import { nsCurrency } from "./filters/currency";
24
24
import Print from "./libraries/print" ;
25
25
import Tax from "./libraries/tax" ;
26
26
import * as math from "mathjs"
27
+ import nsPosLoadingPopupVue from "./popups/ns-pos-loading-popup.vue" ;
27
28
28
29
29
30
/**
@@ -1575,8 +1576,43 @@ export class POS {
1575
1576
this . _types . next ( types ) ;
1576
1577
}
1577
1578
1578
- removeProductUsingIndex ( index ) {
1579
+ async removeProductUsingIndex ( index ) {
1579
1580
const products = this . _products . getValue ( ) ;
1581
+ const product = products [ index ] ;
1582
+
1583
+ /**
1584
+ * if the product is persistent,
1585
+ * we should check on the database if the user is allowed
1586
+ * to delete those products.
1587
+ */
1588
+ if ( product . id ) {
1589
+ try {
1590
+ await new Promise ( ( resolve , reject ) => {
1591
+ const popup = Popup . show ( nsPosLoadingPopupVue ) ;
1592
+ nsHttpClient . post ( `/api/users/check-permission/` , {
1593
+ permission : 'nexopos.pos.delete-order-product'
1594
+ } ) . subscribe ( {
1595
+ next : ( response : any ) => {
1596
+ popup . close ( ) ;
1597
+ resolve ( response ) ;
1598
+ } ,
1599
+ error : error => {
1600
+ popup . close ( ) ;
1601
+ reject ( error ) ;
1602
+ }
1603
+ } )
1604
+ } ) ;
1605
+
1606
+ this . resumeRemovingProductUsingIndex ( index , products ) ;
1607
+ } catch ( exception ) {
1608
+ nsNotice . error ( __ ( 'Forbidden Action' ) , __ ( 'You are not allowed to remove this product.' ) ) ;
1609
+ }
1610
+ } else {
1611
+ this . resumeRemovingProductUsingIndex ( index , products ) ;
1612
+ }
1613
+ }
1614
+
1615
+ private resumeRemovingProductUsingIndex ( index , products ) {
1580
1616
products . splice ( index , 1 ) ;
1581
1617
this . products . next ( products ) ;
1582
1618
nsHooks . doAction ( 'ns-after-cart-changed' ) ;
0 commit comments