Import shipping lines

This commit is contained in:
Sergi Almacellas Abellana 2020-06-30 10:17:59 +02:00
parent b364d2eebf
commit 30ed06fcbf
5 changed files with 60 additions and 1 deletions

View File

@ -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\"."

View File

@ -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\"."

View File

@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_sincronization_error">
<field name="text">Error while sincronizing woocommerce records: "%(response)s".</field>
</record>
<record model="ir.message" id="msg_missing_shipping_product">
<field name="text">It is not possible to import orders because shop "%(shop)s" does not have any shipping product.</field>
</record>
</data>
</tryton>

View File

@ -5,6 +5,8 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/label[@name='guest_party']" position="before">
<label name="price_list"/>
<field name="price_list"/>
<label name="shipping_product"/>
<field name="shipping_product"/>
</xpath>
<xpath expr="//notebook/page[@id='products']" position="after">
<page string="WooCommerce" id="woocommerce" col="2">

32
web.py
View File

@ -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()