| 1 | unit UMainForm;
|
|---|
| 2 |
|
|---|
| 3 | {$mode objfpc}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
|
|---|
| 9 |
|
|---|
| 10 | type
|
|---|
| 11 |
|
|---|
| 12 | { TForm1 }
|
|---|
| 13 |
|
|---|
| 14 | TForm1 = class(TForm)
|
|---|
| 15 | Memo1: TMemo;
|
|---|
| 16 | procedure FormShow(Sender: TObject);
|
|---|
| 17 | private
|
|---|
| 18 | { private declarations }
|
|---|
| 19 | public
|
|---|
| 20 | { public declarations }
|
|---|
| 21 | end;
|
|---|
| 22 |
|
|---|
| 23 | var
|
|---|
| 24 | Form1: TForm1;
|
|---|
| 25 |
|
|---|
| 26 | implementation
|
|---|
| 27 |
|
|---|
| 28 | {$R *.lfm}
|
|---|
| 29 |
|
|---|
| 30 | { TForm1 }
|
|---|
| 31 |
|
|---|
| 32 | procedure TForm1.FormShow(Sender: TObject);
|
|---|
| 33 | var
|
|---|
| 34 | Source, Dest: TStringList;
|
|---|
| 35 | I: Integer;
|
|---|
| 36 | SourceLine, DestLine: TStringList;
|
|---|
| 37 | Typ: TStringList;
|
|---|
| 38 | UserType: string;
|
|---|
| 39 | Sub: string;
|
|---|
| 40 | SubUnderline: string;
|
|---|
| 41 | SubSpace: string;
|
|---|
| 42 | SubName: string;
|
|---|
| 43 | begin
|
|---|
| 44 | try
|
|---|
| 45 | Typ := TStringList.Create;
|
|---|
| 46 | Typ.Add('A=active');
|
|---|
| 47 | Typ.Add('P=passive');
|
|---|
| 48 | Typ.Add('N=expenses');
|
|---|
| 49 | Typ.Add('V=incomes');
|
|---|
| 50 | Typ.Add('=result');
|
|---|
| 51 |
|
|---|
| 52 | Source := TStringList.Create;
|
|---|
| 53 | Dest := TStringList.Create;
|
|---|
| 54 | SourceLine := TStringList.Create;
|
|---|
| 55 | DestLine := TStringList.Create;
|
|---|
| 56 |
|
|---|
| 57 | Dest.Add('<?xml version="1.0" encoding="utf-8"?>');
|
|---|
| 58 | Dest.Add('<openerp>');
|
|---|
| 59 | Dest.Add('<data noupdate="1">');
|
|---|
| 60 |
|
|---|
| 61 | Dest.Add('<record id="' +
|
|---|
| 62 | 'account_template_root" model="account.account.template">');
|
|---|
| 63 | Dest.Add(' <field name="code">root</field>');
|
|---|
| 64 | Dest.Add(' <field name="name">Kořenový účet</field>');
|
|---|
| 65 | Dest.Add(' <field name="parent_id" ref=""/>');
|
|---|
| 66 | Dest.Add(' <field name="type">view</field>');
|
|---|
| 67 | Dest.Add(' <field name="user_type" ref="active"/>');
|
|---|
| 68 | Dest.Add('</record>');
|
|---|
| 69 |
|
|---|
| 70 | Source.LoadFromFile('osnova_tridy.csv');
|
|---|
| 71 | for I := 0 to Source.Count - 1 do begin
|
|---|
| 72 | SourceLine.CommaText := Source[I];
|
|---|
| 73 | Dest.Add('<record id="' +
|
|---|
| 74 | 'account_template_' + Trim(SourceLine[0]) +
|
|---|
| 75 | '" model="account.account.template">');
|
|---|
| 76 | Dest.Add(' <field name="code">' + Trim(SourceLine[0]) + '</field>');
|
|---|
| 77 | Dest.Add(' <field name="name">' + Trim(SourceLine[1]) + '</field>');
|
|---|
| 78 | Dest.Add(' <field name="parent_id" ref="account_template_root"/>');
|
|---|
| 79 | Dest.Add(' <field name="type">view</field>');
|
|---|
| 80 | Dest.Add(' <field name="user_type" ref="active"/>');
|
|---|
| 81 | Dest.Add('</record>');
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | Source.LoadFromFile('osnova_skupiny.csv');
|
|---|
| 85 | for I := 0 to Source.Count - 1 do begin
|
|---|
| 86 | SourceLine.CommaText := Source[I];
|
|---|
| 87 | Dest.Add('<record id="' +
|
|---|
| 88 | 'account_template_' + Trim(SourceLine[0]) +
|
|---|
| 89 | '" model="account.account.template">');
|
|---|
| 90 | Dest.Add(' <field name="code">' + Trim(SourceLine[0]) + '</field>');
|
|---|
| 91 | Dest.Add(' <field name="name">' + Trim(SourceLine[1]) + '</field>');
|
|---|
| 92 | Dest.Add(' <field name="parent_id" ref="' +
|
|---|
| 93 | 'account_template_' + Trim(Copy(SourceLine[0], 1, Length(Trim(SourceLine[0])) - 1)) +
|
|---|
| 94 | '"/>');
|
|---|
| 95 | Dest.Add(' <field name="type">view</field>');
|
|---|
| 96 | Dest.Add(' <field name="user_type" ref="active"/>');
|
|---|
| 97 | Dest.Add('</record>');
|
|---|
| 98 | end;
|
|---|
| 99 |
|
|---|
| 100 | Source.LoadFromFile('osnova_ucty.csv');
|
|---|
| 101 | for I := 0 to Source.Count - 1 do begin
|
|---|
| 102 |
|
|---|
| 103 | SourceLine.CommaText := Source[I];
|
|---|
| 104 | SourceLine[0] := Trim(SourceLine[0]);
|
|---|
| 105 | if Pos(' ', Trim(SourceLine[0])) > 0 then begin
|
|---|
| 106 | Sub := Copy(SourceLine[0], Pos(' ', SourceLine[0]) + 1, 255);
|
|---|
| 107 | SourceLine[0] := Copy(SourceLine[0], 1, Pos(' ', SourceLine[0]) - 1);
|
|---|
| 108 | SubUnderline := '_' + Sub;
|
|---|
| 109 | SubSpace := ' ' + Sub;
|
|---|
| 110 | SubName := ' ' + Trim(SourceLine[4]);
|
|---|
| 111 | end else begin
|
|---|
| 112 | Sub := '';
|
|---|
| 113 | SubUnderline := '';
|
|---|
| 114 | SubSpace := '';
|
|---|
| 115 | SubName := '';;
|
|---|
| 116 | end;
|
|---|
| 117 |
|
|---|
| 118 | Dest.Add('<record id="' +
|
|---|
| 119 | 'account_template_' + Trim(SourceLine[0]) + SubUnderline +
|
|---|
| 120 | '" model="account.account.template">');
|
|---|
| 121 | Dest.Add(' <field name="code">' + Trim(SourceLine[0]) + SubSpace + '</field>');
|
|---|
| 122 | Dest.Add(' <field name="name">' + Trim(SourceLine[3]) + SubName + '</field>');
|
|---|
| 123 | Dest.Add(' <field name="parent_id" ref="' +
|
|---|
| 124 | 'account_template_' + Trim(Copy(SourceLine[0], 1, Length(Trim(SourceLine[0])) - 1)) +
|
|---|
| 125 | '"/>');
|
|---|
| 126 | Dest.Add(' <field name="type">view</field>');
|
|---|
| 127 | UserType := Typ.Values[Trim(SourceLine[1])];
|
|---|
| 128 | if UserType = '' then UserType := 'result';
|
|---|
| 129 |
|
|---|
| 130 | Dest.Add(' <field name="user_type" ref="' + UserType + '"/>');
|
|---|
| 131 | Dest.Add('</record>');
|
|---|
| 132 | Memo1.Lines.Add(IntToStr(SourceLine.Count) + ': ' + SourceLine[1] + ' => ' + Typ.Values[SourceLine[1]]);
|
|---|
| 133 |
|
|---|
| 134 | end;
|
|---|
| 135 |
|
|---|
| 136 | Dest.Add('</data>');
|
|---|
| 137 | Dest.Add('</openerp>');
|
|---|
| 138 |
|
|---|
| 139 | Dest.SaveToFile('account_template.xml');
|
|---|
| 140 | finally
|
|---|
| 141 | SourceLine.Free;
|
|---|
| 142 | DestLine.Free;
|
|---|
| 143 | Source.Free;
|
|---|
| 144 | Dest.Free;
|
|---|
| 145 | Typ.Free;
|
|---|
| 146 | end;
|
|---|
| 147 | end;
|
|---|
| 148 |
|
|---|
| 149 | end.
|
|---|
| 150 |
|
|---|