Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision issue if you use a logic hook to calculate a value triggered by scheduler #10573

Open
trollr opened this issue Nov 14, 2024 · 4 comments
Labels
Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Severity: Moderate Key function failed, but no or little impact Type: Bug Bugs within the core SuiteCRM codebase

Comments

@trollr
Copy link

trollr commented Nov 14, 2024

Issue

We have a scheduler that creates an object once a night with sub-objects with amounts (relationship). After the object is saved, we calculate in a before_save logic hook the total sum of all amounts (in sub objects) and write the calculated sum into a field.

If you edit the object and save it again, the calculation works. The amount is correct. However, if the calculation is triggered from the scheduler, the field is formatted incorrectly. It seems as if the precision of the field is simply added after the calculated value.

This is what it looks like after the scheduler has calculated the field:

scheduler

This is what it looks like when you edit the field

edit

And this happens if you save the object manually (edit->save) without making any changes (the logic hook runs again)

manuel-save

Thats how we calculate the sum

if (count($entries) > 0) {
        $bean->sum = array_sum(array_map(fn($item) => (float)$item->amount, $entries));
        $bean->entries_amount = count($entries);
}

That's the vardefs of the sum field

  'sum' =>
  array (
    'required' => false,
    ...
    'merge_filter' => 'disabled',
    'len' => 26,
    'size' => '20',
    'enable_range_search' => false,
    'precision' => 6,
  ),

How is it possible that the scheduler gives us an incorrect sum?

Possible Fix

No response

Steps to Reproduce the Issue

1. Create a scheduler that creates an object with sub-objects. Each sub-object has an amount field with a value
2. Create a before_save hook that iterates through the subobjects and calculates the total sum
3. Add the total sum to the sum field (Precision 6) of the parent object
4. The precision was simply added as zeros at the end of the calculated sum

Context

No response

Version

7.14.5

What browser are you currently using?

Chrome

Browser Version

No response

Environment Information

7.4.3-4ubuntu2.19

Operating System and Version

Ubuntu

@trollr trollr added the Type: Bug Bugs within the core SuiteCRM codebase label Nov 14, 2024
@pgorod
Copy link
Contributor

pgorod commented Nov 14, 2024

The scheduler uses a different PHP (CLI). This is configured in a separate php.ini file.

Check if you have different settings there that might be affecting this... Locales, number formats, etc

@trollr
Copy link
Author

trollr commented Nov 14, 2024

Hi,

thanks for your response. That was actually the first thing I thought. So I ran a test script via the CLI that basically does the same thing. Result: Everything was correct. No zeros that shouldn't be there. Hence my assumption that it must be a problem in Suite. Especially because there really are 6 zeros appended to the calculated value. If I adjust the precision in the vardefs, it will also be correspondingly more or less

My Testscript for the cli:

<?php

$ar = array(
        (object)array('amount' => 1.23),
        (object)array('amount' => 2.34),
        (object)array('amount' => 3.456)
);

if (count($ar) > 0) {
        echo array_sum(array_map(fn($item) => (float)$item->amount, $ar));
        echo count($ar);
}

@johnM2401 johnM2401 added Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Severity: Moderate Key function failed, but no or little impact labels Nov 14, 2024
@pgorod
Copy link
Contributor

pgorod commented Nov 14, 2024

This is definitely weird...
Have you checked the database to see how values are stored there?

@trollr
Copy link
Author

trollr commented Nov 15, 2024

Yes, it is also saved in the database with the zeros -.-

We still had an old staging system on version 7.13.3. There it worked without any problems or errors.

I have now updated it to the latest Suite version (7.14.6). After the update, the error also occurs on Staging. So there must be some change between version 7.13.3 and 7.14.6. Our production system is also on version 7.14.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Important Issues & PRs that are important; broken functions, errors - there are workarounds Severity: Moderate Key function failed, but no or little impact Type: Bug Bugs within the core SuiteCRM codebase
Projects
None yet
Development

No branches or pull requests

3 participants