Release v6.0

This commit is contained in:
wilson gomez 2021-07-20 17:22:58 -05:00
parent a083aae6f7
commit bc32b445ed
10 changed files with 52 additions and 37 deletions

View File

@ -1,12 +1,13 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of this
#repository contains the full copyright notices and license terms.
# repository contains the full copyright notices and license terms.
from trytond.pool import Pool
import sale
import party
import product
import web_channel
import mercado_libre
import shopify
from . import sale
from . import party
from . import product
from . import web_channel
from . import mercado_libre
from . import shopify
def register():
Pool.register(

17
exceptions.py Normal file
View File

@ -0,0 +1,17 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.exceptions import UserError, UserWarning
# from trytond.model.exceptions import ValidationError
class NotProductFoundError(UserError):
pass
class NotProductFound(UserWarning):
pass
class ErrorSynchronizingSale(UserError):
pass

View File

@ -4,15 +4,14 @@
# the full copyright notices and license terms.
from decimal import Decimal
from trytond.pool import Pool
from itertools import chain
from trytond.transaction import Transaction
import requests
from urllib.parse import urlencode
from datetime import datetime, date
from web_channel import SaleWebChannel
import json
__all__ = ['MercadoLibre']
from .exceptions import NotProductFoundError, NotProductFound
from trytond.i18n import gettext
HEADERS = {
'Accept': 'application/json',
@ -27,11 +26,6 @@ class MercadoLibre(SaleWebChannel):
@classmethod
def __setup__(cls):
super(MercadoLibre, cls).__setup__()
cls._error_messages.update({
'product_not_found': ('Product Not Found'),
'product_generic_not_found': ('Product Generic Not Found, Verify in Configuration'),
# 'product_generic': ('The sale will be created with generic product "%s"')
})
def _get_context(self):
user_ = self._get_user()
@ -108,7 +102,7 @@ class MercadoLibre(SaleWebChannel):
type_document = '31'
customer_name = customer['billing_info']['business_name']
type_person = 'persona_juridica'
create_customer = {
'id_reference': str(customer['id']),
'name': customer_name.upper(),
@ -275,13 +269,13 @@ class MercadoLibre(SaleWebChannel):
products = self._create_product(codes, line)
else:
if not self.generic_product:
return self.raise_user_error('product_generic_not_found')
raise NotProductFoundError(
gettext('sale_web_channel.msg_product_generic_not_found'))
products = [self.generic_product]
generic = True
description = ''
self.raise_user_warning('product_generic',
'The sale will be created with generic product \n %s'
% self.generic_product.rec_name)
raise NotProductFound(
gettext('sale_web_channel.msg_product_not_found', s=self.generic_product.rec_name))
for product in products:
Tax = _pool.get('account.tax')
un_price = Tax.reverse_compute(line['unit_price'],

13
message.xml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="msg_product_not_found">
<field name="text">Product Not Found</field>
</record>
<record model="ir.message" id="msg_product_generic_not_found">
<field name="text">Product Generic Not Found, Verify in Configuration</field>
</record>
</data>
</tryton>

View File

@ -3,8 +3,6 @@
from trytond.model import fields, ModelSQL, ModelView
from trytond.pool import PoolMeta, Pool
__all__ = ['Party']
class Party(metaclass=PoolMeta):
__name__ = 'party.party'

View File

@ -6,9 +6,6 @@ from trytond.model import fields
from trytond.pool import PoolMeta, Pool
__all__ = ['Template']
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
id_reference = fields.Numeric('ID Reference Api')

View File

@ -5,11 +5,7 @@ from trytond.transaction import Transaction
from trytond.wizard import (Wizard, StateView, Button, StateReport,
StateTransition)
from trytond.report import Report
from trytond.transaction import Transaction
from trytond.pyson import Eval
from itertools import chain
__all__ = ['Sale']
class Sale(metaclass=PoolMeta):

View File

@ -15,8 +15,6 @@ import base64
import hmac
import hashlib
__all__ = ['Shopify']
HEADERS = {
'Accept': 'application/json',
'Content-type': 'application/json'

View File

@ -1,5 +1,5 @@
[tryton]
version=5.0.0
version=6.0.0
depends:
sale_pos
product_reference

View File

@ -8,9 +8,8 @@ from datetime import datetime, timedelta
from trytond.pool import Pool
from trytond.wizard import (Wizard, StateTransition, StateView, Button)
from trytond.transaction import Transaction
__all__ = ['SaleWebChannel', 'SynchronizeChannelOrdersStart',
'SynchronizeChannelOrders', 'SynchronizeChannelOrdersDone']
from .exceptions import ErrorSynchronizingSale
from trytond.i18n import gettext
STATES = {
'readonly': (Eval('state') != 'draft')
@ -285,7 +284,8 @@ class SynchronizeChannelOrders(Wizard):
order_id, channel.access_token)
result = MercadoLibre.get_response(URI).json()
if not result:
self.raise_user_error('error', result)
raise ErrorSynchronizingSale(
gettext('sale_web_channel.msg_error_synchronizing_sale', s=result))
sale_created = channel._create_sale(result)
generic_code = self.start.channel.generic_product.code if self.start.channel.generic_product else None
product_generic = [line.product.code for line in sale_created.lines if sale_created and line.product.code == generic_code and generic_code]
@ -327,7 +327,8 @@ class SynchronizeChannelOrders(Wizard):
channel.api_key, channel.password_api, channel.host_name, order_id)
result = Shopify.get_response(URI).json()
if not result:
self.raise_user_error('error', result)
raise ErrorSynchronizingSale(
gettext('sale_web_channel.msg_error_synchronizing_sale', s=result))
sale_created = channel._create_sale(result['orders'][0])
if sale_created and \
sale_created.description.count('fulfilled'):