Example #1
0
    def get_receipt_lines(self, output=None):
        """Get all receipt lines related to this receipt.

        :param output: output method. 'count', 'pids' or None.
        :return a generator of related order lines (or length).
        """
        query = AcqReceiptLinesSearch()\
            .filter('term', acq_receipt__pid=self.pid)

        if output == 'count':
            return query.count()
        elif output == 'pids':
            return sorted_pids(query)
        else:
            return self._list_object_by_id(AcqReceiptLine, query)
Example #2
0
    def get_links_to_me(self, get_pids=False):
        """Record links.

        :param get_pids: if True list of linked pids
                         if False count of linked records
        """
        from ..acq_receipt_lines.api import AcqReceiptLinesSearch
        links = {}
        receipt_lines_query = AcqReceiptLinesSearch() \
            .filter('term', acq_receipt__pid=self.pid)
        if get_pids:
            acq_receipt_lines = sorted_pids(receipt_lines_query)
        else:
            acq_receipt_lines = receipt_lines_query.count()

        if acq_receipt_lines:
            links['acq_receipt_lines'] = acq_receipt_lines
        return links