From c4d1d376bfb411f7fa15831dbbcd7f4b3e405e2a Mon Sep 17 00:00:00 2001 From: Dedalus2000 Date: Thu, 29 May 2025 16:57:19 +0200 Subject: [PATCH 1/2] La query con selection(_aggregateRows=True) sembra fallire in caso di aggregazione di campi testo vuoti. Invece che None torna la stringa vuota '' In questo branch creo la colonna "colonna_testo" in testata fattura e poi eseguo una aggragazione dalla tabella dei clienti Query di verifica e popolamento database sono tra gli script di upgrades --- packages/fatt/lib/upgrades/001_insertmario.py | 20 +++++++++ .../fatt/lib/upgrades/002_read_aggregate.py | 41 +++++++++++++++++++ packages/fatt/model/fattura.py | 3 +- .../tables/prodotto_tipo/th_prodotto_tipo.py | 3 +- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 packages/fatt/lib/upgrades/001_insertmario.py create mode 100644 packages/fatt/lib/upgrades/002_read_aggregate.py diff --git a/packages/fatt/lib/upgrades/001_insertmario.py b/packages/fatt/lib/upgrades/001_insertmario.py new file mode 100644 index 0000000..639ecdb --- /dev/null +++ b/packages/fatt/lib/upgrades/001_insertmario.py @@ -0,0 +1,20 @@ +from gnr.app.gnrapp import GnrApp +from gnr.core.gnrbag import Bag + + + +def main(db): + tbl_fattura = db.table('fatt.fattura') + tbl_cliente = db.table('fatt.cliente') + + name = 'Mario Rossi Srl' + #if tbl_cliente.query(where='$ragione_sociale=:nn', nn=name).count()==0: + + # inserisco il cliente + cliente_record = tbl_cliente.newrecord(ragione_sociale=name) + tbl_cliente.insert(cliente_record) + + # inserisco 10 fatture + # il campo colonna_testo è None + for _ in range(10): + tbl_fattura.insert(tbl_fattura.newrecord(cliente_id=cliente_record['id'])) diff --git a/packages/fatt/lib/upgrades/002_read_aggregate.py b/packages/fatt/lib/upgrades/002_read_aggregate.py new file mode 100644 index 0000000..2cbb899 --- /dev/null +++ b/packages/fatt/lib/upgrades/002_read_aggregate.py @@ -0,0 +1,41 @@ +from gnr.app.gnrapp import GnrApp +from gnr.core.gnrbag import Bag + + + +def main(db): + tbl_fattura = db.table('fatt.fattura') + tbl_cliente = db.table('fatt.cliente') + print('\n') + print ("\nFETCH NORMALE: colonna_testo è None") + for row in map(dict,tbl_cliente.query(columns="@fatture.colonna_testo").fetch()): + row.pop('pkey') + print ("\t", dict(row)) + + print ("\nSELECTION NORMALE: colonna_testo è None") + for row in tbl_cliente.query(columns="@fatture.colonna_testo").selection().output('dictlist'): + row.pop('pkey') + print ("\t", row) + + print ("\nSELECTION CON _aggregateRows: colonna_testo è ''") + for row in tbl_cliente.query(columns="@fatture.colonna_testo").selection(_aggregateRows=True).output('dictlist'): + row.pop('pkey') + print ("\t", row, "<<== DEVE ESSERE None") + + print ("\nSELECTION CON _aggregateRows e colonna rinominata: torna a essere None") + for row in tbl_cliente.query(columns="@fatture.colonna_testo as prova").selection(_aggregateRows=True).output('dictlist'): + row.pop('pkey') + print ("\t", row) + + + print("\nIpotesi: problema in gnrsqldata.SqlSelection._aggregateRows") + print('''Nella riga "mixColumns = [c for c in explodingColumns if c in index and not self.colAttrs[c].get('one_one') and not( aggregateDict and (c in aggregateDict))]"''') + + print ("\nriavviami con python 002_read_aggregate.py") + +if __name__ == '__main__': + gnrapp = GnrApp('sandbox') + db = gnrapp.db + + main(db) + db.commit() \ No newline at end of file diff --git a/packages/fatt/model/fattura.py b/packages/fatt/model/fattura.py index ef7041f..0fd9a2c 100644 --- a/packages/fatt/model/fattura.py +++ b/packages/fatt/model/fattura.py @@ -23,7 +23,8 @@ def config_db(self, pkg): tbl.column('sconto',dtype='percent',name_long='Sconto') tbl.aliasColumn('clientenome','@cliente_id.ragione_sociale',name_long='Cliente') - + tbl.column('colonna_testo', size=":20") + def ricalcolaTotali(self,fattura_id=None,mylist=None): with self.recordToUpdate(fattura_id) as record: totale_lordo,totale_iva = self.db.table('fatt.fattura_riga' diff --git a/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py b/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py index d3ddae9..3f8a045 100644 --- a/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py +++ b/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py @@ -34,4 +34,5 @@ def th_form(self, form): def th_options(self): - return dict(dialog_height='400px', dialog_width='600px',hierarchical=True) + return dict(dialog_height='400px', dialog_width='600px',hierarchical=True, + tree_condition="$hierarchical_descrizione like :nodo1", tree_condition_nodo1="%%nodo1%%") From 1d458a3587cc2f55c7bad8a2630a4e6f3a40a7e4 Mon Sep 17 00:00:00 2001 From: Dedalus2000 Date: Thu, 29 May 2025 17:02:31 +0200 Subject: [PATCH 2/2] riportato all'origine una modifica inutile --- .../fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py b/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py index 3f8a045..d3ddae9 100644 --- a/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py +++ b/packages/fatt/resources/tables/prodotto_tipo/th_prodotto_tipo.py @@ -34,5 +34,4 @@ def th_form(self, form): def th_options(self): - return dict(dialog_height='400px', dialog_width='600px',hierarchical=True, - tree_condition="$hierarchical_descrizione like :nodo1", tree_condition_nodo1="%%nodo1%%") + return dict(dialog_height='400px', dialog_width='600px',hierarchical=True)