def edit_invoice():
     sid = tree.hlist.info_selection()[0]
     smi = _.dbm.session.query(_.dbm.ShipmentItem).get(sid)
     if len(smi.invoiceitem):
         invoice(_, invoice=smi.invoiceitem[0].invoice)
     try:
         for ref in _.refresh:
             ref()
     except AttributeError:
         pass
    def create_invoice():
        """Check if invoiceitem exists already. Currently limited to one."""
        for shipment_id in tree.hlist.info_selection():
            if len(_.dbm.session.query(_.dbm.ShipmentItem).get(shipment_id).invoiceitem) > 0:
                return
        invoice(_, tree.hlist.info_selection())

        try:
            for ref in _.refresh:
                ref()
        except AttributeError:
            pass