Files
jikimo_sf/sf_warehouse/models/sync_common.py

32 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
import logging
import json
import base64
import requests
from odoo import models
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
class MrsShelfLocationDataSync(models.Model):
_name = 'sf.shelf.location.datasync'
_description = '同步库存信息'
def _cron_shelf_location_datasync(self):
try:
shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info()
for item in shelfinfo:
location_id = self.env['sf.shelf.location'].search([('barcode', '=', item['Postion'])], limit=1)
if location_id:
stock_lot_obj = self.env['stock.lot'].search([('rfid', '=', item['RfidCode'])], limit=1)
if stock_lot_obj:
location_id.product_sn_id = stock_lot_obj.id
else:
location_id.product_sn_id = False
logging.info('货架已获取信息:%s' % item)
except Exception as e:
logging.info("捕获错误信息:%s" % e)
raise ValidationError("数据错误导致同步失败,请联系管理员")