diff --git a/.gitignore b/.gitignore index db956ad..44e0ea1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ node_modules/ dist/ build/ +*.egg-info/ # Compiled Java class files *.class diff --git a/mercado_libre.py b/mercado_libre.py index f563dd2..dffd20c 100644 --- a/mercado_libre.py +++ b/mercado_libre.py @@ -29,6 +29,8 @@ class MercadoLibre(SaleWebChannel): 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): @@ -176,6 +178,8 @@ class MercadoLibre(SaleWebChannel): sales = Sale.search([ ('reference', '=', str(sale_['id'])) ]) + # print(sales[0].number) + if sales: if len(sales) == 1 and sale_['status'] == 'cancelled': sale = sales[0] @@ -233,20 +237,28 @@ class MercadoLibre(SaleWebChannel): for line in sale_items: item = line['item'] sku_code = item['seller_sku'] - if sku_code.count('+') > 0: - codes = sku_code.split('+') - line['unit_price'] = Decimal(round((line['unit_price'] / 2), 2)) + if sku_code: + if sku_code.count('+') > 0: + codes = sku_code.split('+') + line['unit_price'] = Decimal(round((line['unit_price'] / 2), 2)) + else: + codes = [sku_code] + products = Product.search([ + ('code', 'in', codes), + ('active', '=', True) + ]) + description = '' + if not products: + products = self._create_product(codes, line) else: - codes = [sku_code] - products = Product.search([ - ('code', 'in', codes), - ('active', '=', True) - ]) - description = '' - if not products: - products = self._create_product(codes, line) - # self.raise_user_error('product_not_found') - # return False + if not self.generic_product: + return self.raise_user_error('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) for product in products: Tax = _pool.get('account.tax') un_price = Tax.reverse_compute(line['unit_price'], @@ -283,7 +295,8 @@ class MercadoLibre(SaleWebChannel): sale.state = 'cancel' else: Sale.quote([sale]) - sale.state = 'confirmed' + if generic: + sale.state = 'confirmed' sale.save() # if shipment_['status'] in ['shipped', 'delivered']: # self._finish_sale(sale) diff --git a/view/sale_web_channel_form.xml b/view/sale_web_channel_form.xml index 7d06da4..4d3cb05 100644 --- a/view/sale_web_channel_form.xml +++ b/view/sale_web_channel_form.xml @@ -46,6 +46,8 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig