# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1565071340 -19800
#      Tue Aug 06 11:32:20 2019 +0530
# Node ID f1a67bb0aa70bb600627afd965271b9d20eeef0b
# Parent  f1324d50d9e54bac4a88f05673333ac56a7b278f
Related to issue 41432 : Cashup data should be updated when doing Cancal And Replace

* When doing CR, oldLines should not be updated in returns and
  newLine should be updated in sales

diff -r f1324d50d9e5 -r f1a67bb0aa70 web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js
--- a/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js	Mon Aug 05 11:52:45 2019 +0530
+++ b/web/org.openbravo.retail.posterminal/js/utils/cashUpReportUtils.js	Tue Aug 06 11:32:20 2019 +0530
@@ -149,10 +149,7 @@
               gross = line.get('discountedGross');
             }
             if (order.get('doCancelAndReplace')) {
-              if (line.get('replacedorderline')) {
-                netReturns = OB.DEC.add(netReturns, line.get('net'));
-                grossReturns = OB.DEC.add(grossReturns, gross);
-              } else {
+              if (!line.get('replacedorderline')) {
                 netSales = OB.DEC.add(netSales, line.get('net'));
                 grossSales = OB.DEC.add(grossSales, gross);
               }
@@ -298,7 +295,10 @@
               order.get('payments').models,
               function(payment) {
                 auxPay = payMthds.filter(function(payMthd) {
-                  return payMthd.get('searchKey') === payment.get('kind');
+                  return (
+                    payMthd.get('searchKey') === payment.get('kind') &&
+                    !payment.get('isPrePayment')
+                  );
                 })[0];
                 if (!auxPay) {
                   //We cannot find this payment in local database, it must be a new payment method, we skip it.
@@ -310,14 +310,6 @@
                 amount = _.isNumber(payment.get('amountRounded'))
                   ? payment.get('amountRounded')
                   : payment.get('amount');
-                if (
-                  order.get('doCancelAndReplace') &&
-                  payment.get('isPrePayment')
-                ) {
-                  amount = OB.DEC.mul(amount, -1);
-                } else if (payment.get('isPrePayment')) {
-                  return;
-                }
                 if (amount < 0) {
                   auxPay.set(
                     'totalReturns',
