Пример #1
0
def enrich_acq_receipt_line_data(sender,
                                 json=None,
                                 record=None,
                                 index=None,
                                 doc_type=None,
                                 arguments=None,
                                 **dummy_kwargs):
    """Signal sent before a record is indexed.

    :param json: The dumped record dictionary which can be modified.
    :param record: The record being indexed.
    :param index: The index in which the record will be indexed.
    :param doc_type: The doc_type for the record.
    """
    if index.split('-')[0] == AcqReceiptLinesSearch.Meta.index:
        if not isinstance(record, AcqReceiptLine):
            record = AcqReceiptLine.get_record_by_pid(record.get('pid'))
        # other dynamic keys
        json.update({
            'acq_account': {
                'pid': record.order_line.account_pid,
                'type': 'acac'
            },
            'document': {
                'pid': record.order_line.document_pid,
                'type': 'doc'
            },
            'total_amount': record.total_amount
        })
Пример #2
0
def acq_receipt_line_fiction_sion(app, acq_receipt_fiction_sion,
                                  acq_order_line_fiction_sion,
                                  acq_receipt_line_fiction_sion_data):
    """Load acq_receipt_line lib sion fiction record."""
    acrl = AcqReceiptLine.create(data=acq_receipt_line_fiction_sion_data,
                                 delete_pid=False,
                                 dbcommit=True,
                                 reindex=True)
    flush_index(AcqReceiptLinesSearch.Meta.index)
    return acrl
Пример #3
0
def test_acq_receipt_lines_es_mapping(es, db, lib_martigny, vendor_martigny,
                                      acq_receipt_line_1_fiction_martigny,
                                      acq_receipt_line_1_fiction_martigny_data
                                      ):
    """Test acquisition receipt lines elasticsearch mapping."""
    search = AcqReceiptLinesSearch()
    mapping = get_mapping(search.Meta.index)
    assert mapping
    receipt = AcqReceiptLine.create(
        acq_receipt_line_1_fiction_martigny_data,
        dbcommit=True,
        reindex=True,
        delete_pid=True
    )
    assert mapping == get_mapping(search.Meta.index)
    receipt.delete(force=True, dbcommit=True, delindex=True)
Пример #4
0
    def create_receipt_lines(self,
                             receipt_lines=None,
                             dbcommit=True,
                             reindex=True):
        """Create multiple receipt lines.

        :param receipt_lines: a list of dicts to create the records.
        :param dbcommit: if True call dbcommit, make the change effective
                         in db.
        :param reindex: reindex the record.
        :returns: a list containing the given data to build the receipt line
                  with a `status` field, either `success` or `failure`.
                  In case of `success`, the created record is returned.
                  In case `failure`, the reason is given in a field `error`
        """
        created_receipt_lines = []
        receipt_lines = receipt_lines or []
        for receipt_line in receipt_lines:
            record = {
                'data': receipt_line,
                'status': AcqReceiptLineCreationStatus.SUCCESS
            }
            receipt_line['acq_receipt'] = {
                '$ref': get_ref_for_pid('acre', self.pid)
            }
            try:
                line = AcqReceiptLine.create(receipt_line,
                                             dbcommit=dbcommit,
                                             reindex=reindex)
                record['receipt_line'] = line
            except Exception as error:
                record['status'] = AcqReceiptLineCreationStatus.FAILURE
                record['error_message'] = str(error)
            created_receipt_lines.append(record)

        return created_receipt_lines