add model get documents eletronic

This commit is contained in:
Wilson Gomez 2022-10-28 16:59:39 -05:00
parent ee85472965
commit f58dcd4a30
4 changed files with 83 additions and 38 deletions

View File

@ -13,6 +13,7 @@ def register():
server.Server,
server.Database,
server.PricePlan,
server.DocumentElectronic,
module='vps', type_='model')
Pool.register(
module='vps', type_='wizard')

43
queries.py Normal file
View File

@ -0,0 +1,43 @@
allow_connection = 'alter database "{name}" with allow_connections {option};'
connection_limit = 'alter database "{name}" with allow_connections {limit};'
getnumberdocuments = """
SELECT z.period,
sum(z.records) FILTER (WHERE z.type_doc = 'invoice_in') as invoice_in,
sum(z.records) FILTER (WHERE z.type_doc = 'invoice_out') as invoice_out,
sum(z.records) FILTER (WHERE z.type_doc = 'payroll') as payroll,
sum(z.records) FILTER (WHERE z.type_doc = 'event') as "event"
FROM (
SELECT
date_trunc('month',a.date_effective) as period,
concat('payroll') as type_doc,
count(a.id) as records
FROM staff_payroll_electronic AS a
WHERE a.electronic_state = 'authorized'
GROUP by a.date_effective, type_doc
UNION ALL
SELECT
date_trunc('month',b.invoice_date) as period,
case
when b.type = 'out' then concat('invoice_out')
when b.type = 'in' then concat('invoice_in')
else null
end as type_doc,
count(b.id) as records
FROM account_invoice AS b
WHERE b.electronic_state = 'authorized'
GROUP BY b.invoice_date, type_doc
UNION ALL
SELECT date_trunc('month', d.date_acceptance)::TIMESTAMP WITH TIME ZONE as period,
concat('event') as type_doc,
count(d.id) as records
FROM account_invoice_event_radian as d
WHERE d.response_acceptance IS NOT NULL
GROUP BY date_trunc('month', d.date_acceptance), type_doc
UNION ALL
SELECT date_trunc('month', e.date_receive_good_service)::TIMESTAMP WITH TIME ZONE as period,
concat('event') as type_doc,
count(e.id) as records
FROM account_invoice_event_radian as e
WHERE e.response_receive_good_service IS NOT NULL
GROUP BY date_trunc('month', e.date_receive_good_service), type_doc) as z where z.period = {period};
"""

View File

@ -9,11 +9,13 @@ from trytond.pyson import Eval, If, In, Get, Bool
from trytond.transaction import Transaction
from trytond.pool import Pool
from trytond.wizard import Wizard, StateTransition
from trytond.backend.postgresql.database import LoggingCursor
import psycopg2
from psycopg2 import Error
import os
from .exceptions import DisableDatabaseWarning
from trytond.i18n import gettext
from . import queries
STATES = {
'readonly': Eval('state') != 'draft',
@ -102,31 +104,21 @@ class Database(Workflow, ModelSQL, ModelView):
def allow_connections_database(self, allow):
connection = None
name= self.name
try:
# connection = psycopg2.connect(user = "psk",
# password = "sion21",
# host = "45.63.106.42",
# port = "5432",
# database = "postgres")
connection = psycopg2.connect(user = self.vps.user,
password = self.vps.password,
host = self.vps.ip_address,
port = self.vps.port,
database = "postgres")
connection = self.get_connection_database('postgres')
cursor = connection.cursor()
create_table_query_1 = ''
create_table_query_2 = ''
if allow:
create_table_query_1 = '''alter database "'''+self.name+'''" with allow_connections true; '''
create_table_query_2 = '''alter database "'''+self.name+'''" connection limit -1; '''
allow_conection = queries.allow_connection.format(name=name, option='true')
connection_limit = queries.connection_limit.format(name=name, option=-1)
self.write([self], {'state': 'enable'})
else:
create_table_query_1 = '''alter database "'''+self.name+'''" with allow_connections false; '''
create_table_query_2 = '''alter database "'''+self.name+'''" connection limit 0; '''
allow_conection = queries.allow_connection.format(name=name, option='false')
connection_limit = queries.connection_limit.format(name=name, option=0)
self.write([self], {'state': 'disable'})
cursor.execute(create_table_query_1)
cursor.execute(create_table_query_2)
cursor.execute(allow_conection)
cursor.execute(connection_limit)
connection.commit()
print("process successfully in PostgreSQL ")
@ -139,6 +131,16 @@ class Database(Workflow, ModelSQL, ModelView):
connection.close()
print("PostgreSQL connection is closed")
def get_connection_database(self, database):
connection = connection = psycopg2.connect(user = self.vps.user,
password = self.vps.password,
host = self.vps.ip_address,
port = self.vps.port,
database = database,
cursor_factory= LoggingCursor,
)
return connection
# os.popen("sudo systemctl restart strytond.service", 'w').write('12345678')
def get_invoices_expiration(self, name):
@ -241,3 +243,17 @@ class PricePlan(ModelSQL, ModelView):
('free', 'Free'),
('payment', 'Payment'),
], 'Kind', required=True,)
class DocumentElectronic(ModelSQL, ModelView):
'Document Electronic'
__name__ = 'vps.document_electronic'
period = fields.Date('Period')
document_support = fields.Integer('Document Support', states={'readonly': True})
invoice = fields.Integer('Invoice', states={'readonly': True})
event = fields.Integer('Event', states={'readonly': True})
payroll = fields.Integer('Payroll', states={'readonly': True})

View File

@ -90,25 +90,14 @@ setup(name=name,
'Intended Audience :: Financial and Insurance Industry',
'Intended Audience :: Legal Industry',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Natural Language :: Bulgarian',
'Natural Language :: Catalan',
'Natural Language :: Chinese (Simplified)',
'Natural Language :: Czech',
'Natural Language :: Dutch',
'Natural Language :: English',
'Natural Language :: French',
'Natural Language :: German',
'Natural Language :: Hungarian',
'Natural Language :: Italian',
'Natural Language :: Portuguese (Brazilian)',
'Natural Language :: Russian',
'Natural Language :: Slovenian',
'Natural Language :: Spanish',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Office/Business',
@ -125,8 +114,4 @@ setup(name=name,
test_suite='tests',
test_loader='trytond.test_loader:Loader',
tests_require=tests_require,
use_2to3=True,
convert_2to3_doctests=[
'tests/scenario.rst',
],
)