Skip to content

Instantly share code, notes, and snippets.

@dmop
Last active January 13, 2022 13:04
Show Gist options
  • Select an option

  • Save dmop/b740d0a4d253d05f8df2ef467f70ac68 to your computer and use it in GitHub Desktop.

Select an option

Save dmop/b740d0a4d253d05f8df2ef467f70ac68 to your computer and use it in GitHub Desktop.

Revisions

  1. dmop revised this gist Jan 13, 2022. 1 changed file with 28 additions and 26 deletions.
    54 changes: 28 additions & 26 deletions force-new-redispatch-order.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    from datetime import datetime
    from typing import List

    from players.models import LoggiUser
    from proto.integration.api.label.v1.label_pb2 import LABEL_RESPONSE_TYPE_URL
    from logging import getLogger
    @@ -11,15 +13,11 @@

    logger = getLogger(__name__)

    package_ids = []
    posting_card_number = "000000000"
    is_emergency = False
    application_name = "xd_app"
    distribution_center_id = 1


    def get_or_create_redispatch_label(
    package_id: int
    def create_new_redispatch(
    package_id: int,
    posting_card_number: str,
    distribution_center_id: int
    ) -> GetOrCreateRedispatchLabelResponse:
    client = RedispatchClient()

    @@ -38,16 +36,16 @@ def get_or_create_redispatch_label(
    confirmed_by = LoggiUser.objects.get(id=created_by_id)

    pkg.make_sure_is_confirmed(confirmed_at=datetime.now(),
    whom=confirmed_by.full_name,
    distribution_center_id=distribution_center_id)
    whom=confirmed_by.full_name,
    distribution_center_id=distribution_center_id)

    client.save_redispatch(
    redispatch_response=response.redispatch,
    package=pkg,
    is_emergency=is_emergency,
    is_emergency=False,
    distribution_center_id=distribution_center_id,
    created_by_id=created_by_id,
    application_name=application_name
    application_name="xd_app"
    )

    with in_read_only_database():
    @@ -56,17 +54,21 @@ def get_or_create_redispatch_label(
    pkg.update_status(task)


    pkgs_processed = 0
    for pkg_id in package_ids:
    print(f"--------------------------------")
    print(f"iniciando -> {pkg_id}")
    get_or_create_redispatch_label(pkg_id)

    pkgs_processed += 1
    print(f"processado {pkgs_processed} -> {pkg_id}")
    print(f"--------------------------------")


    for pkg_id in package_ids:
    pkg = get_package_by_id(pkg_id)
    print(f'curl {pkg.redispatches.last().label_url} -o {pkg_id}.pdf')
    def force_create_new_redispatches(
    package_ids: List[int],
    posting_card_number: str,
    distribution_center_id: int
    ):
    pkgs_processed = 0
    for pkg_id in package_ids:
    print(f"--------------------------------")
    print(f"iniciando -> {pkg_id}")
    create_new_redispatch(pkg_id, posting_card_number, distribution_center_id)

    pkgs_processed += 1
    print(f"processado {pkgs_processed} -> {pkg_id}")
    print(f"--------------------------------")

    for pkg_id in package_ids:
    pkg = get_package_by_id(pkg_id)
    print(f'curl {pkg.redispatches.last().label_url} -o {pkg_id}.pdf')
  2. dmop revised this gist Jan 13, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions force-new-redispatch-order.py
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,10 @@
    logger = getLogger(__name__)

    package_ids = []
    posting_card_number = "0074837273"
    posting_card_number = "000000000"
    is_emergency = False
    application_name = "xd_app"
    distribution_center_id = 1029
    distribution_center_id = 1


    def get_or_create_redispatch_label(
  3. dmop renamed this gist Jan 13, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. dmop renamed this gist Jan 13, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. dmop created this gist Jan 13, 2022.
    72 changes: 72 additions & 0 deletions file.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    from datetime import datetime
    from players.models import LoggiUser
    from proto.integration.api.label.v1.label_pb2 import LABEL_RESPONSE_TYPE_URL
    from logging import getLogger
    from base.db.router import in_eventual_consistence_database, in_read_only_database
    from proto.loggi_web.v1.api_pb2 import GetOrCreateRedispatchLabelResponse
    from wms.redispatch.redispatch_client import RedispatchClient
    from wms.redispatch.repository import (
    get_package_by_id
    )

    logger = getLogger(__name__)

    package_ids = []
    posting_card_number = "0074837273"
    is_emergency = False
    application_name = "xd_app"
    distribution_center_id = 1029


    def get_or_create_redispatch_label(
    package_id: int
    ) -> GetOrCreateRedispatchLabelResponse:
    client = RedispatchClient()

    pkg = get_package_by_id(package_id)
    created_by_id = pkg.redispatches.last().created_by_id

    response, label_error = client.get_or_create_redispatch_label(
    package=pkg,
    distribution_center_id=distribution_center_id,
    posting_card_number=posting_card_number,
    force_create=True,
    response_type=LABEL_RESPONSE_TYPE_URL,
    )

    with in_eventual_consistence_database():
    confirmed_by = LoggiUser.objects.get(id=created_by_id)

    pkg.make_sure_is_confirmed(confirmed_at=datetime.now(),
    whom=confirmed_by.full_name,
    distribution_center_id=distribution_center_id)

    client.save_redispatch(
    redispatch_response=response.redispatch,
    package=pkg,
    is_emergency=is_emergency,
    distribution_center_id=distribution_center_id,
    created_by_id=created_by_id,
    application_name=application_name
    )

    with in_read_only_database():
    task = pkg.tasks.latest('created')

    pkg.update_status(task)


    pkgs_processed = 0
    for pkg_id in package_ids:
    print(f"--------------------------------")
    print(f"iniciando -> {pkg_id}")
    get_or_create_redispatch_label(pkg_id)

    pkgs_processed += 1
    print(f"processado {pkgs_processed} -> {pkg_id}")
    print(f"--------------------------------")


    for pkg_id in package_ids:
    pkg = get_package_by_id(pkg_id)
    print(f'curl {pkg.redispatches.last().label_url} -o {pkg_id}.pdf')