37 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
import logging
from odoo import models, fields, api, _
_logger = logging.getLogger(__name__)
class StockPicking(models.Model):
_inherit = 'stock.picking'
def _action_done(self):
res = super()._action_done()
for picking in self:
# 1. Trigger WhatsApp 'order_shipped' notification on outgoing delivery completion
if picking.picking_type_code == 'outgoing' and picking.sale_id:
try:
self.env['social.whatsapp.notification'].send_order_notification(
order=picking.sale_id,
event_type='order_shipped',
picking=picking
)
except Exception as e:
_logger.warning("Non-blocking error sending WhatsApp shipped notification: %s", e)
# 2. Trigger Meta Catalog stock level sync for products moved
try:
company = picking.company_id or self.env.company
if company.meta_sync_enabled and company.meta_auto_sync_on_write:
queue_model = self.env['social.meta.sync.queue']
for move in picking.move_ids:
product = move.product_id
if product and product.product_tmpl_id.meta_sync_enabled:
queue_model.enqueue_product(product, operation='create_update')
except Exception as e:
_logger.warning("Non-blocking error enqueuing stock update to Meta: %s", e)
return res