Skip to content

Commit

Permalink
Add a workaround for button_immediate_install (runtime method additio…
Browse files Browse the repository at this point in the history
…n) with example of module installation
  • Loading branch information
azawawi committed Jan 23, 2017
1 parent d9abd55 commit d7f4082
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
40 changes: 40 additions & 0 deletions examples/02-module.pl6
@@ -0,0 +1,40 @@


use v6;
use lib 'lib';

use Odoo::Client;

# Create a new odoo JSON-RPC client
my $odoo = Odoo::Client.new(
hostname => "localhost",
port => 8069
);

# Login to odoo
my $uid = $odoo.login(
database => "sample",
username => 'user@example.com',
password => "123"
);


sub install-modules(@modules-to-install) {
my $module = $odoo.model('ir.module.module');
for @modules-to-install -> $module-name {
my $module-ids = $module.search([
['name', '=', $module-name ],
['state', 'not in', ['installed', 'to upgrade']]
]);
if $module-ids {
say "Installing $module-name";
my $result = $module.button-immediate-install($module-ids);
say $result.perl;
}
}
}

install-modules([
'sale',
'crm'
]);
20 changes: 19 additions & 1 deletion lib/Odoo/Client.pm6
Expand Up @@ -113,11 +113,29 @@ multi method invoke(Str :$model, Str :$method, :$method-args) {
Returns an C<Odoo::Client::Model> model. This is a helper method.
=end pod
#TODO should create a model proxy by queries fields for that model
method model(Str $name) {
return Odoo::Client::Model.new(

# Create the model proxy
my $model = Odoo::Client::Model.new(
:client(self),
:name($name)
);

# Workaround for button-immediate-install
if $name eq 'ir.module.module' {
#TODO make this more generic by querying Odoo model
$model.^add_method('button-immediate-install', method ($args){
my $result = $!client.invoke(
model => 'ir.module.module',
method => 'button_immediate_install',
method-args => $args
);
return $result;
})
}

return $model;
}

=begin pod
Expand Down

0 comments on commit d7f4082

Please sign in to comment.