From 584cc385b95627a4cef97cf08fd4cc3de2b8c6f6 Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Tue, 26 May 2026 06:32:21 +0000 Subject: [PATCH] feat: add custom/not_specified shipping modes with cost input for ML publish - build_item_payload supports shipping_cost for custom mode with costs array - Add shipping mode selector: me2, custom, not_specified - Show shipping cost input when custom is selected - Backend passes shipping_cost through custom_data to payload builder --- pos/services/marketplace_external_service.py | 13 ++++++++++--- pos/static/js/inventory.js | 11 +++++++++++ pos/templates/inventory.html | 14 ++++++++++---- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/pos/services/marketplace_external_service.py b/pos/services/marketplace_external_service.py index 9539da3..019d548 100644 --- a/pos/services/marketplace_external_service.py +++ b/pos/services/marketplace_external_service.py @@ -144,6 +144,7 @@ def build_item_payload( listing_type_id: str = "gold_special", custom_title: str = None, extra_attributes: list = None, + shipping_cost: float = None, ) -> dict: """Convert a Nexus inventory row into a MercadoLibre item payload.""" title = custom_title or f"{inventory_row['name']} {inventory_row['brand'] or ''} {inventory_row['part_number'] or ''}".strip() @@ -152,9 +153,11 @@ def build_item_payload( title = title[:57] + "..." shipping_payload = {"mode": shipping_mode} - if shipping_mode == "me2": - # Let ML determine free_shipping/local_pick_up defaults based on account config - pass + if shipping_mode == "custom" and shipping_cost is not None: + shipping_payload["local_pick_up"] = False + shipping_payload["free_shipping"] = False + shipping_payload["methods"] = [] + shipping_payload["costs"] = [{"description": "Envio", "cost": str(shipping_cost)}] payload = { "title": title, "category_id": meli_category_id, @@ -375,11 +378,13 @@ def validate_items( extra_attrs = (custom_data.get("attributes") or {}).get(str(inv_id)) price = (custom_data.get("prices") or {}).get(str(inv_id), inv["price_1"]) item_stock = (custom_data.get("stocks") or {}).get(str(inv_id), stock) + shipping_cost = custom_data.get("shipping_cost") payload = build_item_payload( inv, images, meli_category_id, price, item_stock, shipping_mode=shipping_mode, listing_type_id=listing_type_id, custom_title=title, extra_attributes=extra_attrs, + shipping_cost=shipping_cost, ) try: @@ -480,11 +485,13 @@ def publish_items( extra_attrs = (custom_data.get("attributes") or {}).get(str(inv_id)) price = (custom_data.get("prices") or {}).get(str(inv_id), inv["price_1"]) item_stock = (custom_data.get("stocks") or {}).get(str(inv_id), stock) + shipping_cost = custom_data.get("shipping_cost") payload = build_item_payload( inv, images, meli_category_id, price, item_stock, shipping_mode=shipping_mode, listing_type_id=listing_type_id, custom_title=title, extra_attributes=extra_attrs, + shipping_cost=shipping_cost, ) try: diff --git a/pos/static/js/inventory.js b/pos/static/js/inventory.js index a503d2c..9033b3e 100644 --- a/pos/static/js/inventory.js +++ b/pos/static/js/inventory.js @@ -993,9 +993,20 @@ } }); + window.onMeliShippingChange = function() { + var mode = document.getElementById('meliShippingMode').value; + var costField = document.getElementById('meliShippingCostField'); + if (costField) costField.style.display = (mode === 'custom') ? 'block' : 'none'; + }; + function _collectMeliCustomData() { var ids = Array.from(selectedItems); var customData = { titles: {}, prices: {}, stocks: {}, attributes: {} }; + var mode = document.getElementById('meliShippingMode').value; + if (mode === 'custom') { + var costEl = document.getElementById('meliShippingCost'); + if (costEl) customData.shipping_cost = parseFloat(costEl.value) || 0; + } ids.forEach(function(id) { var titleEl = document.getElementById('meliTitle-' + id); var priceEl = document.getElementById('meliPrice-' + id); diff --git a/pos/templates/inventory.html b/pos/templates/inventory.html index 738efb1..973a569 100644 --- a/pos/templates/inventory.html +++ b/pos/templates/inventory.html @@ -13,7 +13,7 @@ - + @@ -871,10 +871,16 @@
- + + - Tu cuenta requiere ME2 obligatoriamente. + Si no puedes activar ME1/ME2 en ML, prueba 'Propio' o 'No especificado'. +
+ @@ -908,7 +914,7 @@ - +