From 9d58998c413ddbd9440c04af240fa289f478b6d0 Mon Sep 17 00:00:00 2001
From: Prakash M <prakash@qualiantech.com>
Date: Wed, 1 Sep 2021 10:18:58 +0530
Subject: [PATCH] Fixed BUG-47538: Retained original receipt tax info in case
 of verified return * Tax rules are generated from line taxes of original
 receipt in case of verified return * Included needed tax info in paid receipt

---
 .../retail/posterminal/PaidReceipts.java      |  10 +
 .../js/data/dataordertaxes.js                 | 334 ++++++++++--------
 2 files changed, 195 insertions(+), 149 deletions(-)

diff --git a/src/org/openbravo/retail/posterminal/PaidReceipts.java b/src/org/openbravo/retail/posterminal/PaidReceipts.java
index 43b54bbf3..2308e735a 100644
--- a/src/org/openbravo/retail/posterminal/PaidReceipts.java
+++ b/src/org/openbravo/retail/posterminal/PaidReceipts.java
@@ -241,6 +241,16 @@ public class PaidReceipts extends JSONProcessSimple {
             jsonTax.put("docTaxAmount", tax.getTax().getDocTaxAmount());
             jsonTax.put("lineNo", tax.getTax().getLineNo());
             jsonTax.put("cascade", tax.getTax().isCascade());
+            jsonTax.put("summaryLevel", tax.getTax().isSummaryLevel());
+            jsonTax.put("isBom", tax.getTax().getTaxCategory().isAsbom());
+            jsonTax.put("taxExempt", tax.getTax().isTaxExempt());
+            jsonTax.put("default", tax.getTax().isDefault());
+            jsonTax.put("withholdingTax", tax.getTax().isWithholdingTax());
+            jsonTax.put("isCashVAT", tax.getTax().isCashVAT());
+            jsonTax.put("baseAmount", tax.getTax().getBaseAmount());
+            jsonTax.put("taxBase",
+                tax.getTax().getTaxBase() != null ? tax.getTax().getTaxBase().getId() : null);
+            jsonTax.put("taxCategory", tax.getTax().getTaxCategory().getId());
             taxes.put(jsonTax);
           }
 
diff --git a/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js b/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js
index de05706ae..5ba684caa 100644
--- a/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordertaxes.js
@@ -343,162 +343,195 @@
   };
 
   var findTaxesCollection = function(receipt, line, taxCategory) {
-    return new Promise(function(fulfill, reject) {
-      // sql parameters
-      var fromRegionOrg = OB.MobileApp.model.get('terminal')
-          .organizationRegionId,
-        fromCountryOrg = OB.MobileApp.model.get('terminal')
-          .organizationCountryId,
-        bpTaxCategory = receipt.get('bp').get('taxCategory'),
-        bpIsExempt = receipt.get('bp').get('taxExempt'),
-        bpShipLocId = receipt.get('bp').get('shipLocId'),
-        bpName =
-          receipt.get('bp').get('name') ||
-          OB.I18N.getLabel('OBPOS_LblEmptyAddress'),
-        bpShipLocName =
-          receipt.get('bp').get('shipLocName') ||
-          OB.I18N.getLabel('OBPOS_LblEmptyAddress'),
-        bplCountryId = receipt.get('bp').get('shipCountryId')
-          ? receipt.get('bp').get('shipCountryId')
-          : null,
-        bplRegionId = receipt.get('bp').get('shipRegionId')
-          ? receipt.get('bp').get('shipRegionId')
-          : null,
-        isCashVat = OB.MobileApp.model.get('terminal').cashVat;
-      // SQL build
-      // the query is ordered by countryId desc and regionId desc
-      // (so, the first record will be the tax with the same country or
-      // region that the customer,
-      // or if toCountryId and toRegionId are nulls then will be ordered
-      // by validfromdate)
-      var sql = '';
-      if (!bplCountryId) {
-        sql =
-          "select c_tax.c_tax_id, c_tax.name,  c_tax.description, c_tax.taxindicator, c_tax.validfrom, c_tax.issummary, c_tax.rate, c_tax.parent_tax_id, (case when c_tax.c_country_id = '" +
-          fromCountryOrg +
-          "' then c_tax.c_country_id else tz.from_country_id end) as c_country_id, (case when c_tax.c_region_id = '" +
-          fromRegionOrg +
-          "' then c_tax.c_region_id else tz.from_region_id end) as c_region_id, (case when c_tax.to_country_id = bpl.countryId then c_tax.to_country_id else tz.to_country_id end) as to_country_id, (case when c_tax.to_region_id = bpl.regionId then c_tax.to_region_id else tz.to_region_id end)  as to_region_id, c_tax.c_taxcategory_id, c_tax.isdefault, c_tax.istaxexempt, c_tax.sopotype, c_tax.cascade, c_tax.c_bp_taxcategory_id,  c_tax.line, c_tax.iswithholdingtax, c_tax.isnotaxable, c_tax.deducpercent, c_tax.originalrate, c_tax.istaxundeductable,  c_tax.istaxdeductable, c_tax.isnovat, c_tax.baseamount, c_tax.c_taxbase_id, c_tax.doctaxamount, c_tax.iscashvat,  c_tax._identifier,  c_tax._idx,  (case when (c_tax.to_country_id = bpl.countryId or tz.to_country_id= bpl.countryId) then 0 else 1 end) as orderCountryTo,  (case when (c_tax.to_region_id = bpl.regionId or tz.to_region_id = bpl.regionId) then 0 else 1 end) as orderRegionTo,  (case when coalesce(c_tax.c_country_id, tz.from_country_id) is null then 1 else 0 end) as orderCountryFrom,  (case when coalesce(c_tax.c_region_id, tz.from_region_id) is null then 1 else 0 end) as orderRegionFrom  from c_tax left join c_tax_zone tz on tz.c_tax_id = c_tax.c_tax_id  join c_bpartner_location bpl on bpl.c_bpartner_location_id = '" +
-          bpShipLocId +
-          "'   where c_tax.sopotype in ('B', 'S') ";
-      } else {
-        sql =
-          "select c_tax.c_tax_id, c_tax.name,  c_tax.description, c_tax.taxindicator, c_tax.validfrom, c_tax.issummary, c_tax.rate, c_tax.parent_tax_id, (case when c_tax.c_country_id = '" +
-          fromCountryOrg +
-          "' then c_tax.c_country_id else tz.from_country_id end) as c_country_id, (case when c_tax.c_region_id = '" +
-          fromRegionOrg +
-          "' then c_tax.c_region_id else tz.from_region_id end) as c_region_id, (case when c_tax.to_country_id = '" +
-          bplCountryId +
-          "' then c_tax.to_country_id else tz.to_country_id end) as to_country_id, (case when c_tax.to_region_id = '" +
-          bplRegionId +
-          "' then c_tax.to_region_id else tz.to_region_id end)  as to_region_id, c_tax.c_taxcategory_id, c_tax.isdefault, c_tax.istaxexempt, c_tax.sopotype, c_tax.cascade, c_tax.c_bp_taxcategory_id,  c_tax.line, c_tax.iswithholdingtax, c_tax.isnotaxable, c_tax.deducpercent, c_tax.originalrate, c_tax.istaxundeductable,  c_tax.istaxdeductable, c_tax.isnovat, c_tax.baseamount, c_tax.c_taxbase_id, c_tax.doctaxamount, c_tax.iscashvat,  c_tax._identifier,  c_tax._idx,  (case when (c_tax.to_country_id = '" +
-          bplCountryId +
-          "' or tz.to_country_id= '" +
-          bplCountryId +
-          "') then 0 else 1 end) as orderCountryTo,  (case when (c_tax.to_region_id = '" +
-          bplRegionId +
-          "' or tz.to_region_id = '" +
-          bplRegionId +
-          "') then 0 else 1 end) as orderRegionTo,  (case when coalesce(c_tax.c_country_id, tz.from_country_id) is null then 1 else 0 end) as orderCountryFrom,  (case when coalesce(c_tax.c_region_id, tz.from_region_id) is null then 1 else 0 end) as orderRegionFrom  from c_tax left join c_tax_zone tz on tz.c_tax_id = c_tax.c_tax_id  where c_tax.sopotype in ('B', 'S') ";
-      }
-      if (
-        line.has('originalTaxExempt')
-          ? line.get('originalTaxExempt')
-          : bpIsExempt
-      ) {
-        sql = sql + " and c_tax.istaxexempt = 'true'";
-      } else {
-        sql = sql + " and c_tax.c_taxCategory_id = '" + taxCategory + "'";
-        if (bpTaxCategory) {
+    if (line.get('isVerifiedReturn')) {
+      return new Promise(function(resolve, reject) {
+        let taxRules = new Backbone.Collection();
+        line.get('lineTaxes').forEach(lineTax => {
+          let taxRate = new OB.Model.TaxRate();
+          taxRate.set('id', lineTax.taxId);
+          taxRate.set('name', lineTax.identifier);
+          taxRate.set('rate', lineTax.taxRate);
+          taxRate.set('lineNo', lineTax.lineNo);
+          taxRate.set('docTaxAmount', lineTax.docTaxAmount);
+          taxRate.set('cascade', lineTax.cascade);
+          taxRate.set('summaryLevel', lineTax.summaryLevel);
+          taxRate.set('isBom', lineTax.isBom);
+          taxRate.set('taxExempt', lineTax.taxExempt);
+          taxRate.set('default', lineTax.default);
+          taxRate.set('withholdingTax', lineTax.withholdingTax);
+          taxRate.set('isCashVAT', lineTax.isCashVAT);
+          taxRate.set('baseAmount', lineTax.baseAmount);
+          taxRate.set('taxBase', lineTax.taxBase ? lineTax.taxBase : null);
+          taxRate.set('taxCategory', lineTax.taxCategory);
+          taxRules.add(taxRate);
+        });
+        if (line.get('isProductBOM')) {
+          taxRules = new Backbone.Collection(
+            taxRules.models.filter(
+              rule => rule.get('taxCategory') === taxCategory
+            )
+          );
+        }
+        resolve(taxRules);
+      });
+    } else {
+      return new Promise(function(fulfill, reject) {
+        // sql parameters
+        var fromRegionOrg = OB.MobileApp.model.get('terminal')
+            .organizationRegionId,
+          fromCountryOrg = OB.MobileApp.model.get('terminal')
+            .organizationCountryId,
+          bpTaxCategory = receipt.get('bp').get('taxCategory'),
+          bpIsExempt = receipt.get('bp').get('taxExempt'),
+          bpShipLocId = receipt.get('bp').get('shipLocId'),
+          bpName =
+            receipt.get('bp').get('name') ||
+            OB.I18N.getLabel('OBPOS_LblEmptyAddress'),
+          bpShipLocName =
+            receipt.get('bp').get('shipLocName') ||
+            OB.I18N.getLabel('OBPOS_LblEmptyAddress'),
+          bplCountryId = receipt.get('bp').get('shipCountryId')
+            ? receipt.get('bp').get('shipCountryId')
+            : null,
+          bplRegionId = receipt.get('bp').get('shipRegionId')
+            ? receipt.get('bp').get('shipRegionId')
+            : null,
+          isCashVat = OB.MobileApp.model.get('terminal').cashVat;
+        // SQL build
+        // the query is ordered by countryId desc and regionId desc
+        // (so, the first record will be the tax with the same country or
+        // region that the customer,
+        // or if toCountryId and toRegionId are nulls then will be ordered
+        // by validfromdate)
+        var sql = '';
+        if (!bplCountryId) {
           sql =
-            sql + " and c_tax.c_bp_taxcategory_id = '" + bpTaxCategory + "'";
+            "select c_tax.c_tax_id, c_tax.name,  c_tax.description, c_tax.taxindicator, c_tax.validfrom, c_tax.issummary, c_tax.rate, c_tax.parent_tax_id, (case when c_tax.c_country_id = '" +
+            fromCountryOrg +
+            "' then c_tax.c_country_id else tz.from_country_id end) as c_country_id, (case when c_tax.c_region_id = '" +
+            fromRegionOrg +
+            "' then c_tax.c_region_id else tz.from_region_id end) as c_region_id, (case when c_tax.to_country_id = bpl.countryId then c_tax.to_country_id else tz.to_country_id end) as to_country_id, (case when c_tax.to_region_id = bpl.regionId then c_tax.to_region_id else tz.to_region_id end)  as to_region_id, c_tax.c_taxcategory_id, c_tax.isdefault, c_tax.istaxexempt, c_tax.sopotype, c_tax.cascade, c_tax.c_bp_taxcategory_id,  c_tax.line, c_tax.iswithholdingtax, c_tax.isnotaxable, c_tax.deducpercent, c_tax.originalrate, c_tax.istaxundeductable,  c_tax.istaxdeductable, c_tax.isnovat, c_tax.baseamount, c_tax.c_taxbase_id, c_tax.doctaxamount, c_tax.iscashvat,  c_tax._identifier,  c_tax._idx,  (case when (c_tax.to_country_id = bpl.countryId or tz.to_country_id= bpl.countryId) then 0 else 1 end) as orderCountryTo,  (case when (c_tax.to_region_id = bpl.regionId or tz.to_region_id = bpl.regionId) then 0 else 1 end) as orderRegionTo,  (case when coalesce(c_tax.c_country_id, tz.from_country_id) is null then 1 else 0 end) as orderCountryFrom,  (case when coalesce(c_tax.c_region_id, tz.from_region_id) is null then 1 else 0 end) as orderRegionFrom  from c_tax left join c_tax_zone tz on tz.c_tax_id = c_tax.c_tax_id  join c_bpartner_location bpl on bpl.c_bpartner_location_id = '" +
+            bpShipLocId +
+            "'   where c_tax.sopotype in ('B', 'S') ";
         } else {
-          sql = sql + ' and c_tax.c_bp_taxcategory_id is null';
+          sql =
+            "select c_tax.c_tax_id, c_tax.name,  c_tax.description, c_tax.taxindicator, c_tax.validfrom, c_tax.issummary, c_tax.rate, c_tax.parent_tax_id, (case when c_tax.c_country_id = '" +
+            fromCountryOrg +
+            "' then c_tax.c_country_id else tz.from_country_id end) as c_country_id, (case when c_tax.c_region_id = '" +
+            fromRegionOrg +
+            "' then c_tax.c_region_id else tz.from_region_id end) as c_region_id, (case when c_tax.to_country_id = '" +
+            bplCountryId +
+            "' then c_tax.to_country_id else tz.to_country_id end) as to_country_id, (case when c_tax.to_region_id = '" +
+            bplRegionId +
+            "' then c_tax.to_region_id else tz.to_region_id end)  as to_region_id, c_tax.c_taxcategory_id, c_tax.isdefault, c_tax.istaxexempt, c_tax.sopotype, c_tax.cascade, c_tax.c_bp_taxcategory_id,  c_tax.line, c_tax.iswithholdingtax, c_tax.isnotaxable, c_tax.deducpercent, c_tax.originalrate, c_tax.istaxundeductable,  c_tax.istaxdeductable, c_tax.isnovat, c_tax.baseamount, c_tax.c_taxbase_id, c_tax.doctaxamount, c_tax.iscashvat,  c_tax._identifier,  c_tax._idx,  (case when (c_tax.to_country_id = '" +
+            bplCountryId +
+            "' or tz.to_country_id= '" +
+            bplCountryId +
+            "') then 0 else 1 end) as orderCountryTo,  (case when (c_tax.to_region_id = '" +
+            bplRegionId +
+            "' or tz.to_region_id = '" +
+            bplRegionId +
+            "') then 0 else 1 end) as orderRegionTo,  (case when coalesce(c_tax.c_country_id, tz.from_country_id) is null then 1 else 0 end) as orderCountryFrom,  (case when coalesce(c_tax.c_region_id, tz.from_region_id) is null then 1 else 0 end) as orderRegionFrom  from c_tax left join c_tax_zone tz on tz.c_tax_id = c_tax.c_tax_id  where c_tax.sopotype in ('B', 'S') ";
+        }
+        if (
+          line.has('originalTaxExempt')
+            ? line.get('originalTaxExempt')
+            : bpIsExempt
+        ) {
+          sql = sql + " and c_tax.istaxexempt = 'true'";
+        } else {
+          sql = sql + " and c_tax.c_taxCategory_id = '" + taxCategory + "'";
+          if (bpTaxCategory) {
+            sql =
+              sql + " and c_tax.c_bp_taxcategory_id = '" + bpTaxCategory + "'";
+          } else {
+            sql = sql + ' and c_tax.c_bp_taxcategory_id is null';
+          }
+        }
+        if (line.get('originalOrderDate')) {
+          // The taxes calculation is locked so use the originalOrderDate
+          sql =
+            sql +
+            " and c_tax.validFrom <= '" +
+            line.get('originalOrderDate') +
+            "'";
+        } else {
+          sql = sql + ' and c_tax.validFrom <= date()';
+        }
+        if (!bplCountryId) {
+          sql =
+            sql +
+            ' and (c_tax.to_country_id = bpl.countryId   or tz.to_country_id = bpl.countryId   or (c_tax.to_country_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id = bpl.countryId)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id is null))))';
+          sql =
+            sql +
+            ' and (c_tax.to_region_id = bpl.regionId   or tz.to_region_id = bpl.regionId  or (c_tax.to_region_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id = bpl.regionId)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id is null))))';
+        } else {
+          sql =
+            sql +
+            " and (c_tax.to_country_id = '" +
+            bplCountryId +
+            "'   or tz.to_country_id = '" +
+            bplCountryId +
+            "'   or (c_tax.to_country_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id = '" +
+            bplCountryId +
+            "')           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id is null))))";
+          sql =
+            sql +
+            " and (c_tax.to_region_id = '" +
+            bplRegionId +
+            "'   or tz.to_region_id = '" +
+            bplRegionId +
+            "'  or (c_tax.to_region_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id = '" +
+            bplRegionId +
+            "')           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id is null))))";
+        }
+        if (isCashVat) {
+          sql =
+            sql +
+            " and (c_tax.isCashVAT ='" +
+            isCashVat +
+            "' OR (c_tax.isCashVAT = 'false' and (c_tax.isWithholdingTax = 'true' or c_tax.rate=0))) ";
+        } else {
+          sql = sql + " and c_tax.isCashVAT ='false' ";
         }
-      }
-      if (line.get('originalOrderDate')) {
-        // The taxes calculation is locked so use the originalOrderDate
-        sql =
-          sql +
-          " and c_tax.validFrom <= '" +
-          line.get('originalOrderDate') +
-          "'";
-      } else {
-        sql = sql + ' and c_tax.validFrom <= date()';
-      }
-      if (!bplCountryId) {
-        sql =
-          sql +
-          ' and (c_tax.to_country_id = bpl.countryId   or tz.to_country_id = bpl.countryId   or (c_tax.to_country_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id = bpl.countryId)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id is null))))';
-        sql =
-          sql +
-          ' and (c_tax.to_region_id = bpl.regionId   or tz.to_region_id = bpl.regionId  or (c_tax.to_region_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id = bpl.regionId)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id is null))))';
-      } else {
-        sql =
-          sql +
-          " and (c_tax.to_country_id = '" +
-          bplCountryId +
-          "'   or tz.to_country_id = '" +
-          bplCountryId +
-          "'   or (c_tax.to_country_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id = '" +
-          bplCountryId +
-          "')           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_country_id is null))))";
-        sql =
-          sql +
-          " and (c_tax.to_region_id = '" +
-          bplRegionId +
-          "'   or tz.to_region_id = '" +
-          bplRegionId +
-          "'  or (c_tax.to_region_id is null       and (not exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id)           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id = '" +
-          bplRegionId +
-          "')           or exists (select 1 from c_tax_zone z where z.c_tax_id = c_tax.c_tax_id and z.to_region_id is null))))";
-      }
-      if (isCashVat) {
         sql =
           sql +
-          " and (c_tax.isCashVAT ='" +
-          isCashVat +
-          "' OR (c_tax.isCashVAT = 'false' and (c_tax.isWithholdingTax = 'true' or c_tax.rate=0))) ";
-      } else {
-        sql = sql + " and c_tax.isCashVAT ='false' ";
-      }
-      sql =
-        sql +
-        ' order by orderRegionTo, orderRegionFrom, orderCountryTo, orderCountryFrom, c_tax.validFrom desc, c_tax.isdefault desc';
+          ' order by orderRegionTo, orderRegionFrom, orderCountryTo, orderCountryFrom, c_tax.validFrom desc, c_tax.isdefault desc';
 
-      OB.UTIL.HookManager.executeHooks(
-        'OBPOS_FindTaxRate',
-        {
-          context: receipt,
-          line: line,
-          sql: sql
-        },
-        function(args) {
-          OB.Dal.queryUsingCache(
-            OB.Model.TaxRate,
-            args.sql,
-            [],
-            function(coll) {
-              // success
-              if (coll && coll.length > 0) {
-                fulfill(coll);
-              } else {
-                reject(
-                  OB.I18N.getLabel('OBPOS_TaxNotFound_Message', [
-                    bpName,
-                    bpShipLocName
-                  ])
-                );
+        OB.UTIL.HookManager.executeHooks(
+          'OBPOS_FindTaxRate',
+          {
+            context: receipt,
+            line: line,
+            sql: sql
+          },
+          function(args) {
+            OB.Dal.queryUsingCache(
+              OB.Model.TaxRate,
+              args.sql,
+              [],
+              function(coll) {
+                // success
+                if (coll && coll.length > 0) {
+                  fulfill(coll);
+                } else {
+                  reject(
+                    OB.I18N.getLabel('OBPOS_TaxNotFound_Message', [
+                      bpName,
+                      bpShipLocName
+                    ])
+                  );
+                }
+              },
+              function() {
+                // error
+                reject(OB.I18N.getLabel('OBPOS_TaxCalculationError_Message'));
               }
-            },
-            function() {
-              // error
-              reject(OB.I18N.getLabel('OBPOS_TaxCalculationError_Message'));
-            }
-          );
-        }
-      );
-    });
+            );
+          }
+        );
+      });
+    }
   };
 
   var calcProductTaxesIncPrice = function(params) {
@@ -930,6 +963,7 @@
     // Initialize line properties
     delete line.changePrice;
     delete line.changeBackPrice;
+    line.unset('isProductBOM');
     line.set(
       {
         taxLines: {},
@@ -977,6 +1011,7 @@
               }
 
               line.set('isBom', isbom);
+              line.set('isProductBOM', true);
               line.set('bomGross', []);
               line.set('bomNets', []);
               line.set('sortedTaxCollection', []);
@@ -1457,6 +1492,7 @@
   var calcLineTaxesExcPrice = function(receipt, line) {
     delete line.changePrice;
     delete line.changeBackPrice;
+    line.unset('isProductBOM');
     line.set(
       {
         pricenet: line.get('price'),
-- 
2.20.1

