Skip to content

Commit

Permalink
Task to sync all the users (#15)
Browse files Browse the repository at this point in the history
* Odoo user profile

* Add Specs

* Lint files

* Fix typo

* Odoo member authorization

* Fix user_valid method

* Admin panel to manage odoo users

* Fix i18n spec

* Add spec for touch

* Add specs

* Use add_item instead of item

* Fix spec

* Add spec for show email

* Add spec for contact

* Task to sync all the users
  • Loading branch information
fblupi committed Jul 21, 2023
1 parent 0bc8d2d commit dbdd5af
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/jobs/decidim/odoo/sync_users_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Odoo
class SyncUsersJob < ApplicationJob
queue_as :default

def perform(organization_id, odoo_user_id)
def perform(organization_id, odoo_user_id = nil)
odoo_users = Decidim::Odoo::User.where(decidim_organization_id: organization_id)
odoo_users = odoo_users.where(id: odoo_user_id) if odoo_user_id
Rails.logger.warn "SyncUsersJob: WARN: No results found for: organization_id='#{organization_id}' and odoo_user_id='#{odoo_user_id}'" if odoo_users.empty?
Expand Down
16 changes: 16 additions & 0 deletions lib/tasks/decidim_odoo.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

namespace :decidim do
namespace :odoo do
# invoke with 'bundle exec rake "civicrm:sync:groups"'

namespace :sync do
desc "Sync members with Odoo API"
task members: :environment do
Decidim::Organization.find_each do |organization|
Decidim::Odoo::SyncUsersJob.perform_later(organization.id)
end
end
end
end
end
14 changes: 14 additions & 0 deletions spec/tasks/decidim_odoo_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require "spec_helper"

describe "rake decidim:odoo:sync:members", type: :task do
let(:count) { 5 }
let!(:organizations) { create_list :organization, count }

context "when executing task" do
it "enqueues as jobs as organizations in the system" do
expect { task.execute }.to have_enqueued_job(Decidim::Odoo::SyncUsersJob).exactly(count)
end
end
end

0 comments on commit dbdd5af

Please sign in to comment.