-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv2update.py
More file actions
25 lines (20 loc) · 846 Bytes
/
csv2update.py
File metadata and controls
25 lines (20 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Convert a CSV file to Odoo statements which can be run in a scheduled action to update the given records"""
import argparse
import csv
from pathlib import Path
def main():
parser = argparse.ArgumentParser()
parser.add_argument("file")
args = parser.parse_args()
csv_file = Path(args.file).expanduser().absolute()
table_name = Path(args.file).stem.replace(".", "_")
with open(csv_file, "r", encoding="utf-8") as csv_fd:
reader = csv.reader(csv_fd)
columns = next(reader)[1:]
for row in reader:
for field, val in zip(columns, row[1:]):
sql_sentence = f"UPDATE {table_name} SET backup_{field} = '{val}' WHERE id = {row[0]}"
odoo_command = f'env.cr.execute("{sql_sentence}")'
print(odoo_command)
if __name__ == "__main__":
main()