def _create_locations_cell(self, po: ProductOrderDalModel) -> Label: if po.status == PickingStatus.Done: return create_label_cell("-") stock = self.stock_repo.get_stock_for_product(po.product.id) text = "" for si in stock: if len(text) != 0: text += "\n" text += f"{si.quantity} at {si.location}" if len(stock) == 0: text = "Out of Stock" return create_label_cell(text)
def __init__(self, **kw): # self.repo = ProductRepository(DatabaseManager()) self.repo = class_manager.get_instance(ProductRepository) self.products = self.repo.get_all_products() headers = [ TableField("ID", .1, lambda p: create_label_cell(p.id)), TableField("Name", .2, lambda p: create_label_cell(p.name)), TableField("Target Stock", .2, lambda p: create_label_cell(p.target_stock)), TableField("Description", .3, lambda p: _create_desc_label(p.description)), TableField( "Actions", .3, lambda p: _create_action_view( p, self.edit_product, self.remove_product)) ] super().__init__(headers, **kw)
def __init__(self, **kw): self.repo = class_manager.get_instance(StockRepository) self.stock = self.repo.get_all_stock_items() headers = [ TableField("ID", .1, lambda s: create_label_cell(s.id)), TableField("Product Name", .3, lambda s: create_label_cell(s.product.name)), TableField("Location", .1, lambda s: create_label_cell(s.location)), # TODO: Change to quantity table cell TableField( "Quantity", .2, lambda s: _create_qty_cell(s, self.get_stock_modifier(s))), TableField( "Actions", .3, lambda s: _create_action_view( s, self.edit_stock, self.remove_stock)) ] super().__init__(headers, **kw)
def __init__(self, **kw): self.repo = class_manager.get_instance(OrderRepository) self.sync_service = class_manager.get_instance(OrderSyncService) self.mail_service = class_manager.get_instance(MailService) self.orders = self.repo.get_all_orders() headers = [ TableField("ID", .05, lambda o: create_label_cell(o.id)), TableField( "Customer", .3, lambda o: create_label_cell( o.customer_name + "\n" + o.email_address)), TableField("Status", .1, lambda o: create_label_cell(o.status)), # TableField("Store", .1, lambda o: create_label_cell(o.storefront)), TableField("Products", .3, lambda o: _create_products_cell(o)), TableField("Actions", .2, lambda o: self.create_action_cell(o)) ] super().__init__(headers, **kw) self.sync_button = self.ids.sync_button self.sync_button.on_press = self.on_sync self.table.set_row_height(.25)
def _create_actions_cell(self, po: ProductOrderDalModel) -> Widget: if po.status == PickingStatus.NotPicked: stock = self.stock_repo.get_stock_for_product(po.product.id) if len(stock) > 0: btn = Button(text="Start Picking") btn.on_press = lambda: self._start_picking(po) return btn else: return create_label_cell("-") elif po.status == PickingStatus.InProgress: layout = BoxLayout(orientation="vertical") stop_btn = Button(text="Stop Picking") stop_btn.on_press = lambda: self._stop_picking(po) mark_picked_btn = Button(text="Mark as Picked") mark_picked_btn.on_press = lambda: self._mark_picked(po) layout.add_widget(stop_btn) layout.add_widget(mark_picked_btn) return layout else: return create_label_cell("-")
def on_kv_post(self, base_widget): super().on_kv_post(base_widget) self.size_hint_x = .8 self.size_hint_y = .9 self.order_label = self.ids.order_label self.print_button = self.ids.print_button self.table = self.ids.table self.done_button = self.ids.done_button self.done_button.on_press = lambda: self.on_done() self.order_label.text = f"Order #{self.order.id:04d}" self.headers = [ TableField("Item", .3, lambda po: create_label_cell(po.product.name)), TableField("Status", .2, lambda po: create_label_cell(po.status)), TableField("Locations", .2, lambda po: self._create_locations_cell(po)), TableField("Actions", .3, lambda po: self._create_actions_cell(po)) ] self.data = self.order.products self.table.setup(self.headers, self.data) self.table.set_row_height(.3)
def _create_desc_label(text) -> Widget: # TODO: Improve multiple line handling return create_label_cell(text)
def _create_products_cell(o: OrderDalModel) -> Label: prod_names = [f"{p.product.name} - {p.status}" for p in o.products] return create_label_cell("\n".join(prod_names))