Odoo create invoice from picking with XML-RPC call - php

I would like to create an invoice from the picking but trough and XML-RPC call from a PHP file.
I have tried to call the action_id: 359 like this:
$transfer = $rpc->button_click($uid, $pwd, 'stock.invoice.onshipping', 'invoice_open', array(111));
But it doesn't work... Do some one have any clue on how can I do this?

Below i am posing the code it may help in your case:
In Php you can try ripcord library :
For Basic connection setup/authorization just type this code.
$url = "http://localhost:8072";
$db ="my_db";
$username = "prakashsharmacs24#gmail.com";
$password = "7859884833";
$common = ripcord::client("$url/xmlrpc/common");
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;//1
Now create a model instance and call the work flow by exec_workflow:
$models = ripcord::client("$url/xmlrpc/object");
$models->exec_workflow($db, $uid, $password,'account.invoice' ,'invoice_open',14);
Hope this may help in calling the workflow from php.

Related

Basic authorization on PHP soapClient

I am trying to call a function on a web service defined on a Tomcat server, but I can not make the call due to a credentials failure.
The structure of this web service asks for a Basic Authorization embedded on the envelope (not the header itself). Using the SOAPui tool I have no problem to make this call entering the username and password. But using the PHP client is not possible to access the web service.
I have already tried to use nusoal library which actually works, but it doesn't help with the parameters because I can not filter the query. I mean is like this call doesn't use the parameters at all returning all the results.
I would like to give it a try with the default soapClient.
<?php
$username = "user";
$password = "pass";
$wsdl = 'http://192.168.1.185:8080/msw/gestionSolicitudes?wsdl';
$options = array(
'Username' => $username,
'Password' => $password,
);
$client = new SoapClient($wsdl, $options);
$parametros = array("statusId"=>2, "startDate"=>'2019-01-01', "endDate"=>'2019-09-01', "name"=>'Maria');
$result = $client->__soapCall('getSolicitudesLista', $parametros);
foreach ($result as &$valor) {
foreach ($valor as &$solicitud) {
if (is_object($solicitud)) {
echo nl2br (">>>Solicitud init ============================================\r\n");
....
} else {
echo nl2br (">>>Result ============================================\r\n\r\n");
var_dump($solicitud);
echo nl2br (">>>Result ============================================\r\n\r\n");
}
}
}
?>

Create user in ejabbred using PHP

Right now I am trying to create a user in ejabberd using PHP. I have checked many sources From Git. As well as I tried to follow the same answer as given in this question
But sometimes user is going to be created, and sometimes not, so any debug points.
https://github.com/fabiang/xmpp
As per my knowledge there is issue related to time limit between create user one after another in ejabberd.
For example :
My script is going to run and create a user at a time.
Then I have to wait around 8-9 minutes, then I am try executing my script then it will create another user for me on first try but IF I try to create another user just after some time.
Is that possible?
CODE :
<?php
require 'vendor/autoload.php';
error_reporting(-1);
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Protocol\Register;
use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;
$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
$hostname ='192.168.1.12';
$port = 5222;
$connectionType = 'tcp';
$address = "$connectionType://$hostname:$port";
$adminUsername ="admin";
$adminPassword = "admin";
$name ="87878";
$name ="87890";
$password = "maddy";
$options = new Options($address);
$options->setUsername($adminUsername)
->setPassword($adminPassword)
->setContextOptions(['ssl' => ['verify_peer' => false,'verify_peer_name' => false]]);
$client = new Client($options);
$client->connect();
$register = new Register($name, $password);
$client->send($register);
$client->disconnect();
?>
Any suggestions?

Using an existing API with codeigniter 2

I dont ask many questions as I like to research for myself but this has me stumped.
I have an existing Codeigniter2(CI) application and am trying to integrate an existing API for a payment system (MangoPay). I have added it as a library and also preloaded it in autoload.php, it is being included with no errors.
My question is about setting up the class structure and addressing the class from my application.
Now, if you were to get this working from a plain old PHP file, the code would look like this (and btw it works on my machine with no issue from a plain php file)
<?php
require_once('../vendor/autoload.php');
$mangoPayApi = new MangoPay\MangoPayApi();
$mangoPayApi->Config->ClientId = 'user_id';
$mangoPayApi->Config->ClientPassword = 'password_here';
$mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
$User = new MangoPay\UserNatural();
$User->Email = "test_natural#testmangopay.com";
$User->FirstName = "Bob";
$User->LastName = "Briant";
$User->Birthday = 121271;
$User->Nationality = "FR";
$User->CountryOfResidence = "ZA";
$result = $mangoPayApi->Users->Create($User);
var_dump($result);
?>
So, I have created a new class in the libraries folder and if i was to var_dump() the contents of mangoPayApi as below, it throws all kinds of stuff which proves that it is working (ie no PHP errors).
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once('/vendor/autoload.php');
class MangoPayService {
private $mangoPayApi;
private $user;
public function __construct()
{
$this->mangoPayApi = new MangoPay\MangoPayApi();
$this->mangoPayApi->Config->ClientId = 'user_id_here';
$this->mangoPayApi->Config->ClientPassword = 'password_here';
$this->mangoPayApi->Config->TemporaryFolder = 'c:\\wamp\\tmp/';
//var_dump($mangoPayApi);
}
I thought I could just write a method in the class like this
function add_user(){
//CREATE NATURAL USER
$this->user = new user();
$user->Email = 'test_natural#testmangopay.com';
$user->FirstName = "John";
$user->LastName = "Smith";
$user->Birthday = 121271;
$user->Nationality = "FR";
$user->CountryOfResidence = "ZA";
$add_userResult = $this->mangoPayApi->Users->Create($user);
var_dump($add_userResult);
}
and acces it in my application like
<?php echo $this->mangopayservice->add_user() ?>
But i get errors Fatal error: Class 'user' not found in C:\wamp\www\mpapp\application\libraries\MangoPayService.php on line 25 (which is this->user = new user(); this line)
Can anyone explain how to correctly set up this scenario and how to integrate correctly with the API.
if I can get something to create a user simply when a page is opened, I think I can work it from there using the solution as a roadmap.
I will be writing all the integration code once I understand how to make this work.
Thank in advance
MangoPay requires a NaturalUser class. You try to instantiate a user class.
Simply replace your first line of the add_user function with :
$user = new MangoPay\UserNatural();

Call FluentPDO once

I am using slim framework together with FluentPDO query builder and this is what I'm currently doing:
$app->get('/song/remove/:songID', function($songID) use($app) {
$pdo = new PDO("mysql:dbname=songs", "root");
$fpdo = new FluentPDO($pdo);
$query = $fpdo->deleteFrom('songlist')->where('songID', $songID)->execute();
$app->flash('msg', 'Song ID '.$songID.' removed.');
$app->redirect('/');
});
$app->get('/song/view/:songID', function($songID) use($app) {
$pdo = new PDO("mysql:dbname=songs", "root");
$fpdo = new FluentPDO($pdo);
$song = $fpdo->from('songlist')->where('songID', $songID);
$app->render('view-song.html', [
'song' => $song //pass variable to template
]);
});
As you can see, I am calling this code in every function:
$pdo = new PDO("mysql:dbname=songs", "root");
$fpdo = new FluentPDO($pdo);
What I wanted to do is to just call it once, so that if I will change something in my database, I'll only change a single line. How can I accomplish that? THank you.
It depends on your project structure, the logic is to create a bootstrap or configuration file that will contains all your project constants (database connection, paths ...) that will be loaded by default in your entire application.
this video by codeschool may help setting up one:
https://www.youtube.com/watch?v=NFeWo1cqxnM
here is a project skeleton that you may consider:
https://github.com/slimphp/Slim-Skeleton
Hope it helps

How to call a function inside a class that's need login?

I'm using an api, example:
// Log in:
$obj = new example('username', 'password');
// Get your feed:
$snaps = $obj->feed();
// Get your friends' stories:
$stories = $obj->stories();
But in the api theres a register function that's under example->register but how do i use it if I need to login to use the rest, specifically how would I use the register function for https://github.com/JorgenPhi/php-snapchat
All of the __construct (the method which is called when creating a new Snapchat object) parameters are optional. As you can see here, they all have a default value of null.
public function __construct($username = NULL, $password = NULL, $auth_token = NULL) {
This means you can pass no parameters and it will still create an instance. So to answer your question, you would do it like this.
$snapchat = new Snapchat();
$snapchat->register($username, $password, $email, $birthday);
You can call the constructor without username and password like this
$obj = new Snapchat();
$obj->register('username', 'password');

Categories