Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aaaaaaaa #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions tupande_odoo_connector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@

# Tupande odoo connector

We recived the endpoint from Tupande as json and based upon the paramerters we create the sale order and client on odoo.

# Tech Stack

Languages Used: Python, XML

Technologies Used: Python 3, Odoo v14

Developed For: Odoo v14

# Sale order Functionality

Create Sale Order Management: Creates new Sale order records in Odoo if they don't already exist.
Unique Identifier Handling for Sale order is tupande_sale_ref as a mandatory key for accurate message processing.
Update Sale Order Management: update sale order records in Odoo if they exist base upon tupande_sale_ref.
If sale order is not fulfill then we can update all order else we can't

## Client Functionality

Create Client Order Management: Creates new client records in Odoo if they don't already exist.
Unique Identifier Handling for client is tupande_client_id as a mandatory key for accurate message processing. we can create multiple client on the same time.
Update Client Order Management: update sale order records in Odoo if they exist base upon tupande_client_id.
We can update multiple client on the same time.

## API Reference

### Get client data

`GET /tupande/clinet`

| Parameter | Type | Description |
|-------------|---------|--------------------------------------------------|
| `id` | `string` | **Required**. tupande client ID |
| `firstName` | `string` | **Required**. client firstName |
| `lastName` | `string` | **Required**. Client lastName |
| `phoneNumber` | `string` | **Required**. Client phoneNumber |
| `gender` | `string` | Gender (Male, Female) |
| `dob` | `string` | Client Date of birth |
| `nid` | `string` | national Id number of client |
| `age` | `string` | Clinet age like '18 - 25', '26 - 30', '26 - 30' etc |

#### Get order data

`GET /tupande/order`

| Parameter | Type | Description |
| :-------- | :------- |:--------------------------------------------------------------|
| `clientId` | `string` | **Required**. tupande client ID |
| `firstName` | `string` | **Required**. client first name key |
| `lastName` | `string`| **Required**. Client's last name key |
| `phoneNumber` | `string` | **Required**. Client phone key |
| `orderDate` | `string` | Sale order Date key |
| `shopId` | `string` | **Required**. Shop id of odoo |
| `chanalId` | `string` | **Required**. Chanal id of odoo |
| `orderRef` | `string` | **Required**. Sale order Reference number key |
| `amountTotal` | `string` | **Required**. Sale Order Total Amount |
| `orderLines` | `list` | **Required**. Sale order line [product_name, qty, unit_price] |

## Appendix

We can able to create and as well update sale order if any fulfillemt is not done.
Similarly we can able to create and update client singuler and bulk as well.

## Testing

To run the tests for this module, run the following command:

./odoo-bin -c {path/to/odoo.conf} -d {db_name} -i tupande_odoo_connector --test-enable --stop-after-init

## Authors

- [@Usman](https://www.github.com/usmanjoiya)
Sync Product from tupande to Odoo

---------------------------------------

We want to create client from tupande to odoo and it can be on bulk as well single.
I create only one end point for all of these options
1- Create/Update single Client
2- Create/Update Bulk Client

# Create/Update single Client

---------------------------------;

We received Json format like below and it's either create or update client
{
"id":"222",
"firstName": "John",
"lastName": "Doe",
"gender": "Male",
"verified": "false",
"nid": "xxxx-xxx-xxx",
"phoneNumber": "+25478398xxx22222"
}

Case-1
If client not exist we create and assign tupande_client_id

Case-2
If phone number already exist we assign tupande_client_id with that client

Case-3
If tupande_client_id already exist we update all it's parameters

# Create/Update bulk Client

----------------------------------;

We received list of dictionary format like below and it's either create or update client
[{
"id":"222",
"firstName": "John",
"lastName": "Doe",
"gender": "Male",
"verified": "false",
"nid": "xxxx-xxx-xxx",
"picture": "http://localhost:8060/web/image?model=res.partner&id=26&field=image_128&unique=02292024233926",
"phoneNumber": "+25478398xxx22222"
},
{
"id":"333",
"firstName": "John-1",
"lastName": "Doe-1",
"gender": "Male",
"verified": "false",
"nid": "xxxx-xxx-xxx",
"picture": "http://localhost:8060/web/image?model=res.partner&id=26&field=image_128&unique=02292024233926",
"phoneNumber": "+25478398xxx333"
},
{
"id":"444",
"firstName": "John-3",
"lastName": "Doe-3",
"gender": "Male",
"verified": "false",
"nid": "xxxx-xxx-xxx",
"picture": "http://localhost:8060/web/image?model=res.partner&id=26&field=image_128&unique=02292024233926",
},
]

It always shows 200 response but a list of dictionary

Response 200 and the reason is if one client fails based on that i can't stop the whole process
[{
'httpStatusCode': '200',
'id': 222,
'odoo-id': 456,
'message': "Client Details updated successfully"
},
{
'httpStatusCode': '201',
'id': 333,
'odoo-id': 457,
'message': "Client created successfully on odoo"
},
{
'httpStatusCode': '400',
'id': 444,
'odoo-id': False,
'message': "Phone Number is required and not received"
}
]
3 changes: 3 additions & 0 deletions tupande_odoo_connector/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers, models
25 changes: 25 additions & 0 deletions tupande_odoo_connector/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
{
"name": "Tupande Odoo Connector",
"summary": """
Syncing data between Tupande and odoo with rest API
sale order and client""",
"description": """
Handling syncing form tupande to odoo.
Sale order and Client
""",
"author": "Usman Akbar",
"website": "https://oneacrefund.org/",
# for the full list
"category": "Customization",
"version": "0.1",
# any module necessary for this one to work correctly
"depends": ["base", "ce_portal", "rest_api"],
# always loaded
"data": [
"views/res_partner.xml",
"views/sale_order.xml",
],
# only loaded in demonstration mode
"demo": [],
}
4 changes: 4 additions & 0 deletions tupande_odoo_connector/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import sale_order
83 changes: 83 additions & 0 deletions tupande_odoo_connector/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import json
import logging

from odoo import http
from odoo.addons.rest_api.controllers.main import (
check_permissions,
error_response,
successful_response,
)
from odoo.http import request

_logger = logging.getLogger(__name__)


class TupandeResPartnerController(http.Controller):
@http.route(
["/tupande/client", "/tupande/client/<int:client_id>"],
methods=["POST"],
type="http",
auth="none",
csrf=False,
)
@check_permissions
def tupande_client_creation(self, client_id=False):
cr = request.cr
uid = request.session.uid
try:
odoo_response = json.loads(request.httprequest.data)
except Exception as e:
return error_response(
400,
"Payload is causing issue",
{
"response": "Request Payload is causing issue",
"Exception Is": str(e),
"Payload Is": str(request.httprequest.data),
},
)

company_id = (
request.env(cr, uid).ref("oaf_countries_and_companies.company_loc_kenya").id
)
country_id = request.env(cr, uid).ref("base.ke").id
res_partner = request.env(cr, uid)["res.partner"].sudo()
_logger.info(odoo_response)
bulk_update = not isinstance(odoo_response, dict)
if not bulk_update:
response = res_partner.handle_client_info(
odoo_response, res_partner, country_id, company_id, client_id
)
if int(response.get("httpStatusCode")) not in [201, 200]:
return error_response(
int(response.get("httpStatusCode")),
"Failed to create Client",
{
"odoo_response": response.get("message"),
},
)

return successful_response(
status=int(response.get("httpStatusCode")), dict_data=response
)
elif client_id:
return error_response(
400,
"You should send Json format if you want to update client",
{
"response": "Request Payload is causing issue",
"Payload Is": str(request.httprequest.data),
},
)

response = []
for commit_data, customer in enumerate(odoo_response, start=1):
if commit_data % 50 == 0:
request.env.cr.commit()

response.append(
res_partner.handle_client_info(
customer, res_partner, country_id, company_id
)
)
return successful_response(status=200, dict_data={"response": response})
Loading
Loading