Skip to content

Commit 8e416b5

Browse files
committed
m
1 parent 2ec22da commit 8e416b5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/spreadsheet/tests/test_spreadsheet_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from odoo.addons.base.maintenance.migrations.testing import UnitTestCase
2-
from odoo.addons.base.maintenance.migrations.spreadsheet.parser import (
2+
from odoo.addons.base.maintenance.migrations.util.spreadsheet.parser import (
33
BinaryOperation,
44
FunctionCall,
55
Literal,

src/util/spreadsheet/o_spreadsheet.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ def upgrade_data(data, upgrade_functions, to_version, version_field="version"):
7474
cell_reference = re.compile(r"\$?([A-Z]{1,3})\$?([0-9]{1,7})")
7575

7676

77+
def zone_to_xc(zone) -> str:
78+
top = zone["top"]
79+
bottom = zone["bottom"]
80+
left = zone["left"]
81+
right = zone["right"]
82+
83+
has_header = zone.get("hasHeader", False)
84+
is_one_cell = top == bottom and left == right
85+
86+
if bottom is None and right is not None:
87+
return f"{number_to_letters(left)}:{number_to_letters(right)}" if top == 0 and not has_header else f"{to_xc(left, top)}:{number_to_letters(right)}"
88+
elif right is None and bottom is not None:
89+
return f"{top + 1}:{bottom + 1}" if left == 0 and not has_header else f"{to_xc(left, top)}:{bottom + 1}"
90+
elif bottom is not None and right is not None:
91+
return to_xc(left, top) if is_one_cell else f"{to_xc(left, top)}:{to_xc(right, bottom)}"
92+
93+
raise ValueError("Bad zone format")
94+
7795
def letters_to_number(letters):
7896
"""
7997
Convert a string (describing a column) to its number value.
@@ -217,3 +235,11 @@ def to_xc(col, row):
217235
'B2'
218236
"""
219237
return number_to_letters(col) + str(row + 1)
238+
239+
240+
def overlap(z1, z2) -> bool:
241+
if z1["bottom"] < z2["top"] or z2["bottom"] < z1["top"]:
242+
return False
243+
if z1["right"] < z2["left"] or z2["right"] < z1["left"]:
244+
return False
245+
return True

0 commit comments

Comments
 (0)