feat: Add Populate Scripts
This commit is contained in:
39
demo/populate_scripts/parties.py
Normal file
39
demo/populate_scripts/parties.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
|
||||
from proteus import Model
|
||||
from proteus import config as pconfig
|
||||
|
||||
from tools import open_file
|
||||
|
||||
import json
|
||||
|
||||
dir = "./demo/data"
|
||||
file_ = "parties.csv"
|
||||
path = "".join([dir, "/", file_])
|
||||
|
||||
|
||||
def set_config(database, config_file):
|
||||
return pconfig.set_trytond(database, config_file=config_file)
|
||||
|
||||
|
||||
def setup_parties(database, config_file):
|
||||
set_config(database, config_file)
|
||||
data = open_file(path)
|
||||
|
||||
Party = Model.get("party.party")
|
||||
parties = [
|
||||
Party(name=r.get("Name")) for r in data]
|
||||
|
||||
return Party.save(parties)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
with open('demo/data/config.json') as file:
|
||||
config_tryton = json.load(file)
|
||||
|
||||
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('-c', '--config', dest='config_file')
|
||||
parser.add_argument('-d', '--database', dest='database',
|
||||
default='demo', help="database name")
|
||||
options = parser.parse_args()
|
||||
|
||||
setup_parties(options.database, options.config_file)
|
||||
Reference in New Issue
Block a user