/**
  * Adds the line item as a child to this line item. If there is another child line
  * item with the same LIN_code, it is overwritten by this new one
  * @param EEI_Line_Item $line_item
  * @param bool         $set_order
  * @return bool success
  * @throws \EE_Error
  */
 function add_child_line_item(EEI_Line_Item $line_item, $set_order = true)
 {
     // should we calculate the LIN_order for this line item ?
     if ($set_order || $line_item->order() === null) {
         $line_item->set_order(count($this->children()));
     }
     if ($this->ID()) {
         //check for any duplicate line items (with the same code), if so, this replaces it
         $line_item_with_same_code = $this->get_child_line_item($line_item->code());
         if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) {
             $this->delete_child_line_item($line_item_with_same_code->code());
         }
         $line_item->set_parent_ID($this->ID());
         if ($this->TXN_ID()) {
             $line_item->set_TXN_ID($this->TXN_ID());
         }
         return $line_item->save();
     } else {
         $this->_children[$line_item->code()] = $line_item;
         if ($line_item->parent() != $this) {
             $line_item->set_parent($this);
         }
         return TRUE;
     }
 }