-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] functions: create helper for COUNTUNIQUE
This commit is a step to introduce the spreadsheet pivot. The function COUNTUNIQUE is used in the pivot table to count the unique values in a range. The helper function is created to avoid code duplication. Task: 3748717 Part-of: #4025 Co-authored-by: rrahir <rar@odoo.com> Co-authored-by: Pierre Rousseau <pro@odoo.com>
- Loading branch information
Showing
2 changed files
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { Arg, Locale } from "../types"; | ||
import { reduceNumbers } from "./helpers"; | ||
import { Arg, FPayload, Locale } from "../types"; | ||
import { reduceAny, reduceNumbers } from "./helpers"; | ||
|
||
export function isDefined(data: FPayload | undefined): boolean { | ||
if (data === undefined) { | ||
return false; | ||
} | ||
const { value } = data; | ||
if (value === null || value === "") { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
export function sum(values: Arg[], locale: Locale): number { | ||
return reduceNumbers(values, (acc, a) => acc + a, 0, locale); | ||
} | ||
|
||
export function countUnique(args: Arg[]): number { | ||
return reduceAny(args, (acc, a) => (isDefined(a) ? acc.add(a?.value) : acc), new Set()).size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters