@bisondesk/core-sdk 1.0.608 → 1.0.610

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/constants.d.ts +1 -0
  2. package/lib/constants.d.ts.map +1 -1
  3. package/lib/constants.js +1 -0
  4. package/lib/constants.js.map +1 -1
  5. package/lib/types/leasing-debtors.d.ts +2 -0
  6. package/lib/types/leasing-debtors.d.ts.map +1 -1
  7. package/lib/types/leasing-debtors.js.map +1 -1
  8. package/lib/types/opportunities.d.ts +6 -1
  9. package/lib/types/opportunities.d.ts.map +1 -1
  10. package/lib/types/opportunities.js +1 -0
  11. package/lib/types/opportunities.js.map +1 -1
  12. package/lib/types/reports-leasing.d.ts +93 -0
  13. package/lib/types/reports-leasing.d.ts.map +1 -0
  14. package/lib/types/reports-leasing.js +11 -0
  15. package/lib/types/reports-leasing.js.map +1 -0
  16. package/lib/types/reports-sales.d.ts +12 -0
  17. package/lib/types/reports-sales.d.ts.map +1 -1
  18. package/lib/types/reports-sales.js.map +1 -1
  19. package/lib/types/tenants.d.ts +2 -0
  20. package/lib/types/tenants.d.ts.map +1 -1
  21. package/lib/types/tenants.js.map +1 -1
  22. package/lib/types/vehicles.d.ts +1 -0
  23. package/lib/types/vehicles.d.ts.map +1 -1
  24. package/lib/types/vehicles.js.map +1 -1
  25. package/lib/utils/accounting.d.ts +6 -0
  26. package/lib/utils/accounting.d.ts.map +1 -0
  27. package/lib/utils/accounting.js +26 -0
  28. package/lib/utils/accounting.js.map +1 -0
  29. package/lib/utils/accounting.test.d.ts +2 -0
  30. package/lib/utils/accounting.test.d.ts.map +1 -0
  31. package/lib/utils/accounting.test.js +93 -0
  32. package/lib/utils/accounting.test.js.map +1 -0
  33. package/package.json +1 -1
  34. package/src/constants.ts +6 -0
  35. package/src/types/leasing-debtors.ts +3 -0
  36. package/src/types/opportunities.ts +12 -0
  37. package/src/types/reports-leasing.ts +186 -0
  38. package/src/types/reports-sales.ts +22 -3
  39. package/src/types/tenants.ts +4 -0
  40. package/src/types/vehicles.ts +1 -0
  41. package/src/utils/accounting.test.ts +115 -0
  42. package/src/utils/accounting.ts +40 -0
  43. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,115 @@
1
+ import { Branch, Tenant } from '../types/tenants.js';
2
+ import {
3
+ branchHasAccounting,
4
+ branchHasAccountingInTenant,
5
+ branchProvider,
6
+ tenantHasAccounting,
7
+ } from './accounting.js';
8
+
9
+ const makeBranch = (overrides: Partial<Branch> = {}): Branch => ({
10
+ id: 'b1',
11
+ name: 'Branch 1',
12
+ country: 'ci',
13
+ language: 'fr',
14
+ currency: 'XOF',
15
+ adminNumberPrefix: '',
16
+ stockNumberPrefix: '',
17
+ vatNumber: '',
18
+ vatRates: { standard: '18' },
19
+ location: { country: 'ci' },
20
+ ...overrides,
21
+ });
22
+
23
+ const makeTenant = (branches: Branch[], overrides: Partial<Tenant> = {}): Tenant =>
24
+ ({
25
+ id: 't',
26
+ name: 't',
27
+ region: 'eu-west-1',
28
+ defaultCountry: 'ci',
29
+ defaultCurrency: 'XOF',
30
+ defaultLanguage: 'fr',
31
+ subdomains: ['t'],
32
+ languages: ['fr'],
33
+ emailDomain: 'example.com',
34
+ branches: branches as [Branch, ...Branch[]],
35
+ modules: [],
36
+ opportunities: { types: [] },
37
+ ...overrides,
38
+ }) as Tenant;
39
+
40
+ describe('branchProvider', () => {
41
+ it('returns undefined for missing branch', () => {
42
+ expect(branchProvider(undefined)).toBeUndefined();
43
+ });
44
+
45
+ it('prefers the new discriminator over the legacy boolean', () => {
46
+ const branch = makeBranch({ accounting: 'odoo', exactAccounting: true });
47
+ expect(branchProvider(branch)).toBe('odoo');
48
+ });
49
+
50
+ it('falls back to legacy boolean as exact', () => {
51
+ const branch = makeBranch({ exactAccounting: true });
52
+ expect(branchProvider(branch)).toBe('exact');
53
+ });
54
+
55
+ it('returns undefined when neither field is set', () => {
56
+ expect(branchProvider(makeBranch())).toBeUndefined();
57
+ });
58
+
59
+ it('returns undefined when legacy boolean is false', () => {
60
+ expect(branchProvider(makeBranch({ exactAccounting: false }))).toBeUndefined();
61
+ });
62
+ });
63
+
64
+ describe('branchHasAccounting', () => {
65
+ it('is true when accounting is set', () => {
66
+ expect(branchHasAccounting(makeBranch({ accounting: 'odoo' }))).toBe(true);
67
+ });
68
+
69
+ it('is true when legacy exactAccounting is true', () => {
70
+ expect(branchHasAccounting(makeBranch({ exactAccounting: true }))).toBe(true);
71
+ });
72
+
73
+ it('is false otherwise', () => {
74
+ expect(branchHasAccounting(makeBranch())).toBe(false);
75
+ expect(branchHasAccounting(undefined)).toBe(false);
76
+ });
77
+ });
78
+
79
+ describe('tenantHasAccounting', () => {
80
+ it('is true when tenant-level legacy flag is set', () => {
81
+ const tenant = makeTenant([makeBranch()], { exactAccounting: true });
82
+ expect(tenantHasAccounting(tenant)).toBe(true);
83
+ });
84
+
85
+ it('is true when any branch has accounting', () => {
86
+ const tenant = makeTenant([makeBranch(), makeBranch({ id: 'b2', accounting: 'odoo' })]);
87
+ expect(tenantHasAccounting(tenant)).toBe(true);
88
+ });
89
+
90
+ it('is false when no branch has accounting and tenant flag is not set', () => {
91
+ expect(tenantHasAccounting(makeTenant([makeBranch()]))).toBe(false);
92
+ expect(tenantHasAccounting(undefined)).toBe(false);
93
+ });
94
+ });
95
+
96
+ describe('branchHasAccountingInTenant', () => {
97
+ it('resolves per branch in a mixed tenant', () => {
98
+ const tenant = makeTenant([
99
+ makeBranch({ id: 'odoo-branch', accounting: 'odoo' }),
100
+ makeBranch({ id: 'plain-branch' }),
101
+ ]);
102
+ expect(branchHasAccountingInTenant(tenant, 'odoo-branch')).toBe(true);
103
+ expect(branchHasAccountingInTenant(tenant, 'plain-branch')).toBe(false);
104
+ });
105
+
106
+ it('ignores the deprecated tenant-wide flag and resolves per branch', () => {
107
+ const tenant = makeTenant([makeBranch({ id: 'plain-branch' })], { exactAccounting: true });
108
+ expect(branchHasAccountingInTenant(tenant, 'plain-branch')).toBe(false);
109
+ });
110
+
111
+ it('is false for an unknown branch or missing tenant', () => {
112
+ expect(branchHasAccountingInTenant(makeTenant([makeBranch()]), 'nope')).toBe(false);
113
+ expect(branchHasAccountingInTenant(undefined, 'b1')).toBe(false);
114
+ });
115
+ });
@@ -0,0 +1,40 @@
1
+ import { AccountingProvider, Branch, Tenant } from '../types/tenants.js';
2
+
3
+ export const branchProvider = (branch: Branch | undefined): AccountingProvider | undefined => {
4
+ if (branch == null) {
5
+ return undefined;
6
+ }
7
+ if (branch.accounting != null) {
8
+ return branch.accounting;
9
+ }
10
+ return branch.exactAccounting ? 'exact' : undefined;
11
+ };
12
+
13
+ export const branchHasAccounting = (branch: Branch | undefined): boolean =>
14
+ branchProvider(branch) != null;
15
+
16
+ export const tenantHasAccounting = (tenant: Tenant | undefined): boolean => {
17
+ if (tenant == null) {
18
+ return false;
19
+ }
20
+ if (tenant.exactAccounting) {
21
+ return true;
22
+ }
23
+ return tenant.branches.some((b) => branchHasAccounting(b));
24
+ };
25
+
26
+ /**
27
+ * Whether a specific branch books through an accounting integration. Resolves
28
+ * purely per branch — a tenant can mix accounting and non-accounting branches.
29
+ * Accounting is carried on the branch (`accounting`, or the deprecated
30
+ * `exactAccounting`), so the tenant-wide flag is not consulted.
31
+ */
32
+ export const branchHasAccountingInTenant = (
33
+ tenant: Tenant | undefined,
34
+ branchId: string,
35
+ ): boolean => {
36
+ if (tenant == null) {
37
+ return false;
38
+ }
39
+ return branchHasAccounting(tenant.branches.find((b) => b.id === branchId));
40
+ };