fix orders with pack id mercado libre
This commit is contained in:
parent
0d34903250
commit
abb03e1e0c
22
api_log.py
22
api_log.py
|
@ -2,23 +2,23 @@
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
from trytond.model import ModelView, ModelSQL, fields
|
from trytond.model import ModelView, ModelSQL, fields
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool, PoolMeta
|
||||||
|
|
||||||
STATES = {'readonly': True}
|
STATES = {'readonly': True}
|
||||||
|
|
||||||
|
|
||||||
class ApiLog(ModelSQL, ModelView):
|
class ApiLog(metaclass=PoolMeta):
|
||||||
"API Log"
|
"API Log"
|
||||||
__name__ = "api.log.channel"
|
__name__ = "api.log"
|
||||||
channel = fields.Many2One('sale.web_channel', 'channel', states=STATES)
|
channel = fields.Many2One('sale.web_channel', 'channel', states=STATES)
|
||||||
number = fields.Char('Number Doc', states=STATES)
|
# number = fields.Char('Number Doc', states=STATES)
|
||||||
order = fields.Char('Order', states=STATES)
|
# order = fields.Char('Order', states=STATES)
|
||||||
record_date = fields.Date('Record Date', states=STATES)
|
# record_date = fields.Date('Record Date', states=STATES)
|
||||||
msg_response = fields.Char('Msg Response', states=STATES)
|
# msg_response = fields.Char('Msg Response', states=STATES)
|
||||||
request_json = fields.Text("Request Json", states=STATES)
|
# request_json = fields.Text("Request Json", states=STATES)
|
||||||
headers_json = fields.Text("Header Json", states=STATES)
|
# headers_json = fields.Text("Header Json", states=STATES)
|
||||||
file_json = fields.Binary("File Json", states=STATES)
|
# file_json = fields.Binary("File Json", states=STATES)
|
||||||
status = fields.Char('Status', states=STATES)
|
# status = fields.Char('Status', states=STATES)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
|
|
@ -4,7 +4,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<tryton>
|
<tryton>
|
||||||
<data>
|
<data>
|
||||||
|
|
||||||
<record model="ir.ui.view" id="api_log_view_tree">
|
<!-- <record model="ir.ui.view" id="api_log_view_tree">
|
||||||
<field name="model">api.log.channel</field>
|
<field name="model">api.log.channel</field>
|
||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="priority">20</field>
|
<field name="priority">20</field>
|
||||||
|
@ -62,7 +62,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="perm_write" eval="True"/>
|
<field name="perm_write" eval="True"/>
|
||||||
<field name="perm_create" eval="True"/>
|
<field name="perm_create" eval="True"/>
|
||||||
<field name="perm_delete" eval="True"/>
|
<field name="perm_delete" eval="True"/>
|
||||||
</record>
|
</record> -->
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -262,17 +262,22 @@ class MercadoLibre(SaleWebChannel):
|
||||||
|
|
||||||
def validate_sale(self, sale_):
|
def validate_sale(self, sale_):
|
||||||
if sale_.get('pack_id'):
|
if sale_.get('pack_id'):
|
||||||
if not sale_.get('shipping'):
|
# if not sale_.get('shipping'):
|
||||||
return
|
# return
|
||||||
shipment_id = sale_['shipping']['id']
|
# shipment_id = sale_['shipping']['id']
|
||||||
URI = 'https://api.mercadolibre.com/shipments/%s/items?access_token=%s' % (
|
# URI = 'https://api.mercadolibre.com/shipments/%s/items?access_token=%s' % (
|
||||||
shipment_id, self.access_token)
|
# shipment_id, self.access_token)
|
||||||
res = self.get_response(URI)
|
# res = self.get_response(URI)
|
||||||
shipment_items = res.json()
|
# shipment_items = res.json()
|
||||||
if len(shipment_items) > 1:
|
# if len(shipment_items) > 1:
|
||||||
|
URI = 'https://api.mercadolibre.com/packs/%s?access_token=%s' % (
|
||||||
|
sale_.get('pack_id'), self.access_token)
|
||||||
|
response = self.get_response(URI)
|
||||||
|
response = response.json()
|
||||||
|
if response.get('orders'):
|
||||||
ids = ''
|
ids = ''
|
||||||
for item in shipment_items:
|
for item in response['orders']:
|
||||||
order_id = item['order_id']
|
order_id = str(item['id'])
|
||||||
if order_id != str(sale_['id']):
|
if order_id != str(sale_['id']):
|
||||||
URI2 = 'https://api.mercadolibre.com/orders/%s?access_token=%s' % (
|
URI2 = 'https://api.mercadolibre.com/orders/%s?access_token=%s' % (
|
||||||
order_id, self.access_token)
|
order_id, self.access_token)
|
||||||
|
|
28
shopify.py
28
shopify.py
|
@ -53,12 +53,10 @@ class Shopify(SaleWebChannel):
|
||||||
description = line['variant_title']
|
description = line['variant_title']
|
||||||
list_price = round(float(line['price'])/1.19, 2)
|
list_price = round(float(line['price'])/1.19, 2)
|
||||||
sale_price_w_tax = round(Decimal(line['price']), 2)
|
sale_price_w_tax = round(Decimal(line['price']), 2)
|
||||||
print(list_price)
|
|
||||||
print(sale_price_w_tax)
|
|
||||||
create_template = {
|
create_template = {
|
||||||
'name': line['title'],
|
'name': line['title'],
|
||||||
'list_price': 1,
|
'list_price': list_price,
|
||||||
'sale_price_w_tax': 1,
|
'sale_price_w_tax': sale_price_w_tax,
|
||||||
'type': 'goods',
|
'type': 'goods',
|
||||||
'salable': True,
|
'salable': True,
|
||||||
'purchasable': True,
|
'purchasable': True,
|
||||||
|
@ -66,6 +64,7 @@ class Shopify(SaleWebChannel):
|
||||||
'sale_uom': 1,
|
'sale_uom': 1,
|
||||||
'default_uom': 1,
|
'default_uom': 1,
|
||||||
'account_category': 7,
|
'account_category': 7,
|
||||||
|
'code': code,
|
||||||
}
|
}
|
||||||
template, = Template.create([create_template])
|
template, = Template.create([create_template])
|
||||||
create_product = []
|
create_product = []
|
||||||
|
@ -185,12 +184,17 @@ class Shopify(SaleWebChannel):
|
||||||
year, month, day = date_created[0].split('-')
|
year, month, day = date_created[0].split('-')
|
||||||
sale_date = date(int(year), int(month), int(day))
|
sale_date = date(int(year), int(month), int(day))
|
||||||
with Transaction().set_user(ctx['user']):
|
with Transaction().set_user(ctx['user']):
|
||||||
|
comment = ''
|
||||||
|
try:
|
||||||
|
comment = 'GUIA DE ENVIO NO. ' + sale_['fulfillments'][0].get('tracking_number', '')\
|
||||||
|
if sale_['fulfillment_status'] == 'fulfilled' and sale_['fulfillments'] else ''
|
||||||
|
except:
|
||||||
|
pass
|
||||||
sale, = Sale.create([{
|
sale, = Sale.create([{
|
||||||
'payment_term': 1,
|
'payment_term': 1,
|
||||||
'party': party.id,
|
'party': party.id,
|
||||||
'sale_date': sale_date,
|
'sale_date': sale_date,
|
||||||
'comment': 'GUIA DE ENVIO NO. ' + sale_['fulfillments'][0].get('tracking_number', '')
|
'comment': comment,
|
||||||
if sale_['fulfillment_status'] == 'fulfilled' and sale_['fulfillments'] else '',
|
|
||||||
'state': 'draft',
|
'state': 'draft',
|
||||||
'company': ctx['company'],
|
'company': ctx['company'],
|
||||||
'currency': user_.company.currency.id,
|
'currency': user_.company.currency.id,
|
||||||
|
@ -289,9 +293,10 @@ class Shopify(SaleWebChannel):
|
||||||
'type': 'line',
|
'type': 'line',
|
||||||
'unit': product.default_uom.id,
|
'unit': product.default_uom.id,
|
||||||
'quantity': quantity,
|
'quantity': quantity,
|
||||||
|
'base_price': round(Decimal(un_price), 3),
|
||||||
'unit_price': round(Decimal(un_price), 3),
|
'unit_price': round(Decimal(un_price), 3),
|
||||||
'unit_price_full': round(Decimal(line['price']),2),
|
'unit_price_full': round(Decimal(line['price']),2),
|
||||||
'discount': 0,
|
# 'discount': 0,
|
||||||
'product': product.id,
|
'product': product.id,
|
||||||
'taxes': [('add', product.customer_taxes_used)],
|
'taxes': [('add', product.customer_taxes_used)],
|
||||||
'description': description,
|
'description': description,
|
||||||
|
@ -350,10 +355,15 @@ class Shopify(SaleWebChannel):
|
||||||
# channel.upload_note(sale, 'Error, al generar factura orden duplicada')
|
# channel.upload_note(sale, 'Error, al generar factura orden duplicada')
|
||||||
return response
|
return response
|
||||||
if data.get('fulfillment_status') == 'fulfilled':
|
if data.get('fulfillment_status') == 'fulfilled':
|
||||||
|
track_number = ''
|
||||||
|
try:
|
||||||
|
track_number = str(data['fulfillments'][0]['tracking_number'])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
Sale.write([sale], {
|
Sale.write([sale], {
|
||||||
'description': sale.description + ' - ' + data['fulfillment_status'],
|
'description': sale.description + ' - ' + data['fulfillment_status'],
|
||||||
'comment': 'GUIA DE ENVIO NO. ' + data['fulfillments'][0]['tracking_number'],
|
'comment': 'GUIA DE ENVIO NO. ' + track_number,
|
||||||
'tracking_number': data['fulfillments'][0]['tracking_number']
|
'tracking_number': track_number
|
||||||
})
|
})
|
||||||
return sale
|
return sale
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
[tryton]
|
[tryton]
|
||||||
version=6.0.1
|
version=6.0.2
|
||||||
depends:
|
depends:
|
||||||
sale_pos
|
sale_pos
|
||||||
product_reference
|
product_reference
|
||||||
|
log
|
||||||
xml:
|
xml:
|
||||||
web_channel.xml
|
web_channel.xml
|
||||||
sale.xml
|
sale.xml
|
||||||
|
|
|
@ -201,8 +201,8 @@ class SaleWebChannel(Workflow, ModelSQL, ModelView):
|
||||||
def get_status_token(self, name):
|
def get_status_token(self, name):
|
||||||
if self.creation_time:
|
if self.creation_time:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
res = now - self.creation_time
|
res = (now - self.creation_time).total_seconds()
|
||||||
if res.seconds >= 21600:
|
if res >= 21600:
|
||||||
return 'expired'
|
return 'expired'
|
||||||
else:
|
else:
|
||||||
return 'active'
|
return 'active'
|
||||||
|
|
Loading…
Reference in New Issue