68 lines
2.6 KiB
Python
68 lines
2.6 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
import gi
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import GLib, Gtk, Gdk
|
|
|
|
from .view import View
|
|
from yms import gtkutils, combobox, treeview
|
|
from yms.model import inventory
|
|
|
|
class InventoryView(View):
|
|
|
|
def __init__(self, context):
|
|
super().__init__(context, _("Inventory"), "inventory.ui")
|
|
|
|
self.inv = inventory.Inventory(context.db) # current record
|
|
self.newrecord = False
|
|
|
|
# Inventory gets vessel assignment via
|
|
# - storage direct
|
|
# - or via box which is assigned to a storage
|
|
self.lst_inventory = Gtk.ListStore(int, str, str, int, str, str)
|
|
sql = (
|
|
"SELECT i.invid, i.invname, s.sname AS container, i.number, i.invcond, i.remarks "
|
|
"FROM inventory AS i JOIN storage AS s ON (i.conttype='storage' AND i.sid=s.sid) "
|
|
"WHERE s.vid=%s "
|
|
"UNION SELECT i.invid, i.invname, b.label AS container, i.number, i.invcond, i.remarks "
|
|
"FROM inventory AS i JOIN box AS b ON (i.conttype='box' AND i.boxid=b.boxid) JOIN storage AS s ON (b.sid=s.sid) "
|
|
"WHERE s.vid=%s"
|
|
)
|
|
self.db.cur.execute(sql, (context.vessel.vid, context.vessel.vid))
|
|
for row in self.db.cur.fetchall():
|
|
self.lst_inventory.append(row)
|
|
|
|
treeview.add_column(self.tree['inventory'], _('ID'), 0)
|
|
treeview.add_column(self.tree['inventory'], _('Name'), 1)
|
|
treeview.add_column(self.tree['inventory'], _('Container'), 2)
|
|
treeview.add_column(self.tree['inventory'], _('Number'), 3)
|
|
treeview.add_column(self.tree['inventory'], _('Condition'), 4)
|
|
treeview.add_column(self.tree['inventory'], _('Remarks'), 5)
|
|
self.tree['inventory'].set_model(self.lst_inventory)
|
|
|
|
# buttons on list page
|
|
def on_but_new_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inv_edit'])
|
|
|
|
def on_but_edit_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inv_edit'])
|
|
|
|
def on_but_detail_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inv_detail'])
|
|
|
|
# buttons on detail page
|
|
# edit2 uses edit callback
|
|
def on_but_close_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inventory'])
|
|
|
|
def on_but_delete_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inventory'])
|
|
|
|
# buttons on edit page
|
|
def on_but_save_clicked(self, widget):
|
|
pass
|
|
|
|
def on_but_cancel_clicked(self, widget):
|
|
self.topwidget.set_visible_child(self.box['inventory'])
|