def __init__(self, master=None, item_data=None, **kwargs):

        printt(item_data)
        if master is not None:
            self.master = master
        else:
            self.master = Tk()

        Frame.__init__(self, self.master, kwargs)
        self.grid(padx=(0, 0), pady=4, sticky=W + E + N + S)
        self.grid_columnconfigure(0, weight=1, uniform="item_info")
        self.grid_columnconfigure(1, weight=1, uniform="item_info")

        # Fill down into parent
        self.grid_rowconfigure(1, weight=1)
        self.grid_rowconfigure(3, weight=1)
        self.grid_rowconfigure(5, weight=1)

        self.label_heading_font = Font(size=10, underline=0)
        self.underline_heading_font = Font(size=10, underline=1)
        self.item_info_heading_font = Font(size=13, weight=NORMAL)
        self.frame_heading_font = Font(size=10, weight=BOLD, underline=1)

        self.product = Product(item_data)

        if item_data:
            self.load_data(item_data)
    def get_order_info(self, order_id):

        r = self.wcapi.get("orders/" + str(order_id))
        if r.status_code == 404:
            return {"error": "Order not found"}
        elif r.status_code == 401:
            return {"error": "Unauthorized"}
        elif r.status_code == 403:
            return {"error": "Forbidden"}
        elif r.status_code != 200:
            return {"error": "Unexpected response"}
        response = None
        try:
            response = r.json()
        except ValueError():
            printt("get_order_info(): Can't parse response JSON")
        if response:
            order_data = {}
            order_data["id"] = response["number"]
            order_data["status"] = response["status"]
            order_data["date_created"] = response["date_created"]
            order_data["total"] = response["total"]
            order_data["customer_note"] = response["customer_note"]
            # populate customer data
            order_data["customer"] = {}
            order_data["customer"]["first_name"] = response["shipping"][
                "first_name"]
            order_data["customer"]["last_name"] = response["shipping"][
                "last_name"]
            order_data["customer"]["full_name"] = order_data["customer"]["first_name"] + \
                " " + order_data["customer"]["last_name"]
            order_data["customer"]["phone"] = response["billing"]["phone"]
            order_data["customer"]["email"] = response["billing"]["email"]
            order_data["customer"]["address_1"] = response["shipping"][
                "address_1"]
            order_data["customer"]["address_2"] = response["shipping"][
                "address_2"]
            order_data["customer"]["city"] = response["shipping"]["city"]
            order_data["customer"]["state"] = response["shipping"]["state"]
            order_data["customer"]["postcode"] = response["shipping"][
                "postcode"]
            order_data["customer"]["country"] = response["shipping"]["country"]

            ##
            # Delivery Signature Fee
            ##
            if "fee_lines" in response:
                sig_fee = False
                fee_data = response["fee_lines"]
                for fee in fee_data:
                    if fee["name"] == "Delivery Signature Fee":
                        sig_fee = True
                order_data["delivery_signature"] = sig_fee
                order_data["fees"] = fee_data
            if "line_items" in response:
                order_data["line_items"] = response["line_items"]
            return order_data
        return None
Beispiel #3
0
 def __init__(self, pin):
     if name is 'posix':
         GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme
         GPIO.setup(pin, GPIO.OUT)  # PWM pin set as output
         self.pwm = GPIO.PWM(pin, self.dc)  # Initialize PWM on pwmPin
         self.supported_platform = True
     else:
         printt(
             "This platform does not support the (Linux Only) GPIO Library")
Beispiel #4
0
 def start(self, duty_cycle=10):
     if not self.supported_platform:
         printt(
             'Warning: Unsupported GPIO environment. Buzzer would have started.'
         )
         return
     if not self.active:
         self.pwm.start(duty_cycle)
         self.active = True
Beispiel #5
0
 def decrease_item_quantity(self, qr_data, amount=1):
     index = self.index_of(qr_data)
     if index == -1:
         return False
     else:
         printt("Decreasing item quantity by " + str(amount))
         self.order_items[index].fill_packs(amount)
         self.update_order_items()
         return True
Beispiel #6
0
    def stop(self):
        self.active = False

        if not self.supported_platform:
            printt(
                'Warning: Unsupported GPIO environment. Buzzer would have stopped.'
            )
            return

        self.pwm.stop()
 def get_selection(self, event=None):
     try:
         selection = self.items_listbox.curselection()[0]
         printt(selection)
         # Load selected Order data
         self.frame_order_item_info.load_data(
             self.order_data["line_items"][selection])
         return int(selection)
     except TypeError:
         printt("There was an issue getting the listbox selection index.")
         return 0
Beispiel #8
0
    def load_order(wp_rest_interface, order_id, filter=[]):
        # type: (WPRestInterface, int, dict) -> Order
        """
        :rtype: Order
        """
        order_items = wp_rest_interface.get_order_items(order_id, filter)
        if "error" in order_items:
            printt("An error occurred while loading the order: " +
                   str(order_items["error"]))
            return None
        data = {"order_id": order_id, "items": order_items}
        order = Order(wp_rest_interface, data)
        printt("----Loaded order " + str(order_id) + "----")

        return order
    def save_tracking(self, order_id, code):
        data = {"order_id": str(order_id), "tracking_num": str(code)}

        self.wpapi.set_api_version('xxxx/v1')
        r = self.wpapi.post("tracking/", data)

        if r.status_code == 404:
            tracking = {"error": "404"}
        elif r.status_code == 200:
            tracking = True
        else:
            tracking = {"error": "unexpected error."}

        printt(r.json(), True)
        return tracking
Beispiel #10
0
    def extract_variation_qty(line_item):
        sku = []
        if not line_item:
            if isinstance(line_item, types.StringType) is not True and 'sku' not in line_item:
                printt("extract_variation_qty: line_item must be provided as either: \n"
                       "OrderItem, str, or dict with an sku key present. Provided: " + str(line_item))
            return -1
        elif isinstance(line_item, types.DictionaryType):
            sku.append(line_item["sku"])
        elif isinstance(line_item, types.StringTypes):
            sku.append(str(line_item))
        elif isinstance(line_item, Product):
            sku.append(line_item.sku)

        pieces = str.split(sku[0], '-')
        if len(pieces) != 2:
            printt("Variation quantity not found in SKU '" +
                   str(sku[0]) + "'. Assuming product is non variable.")
            return -1
        return int(pieces[1])
Beispiel #11
0
    def save(self):
        order_id = self.order_id
        if self.tracking:
            tracking = self.wp_rest.save_tracking(order_id, self.tracking)
            if tracking:
                printt("Saved Tracking Number")
            else:
                printt("Issue saving tracking number")

        if self.image_path:
            result = self.wp_rest.upload_order_image(order_id, self.image_path)
            printt(result)

        if self.status:
            data = {"status": str(self.status)}
            status = self.wp_rest.update_order(order_id, data)
            if status:
                printt("Updated Order Status")
            else:
                printt("Issue updating order status")
    def add_order_note(self, id, note, customer_note=False):
        if not id:
            printt('add_order_note failed: order_id not set.')
        elif not note:
            printt('add_order_note_failed: note cannot be empty.')

        data = {"note": str(note), "customer_note": customer_note}
        r = self.wcapi.post("orders/" + str(id) + "/notes", data)

        result = False
        if r.status_code == 404:
            result = {"error": "404"}
        elif r.status_code == 200:
            result = True
        elif r.status_code == 201:
            result = {"error": "Unauthorized"}
        else:
            result = {"error": "unexpected error."}

        return result
Beispiel #13
0
    def request_auth_token(self, error_title=None):
        if not error_title:
            error_title = "Error Authenticating with the Server"

        frame = LoginFrame(width=600, height=325)
        client_creds = frame.get_user_info()

        response = self.request_grant_token(consumer_key=self.client_id,
                                            consumer_secret=self.client_secret,
                                            username=client_creds[0],
                                            password=client_creds[1])
        printt(response.status_code)

        if response.status_code in (403, 401):
            tkMessageBox.showerror(
                error_title,
                str("There was an issue while authenticating with the store! \n You've entered an incorrect username "
                    "or password. Please try again later. If the issue persists then please reset your store password."
                    ))
            return {}
        elif not self.is_json(response.text):
            tkMessageBox.showerror(
                error_title,
                str("There was an issue while authenticating with the store — the response returned from the server was"
                    "unexpected and authentication cannot continue.\nPlease try again later. If the issue persists,"
                    " contact: [email protected] for assistance."))
            return {}
        elif not (response.status_code == 200):
            tkMessageBox.showerror(
                error_title,
                str("There was an unknown issue while authenticating with the store. This is likely caused by a "
                    "communications issue, and is (probably) not an issue with your password. Please try again in 10 "
                    "minutes, and if the issue persists contact: [email protected] for assistance."
                    ))
            printt(
                "There was an issue while authenticating with the store. Details: \n"
                + str(response.status_code))
            printt("Response that indicated an exception:")
            printt(response, pretty=True)
            return {}
        elif 'access_token' in response.json(
        ) and 'refresh_token' in response.json():
            return {
                response.json()['access_token'],
                response.json()['refresh_token']
            }
    def upload_order_image(self, order_id, src_path):
        if not src_path:
            printt("Upload order image failed: order_image_path not set.")
            return False
        elif not path.exists(src_path):
            printt("Upload order image failed: provided path doesn't exist.")
            return False

        filename = "order_" + str(order_id) + "_contents_proof.jpg"

        headers = {
            "content-disposition": "attachment; filename=" + filename,
            # "content-type": "image/jpg"
        }
        files = {'file': (filename, open(src_path, 'rb'), 'image/jpg', {})}
        data = [
            ("title", "Order# " + str(order_id) + " Contents Proof"),
            ("description", "Order # " + str(order_id) + "Contents"),
            ("media_type", "image"),
            # "source_url": "https://xxxxxxx.store/"
        ]

        self.wpapi.set_api_version('wp/v2')
        r = self.wpapi.post("media/", data=data, files=files, headers=headers)

        file_uri = None
        try:
            file_uri = r.json()['media_details']['sizes']['full']['source_url']
        except KeyError:
            printt("Unable to retrieve order image url. Key(s) not found. ")

        if file_uri:
            note = "xxxx POS:  <a href='%s' target='_blank'>Attached Order Image</a>" % file_uri
        else:
            note = "xxxx POS: Unsuccessfully tried to add Order image link.</a>"
            self.add_order_note(order_id, note)

        printt('Added order note to Order %s: %s' % (order_id, note))
        return r.json()
Beispiel #15
0
 def update_order_items(self):
     for item in self.order_items:
         if item.packs_remaining <= 0:
             printt("Finished filling items of this type. Removing.")
             self.remove_item(item)
Beispiel #16
0
 def add_item(self, item):
     self.order_items.append(item)
     printt("Added item to order.")
Beispiel #17
0
 def set_image(self, path):
     if not os.path.isfile(path):
         printt("The provided path is invalid.")
         return
     self.image_path = path
    def load_data(self, order_data):
        if not len(order_data):
            printt(
                "OrderInfoFrame.load_order: valid order_data must be provided."
            )
            raise IndexError("Order data must be provided.")

        # Order Data defaults
        self.order_note = "None provided."
        self.quantity = 0
        self.packs_remaining = 0
        self.customer = {}

        # Load Order information
        self.id = str(order_data["id"])
        self.status = str(order_data["status"])
        self.date_created = str(order_data["date_created"])
        self.value = str(order_data["total"])
        self.customer_note = str(order_data["customer_note"])
        self.signature_waived = order_data["delivery_signature"]

        # Load the Customer information
        self.customer["first_name"] = str(order_data["customer"]["first_name"])
        self.customer["last_name"] = str(order_data["customer"]["last_name"])
        self.customer["full_name"] = str(self.customer["first_name"] + " " +
                                         self.customer["last_name"])
        self.customer["phone"] = str(order_data["customer"]["phone"])
        self.customer["email"] = str(order_data["customer"]["email"])
        self.customer["address_1"] = str(order_data["customer"]["address_1"])
        self.customer["address_2"] = str(order_data["customer"]["address_2"])
        self.customer["city"] = str(order_data["customer"]["city"])
        self.customer["state"] = str(order_data["customer"]["state"])
        self.customer["postcode"] = str(order_data["customer"]["postcode"])
        self.customer["country"] = str(order_data["customer"]["country"])

        # Create Fields
        self.lbl_order_num = Label(self,
                                   text="Order# " + self.id,
                                   font=Font(size=14,
                                             weight="bold",
                                             underline=1),
                                   anchor=W)
        self.lbl_order_num.grid(row=0,
                                column=0,
                                columnspan=2,
                                padx=self.field_pad_x_sm,
                                pady=(self.field_pad_y_sm, 0),
                                sticky=W)

        ###
        # Creation date
        ###
        self.lbl_created = Label(self,
                                 text="Received " +
                                 self.extract_date(self.date_created))
        self.lbl_created.grid(row=1,
                              column=0,
                              padx=self.field_pad_x_sm,
                              pady=self.field_pad_y_sm,
                              sticky=W)

        ##
        # Status
        ##
        self.order_status_field = Label(master=self,
                                        text="-" + str.upper(self.status) +
                                        "-")
        self.order_status_field.grid(row=1,
                                     column=1,
                                     padx=self.field_pad_x_sm * 1.5,
                                     pady=self.field_pad_y_sm)

        #######
        # Inner frame_cust_info
        #######
        self.frame_cust_info = Frame(master=self, border=2, relief=GROOVE)
        self.frame_cust_info.grid(row=2,
                                  rowspan=2,
                                  column=0,
                                  padx=(self.field_pad_x_sm, 0),
                                  sticky="wens")
        self.frame_cust_info.grid_columnconfigure(0, weight=1)

        self.lbl_cust_info_heading = Label(
            master=self.frame_cust_info,
            text="Customer Info",
            font=self.label_heading_font,
        )
        self.lbl_cust_info_heading.grid(row=0,
                                        column=0,
                                        padx=self.field_pad_x_sm,
                                        pady=self.field_pad_y_sm,
                                        sticky=W + E + N + S)

        ####
        # Customer Address Frame
        ####
        self.frame_cust_info.address = Frame(master=self.frame_cust_info,
                                             borderwidth=2,
                                             relief=GROOVE)
        self.frame_cust_info.address.grid(row=1,
                                          column=0,
                                          padx=self.field_pad_x_sm,
                                          pady=self.field_pad_y_sm,
                                          sticky=W + E)
        frame_cust_addr = self.frame_cust_info.address

        ##
        # Full Name
        ##
        self.name_field = Label(master=frame_cust_addr,
                                text=self.customer["full_name"],
                                anchor=W)
        self.name_field.grid(row=0,
                             column=0,
                             padx=self.field_pad_x_sm,
                             pady=self.field_pad_y_sm,
                             sticky=W)

        ##
        # Address
        ##
        self.address_field = Label(
            master=frame_cust_addr,
            text=self.customer["address_1"],
        )
        self.address_field.grid(row=1,
                                column=0,
                                padx=self.field_pad_x_sm,
                                pady=self.field_pad_y_sm)

        ##
        # Address Line 2
        ##
        text = str(self.customer["address_2"])

        if self.customer["address_2"] is not "":
            self.address2_field = Label(
                master=frame_cust_addr,
                text=text,
            )
            self.address2_field.grid(row=2,
                                     column=0,
                                     padx=self.field_pad_x_sm,
                                     pady=self.field_pad_y_sm)

        ###
        # City, State
        ###
        the_row = 3
        if self.customer["address_2"] is not "":
            the_row = 2

        self.city_state_field = Label(master=frame_cust_addr,
                                      text=self.customer["city"] + ", " +
                                      self.customer["state"],
                                      anchor=W)
        self.city_state_field.grid(row=the_row,
                                   column=0,
                                   padx=self.field_pad_x_sm,
                                   pady=self.field_pad_y_sm,
                                   sticky=W + E)

        ###############################
        # Outer Order Note Container  #
        ###############################
        self.frame_order_note_container = Frame(
            self.frame_cust_info,
            border=2,
            relief=GROOVE,
        )
        self.frame_order_note_container.grid(row=2,
                                             column=0,
                                             padx=self.field_pad_x_sm,
                                             pady=self.field_pad_y_sm,
                                             sticky=W + E)

        ###
        # Order Note Frame
        ###
        self.frame_order_note = Frame(
            self.frame_order_note_container,
            border=2,
            relief=GROOVE,
        )
        self.frame_order_note.grid(row=2,
                                   column=0,
                                   padx=self.field_pad_x_sm,
                                   pady=self.field_pad_y_sm,
                                   sticky=W + E + N + S)

        self.order_note_label = Label(
            master=self.frame_order_note_container,
            text="Order Note",
            font=self.label_heading_font,
        )
        self.order_note_label.grid(row=0,
                                   column=0,
                                   padx=self.field_pad_x_sm,
                                   pady=self.field_pad_y_sm,
                                   sticky=W + E)

        self.order_note_field = Label(
            master=self.frame_order_note,
            text=self.order_note,
        )
        self.order_note_field.grid(row=3,
                                   column=0,
                                   padx=self.field_pad_x_sm,
                                   pady=self.field_pad_y_sm,
                                   sticky=S + N + E + W)

        ##
        # Signature on Delivery Opt-out
        ##
        text = "--SIGNATURE REQUIRED--"
        color = "green"
        if self.signature_waived:
            text = "--NO SIGNATURE REQ.--"
            color = "red"
        self.lbl_sig_delivery = Label(self,
                                      text=text,
                                      font=self.label_heading_font,
                                      fg=color)
        self.lbl_sig_delivery.grid(row=1,
                                   column=2,
                                   padx=self.field_pad_x_sm,
                                   pady=self.field_pad_y_sm)

        ##########################
        # Order Items List Frame #
        ##########################
        self.frame_items_list = Frame(self)
        self.frame_items_list.config(bg="green")
        self.frame_items_list.grid(row=2,
                                   column=1,
                                   rowspan=2,
                                   columnspan=2,
                                   sticky=N + E + W + S)
        self.frame_items_list.grid_columnconfigure(0, weight=1)

        #####
        # Order Items heading
        #####
        self.order_items_label = Label(master=self.frame_items_list,
                                       text="Order Items",
                                       font=self.label_heading_font,
                                       anchor=W)
        self.order_items_label.grid(row=2,
                                    column=0,
                                    padx=self.field_pad_x_sm,
                                    pady=self.field_pad_y_sm,
                                    sticky=W)

        ##
        # Items Scrollbar
        ##
        self.items_scrollbar = Scrollbar(self.frame_items_list)
        self.items_scrollbar.grid(row=3,
                                  column=1,
                                  padx=(0),
                                  pady=(0, self.field_pad_y_sm),
                                  sticky=N + S + W)

        ####
        # Items Listbox
        #####
        self.items_listbox = Listbox(master=self.frame_items_list,
                                     font=self.list_item_font,
                                     selectmode=SINGLE,
                                     yscrollcommand=self.items_scrollbar.set,
                                     width=52)
        self.items_listbox.grid(row=3,
                                column=0,
                                padx=(self.field_pad_x_sm, 0),
                                pady=(0, self.field_pad_y_sm),
                                sticky=W + E + N + S)
        self.items_scrollbar.config(command=self.items_listbox.yview)
        self.frame_items_list.grid_rowconfigure(3, weight=1)
        self.frame_items_list.grid_rowconfigure(0, weight=1)

        #####
        # Item Info Container
        #####
        self.frame_order_item_info = Frame_Product(
            master=self.frame_items_list,
            item_data=order_data["line_items"][self.order_item_index],
            border=2,
            relief=GROOVE,
        )
        self.frame_order_item_info.grid(row=0,
                                        column=0,
                                        columnspan=2,
                                        pady=(0, 4),
                                        sticky=W + E + N + S)
        self.frame_order_item_info.config(bg="orange")

        # process new listbox selections
        self.items_listbox.bind('<<ListboxSelect>>', self.get_selection)
        self.fill_listbox(order_data["line_items"])

        #############################
        # Actions Toolbox Container #
        #############################
        self.frame_actions_toolbox = Frame_Actions(self.id, master=self)
        self.frame_actions_toolbox.grid(row=2,
                                        rowspan=2,
                                        column=3,
                                        sticky=W + E + N + S)

        self.frame_actions_toolbox.config(bg="green")

        # Stretch actions container to height and width available
        self.frame_actions_toolbox.rowconfigure(0, weight=1)
        self.frame_actions_toolbox.rowconfigure(1, weight=1)
        self.frame_actions_toolbox.columnconfigure(0, weight=1)

        self.mainloop()
    def load_data(self, item_data):
        if type(item_data) is not DictionaryType:
            raise ValueError("Valid item_data dict is required")
        elif "line_items" in item_data:
            raise ValueError("Got Order data when expecting Item data")

        try:
            self.sku = item_data["sku"]
            self.name = item_data["name"]
            self.product_id = item_data["product_id"]
            self.variation_id = item_data["variation_id"]
            self.quantity = item_data["quantity"]
            printt("Quantity: " + str(item_data["quantity"]))
        except KeyError:
            printt(
                "OrderItemInfoFrame.load_order: unable to locate keys in item_data."
            )
            return False
        self.product.packs_remaining = self.quantity

        ##
        # Name
        ##
        self.lbl_name = Label(self,
                              text="Name",
                              font=self.underline_heading_font)
        self.lbl_name.grid(row=0,
                           column=0,
                           pady=self.lbl_heading_pady,
                           sticky=W + S)
        self.name_field = Label(self,
                                text=self.name,
                                font=self.item_info_heading_font,
                                border=2,
                                relief=GROOVE)
        self.name_field.grid(row=1,
                             column=0,
                             columnspan=2,
                             sticky=N + W + E + S)

        ##
        # SKU
        ##
        self.lbl_sku = Label(self,
                             text="SKU",
                             font=self.underline_heading_font)
        self.lbl_sku.grid(row=2,
                          column=1,
                          padx=self.lbl_heading_padx,
                          pady=self.lbl_heading_pady,
                          sticky=self.lbl_sticky)
        self.sku_field = Label(self,
                               text=self.sku,
                               font=self.item_info_heading_font,
                               border=2,
                               relief=GROOVE)
        self.sku_field.grid(row=3, column=1, sticky=N + S + W + E)

        ##
        # Product_id
        ##
        self.lbl_pid = Label(self,
                             text="Product ID",
                             font=self.underline_heading_font)
        self.lbl_pid.grid(row=2,
                          column=0,
                          padx=self.lbl_heading_padx,
                          pady=self.lbl_heading_pady,
                          sticky=N + W + S)

        self.pid_field = Label(self,
                               text=self.product_id,
                               font=self.item_info_heading_font,
                               border=2,
                               relief=GROOVE)
        self.pid_field.grid(row=3,
                            column=0,
                            padx=self.col0_pad,
                            sticky=W + N + E + S)

        ##
        # Variation_id
        ##
        self.lbl_vid = Label(
            self,
            text="Variation ID",
            font=self.underline_heading_font,
        )
        self.lbl_vid.grid(row=4,
                          column=0,
                          padx=self.lbl_heading_padx,
                          pady=self.lbl_heading_pady,
                          sticky=W)
        self.vid_field = Label(self,
                               text=self.variation_id,
                               font=self.item_info_heading_font,
                               border=2,
                               relief=GROOVE)
        self.vid_field.grid(
            row=5,
            column=0,
            padx=self.col0_pad,
            # pady=self.field_pad_y,
            sticky=W + E + N + S)

        # ##
        # # Quantity
        # ##
        # self.lbl_quant = Label(
        #     self,
        #     text="Total Quantity",
        #     font=self.underline_heading_font
        # )
        # self.lbl_quant.grid(
        #     row=4,
        #     column=1,
        #     padx=self.lbl_heading_padx,
        #     pady=self.lbl_heading_pady,
        #     sticky=self.lbl_sticky
        # )
        # self.quant_field = Label(
        #     self,
        #     text=self.quantity,
        #     font=self.item_info_heading_font,
        #     border=2,
        #     relief=GROOVE
        # )
        # self.quant_field.grid(
        #     row=5,
        #     column=1,
        #     sticky=W+E
        # )

        ##
        # Remaining Packs
        ##
        self.lbl_remaining = Label(
            self,
            text="Packs to Go",
            font=self.underline_heading_font,
            anchor=W,
        )
        self.lbl_remaining.grid(row=4,
                                column=1,
                                padx=self.lbl_heading_padx,
                                pady=self.lbl_heading_pady,
                                sticky=self.lbl_sticky)
        self.remaining_field = Label(self,
                                     text=self.product.packs_remaining,
                                     font=self.item_info_heading_font,
                                     border=2,
                                     relief=GROOVE)
        self.remaining_field.grid(row=5, column=1, sticky=W + E + N + S)
Beispiel #20
0
    def set_state(self, state):

        state = str(state).upper()
        if state in self.STATES:
            printt("Order State Change: " + self.state + "->" + state)
            self.state = state