diff --git a/api_log.py b/api_log.py index 2a392f1..b637f94 100644 --- a/api_log.py +++ b/api_log.py @@ -2,23 +2,23 @@ # this repository contains the full copyright notices and license terms. from trytond.model import ModelView, ModelSQL, fields import simplejson as json -from trytond.pool import Pool +from trytond.pool import Pool, PoolMeta STATES = {'readonly': True} -class ApiLog(ModelSQL, ModelView): +class ApiLog(metaclass=PoolMeta): "API Log" - __name__ = "api.log.channel" + __name__ = "api.log" channel = fields.Many2One('sale.web_channel', 'channel', states=STATES) - number = fields.Char('Number Doc', states=STATES) - order = fields.Char('Order', states=STATES) - record_date = fields.Date('Record Date', states=STATES) - msg_response = fields.Char('Msg Response', states=STATES) - request_json = fields.Text("Request Json", states=STATES) - headers_json = fields.Text("Header Json", states=STATES) - file_json = fields.Binary("File Json", states=STATES) - status = fields.Char('Status', states=STATES) + # number = fields.Char('Number Doc', states=STATES) + # order = fields.Char('Order', states=STATES) + # record_date = fields.Date('Record Date', states=STATES) + # msg_response = fields.Char('Msg Response', states=STATES) + # request_json = fields.Text("Request Json", states=STATES) + # headers_json = fields.Text("Header Json", states=STATES) + # file_json = fields.Binary("File Json", states=STATES) + # status = fields.Char('Status', states=STATES) @classmethod def __setup__(cls): diff --git a/api_log.xml b/api_log.xml index 4f0174e..b8f83bd 100644 --- a/api_log.xml +++ b/api_log.xml @@ -4,7 +4,7 @@ this repository contains the full copyright notices and license terms. --> - + - + --> diff --git a/mercado_libre.py b/mercado_libre.py index 4e51401..a575d2e 100644 --- a/mercado_libre.py +++ b/mercado_libre.py @@ -262,17 +262,22 @@ class MercadoLibre(SaleWebChannel): def validate_sale(self, sale_): if sale_.get('pack_id'): - if not sale_.get('shipping'): - return - shipment_id = sale_['shipping']['id'] - URI = 'https://api.mercadolibre.com/shipments/%s/items?access_token=%s' % ( - shipment_id, self.access_token) - res = self.get_response(URI) - shipment_items = res.json() - if len(shipment_items) > 1: + # if not sale_.get('shipping'): + # return + # shipment_id = sale_['shipping']['id'] + # URI = 'https://api.mercadolibre.com/shipments/%s/items?access_token=%s' % ( + # shipment_id, self.access_token) + # res = self.get_response(URI) + # shipment_items = res.json() + # 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 = '' - for item in shipment_items: - order_id = item['order_id'] + for item in response['orders']: + order_id = str(item['id']) if order_id != str(sale_['id']): URI2 = 'https://api.mercadolibre.com/orders/%s?access_token=%s' % ( order_id, self.access_token) diff --git a/shopify.py b/shopify.py index 1093a6b..e4225ec 100644 --- a/shopify.py +++ b/shopify.py @@ -53,12 +53,10 @@ class Shopify(SaleWebChannel): description = line['variant_title'] list_price = round(float(line['price'])/1.19, 2) sale_price_w_tax = round(Decimal(line['price']), 2) - print(list_price) - print(sale_price_w_tax) create_template = { 'name': line['title'], - 'list_price': 1, - 'sale_price_w_tax': 1, + 'list_price': list_price, + 'sale_price_w_tax': sale_price_w_tax, 'type': 'goods', 'salable': True, 'purchasable': True, @@ -66,6 +64,7 @@ class Shopify(SaleWebChannel): 'sale_uom': 1, 'default_uom': 1, 'account_category': 7, + 'code': code, } template, = Template.create([create_template]) create_product = [] @@ -185,12 +184,17 @@ class Shopify(SaleWebChannel): year, month, day = date_created[0].split('-') sale_date = date(int(year), int(month), int(day)) 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([{ 'payment_term': 1, 'party': party.id, 'sale_date': sale_date, - 'comment': 'GUIA DE ENVIO NO. ' + sale_['fulfillments'][0].get('tracking_number', '') - if sale_['fulfillment_status'] == 'fulfilled' and sale_['fulfillments'] else '', + 'comment': comment, 'state': 'draft', 'company': ctx['company'], 'currency': user_.company.currency.id, @@ -289,9 +293,10 @@ class Shopify(SaleWebChannel): 'type': 'line', 'unit': product.default_uom.id, 'quantity': quantity, + 'base_price': round(Decimal(un_price), 3), 'unit_price': round(Decimal(un_price), 3), 'unit_price_full': round(Decimal(line['price']),2), - 'discount': 0, + # 'discount': 0, 'product': product.id, 'taxes': [('add', product.customer_taxes_used)], 'description': description, @@ -350,10 +355,15 @@ class Shopify(SaleWebChannel): # channel.upload_note(sale, 'Error, al generar factura orden duplicada') return response if data.get('fulfillment_status') == 'fulfilled': + track_number = '' + try: + track_number = str(data['fulfillments'][0]['tracking_number']) + except: + pass Sale.write([sale], { 'description': sale.description + ' - ' + data['fulfillment_status'], - 'comment': 'GUIA DE ENVIO NO. ' + data['fulfillments'][0]['tracking_number'], - 'tracking_number': data['fulfillments'][0]['tracking_number'] + 'comment': 'GUIA DE ENVIO NO. ' + track_number, + 'tracking_number': track_number }) return sale diff --git a/tryton.cfg b/tryton.cfg index e697e8c..540d728 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,8 +1,9 @@ [tryton] -version=6.0.1 +version=6.0.2 depends: sale_pos product_reference + log xml: web_channel.xml sale.xml diff --git a/web_channel.py b/web_channel.py index f212954..91f57e0 100644 --- a/web_channel.py +++ b/web_channel.py @@ -201,8 +201,8 @@ class SaleWebChannel(Workflow, ModelSQL, ModelView): def get_status_token(self, name): if self.creation_time: now = datetime.now() - res = now - self.creation_time - if res.seconds >= 21600: + res = (now - self.creation_time).total_seconds() + if res >= 21600: return 'expired' else: return 'active'