Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuioli committed Aug 4, 2021
0 parents commit 96cbdd5
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# andreani_odoo
Odoo Connector with Andreani for Delivey

Note: This connector is just for simulator
4 changes: 4 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import models
23 changes: 23 additions & 0 deletions __manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
{
'name': "PedidosYa Odoo Connector",

'summary': """
Connector Odoo-PedidosYa""",

'description': """
Connector Odoo-PedidosYa for Sale Orders
""",

'author': "Codize",
'website': "https://www.codize.ar",

'category': 'Sales',
'version': '0.1',

'depends': ['base', 'sale'],

'data': [
'views/res_company.xml',
]
}
3 changes: 3 additions & 0 deletions controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import controllers
20 changes: 20 additions & 0 deletions controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from odoo import http

# class AndreaniOdoo(http.Controller):
# @http.route('/andreani_odoo/andreani_odoo/', auth='public')
# def index(self, **kw):
# return "Hello, world"

# @http.route('/andreani_odoo/andreani_odoo/objects/', auth='public')
# def list(self, **kw):
# return http.request.render('andreani_odoo.listing', {
# 'root': '/andreani_odoo/andreani_odoo',
# 'objects': http.request.env['andreani_odoo.andreani_odoo'].search([]),
# })

# @http.route('/andreani_odoo/andreani_odoo/objects/<model("andreani_odoo.andreani_odoo"):obj>/', auth='public')
# def object(self, obj, **kw):
# return http.request.render('andreani_odoo.object', {
# 'object': obj
# })
30 changes: 30 additions & 0 deletions demo/demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<odoo>
<data>
<!-- -->
<!-- <record id="object0" model="andreani_odoo.andreani_odoo"> -->
<!-- <field name="name">Object 0</field> -->
<!-- <field name="value">0</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object1" model="andreani_odoo.andreani_odoo"> -->
<!-- <field name="name">Object 1</field> -->
<!-- <field name="value">10</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object2" model="andreani_odoo.andreani_odoo"> -->
<!-- <field name="name">Object 2</field> -->
<!-- <field name="value">20</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object3" model="andreani_odoo.andreani_odoo"> -->
<!-- <field name="name">Object 3</field> -->
<!-- <field name="value">30</field> -->
<!-- </record> -->
<!-- -->
<!-- <record id="object4" model="andreani_odoo.andreani_odoo"> -->
<!-- <field name="name">Object 4</field> -->
<!-- <field name="value">40</field> -->
<!-- </record> -->
<!-- -->
</data>
</odoo>
3 changes: 3 additions & 0 deletions models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
106 changes: 106 additions & 0 deletions models/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-

from odoo import models, fields, api
from odoo.exceptions import ValidationError

import logging
_logger = logging.getLogger(__name__)

import requests
import json

class ResCompany(models.Model):
_inherit = 'res.company'

def action_py_login(self):
url = 'https://auth-api.pedidosya.com/v1/token'
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
obj = {
"client_id": self.py_client_id,
"client_secret": self.py_client_secret,
"grant_type": "password",
"password": self.py_password,
"username": self.py_username
}
x = requests.post(url, data=json.dumps(obj), headers=headers)
self.py_token = x.json()['access_token']


py_client_id = fields.Char(string='PedidosYa Client Id', help='PedidosYa Client Id')
py_client_secret = fields.Char(string='PedidosYa Client Secret', help='PedidosYa Client Secret')
py_username = fields.Char(string='PedidosYa Username', help='PedidosYa Username')
py_password = fields.Char(string='PedidosYa Password', help='PedidosYa Password')
py_reference_id = fields.Char(string='PedidosYa Reference ID', help='Client Reference ID. The cadet requests it to withdraw the package.')

py_token = fields.Char(string='PedidosYa Token', help='PedidosYa Token', readonly="True")

class DeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'

urlPYRateShipment = 'https://courier-api.pedidosya.com/v1/estimates/shippings'

delivery_type = fields.Selection(selection_add=[('pedidosya', 'Pedidos Ya')])

def pedidosya_rate_shipment(self, order):
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": self.company_id.py_token
}

payload = {
"referenceId": "Client Internal Reference",
"isTest": true,
"deliveryTime": "2020-06-24T19:00:00Z",
"notificationMail": "[email protected]",
"volume": 20.02,
"weight": 0.8,
"items": [
{
"categoryId": 123,
"value": 1250.6,
"description": "Unos libros de Kotlin y una notebook.",
"quantity": 1,
"volume": 10.01,
"weight": 0.5
},
{
"categoryId": 124,
"value": 250,
"description": "Una remera",
"quantity": 1,
"volume": 10.01,
"weight": 0.3
}
],
"waypoints": [
{
"type": "PICK_UP",
"addressStreet": "Plaza Independencia 755",
"addressAdditional": "Piso 6 Recepción",
"city": "Montevideo",
"latitude": -34.905988,
"longitude": -56.199592,
"phone": "+59898765432",
"name": "Oficina Ciudad Vieja",
"instructions": "El ascensor esta roto.",
"order": 1
},
{
"type": "DROP_OFF",
"latitude": -34.9138414,
"longitude": -56.1837661,
"addressStreet": "La Cumparsita 1475",
"addressAdditional": "Piso 1, Oficina Delivery",
"city": "Montevideo",
"phone": "+59812345678",
"name": "Agustin",
"instructions": "Entregar en mano",
"order": 2
}
]
}

response = requests.request("POST", urlPYRateShipment, json=payload, headers=headers)

print(response.text)
2 changes: 2 additions & 0 deletions security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_andreani_odoo_andreani_odoo,andreani_odoo.andreani_odoo,model_andreani_odoo_andreani_odoo,,1,0,0,0
39 changes: 39 additions & 0 deletions views/res_company.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<odoo>
<data>

<record model="ir.ui.view" id="view_company_page_pedidosya">
<field name="name">res.company.form.pedidosya</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<data>
<notebook>
<page string="PedidosYa">
<div class="oe_button_box" name="button_box_py" style="width: auto;">
<button name='action_py_login' type="object"
string="Obtener Token"
title="Obtener Token PedidosYa"
class="oe_stat_button"
icon="fa-user-circle"/>
<button name='action_py_import' type="object"
string="Importar Pedidos"
title="Importar Pedidos desde PedidosYa"
class="oe_stat_button"
icon="fa-cloud-download"/>
</div>

<group>
<field name="py_client_id" />
<field name="py_client_secret" />
<field name="py_username" />
<field name="py_password" />
<field name="py_token" readonly="True" />
</group>
</page>
</notebook>
</data>
</field>
</record>

</data>
</odoo>

0 comments on commit 96cbdd5

Please sign in to comment.