Exemple #1
0
    def _download_on_button_id(self, button_id, destination):
        """ Download a file.
        Returns the path to file or None if nothing was downloaded
        """

        # mainlog.debug("_download_on_button_id() : button_id={}".format(button_id))
        doc_id = self.button_data[button_id]

        # if os.path.isabs(full_path_client):
        #     # The file was uploaded during this GUI session. Therefore we
        #     # still know where we picked it from (FIXME unless someone has
        #     # removed it...)
        #
        #     return full_path_client
        # else:

        progress_bar = make_progress(_("Downloading"), 100)

        def progress_tracker(percent):
            progress_bar.setValue(int(percent))

        try:
            path = download_document(doc_id, progress_tracker, destination)
            return path
        except Exception as exc:
            progress_bar.close()
            showErrorBox(_(
                "There was a problem while downloading the file from the server"
            ),
                         ex=exc,
                         object_name="file_upload_error")
            return None

        progress_bar.close()
Exemple #2
0
def upload_download(pid):
    for i in range(100):
        print("[{}] {}".format(pid,i))

        # Download the delivery_slips version
        next_version = get_server_version(configuration.update_url_version) # available on the server (abd maybe already downloaded)

        # Download the delivery_slips
        tmpfile = r"c:\temp\test_{}.tst".format(pid)
        # download_file(configuration.update_url_file,tmpfile)

        # Upload a document
        n = r"c:\temp\test_{}_{}.tst".format(pid,i)
        fh = open(n,'w')
        fh.write(n)
        fh.close()

        doc_id = 0
        try:
            doc_id = upload_document(n)
        except BadStatusLine as ex:
            print("upload")
            print(doc_id)
            print( ex.__dir__())
            raise ex

        df = None
        try:
            df = download_document(doc_id) # sys.executable
        except BadStatusLine as ex:
            print("download")
            print(doc_id)
            print( ex.__dir__())
            raise ex

        fh = open(df,'r')
        t = fh.read(1000)
        fh.close()

        assert t == n
def print_order_confirmation_report(order_id):

    documents_service = JsonCallWrapper(DocumentsService(),
                                        JsonCallWrapper.HTTP_MODE)
    doc_id = documents_service.reference_to_document_id(HORSE_REFERENCE)

    if not doc_id:
        raise Exception(
            _("The template document with reference <code>{}</code> was not found. Check your templates."
              ).format(HORSE_REFERENCE))

    tpl_path = download_document(doc_id)

    order = dao.order_dao.find_by_id(order_id)

    from decimal import localcontext, Decimal

    with localcontext() as ctx:  # decimal context
        ctx.prec = 10 + 2
        qtize = Decimal(10)**-2

        grand_total = Decimal(0)
        from koi.reporting.utils import moneyfmt

        parts_table = []
        for part in order.parts:

            qty = Decimal(part.qty).quantize(qtize)
            sell_price = Decimal(part.sell_price).quantize(qtize)
            total_price = (qty * sell_price).quantize(qtize)

            grand_total += total_price

            parts_table.append({
                'ref': part.human_identifier,
                'description': part.description or "",
                'quantity': part.qty,
                'unit_price': moneyfmt(sell_price),
                'total_price': moneyfmt(total_price)
            })

    context = {
        'customer_name': order.customer.fullname or "",
        'customer_address1': order.customer.address1 or "",
        'customer_address2': order.customer.address2 or "",
        'customer_country': order.customer.country or "",
        'order_number': order.accounting_label or order.preorder_label,
        'order_reference_customer': order.customer_order_name or "",
        'total_parts': moneyfmt(grand_total),
        'items': parts_table,
    }

    tpl = DocxTemplate(tpl_path)
    tpl.render(context)
    doc_path = make_home_file("order_confirmation_report_{}.docx".format(
        order.accounting_label or order.preorder_label))

    tpl.save(doc_path)

    os.unlink(tpl_path)

    open_a_file_on_os(doc_path)