@@ -106,12 +106,13 @@ The following methods are supported and will return a collection:
106106* getResourceIds - collection of integers
107107* fieldsGet() - collection of arrays
108108
109- The following helper functions return a native PHP type insead :
109+ The following helper functions return a native PHP type instead :
110110
111111* searchCount - integer
112112* getResourceId - integer
113113* unlink - boolean
114114* create - integer
115+ * write - boolean
115116
116117All ` read() ` and ` searchRead() ` methods will return a collection of models.
117118The default model will be ` Consilience\OdooApi\Model ` , but other models can be specified.
@@ -129,7 +130,7 @@ The `read()` method takes an options array that varies significantly
129130between OpenERP/Odoo versions.
130131This package does not attempt to deal with that at this time.
131132
132- Fpor example, to restrict the read to named attributes, the following
133+ For example, to restrict the read to named attributes, the following
133134formats are used:
134135
135136* OpenERP 7: $client->read('account.invoice', [ 123] , [ 'type', 'partner_id'] );
@@ -153,11 +154,92 @@ $response = $client->write(
153154 $partnerResourceId,
154155 [
155156 'invoice_ids' => $client->relationReplaceAllLinks($invoiceIds),
156- // other optional fields and relations can be set here too
157+
158+ // other optional fields and relations can be set here as nornmal
157159 ]
158160);
159161```
160162
163+ The general way to set a relationship is to set the relation (` invoice_ids ` in this
164+ case) to a data structure which contains a list of IDs and instructions on
165+ what to do with those IDs.
166+
167+ The ` relationReplaceAllLinks() ` here generates the data structure to instruct Odoo
168+ to replace all links between the ` res.partner ` and any invoices they have, with
169+ the new list of ` $invoiceIds ` (an array).
170+ You can construct those data structures yourself, or use the following helpers:
171+
172+ ``` php
173+ // Relate a resource.
174+ $client->relationCreate(array $resourceIds)
175+
176+ // Update a related resource.
177+ // e.g. change the product on an invoice line for an invoice
178+ relationUpdate(int $resourceId, array $values)
179+
180+ // Delete a related resource completely.
181+ // e.g. delete an invoice line on an invoice
182+ relationDelete(int $resourceId)
183+
184+ // Remove the relation to a related resource, but leave the resource intact.
185+ // e.g. remove an invoice from a contact so it can be adde to a new contact
186+ relationRemoveLink(int $resourceId)
187+
188+ // Add a resource to a relation, leaving existing relations intact.
189+ // e.g. add an additional line to an invoice.
190+ relationAddLink(int $resourceId)
191+
192+ // Remove all relations to a resource type.
193+ // e.g. remove all invoices from a contact, before the contatc can is deleted.
194+ relationRemoveAllLinks()
195+
196+ // Replace all relations with a new set of relations.
197+ // e.g. remove all invoices from contact, and give them a new bunch of invoices
198+ // to be responsible for.
199+ relationReplaceAllLinks(iterable $resourceIds)
200+ ```
201+
202+ # Non-CRUD Requests
203+
204+ There are helper functions to provide ` read ` , ` write ` , ` unlink ` , ` search ` functionality,
205+ but you also have access to other API methods at a lower level.
206+ For example, a note can be added to a sales invoice using the ` message_post ` function
207+ for a sales order.
208+ The example below shows how.
209+
210+ ``` php
211+ use OdooApi;
212+
213+ $client = OdooApi::getClient();
214+
215+ // Resource and action, the remote RPC function.
216+ // Note that the message_post() function for each resource type is
217+ // different, i.e. this is not something that can be genereralised
218+ // in the API.
219+ // This starts to build the request message and addes the first
220+ // few positional parameters and authentication details.
221+
222+ $msg = $client->getBaseObjectRequest('sale.order', 'message_post');
223+
224+ // Further positional parameters.
225+ // This is for an Odoo 7.0 installation. Other versions may differ.
226+
227+ $msg->addParam($client->nativeToValue([$orderId])); // Resource(s) ID
228+ $msg->addParam($client->nativeToValue($text_message)); // Body
229+ $msg->addParam($client->nativeToValue(false)); // Subject
230+ $msg->addParam($client->nativeToValue('comment')); // Subtype
231+ $msg->addParam($client->nativeToValue(false)); // Partner IDs to send a copy to
232+
233+ // Send the message.
234+
235+ $response = $client->getXmlRpcClient('object')->send($msg);
236+
237+ // If you want to inspect the result, then this will give you
238+ // what the Odoo message_post() function returns.
239+
240+ $result = $client->valueToNative($response->value());
241+ ```
242+
161243# TODO
162244
163245* Conversion of ` date ` types have not been tested.
@@ -173,6 +255,6 @@ $response = $client->write(
173255 For example, specifying the list of fields to retrieve for a ` read `
174256 has new structures introduced for versions 7, 8 and 10.
175257 The client class is also going to star getting a bit cumbersome at this
176- point, so moving some of the XML-RPC sepcific stuff (message creation, data
177- conversion) would be best moved to a separate connction class).
178-
258+ point, so moving some of the XML-RPC specific stuff (message creation, data
259+ conversion) would be best moved to a separate connection class).
260+ * Positional parameter builder helper.
0 commit comments