Commit 469832f9 authored by Jérome Perrin's avatar Jérome Perrin

fix formatting

parent 1a2a88e7
...@@ -5,17 +5,20 @@ We all remember problems we had in school, stated likes: ...@@ -5,17 +5,20 @@ We all remember problems we had in school, stated likes:
> Alice recieve 10 candies from her grandmother and later gives 2 candies to Bob. > Alice recieve 10 candies from her grandmother and later gives 2 candies to Bob.
> How many candies has Alice left ? > How many candies has Alice left ?
We will walk through ERP5 business model and Inventory API using that problem as an example.
The 5 base classes of ERP5, also called _Universal Business Model_ are shown in the picture below.
![ERP5's 5 classes](https://www.erp5.com/developer-ERP5.UBM.Picture?quality=75.0&display=small&format=png "ERP5 5 classes")
Using ERP5 Universal Business Model this simple problem will be modeled using: Using ERP5 Universal Business Model this simple problem will be modeled using:
- resource: The resource are candies - resource: The resource are candies
- node: Alice, Bob and the Grandmother are nodes - node: Alice, Bob and the Grandmother are nodes
- movements: When Alice gives 2 candies to Bob, there is a movement where Alice is _source_ and Bob is _destination_. The resource of this movement is candy. - movements: When Alice gives 2 candies to Bob, there is a movement where Alice is _source_ and Bob is _destination_. The resource of this movement is candy.
![ERP5's 5 classes](https://www.erp5.com/developer-ERP5.UBM.Picture?quality=75.0&display=small&format=png "ERP5 5 classes") In our problem, there are two movements:
In this problem, there are two movements:
| Movement | Source | Destination | Resource | Quantity | | Movement | Source | Destination | Resource | Quantity |
|---------:| ------------- |------------- -| ---------| ---------:| | -------- | ------------- |-------------- | -------- | ---------:|
| M1 | Grandmother | Alice | Candy | 10 | | M1 | Grandmother | Alice | Candy | 10 |
| M2 | Alice | Bob | Candy | 2 | | M2 | Alice | Bob | Candy | 2 |
...@@ -24,7 +27,7 @@ A simple solution to "how many candies Alice has left" is achived by summing the ...@@ -24,7 +27,7 @@ A simple solution to "how many candies Alice has left" is achived by summing the
Which in pseudo SQL format, means: Which in pseudo SQL format, means:
```#SQL ```sql
SELECT SUM(quantity) FROM movements WHERE Source = 'Alice' SELECT SUM(quantity) FROM movements WHERE Source = 'Alice'
- SUM(quantity) FROM movements Where Destination = 'Alice' - SUM(quantity) FROM movements Where Destination = 'Alice'
``` ```
...@@ -38,7 +41,7 @@ The underlying idea of Inventory is to see all movements from the source's point ...@@ -38,7 +41,7 @@ The underlying idea of Inventory is to see all movements from the source's point
We store the movements using the following data structure: We store the movements using the following data structure:
| Movement | Node | Mirror Node | Resource | Quantity | | Movement | Node | Mirror Node | Resource | Quantity |
|---------:| ------------- |------------- -| ---------| ---------:| | -------- | ------------- | ------------- | -------- | ---------:|
| M1 | Grandmother | Alice | Candy | -10 | | M1 | Grandmother | Alice | Candy | -10 |
| M1 | Alice | Grandmother | Candy | 10 | | M1 | Alice | Grandmother | Candy | 10 |
| M2 | Alice | Bob | Candy | -2 | | M2 | Alice | Bob | Candy | -2 |
...@@ -47,19 +50,20 @@ We store the movements using the following data structure: ...@@ -47,19 +50,20 @@ We store the movements using the following data structure:
Using this data structure querying inventory of Alice is much efficient: Using this data structure querying inventory of Alice is much efficient:
```SQL ```sql
SELECT SUM(quantity) FROM stock WHERE Node = 'Alice' SELECT SUM(quantity) FROM stock WHERE Node = 'Alice'
``` ```
Using ERP5 API, this call would be : Using ERP5 API, this call would be :
```#python ```python
return portal_simulation.getInventory( return portal_simulation.getInventory(
node_uid=alice.getUid() node_uid=alice.getUid()
) )
``` ```
--- ---
## Dates ## Dates
...@@ -78,7 +82,7 @@ Let's imagine that on Wednesday Alice send 3 candies to her cousin Carol that li ...@@ -78,7 +82,7 @@ Let's imagine that on Wednesday Alice send 3 candies to her cousin Carol that li
| Movement | Node | Mirror Node | Resource | Quantity | Date | | Movement | Node | Mirror Node | Resource | Quantity | Date |
|---------:| ------------- |------------- -| ---------| ---------:|-----------| | -------- | ------------- | ------------- | -------- | ---------:| --------- |
| M1 | Grandmother | Alice | Candy | -10 | Monday | | M1 | Grandmother | Alice | Candy | -10 | Monday |
| M1 | Alice | Grandmother | Candy | 10 | Monday | | M1 | Alice | Grandmother | Candy | 10 | Monday |
| M2 | Alice | Bob | Candy | -2 | Tuesday | | M2 | Alice | Bob | Candy | -2 | Tuesday |
...@@ -88,23 +92,23 @@ Let's imagine that on Wednesday Alice send 3 candies to her cousin Carol that li ...@@ -88,23 +92,23 @@ Let's imagine that on Wednesday Alice send 3 candies to her cousin Carol that li
In this table it, as easy to see that before Tuesday evening, Alice had 8 candies: In this table it, as easy to see that before Tuesday evening, Alice had 8 candies:
```#python ```python
>>> getInventory(node=Alice, at_date=Tuesday) >>> getInventory(node=Alice, at_date=Tuesday)
8 # M1 & M2 8 # M1 & M2
``` ```
Because under the hood, this will use a query like: Because under the hood, this will use a query like:
```SQL ```sql
SELECT SUM(quantity) from stock where Node='Alice' and Date <= Monday SELECT SUM(quantity) from stock where Node='Alice' and Date <= Monday
``` ```
On Wednesday evening, has only 5 Candies because the movement already decreased her stock On Wednesday evening, has only 5 Candies because the movement already decreased her stock
```#python ```python
>>> getInventory(node=Alice, at_date=Tuesday) >>> getInventory(node=Alice, at_date=Tuesday)
5 # M1 & M2 & M3 5 # M1 & M2 & M3
``` ```
```#SQL ```sql
SELECT SUM(quantity) from stock where Node='Alice' and Date <= Tuesday SELECT SUM(quantity) from stock where Node='Alice' and Date <= Tuesday
``` ```
...@@ -113,16 +117,16 @@ But Carol's inventory of candies is still 0 on Wednesday: ...@@ -113,16 +117,16 @@ But Carol's inventory of candies is still 0 on Wednesday:
>>> getInventory(node=Carol, at_date=Wednesday) >>> getInventory(node=Carol, at_date=Wednesday)
0 0
``` ```
```#SQL ```sql
SELECT SUM(quantity) from stock where Node='Carol' and Date <= Tuesday SELECT SUM(quantity) from stock where Node='Carol' and Date <= Tuesday
``` ```
And this inventory is only increased on Thursday: And this inventory is only increased on Thursday:
```#python ```python
>>> getInventory(node=Carol, at_date=Thursday) >>> getInventory(node=Carol, at_date=Thursday)
3 3
``` ```
```#SQL ```sql
SELECT SUM(quantity) from stock where Node='Carol' and Date <= Thursday SELECT SUM(quantity) from stock where Node='Carol' and Date <= Thursday
``` ```
...@@ -174,7 +178,4 @@ linear movements ...@@ -174,7 +178,4 @@ linear movements
# Tracking API # Tracking API
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment