# Copyright (C) 2010-2011 Richard Lincoln
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.

from CIM15.IEC61970.Core.IdentifiedObject import IdentifiedObject

class ErpPayableLineItem(IdentifiedObject):
    """Of an ErpPayable, a line item references an ErpInvoiceLineitem or other source such as credit memos.Of an ErpPayable, a line item references an ErpInvoiceLineitem or other source such as credit memos.
    """

    def __init__(self, ErpPayments=None, ErpJournalEntries=None, ErpInvoiceLineItem=None, ErpPayable=None, status=None, *args, **kw_args):
        """Initialises a new 'ErpPayableLineItem' instance.

        @param ErpPayments:
        @param ErpJournalEntries:
        @param ErpInvoiceLineItem:
        @param ErpPayable:
        @param status:
        """
        self._ErpPayments = []
        self.ErpPayments = [] if ErpPayments is None else ErpPayments

        self._ErpJournalEntries = []
        self.ErpJournalEntries = [] if ErpJournalEntries is None else ErpJournalEntries

        self._ErpInvoiceLineItem = None
        self.ErpInvoiceLineItem = ErpInvoiceLineItem

        self._ErpPayable = None
        self.ErpPayable = ErpPayable

        self.status = status

        super(ErpPayableLineItem, self).__init__(*args, **kw_args)

    _attrs = []
    _attr_types = {}
    _defaults = {}
    _enums = {}
    _refs = ["ErpPayments", "ErpJournalEntries", "ErpInvoiceLineItem", "ErpPayable", "status"]
    _many_refs = ["ErpPayments", "ErpJournalEntries"]

    def getErpPayments(self):
        
        return self._ErpPayments

    def setErpPayments(self, value):
        for p in self._ErpPayments:
            filtered = [q for q in p.ErpPayableLineItems if q != self]
            self._ErpPayments._ErpPayableLineItems = filtered
        for r in value:
            if self not in r._ErpPayableLineItems:
                r._ErpPayableLineItems.append(self)
        self._ErpPayments = value

    ErpPayments = property(getErpPayments, setErpPayments)

    def addErpPayments(self, *ErpPayments):
        for obj in ErpPayments:
            if self not in obj._ErpPayableLineItems:
                obj._ErpPayableLineItems.append(self)
            self._ErpPayments.append(obj)

    def removeErpPayments(self, *ErpPayments):
        for obj in ErpPayments:
            if self in obj._ErpPayableLineItems:
                obj._ErpPayableLineItems.remove(self)
            self._ErpPayments.remove(obj)

    def getErpJournalEntries(self):
        
        return self._ErpJournalEntries

    def setErpJournalEntries(self, value):
        for p in self._ErpJournalEntries:
            filtered = [q for q in p.ErpPayableLineItems if q != self]
            self._ErpJournalEntries._ErpPayableLineItems = filtered
        for r in value:
            if self not in r._ErpPayableLineItems:
                r._ErpPayableLineItems.append(self)
        self._ErpJournalEntries = value

    ErpJournalEntries = property(getErpJournalEntries, setErpJournalEntries)

    def addErpJournalEntries(self, *ErpJournalEntries):
        for obj in ErpJournalEntries:
            if self not in obj._ErpPayableLineItems:
                obj._ErpPayableLineItems.append(self)
            self._ErpJournalEntries.append(obj)

    def removeErpJournalEntries(self, *ErpJournalEntries):
        for obj in ErpJournalEntries:
            if self in obj._ErpPayableLineItems:
                obj._ErpPayableLineItems.remove(self)
            self._ErpJournalEntries.remove(obj)

    def getErpInvoiceLineItem(self):
        
        return self._ErpInvoiceLineItem

    def setErpInvoiceLineItem(self, value):
        if self._ErpInvoiceLineItem is not None:
            self._ErpInvoiceLineItem._ErpPayableLineItem = None

        self._ErpInvoiceLineItem = value
        if self._ErpInvoiceLineItem is not None:
            self._ErpInvoiceLineItem.ErpPayableLineItem = None
            self._ErpInvoiceLineItem._ErpPayableLineItem = self

    ErpInvoiceLineItem = property(getErpInvoiceLineItem, setErpInvoiceLineItem)

    def getErpPayable(self):
        
        return self._ErpPayable

    def setErpPayable(self, value):
        if self._ErpPayable is not None:
            filtered = [x for x in self.ErpPayable.ErpPayableLineItems if x != self]
            self._ErpPayable._ErpPayableLineItems = filtered

        self._ErpPayable = value
        if self._ErpPayable is not None:
            if self not in self._ErpPayable._ErpPayableLineItems:
                self._ErpPayable._ErpPayableLineItems.append(self)

    ErpPayable = property(getErpPayable, setErpPayable)

    status = None

