Importing spent time
Added by Domhnall Currie over 3 years ago
I've read what information I can find where this feature was added, but I don't understand how this actually works. I created a .CSV file to try to match what RM is looking to import. It lets me map every field but Project where it makes me choose a project. Is this how this is supposed to work? So every line imported from a given file has to go into one project or is there a way to read the Project field from the .CSV file and each line in the import goes into the appropriate project?
Replies (2)
RE: Importing spent time - Added by Marius BĂLTEANU over 3 years ago
Importing time entries on multiple projects is not supported. You should open a feature request.
RE: Importing spent time - Added by Murilo Habermann Torquato about 3 years ago
Domhnall Currie wrote:
I've read what information I can find where this feature was added, but I don't understand how this actually works. I created a .CSV file to try to match what RM is looking to import. It lets me map every field but Project where it makes me choose a project. Is this how this is supposed to work? So every line imported from a given file has to go into one project or is there a way to read the Project field from the .CSV file and each line in the import goes into the appropriate project?
I did a trick here to allow my internal team to import CSV times from multiple projects.
- created a new customized field "project import" on time entries
- created a new customized field "issue import" on time entries
- create 2 triggers as follows:
CREATE OR REPLACE FUNCTION update_project() RETURNS trigger AS $$ declare import_project_id integer; begin -- only execute the trigger if the field is 73 IF NEW.custom_field_id != 73 THEN RETURN NEW; END IF; raise NOTICE 'import_project: "%" ', NEW.value; -- check if the import_project is not empty IF coalesce(new.value,'') != '' then -- get the project ID SELECT id INTO import_project_id FROM public.projects WHERE identifier = NEW.value; raise notice 'import_project_id: "%"', import_project_id; IF import_project_id = 0 THEN RAISE EXCEPTION 'Projeto (Importação) inválido: verifique o identificador antes de seguir.'; END IF; -- atualiza o ID do projeto para o tempo importado update public.time_entries set project_id = import_project_id where id = new.customized_id; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; ALTER FUNCTION public.update_project() OWNER TO redmine; GRANT ALL ON FUNCTION public.update_project() TO redmine; DROP TRIGGER IF EXISTS update_project ON custom_values; CREATE TRIGGER update_project AFTER insert or UPDATE ON custom_values FOR EACH ROW EXECUTE PROCEDURE update_project(); CREATE OR REPLACE FUNCTION update_issue() RETURNS trigger AS $$ declare import_issue_id integer; import_project_issue_id integer; begin -- only execute the trigger if the field is 74 IF NEW.custom_field_id != 74 or coalesce(new.VALUE,'') = '' THEN RETURN NEW; END IF; import_issue_id := NEW.value::integer; raise NOTICE 'import_issue_id: "%" ', import_issue_id; -- verifica se não houver um valor para a tarefa de importacao IF import_issue_id > 0 then -- grava o valor do ID do projeto da tarefa informada no campo de importacao na variavel import_project_issue_id SELECT project_id INTO import_project_issue_id FROM public.issues WHERE id = import_issue_id; raise notice 'import_project_issue_id: "%"', import_project_issue_id; -- atualiza o ID do projeto para o tempo importado update public.time_entries set project_id = import_project_issue_id, issue_id = import_issue_id where id = new.customized_id; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql; ALTER FUNCTION public.update_issue() OWNER TO redmine; GRANT ALL ON FUNCTION public.update_issue() TO redmine; DROP TRIGGER IF EXISTS update_issue ON custom_values; CREATE TRIGGER update_issue AFTER insert or UPDATE ON custom_values FOR EACH ROW EXECUTE PROCEDURE update_issue();
after that, my team is using a spreadsheet for support tracking times during the day and after they can import a CSV (attached as example)
RedmineTimeTracker.csv (1.19 KB) RedmineTimeTracker.csv |