From c55a54f35518d72fa8a1a30f75499b32b74ac9c1 Mon Sep 17 00:00:00 2001 From: Reuben Rissler Date: Mon, 21 Jan 2019 08:53:24 -0500 Subject: [PATCH] version 0.5.9 add gl_transaction_id to incoming_invoices table --- src/db/update_db_minor.sql | 4 ++++ src/incoming_invoice.py | 22 +++++++++++++--------- src/pygtk_posting.ui | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/db/update_db_minor.sql b/src/db/update_db_minor.sql index ab9258bb..e09ef74e 100644 --- a/src/db/update_db_minor.sql +++ b/src/db/update_db_minor.sql @@ -139,5 +139,9 @@ CREATE TABLE IF NOT EXISTS incoming_invoices_gl_entry_expenses_ids (id bigserial --version 0.5.8 ALTER TABLE public.purchase_order_line_items DROP CONSTRAINT IF EXISTS purchase_order_line_items_expense_account_fkey; ALTER TABLE public.purchase_order_line_items ADD CONSTRAINT purchase_order_line_items_expense_account_fkey FOREIGN KEY (expense_account) REFERENCES public.gl_accounts ("number") MATCH SIMPLE ON UPDATE CASCADE ON DELETE RESTRICT; +--version 0.5.9 +ALTER TABLE incoming_invoices ADD COLUMN IF NOT EXISTS gl_transaction_id bigint REFERENCES gl_transactions ON DELETE RESTRICT; +UPDATE incoming_invoices SET gl_transaction_id = ge.gl_transaction_id FROM (SELECT id, gl_transaction_id FROM gl_entries) AS ge WHERE incoming_invoices.gl_entry_id = ge.id AND incoming_invoices.gl_transaction_id IS NULL; +UPDATE incoming_invoices SET gl_transaction_id = ge.gl_transaction_id FROM (SELECT date_inserted, amount, gl_transaction_id FROM gl_entries) AS ge WHERE incoming_invoices.amount = ge.amount AND incoming_invoices.gl_transaction_id IS NULL AND incoming_invoices.date_created = ge.date_inserted ; diff --git a/src/incoming_invoice.py b/src/incoming_invoice.py index 0442d82e..82799c70 100644 --- a/src/incoming_invoice.py +++ b/src/incoming_invoice.py @@ -336,25 +336,29 @@ def print_check_clicked (self, button): self.window.destroy() def save_incoming_invoice (self): + c = self.db.cursor() contact_id = self.builder.get_object('combobox1').get_active_id() description = self.builder.get_object('entry1').get_text() total = Decimal(self.builder.get_object('spinbutton1').get_text()) self.invoice = transactor.ServiceProviderPayment (self.db, self.date, total) - self.cursor.execute("INSERT INTO incoming_invoices " - "(contact_id, date_created, amount, description) " - "VALUES (%s, %s, %s, %s) RETURNING id", - (contact_id, self.date, total, description)) - invoice_id = self.cursor.fetchone()[0] - if self.file_data != None: - self.cursor.execute("UPDATE incoming_invoices " - "SET attached_pdf = %s " - "WHERE id = %s", (self.file_data, invoice_id)) + c.execute( "INSERT INTO incoming_invoices " + "(contact_id, " + "date_created, " + "amount, " + "description, " + "gl_transaction_id, " + "attached_pdf) " + "VALUES (%s, %s, %s, %s, %s, %s) RETURNING id", + (contact_id, self.date, total, description, + self.invoice.transaction_id, self.file_data)) + invoice_id = c.fetchone()[0] for row in self.expense_percentage_store: amount = row[1] expense_account = row[2] self.invoice.expense(amount, expense_account, invoice_id) + c.close() return invoice_id, total def balance_this_row_activated (self, menuitem): diff --git a/src/pygtk_posting.ui b/src/pygtk_posting.ui index 156b4a3d..419bbc40 100644 --- a/src/pygtk_posting.ui +++ b/src/pygtk_posting.ui @@ -1421,7 +1421,7 @@ main_window True PyGtk Posting - 0.5.8 (alpha) + 0.5.9 (alpha) Copyleft Reuben Rissler 2015-2018 Accounting and business management for Linux Reuben Rissler <pygtk.posting@gmail.com>