Skip to content

FEATURE: pass object representation to all *Create and *Update classes' constructor methods #132

Description

@craibuc

Rather than having to do this:

const invoiceCreate = new IA.Functions.AccountsReceivable.InvoiceCreate();
invoiceCreate.customerId = 'Acme, Inc.';
invoiceCreate. glPostingDate = '2024-05-31';
...

const invoiceLineCreate = new IA.Functions.AccountsReceivable.InvoiceLineCreate();
invoiceLineCreate.departmentId = 'Department A';
...

invoiceCreate.lines.add(invoiceLineCreate);
...

It would be helpful to be able to do this instead:

class InvoiceCreate {

  constructor (keyValues) {
    this.lines = []

    for (let key in keyValues) {

      if (key === 'lines') {
        keyValues['lines'].forEach(line => {
          const invoiceLineCreate = new InvoiceLineCreate(line);
          this.lines.push(invoiceLineCreate);            
        });
      }
      else {
        Reflect.set(this, key, keyValues[key]);
      }

    };

  }

}

class InvoiceLineCreate {

  constructor (keyValues) {
    this.customFields = [];

    for (let key in keyValues) {
    
      if (key === 'customFields') {
        keyValues['customFields'].forEach(field => {
          this.customFields.push(field);       
        });
      }
      else {
        Reflect.set(this, key, keyValues[key]);
      }

    };

  }

}

// usage of Update and Creates are greatly simplified
const invoiceCreate = new InvoiceCreate({
  customerId: 'Acme, Inc.',
  invoiceNumber: '12345',
  description: 'lorem ipsum',
  paymentTerm: 'Pre-pay',
  transactionDate: '2024-05-31',
  glPostingDate: '2024-05-31',
  dueDate: '2024-06-30',
  lines: [
    {
      glAccountNumber: '100100',
      transactionAmount: 123.45,
      memo: 'lorem ipsum',
      locationId: 'Location A',
      departmentId: 'Department A',
      projectId: 'Project A',
      customerId: 'Customer A',
      classId: 'Class A',
      customFields: [
        {
          customFieldName: 'some name',
          customFieldValue: 'some value'
        }
      ],
    }
  ]
});

console.log('invoiceCreate',invoiceCreate);
..
// save, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions