<commit_before>/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import Realm from 'realm';
import { complement } from 'set-manipulator';

import { createRecord, getTotal } from '../utilities';

/**
 * A requisition.
 *
 * @property  {string}                  id
 * @property  {string}                  status
 * @property  {Name}                    otherStoreName
 * @property  {string}                  type                Type of requisition, valid values
 *                                                          are 'imprest', 'forecast', 'request',
 *                                                          'response'.
 * @property  {Date}                    entryDate
 * @property  {number}                  daysToSupply
 * @property  {string}                  serialNumber
 * @property  {string}                  requesterReference
 * @property  {string}                  comment
 * @property  {User}                    enteredBy
 * @property  {List.<RequisitionItem>}  items
 * @property  {Transaction}             linkedTransaction
 * @property  {MasterList}              program
 * @property  {Period}                  period
 * @property  {String}                  orderType
 */
export class Requisition extends Realm.Object {
  /**
   * Create a new requisition.
   */
  constructor() {
    super();
    this.removeItemsById = this.removeItemsById.bind(this);
    this.addItemsFromMasterList = this.addItemsFromMasterList.bind(this);
    this.addItem = this.addItem.bind(this);
    this.setRequestedToSuggested = this.setRequestedToSuggested.bind(this);
  }

  /**
   * Delete requisition and associated requisition items/period.
   *
   * @param {Realm} database
   */
  destructor(database) {
    if (this.period) {
      this.period.removeRequisition(this, database);
    }
    database.delete('RequisitionItem', this.items);
  }

  /**
   * Get if requisition is confirmed.
   *
   * @return  {boolean}
   */
  get isConfirmed() {
    return this.status === 'confirmed';
  }

  /**
   * Get if requisition is finalised.
   *
   * @return  {boolean}
   */
  get isFinalised() {
    return this.status === 'finalised';
  }

  /**<commit_msg>Add removal of requisition destructor update<commit_after>/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import Realm from 'realm';
import { complement } from 'set-manipulator';

import { createRecord, getTotal } from '../utilities';

/**
 * A requisition.
 *
 * @property  {string}                  id
 * @property  {string}                  status
 * @property  {Name}                    otherStoreName
 * @property  {string}                  type                Type of requisition, valid values
 *                                                          are 'imprest', 'forecast', 'request',
 *                                                          'response'.
 * @property  {Date}                    entryDate
 * @property  {number}                  daysToSupply
 * @property  {string}                  serialNumber
 * @property  {string}                  requesterReference
 * @property  {string}                  comment
 * @property  {User}                    enteredBy
 * @property  {List.<RequisitionItem>}  items
 * @property  {Transaction}             linkedTransaction
 * @property  {MasterList}              program
 * @property  {Period}                  period
 * @property  {String}                  orderType
 */
export class Requisition extends Realm.Object {
  /**
   * Create a new requisition.
   */
  constructor() {
    super();
    this.removeItemsById = this.removeItemsById.bind(this);
    this.addItemsFromMasterList = this.addItemsFromMasterList.bind(this);
    this.addItem = this.addItem.bind(this);
    this.setRequestedToSuggested = this.setRequestedToSuggested.bind(this);
  }

  /**
   * Delete requisition and associated requisition items/period.
   *
   * @param {Realm} database
   */
  destructor(database) {
    database.delete('RequisitionItem', this.items);
  }

  /**
   * Get if requisition is confirmed.
   *
   * @return  {boolean}
   */
  get isConfirmed() {
    return this.status === 'confirmed';
  }

  /**
   * Get if requisition is finalised.
   *
   * @return  {boolean}
   */
  get isFinalised() {
    return this.status === 'finalised';
  }

  /**
{'fraction_non_alphanumeric': 0.11178247734138973, 'fraction_numerical': 0.0018591680223100163, 'mean_word_length': 1.8185985592665357, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1197567', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1141, 'n_words': 275}