106 lines
4.4 KiB
Python
106 lines
4.4 KiB
Python
# SPDX-License-Identifier: WTFPL
|
|
|
|
import os
|
|
from gi.repository import GLib, Gtk, Gdk
|
|
|
|
from .view import View
|
|
from yms import gtkutils, combobox, treeview
|
|
from yms.lookup import Dropdown
|
|
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)
|
|
|
|
self.dd_category = self.context.lookup.dropdown(Dropdown.INVENTORY_CATEGORY)
|
|
|
|
# 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):
|
|
invid = treeview.get_value(self.tree['inventory'], 0)
|
|
self.inv.load(invid)
|
|
self.display_record()
|
|
self.topwidget.set_visible_child(self.box['inv_detail'])
|
|
self.button['close'].grab_focus()
|
|
|
|
def on_tvw_inventory_row_activated(self, widget, path, column):
|
|
invid = treeview.get_value(widget, 0)
|
|
self.inv.load(invid)
|
|
self.display_record()
|
|
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'])
|
|
|
|
def display_record(self):
|
|
# TODO nice formatting
|
|
self.label['name'].set_text(self.inv.invname)
|
|
self.label['conttype'].set_text(self.inv.conttype)
|
|
self.label['storage'].set_text(str(self.inv.sid))
|
|
self.label['box'].set_text(str(self.inv.boxid))
|
|
self.label['equipment'].set_text(str(self.inv.eid))
|
|
self.label['number'].set_text(self.format_int(self.inv.number))
|
|
self.label['weight'].set_text(self.format_float(self.inv.weight, suffix='kg'))
|
|
self.label['price'].set_text(self.format_float(self.inv.price, suffix='€'))
|
|
self.label['purchdate'].set_text(self.format_date(self.inv.purchdate))
|
|
self.label['condition'].set_text(self.inv.invcond)
|
|
if self.inv.icat is not None:
|
|
self.label['category'].set_text(self.dd_category[self.inv.icat])
|
|
else:
|
|
self.label['category'].set_text('')
|
|
self.label['remarks'].set_text(self.inv.remarks or '')
|
|
|
|
def edit_record(self):
|
|
self.entry['user_login'].set_text(user.login)
|
|
self.entry['user_displayname'].set_text(user.displayname)
|
|
combobox.activate_row(self.combo['user_role'], user.role)
|
|
combobox.activate_row(self.combo['user_lang'], user.language)
|
|
self.check['user_locked'].set_active('locked' in user.flags)
|
|
self.check['user_deleted'].set_active('deleted' in user.flags)
|
|
self.entry['user_pass'].set_text('')
|