@darkpos/pricing 1.0.100 → 1.0.101

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.
@@ -239,4 +239,64 @@ describe('pickEndDate function', () => {
239
239
 
240
240
  expect(result).toBe('2025-05-14T15:00:00Z');
241
241
  });
242
+
243
+ test('pickEndDate - filters out schedules with departments', () => {
244
+ const schedulesWithDepartments = [
245
+ {
246
+ _id: 'schedule-with-departments',
247
+ dayOfWeek: [2],
248
+ recommended: 'auto_recommended',
249
+ addDays: 2,
250
+ cutDay: 1,
251
+ skipDays: [1],
252
+ readyHour: { hour: 18, minute: 0 },
253
+ cutHour: { hour: 16, minute: 0 },
254
+ departments: [{ _id: 'department-id' }],
255
+ },
256
+ {
257
+ _id: 'schedule-without-departments',
258
+ dayOfWeek: [2],
259
+ recommended: 'auto_recommended',
260
+ addDays: 1,
261
+ cutDay: 1,
262
+ skipDays: [1],
263
+ readyHour: { hour: 17, minute: 0 },
264
+ cutHour: { hour: 16, minute: 0 },
265
+ },
266
+ ];
267
+
268
+ const pricingService = usePricing(
269
+ getDefaultSettings(schedulesWithDepartments)
270
+ );
271
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
272
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
273
+
274
+ const result = pricingService.store.pickEndDate();
275
+
276
+ expect(result).toBe('2025-05-14T21:00:00Z');
277
+ });
278
+
279
+ test('pickEndDate - uses provided schedules even with departments', () => {
280
+ const scheduleWithDepartments = [
281
+ {
282
+ _id: 'schedule-with-departments',
283
+ dayOfWeek: [2],
284
+ recommended: 'auto_recommended',
285
+ addDays: 2,
286
+ cutDay: 1,
287
+ skipDays: [1],
288
+ readyHour: { hour: 18, minute: 0 },
289
+ cutHour: { hour: 16, minute: 0 },
290
+ departments: [{ _id: 'department-id' }],
291
+ },
292
+ ];
293
+
294
+ const pricingService = usePricing(getDefaultSettings());
295
+ const now = moment('2025-05-13T15:00:00Z').tz('America/New_York');
296
+ jest.spyOn(moment, 'now').mockImplementation(() => now.valueOf());
297
+
298
+ const result = pricingService.store.pickEndDate(scheduleWithDepartments);
299
+
300
+ expect(result).toBe('2025-05-15T22:00:00Z');
301
+ });
242
302
  });
@@ -1,4 +1,12 @@
1
- module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
1
+ module.exports = ({
2
+ utils,
3
+ _,
4
+ actions,
5
+ itemActions,
6
+ modifierActions,
7
+ settings,
8
+ storeActions,
9
+ }) => {
2
10
  const { helpers } = utils;
3
11
 
4
12
  const isSplitByPieces = splitUnit => splitUnit === 'pieces';
@@ -26,16 +34,45 @@ module.exports = ({ utils, _, actions, itemActions, modifierActions }) => {
26
34
  return { ...order, items };
27
35
  });
28
36
 
29
- return function splitByDepartments({ parentOrder, newItems }) {
37
+ const getDepartmentSchedules = department => {
38
+ if (!department) return null;
39
+ const allSchedules = _.get(settings, 'order.schedules', []);
40
+ return allSchedules.filter(item =>
41
+ item.departments.some(dep => dep._id === department.modifierId)
42
+ );
43
+ };
44
+
45
+ return function splitByDepartments({
46
+ parentOrder: parentOrderParam,
47
+ newItems,
48
+ }) {
30
49
  const itemsByDepartments = _.groupBy(newItems, getDepartmentName);
31
50
  const itemGroups = Object.values(itemsByDepartments);
32
51
  let splitOrders = [];
52
+ const defaultEndDate = storeActions.pickEndDate();
53
+ const isDefaultEndDate =
54
+ !parentOrderParam.end ||
55
+ !parentOrderParam.end.requestDate ||
56
+ utils.date.isEqual(defaultEndDate, parentOrderParam.end.requestDate);
33
57
 
34
58
  itemGroups.forEach(items => {
35
59
  // Assuming there is one department in the item
36
60
  const department = itemActions.getDepartmentModifiers(items[0])[0];
37
61
  const departmentName = getDepartmentName(items[0]);
38
62
  const maxItems = modifierActions.getDepartmentMaxItems(department);
63
+ const departmentSchedules = getDepartmentSchedules(department);
64
+ let parentOrder = { ...parentOrderParam };
65
+
66
+ if (
67
+ departmentSchedules &&
68
+ departmentSchedules.length &&
69
+ isDefaultEndDate
70
+ ) {
71
+ parentOrder = actions.changeEndDate({
72
+ date: storeActions.pickEndDate(departmentSchedules),
73
+ order: parentOrder,
74
+ });
75
+ }
39
76
 
40
77
  const autoSplit = _.get(
41
78
  department || {},
@@ -1,5 +1,7 @@
1
1
  module.exports = ({ settings, _, moment }) => {
2
- const timezone = _.get(settings, 'localization.timezone', 'America/New_York');
2
+ const timezone =
3
+ _.get(settings, 'localization.timezone', 'America/New_York') ||
4
+ 'America/New_York';
3
5
 
4
6
  const getSchedule = (schedules, isoWeekday) => {
5
7
  const todayTZ = moment().tz(timezone);
@@ -7,7 +9,9 @@ module.exports = ({ settings, _, moment }) => {
7
9
  const _schedules =
8
10
  schedules && schedules.length
9
11
  ? schedules
10
- : _.get(settings, 'order.schedules', []);
12
+ : _.get(settings, 'order.schedules', []).filter(
13
+ item => !item.departments || !item.departments.length
14
+ );
11
15
 
12
16
  if (!_schedules.length) {
13
17
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.100",
3
+ "version": "1.0.101",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -54,5 +54,5 @@
54
54
  "supertest": "^6.2.3",
55
55
  "supervisor": "^0.12.0"
56
56
  },
57
- "gitHead": "dbe4e7f639282d1eb04927708dac5195275fe5e4"
57
+ "gitHead": "aad940d770d15b6072fd45e300302002bfc8fc08"
58
58
  }