@fabriktor/fx 0.0.121 → 0.0.122

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.
@@ -88,7 +88,9 @@ export type CreateVendorInvoiceOptions = VendorInvoiceInsertOptions & MultiCreat
88
88
  owner_id: string;
89
89
  allow_duplicate?: boolean;
90
90
  };
91
- export type ReplaceVendorInvoiceOptions = VendorInvoiceReplaceOptions;
91
+ export type ReplaceVendorInvoiceOptions = VendorInvoiceReplaceOptions & {
92
+ allow_duplicate?: boolean;
93
+ };
92
94
  export type SearchVendorInvoicesOptions = OwnerSearchOptions & Partial<Pick<VendorInvoice, "is_archived">>;
93
95
  export type SearchVendorInvoicesPage = SearchPage<VendorInvoice>;
94
96
  export type CreateWarehouseOptions = WarehouseInsertOptions & MultiCreateCheckpoint;
@@ -380,8 +380,17 @@ export class BillableFX {
380
380
  return await this.findVendorInvoice(id);
381
381
  }
382
382
  async replaceVendorInvoice(opts) {
383
- await this.billable.replaceOneVendorInvoice(opts);
384
- return await this.findVendorInvoice(opts.id);
383
+ const { allow_duplicate, ...request } = opts;
384
+ if (request.in.number !== undefined) {
385
+ const current = await this.findVendorInvoice(request.id);
386
+ const number = request.in.number.trim();
387
+ if (!allow_duplicate && number !== current.number) {
388
+ await this.checkVendorInvoiceNumber(current.owner_id, number, current.id);
389
+ }
390
+ request.in = { ...request.in, number };
391
+ }
392
+ await this.billable.replaceOneVendorInvoice(request);
393
+ return await this.findVendorInvoice(request.id);
385
394
  }
386
395
  async searchVendorInvoices(opts) {
387
396
  return await runOwnerSearch({
@@ -479,14 +488,14 @@ export class BillableFX {
479
488
  const id = requiredOperationID(out, msgCreatedBillIDMissing);
480
489
  return await this.findBill(id);
481
490
  }
482
- async checkVendorInvoiceNumber(owner_id, number) {
491
+ async checkVendorInvoiceNumber(owner_id, number, excluding_id) {
483
492
  await runPreActionCheck({
484
493
  reason: BillablePreActionReason.VendorInvoiceNumberExists,
485
494
  allowed: async () => {
486
495
  const out = await this.billable.queryVendorInvoices({
487
496
  query: withOwnerQuery(owner_id, queryParams({ number })),
488
497
  });
489
- return (out.value?.length ?? 0) === 0;
498
+ return !(out.value ?? []).some((record) => record.id !== excluding_id);
490
499
  },
491
500
  });
492
501
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabriktor/fx",
3
- "version": "0.0.121",
3
+ "version": "0.0.122",
4
4
  "description": "![Fabriktor Logo](./img/fabriktor-character.gif)",
5
5
  "type": "module",
6
6
  "exports": {