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 # 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 from trytond.pool import Pool
import sale from . import sale
import party from . import party
import product from . import product
import web_channel from . import web_channel
import mercado_libre from . import mercado_libre
import shopify from . import shopify
def register(): def register():
Pool.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. # the full copyright notices and license terms.
from decimal import Decimal from decimal import Decimal
from trytond.pool import Pool from trytond.pool import Pool
from itertools import chain
from trytond.transaction import Transaction from trytond.transaction import Transaction
import requests import requests
from urllib.parse import urlencode from urllib.parse import urlencode
from datetime import datetime, date from datetime import datetime, date
from web_channel import SaleWebChannel from web_channel import SaleWebChannel
import json import json
from .exceptions import NotProductFoundError, NotProductFound
__all__ = ['MercadoLibre'] from trytond.i18n import gettext
HEADERS = { HEADERS = {
'Accept': 'application/json', 'Accept': 'application/json',
@ -27,11 +26,6 @@ class MercadoLibre(SaleWebChannel):
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
super(MercadoLibre, cls).__setup__() 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): def _get_context(self):
user_ = self._get_user() user_ = self._get_user()
@ -108,7 +102,7 @@ class MercadoLibre(SaleWebChannel):
type_document = '31' type_document = '31'
customer_name = customer['billing_info']['business_name'] customer_name = customer['billing_info']['business_name']
type_person = 'persona_juridica' type_person = 'persona_juridica'
create_customer = { create_customer = {
'id_reference': str(customer['id']), 'id_reference': str(customer['id']),
'name': customer_name.upper(), 'name': customer_name.upper(),
@ -275,13 +269,13 @@ class MercadoLibre(SaleWebChannel):
products = self._create_product(codes, line) products = self._create_product(codes, line)
else: else:
if not self.generic_product: 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] products = [self.generic_product]
generic = True generic = True
description = '' description = ''
self.raise_user_warning('product_generic', raise NotProductFound(
'The sale will be created with generic product \n %s' gettext('sale_web_channel.msg_product_not_found', s=self.generic_product.rec_name))
% self.generic_product.rec_name)
for product in products: for product in products:
Tax = _pool.get('account.tax') Tax = _pool.get('account.tax')
un_price = Tax.reverse_compute(line['unit_price'], 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.model import fields, ModelSQL, ModelView
from trytond.pool import PoolMeta, Pool from trytond.pool import PoolMeta, Pool
__all__ = ['Party']
class Party(metaclass=PoolMeta): class Party(metaclass=PoolMeta):
__name__ = 'party.party' __name__ = 'party.party'

View File

@ -6,9 +6,6 @@ from trytond.model import fields
from trytond.pool import PoolMeta, Pool from trytond.pool import PoolMeta, Pool
__all__ = ['Template']
class Template(metaclass=PoolMeta): class Template(metaclass=PoolMeta):
__name__ = 'product.template' __name__ = 'product.template'
id_reference = fields.Numeric('ID Reference Api') 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, from trytond.wizard import (Wizard, StateView, Button, StateReport,
StateTransition) StateTransition)
from trytond.report import Report from trytond.report import Report
from trytond.transaction import Transaction
from trytond.pyson import Eval from trytond.pyson import Eval
from itertools import chain
__all__ = ['Sale']
class Sale(metaclass=PoolMeta): class Sale(metaclass=PoolMeta):

View File

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

View File

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

View File

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