diff --git a/locale/ca.po b/locale/ca.po index 596c631..b168db8 100644 --- a/locale/ca.po +++ b/locale/ca.po @@ -10,6 +10,10 @@ msgctxt "field:web.shop,price_list:" msgid "Price List" msgstr "Tarifa" +msgctxt "field:web.shop,shipping_product:" +msgid "Shipping Product" +msgstr "Producte transport" + msgctxt "field:web.shop,woocommerce_consumer_key:" msgid "WooCommerce Consumer Key" msgstr "Clau consumidor WooCommerce" @@ -46,6 +50,14 @@ msgstr "" "Per sincronitzar els registres \"%(records)s\" heu de sincronitzar també els" " seus registres pare." +msgctxt "model:ir.message,text:msg_missing_shipping_product" +msgid "" +"It is not possible to import orders because shop \"%(shop)s\" does not have " +"any shipping product." +msgstr "" +"No es pot importar les comandes de la tenda \"%(shop)s\" perquè no té un " +"producte per al transport." + msgctxt "model:ir.message,text:msg_sincronization_error" msgid "Error while sincronizing woocommerce records: \"%(response)s\"." msgstr "Error al sincronizar els registres de woocommernce: %(response)s\"." diff --git a/locale/es.po b/locale/es.po index 8e08ce8..2373d60 100644 --- a/locale/es.po +++ b/locale/es.po @@ -10,6 +10,10 @@ msgctxt "field:web.shop,price_list:" msgid "Price List" msgstr "Tarifa" +msgctxt "field:web.shop,shipping_product:" +msgid "Shipping Product" +msgstr "Producto transporte" + msgctxt "field:web.shop,woocommerce_consumer_key:" msgid "WooCommerce Consumer Key" msgstr "Clave consumidor WooCommerce" @@ -46,6 +50,14 @@ msgstr "" "Para sincronizar los registros \"%(records)s\" debeis sincronizar también " "sus registros padre." +msgctxt "model:ir.message,text:msg_missing_shipping_product" +msgid "" +"It is not possible to import orders because shop \"%(shop)s\" does not have " +"any shipping product." +msgstr "" +"No se puede importar los pedidos porqué la tienda \"%(shop)s\" no tiene " +"producto para el transporte." + msgctxt "model:ir.message,text:msg_sincronization_error" msgid "Error while sincronizing woocommerce records: \"%(response)s\"." msgstr "Error al sincronizar los registros de woocommernce: %(response)s\"." diff --git a/message.xml b/message.xml index a46d26c..72e1f17 100644 --- a/message.xml +++ b/message.xml @@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. --> Error while sincronizing woocommerce records: "%(response)s". + + It is not possible to import orders because shop "%(shop)s" does not have any shipping product. + diff --git a/view/shop_form.xml b/view/shop_form.xml index a5653bd..831de7d 100644 --- a/view/shop_form.xml +++ b/view/shop_form.xml @@ -5,6 +5,8 @@ this repository contains the full copyright notices and license terms. --> diff --git a/web.py b/web.py index c3b1e05..803b0a7 100644 --- a/web.py +++ b/web.py @@ -14,6 +14,7 @@ from trytond.tools import grouped_slice from trytond.transaction import Transaction from trytond.modules.product import round_price +from trytond.model.modelstorage import RequiredValidationError from .exceptions import WooCommerceError, MissingParentsError logger = logging.getLogger(__name__) @@ -130,6 +131,11 @@ class Shop(metaclass=PoolMeta): }, depends=['type']) price_list = fields.Many2One('product.price_list', "Price List") + shipping_product = fields.Many2One('product.product', "Shipping Product", + domain=[ + ('salable', '=', True), + ('type', '=', 'service'), + ]) @classmethod def __setup__(cls): @@ -393,8 +399,12 @@ class Shop(metaclass=PoolMeta): line = self.woocommerce_sale_line(order, item, sale) if line: lines.append(line) + if order.get('shipping_lines'): + for item in order['shipping_lines']: + line = self.woocommerce_shipping_line(order, item, sale) + if line: + lines.append(line) sale.lines = lines - # TODO: Add shipping return sale def woocommerce_sale_line(self, order, item, sale): @@ -412,6 +422,26 @@ class Shop(metaclass=PoolMeta): line.unit_price = round_price(Decimal(str(item['price']))) return line + def woocommerce_shipping_line(self, order, item, sale): + pool = Pool() + Line = pool.get('sale.line') + + if not self.shipping_product: + raise RequiredValidationError( + gettext('web_shop_woocommerce' + '.msg_missing_shipping_product', + shop=self.rec_name)) + + line = Line() + line.type = 'line' + line.sale = sale + line.product = self.shipping_product + line.description = item['method_title'] + line.quantity = 1.0 + line.on_change_product() + line.unit_price = round_price(Decimal(str(item['total']))) + return line + @classmethod def woocommerce_download_orders(cls, shops=None): pool = Pool()