LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
LeenoComputo.py
Vai alla documentazione di questo file.
1 from com.sun.star.table import CellRangeAddress
2 import SheetUtils
3 import LeenoUtils
4 import LeenoSheetUtils
5 import LeenoConfig
6 import LeenoDialogs as DLG
7 
8 import pyleeno as PL
9 
10 def datiVoceComputo (oSheet, lrow):
11  '''
12  Ricava i dati dalla voce di COMPUTO / CONTABILITA
13  '''
14 
15  # ~oDoc = LeenoUtils.getDocument()
16  # ~oSheet = oDoc.CurrentController.ActiveSheet
17  # ~lrow = PL.LeggiPosizioneCorrente()[1]
18 
19  sStRange = circoscriveVoceComputo(oSheet, lrow)
20  i = sStRange.RangeAddress.StartRow
21  f = sStRange.RangeAddress.EndRow
22  # ~DLG.chi((i, f))
23  # ~return
24  num = oSheet.getCellByPosition(0, i+1).String
25  art = oSheet.getCellByPosition(1, i+1).String
26  desc = oSheet.getCellByPosition(2, i+1).String
27  quantP = oSheet.getCellByPosition(9, f).Value
28  mdo = oSheet.getCellByPosition(30, f).Value
29  sic = oSheet.getCellByPosition(17, f).Value
30  voce = []
31  REG = []
32  SAL = []
33  if oSheet.Name in ('CONTABILITA'):
34  quantN = 1
35  if quantP < 0:
36  quantN = quantP
37  quantP = 1
38  data = oSheet.getCellByPosition(1, i+2).String
39  um = oSheet.getCellByPosition(9, i+1).String
40  Nlib = int(oSheet.getCellByPosition(19, i+1).Value)
41  Plib = int(oSheet.getCellByPosition(20, i+1).Value)
42  flag = oSheet.getCellByPosition(22, i+1).String
43  nSal = int(oSheet.getCellByPosition(23, i+1).Value)
44  prezzo = oSheet.getCellByPosition(13, f).Value
45  importo = oSheet.getCellByPosition(15, f).Value
46  sic = oSheet.getCellByPosition(17, f).Value
47  mdo = oSheet.getCellByPosition(30, f).Value
48 
49  REG = ((num + '\n' + art + '\n' + data), desc, Nlib, Plib, um, quantP,
50  quantN, prezzo, importo)#, sic, mdo, flag, nSal)
51  if quantP != 0:
52  quant = quantP
53  else:
54  quant = quantN
55  SAL = (art, desc, um, quant, prezzo, importo, sic, mdo)
56  return REG, SAL
57  elif oSheet.Name in ('COMPUTO', 'VARIANTE'):
58  um = oSheet.getCellByPosition(8, f).String.split('[')[-1].split('[')[0]
59  prezzo = oSheet.getCellByPosition(11, f).Value
60  importo = oSheet.getCellByPosition(18, f).Value
61  voce = (num, art, desc, um, quantP, prezzo, importo, sic, mdo)
62  return voce
63 
64 
65 def circoscriveVoceComputo(oSheet, lrow):
66  '''
67  lrow { int } : riga di riferimento per
68  la selezione dell'intera voce
69 
70  Circoscrive una voce di COMPUTO, VARIANTE o CONTABILITÀ
71  partendo dalla posizione corrente del cursore
72  '''
73  # li predefinisco... @@@
74  lrowS = lrow
75  lrowE = lrow
76 
77  # lrow = LeggiPosizioneCorrente()[1]
78  # if oSheet.Name in('VARIANTE', 'COMPUTO','CONTABILITA'):
79  if oSheet.getCellByPosition(0, lrow).CellStyle in (
80  'comp progress', 'comp 10 s',
81  'Comp Start Attributo', 'Comp End Attributo',
82  'Comp Start Attributo_R', 'comp 10 s_R',
83  'Comp End Attributo_R', 'Livello-0-scritta',
84  'Livello-1-scritta', 'livello2 valuta'):
85  y = lrow
86  while oSheet.getCellByPosition(0, y).CellStyle not in ('Comp End Attributo', 'Comp End Attributo_R'):
87  y += 1
88  lrowE = y
89  y = lrow
90  try:
91  while oSheet.getCellByPosition(0, y).CellStyle not in ('Comp Start Attributo', 'Comp Start Attributo_R'):
92  y -= 1
93  except:
94  return
95  lrowS = y
96  #trova il range di firme in CONTABILITA
97  elif oSheet.getCellByPosition(0, lrow).CellStyle == 'Ultimus_centro_bordi_lati':
98  for y in reversed (range(0, lrow)):
99  if oSheet.getCellByPosition(0, y).CellStyle != 'Ultimus_centro_bordi_lati':
100  lrowS = y + 1
101  break
102  for y in range(lrow, SheetUtils.getLastUsedRow(oSheet)):
103  if oSheet.getCellByPosition(0, y).CellStyle != 'Ultimus_centro_bordi_lati':
104  lrowE = y - 1
105  break
106  elif 'ULTIMUS' in oSheet.getCellByPosition(0, lrow).CellStyle:
107  lrowS = LeenoSheetUtils.cercaUltimaVoce(oSheet) +2
108  lrowE = LeenoSheetUtils.rRow(oSheet) -1
109  else:
110  return
111  celle = oSheet.getCellRangeByPosition(0, lrowS, 250, lrowE)
112  return celle
113 
114 
115 def insertVoceComputoGrezza(oSheet, lrow):
116 
117  # lrow = LeggiPosizioneCorrente()[1]
118 
122 
123  # insRows(lrow,4) #inserisco le righe
124  # oSheet.getCellByPosition(0,lrow).CellStyle = 'Comp Start Attributo'
125  # oSheet.getCellRangeByPosition(0,lrow,30,lrow).CellStyle = 'Comp-Bianche sopra'
126  # oSheet.getCellByPosition(2,lrow).CellStyle = 'Comp-Bianche sopraS'
127  #
128  # oSheet.getCellByPosition(0,lrow+1).CellStyle = 'comp progress'
129  # oSheet.getCellByPosition(1,lrow+1).CellStyle = 'comp Art-EP'
130  # oSheet.getCellRangeByPosition(2,lrow+1,8,lrow+1).CellStyle = 'Comp-Bianche in mezzo Descr'
131  # oSheet.getCellRangeByPosition(2,lrow+1,8,lrow+1).merge(True)
132 
133 
134  oDoc = SheetUtils.getDocumentFromSheet(oSheet)
135 
136  # vado alla vecchia maniera ## copio il range di righe computo da S5 ##
137  oSheetto = oDoc.getSheets().getByName('S5')
138 
139  oRangeAddress = oSheetto.getCellRangeByPosition(0, 8, 42, 11).getRangeAddress()
140  oCellAddress = oSheet.getCellByPosition(0, lrow).getCellAddress()
141 
142  oSheet.getRows().insertByIndex(lrow, 4)
143  oSheet.copyRange(oCellAddress, oRangeAddress)
144 
145  # raggruppo i righi di misura
146  iSheet = oSheet.RangeAddress.Sheet
147  oCellRangeAddr = CellRangeAddress()
148  oCellRangeAddr.Sheet = iSheet
149  oCellRangeAddr.StartColumn = 0
150  oCellRangeAddr.EndColumn = 0
151  oCellRangeAddr.StartRow = lrow + 2
152  oCellRangeAddr.EndRow = lrow + 2
153  oSheet.group(oCellRangeAddr, 1)
154 
155  # correggo alcune formule
156  oSheet.getCellByPosition(13, lrow + 3).Formula = '=J' + str(lrow + 4)
157  oSheet.getCellByPosition(35, lrow + 3).Formula = '=B' + str(lrow + 2)
158 
159  if oSheet.getCellByPosition(31,lrow - 1).CellStyle in (
160  'livello2 valuta',
161  'Livello-0-scritta',
162  'Livello-1-scritta',
163  'compTagRiservato'):
164  oSheet.getCellByPosition(31, lrow + 3).Value = oSheet.getCellByPosition(31, lrow - 1).Value
165  oSheet.getCellByPosition(32, lrow + 3).Value = oSheet.getCellByPosition(32, lrow - 1).Value
166  oSheet.getCellByPosition(33,lrow + 3).Value = oSheet.getCellByPosition(33, lrow - 1).Value
167 
168 
169 # TROPPO LENTA
170 def ins_voce_computo(cod=None):
171  '''
172  cod { string }
173  Se cod è presente, viene usato come codice di voce
174  '''
175  oDoc = LeenoUtils.getDocument()
176  oSheet = oDoc.CurrentController.ActiveSheet
177  noVoce = LeenoUtils.getGlobalVar('noVoce')
178  stili_computo = LeenoUtils.getGlobalVar('stili_computo')
179  stili_cat = LeenoUtils.getGlobalVar('stili_cat')
180  lrow = PL.LeggiPosizioneCorrente()[1]
181  stile = oSheet.getCellByPosition(0, lrow).CellStyle
182  if stile in stili_cat:
183  lrow += 1
184  elif stile in (noVoce + stili_computo):
185  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 1)
186  else:
187  return
188  if lrow == 2:
189  lrow += 1
190  insertVoceComputoGrezza(oSheet, lrow)
191  if cod:
192  oSheet.getCellByPosition(1, lrow + 1).String = cod
193  # @@ PROVVISORIO !!!
194  PL._gotoCella(1, lrow + 1)
195 
196  #PL.numera_voci(0)
197  LeenoSheetUtils.numeraVoci(oSheet, lrow + 1, False)
198  if LeenoConfig.Config().read('Generale', 'pesca_auto') == '1':
199  PL.pesca_cod()
200 
LeenoUtils.getGlobalVar
def getGlobalVar(name)
Definition: LeenoUtils.py:123
LeenoComputo.ins_voce_computo
def ins_voce_computo(cod=None)
Definition: LeenoComputo.py:170
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
LeenoSheetUtils.cercaUltimaVoce
def cercaUltimaVoce(oSheet)
Definition: LeenoSheetUtils.py:184
LeenoSheetUtils.prossimaVoce
def prossimaVoce(oSheet, lrow, n=1, saltaCat=False)
Definition: LeenoSheetUtils.py:281
LeenoSheetUtils.rRow
def rRow(oSheet)
Definition: LeenoSheetUtils.py:173
LeenoComputo.insertVoceComputoGrezza
def insertVoceComputoGrezza(oSheet, lrow)
Definition: LeenoComputo.py:115
LeenoConfig.Config
Definition: LeenoConfig.py:26
LeenoComputo.circoscriveVoceComputo
def circoscriveVoceComputo(oSheet, lrow)
Definition: LeenoComputo.py:65
LeenoSheetUtils.numeraVoci
def numeraVoci(oSheet, lrow, tutte)
Definition: LeenoSheetUtils.py:730
SheetUtils.getLastUsedRow
def getLastUsedRow(oSheet)
Definition: SheetUtils.py:392
LeenoComputo.datiVoceComputo
def datiVoceComputo(oSheet, lrow)
Definition: LeenoComputo.py:10
SheetUtils.getDocumentFromSheet
def getDocumentFromSheet(oSheet)
Definition: SheetUtils.py:76