-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathCustomer.php
127 lines (85 loc) · 3.61 KB
/
Customer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once('ripcord.php');
require_once('Odoo.php');
class Customer {
var $odoo;
public function __construct($odoo) {
$this->odoo = $odoo;
}
function editCustomer() {
$name = $_POST['name'];
$key = $_POST['key'];
$value = $_POST['value'];
$models = ripcord::client($this->odoo->url . "/xmlrpc/2/object");
$customer_ids = $models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'search_read', array(array(array('customer', '=', true), array('name', '=', $name))), array(
'limit' => 1,
'fields' => array('id')))[0];
foreach ($customer_ids as $uid) {
$customer_id = $uid;
}
$models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'write', array(array($customer_id), array($key => $value)));
}
function getCustomer() {
$name = $_POST['name'];
$models = ripcord::client($this->odoo->url . "/xmlrpc/2/object");
$client = $models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'search_read', array(array(array('customer', '=', true), array('name', '=', $name))), array(
'limit' => 1,
'fields' => array(
'birthdate',
'phone',
'function',
'name',
'email',
'address',
'website')))[0];
self::response($client);
}
function addCustomer() {
$name = $_POST['name'];
$email = $_POST['email'];
$title = $_POST['title'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$birthdate = $_POST['birthdate'];
$models = ripcord::client($this->odoo->url . "/xmlrpc/2/object");
//Add user to DB
$id = $models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'create', array(array('name' => $name,
'birthdate' => $birthdate,
'phone' => $phone,
'function' => $title,
'email' => $email,
'website' => $website)));
//Display Profile
$client = $models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'search_read', array(array(array('customer', '=', true), array('name', '=', $name))), array(
'limit' => 1,
'fields' => array('birthdate', 'phone', 'function', 'name',
'email',
'address',
'website')))[0];
self::response($client);
}
function listAll() {
$models = ripcord::client($this->odoo->url . "/xmlrpc/2/object");
$client = $models->execute_kw($this->odoo->db, $this->odoo->user_id, $this->odoo->password, 'res.partner', 'search_read', array(array(array('customer', '=', true))), array(
'limit' => 100,
'fields' => array(
'birthdate',
'phone',
'function',
'name',
'email',
'address',
'website',
)));
self::response($client);
}
function response($client) {
echo json_encode($client);
//
}
}