Sum is not calculated well when calculated via Formula before safe

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • macistda
    Senior Member
    • Jul 2022
    • 122

    #1

    Sum is not calculated well when calculated via Formula before safe

    I think from Sales Pack 4.4.2 on could be a new bug.

    I calculate different sums via a before safe script at entity quote

    here an example (not complete): product.customtyp is a use defined field as others.
    Code:
    $items = record\findRelatedMany('Quote', id, 'items', 100000);
    
    $support = 0;
    $entwicklung = 0;
    $sonstiges = 0;
    
    $i = 0;
    while(
    $i < array\length($items),
    (
    $productType = record\attribute('QuoteItem', array\at($items, $i), 'product.customtyp');
    $amount = record\attribute('QuoteItem', array\at($items, $i), 'amount');
    
    ifThen($productType == 'Dienstleistung TKD und Support', $support = $support + $amount);
    ifThen($productType == 'Dienstleistung Entwicklung', $entwicklung = $entwicklung + $amount);
    ifThen($productType == 'Betrag Sonstiges' || $productType == null, $sonstiges = $sonstiges + $amount);
    ifThen($productType == 'Reise', $reise = $reise + $amount);
    $i = $i + 1;
    
    )
    );
    
    ifThenElse($support > 0, cAmmountDLTKDSup = $support, cAmmountDLTKDSup = null);
    ifThenElse($entwicklung > 0, cAmmountDLEntw = $entwicklung, cAmmountDLEntw = null);
    ifThenElse($sonstiges > 0, cAmmountsonst = $sonstiges, cAmmountsonst = null);
    
    cAmmountdl=cAmmountDLEntw+cAmmountDLTKDSup;
    $sonstiges = cAmmountsonst+cAmmountreise;
    
    amount=cAmmountdl+$sonstiges;
    
    ifThenElse(cAmmountdl > 0, cAmmountDLGesetzt = true, cAmmountDLGesetzt = false);
    ifThenElse(cAmmountreise > 0, cAmmountreiseGesetzt = true, cAmmountreiseGesetzt = false);
    The Problem is, that some amounts are not calulated if changing positions automatically. Some are and some are not.

    Second if i insert more positions via a workflow, the tax rate is always 0 % if price is 0.
    This is for a block that is used as a template and some prices have to be filled in.

    I insert on Position No. 907, 908 and 909 and so on.

    In the past that was working without the need of programming workarounds or buttons to get correct sums.

    ​
    ​
  • yuri
    EspoCRM product developer
    • Mar 2014
    • 10125

    #2
    It could be not a bug but an intentional behavior.

    Since we have complex tax calculations, the code calculating totals has became more ridgid.
    Last edited by yuri; Today, 01:45 PM.

    Comment

    • macistda
      Senior Member
      • Jul 2022
      • 122

      #3
      Simpler example:

      "Amount before discount" is calculated
      "Amount" is not calculated

      If I press "apply tax profile" in the positions "...", the Amount is calculated correctly, too (Tax was correct in this case before pressing "apply tax profile")

      Unsaved:
      Click image for larger version  Name:	image.png Views:	0 Size:	52.7 KB ID:	128651

      After saved:
      Click image for larger version  Name:	image.png Views:	0 Size:	48.9 KB ID:	128650​

      After applied "apply tax profile":
      ​​Click image for larger version

Name:	image.png
Views:	12
Size:	45.6 KB
ID:	128653​
      ​
      ​
      Last edited by macistda; Today, 01:52 PM.

      Comment

      • yuri
        EspoCRM product developer
        • Mar 2014
        • 10125

        #4
        I see that your custom code adds an additional value to the amount. This goes against the internal logic of the system. For example, sums won't add up in E-Invoices.

        Having this value registered as a separate line item would be more a proper way.

        Comment

        • macistda
          Senior Member
          • Jul 2022
          • 122

          #5
          Thanks for pointing that out. I’m not sure why that formula was included; it likely dates back to a time before e-invoices. I’ve removed it, and the program’s behavior has changed as a result. At first glance, it seems better. If I’m mistaken, I’ll be back in touch—thanks a lot!

          Comment

          Working...