提交 4d3806c3 authored 作者: 伍姿英's avatar 伍姿英

Merge branch 'release/V2.7.0'

# -*- coding: utf-8 -*-
import datetime
import re
import pytz
from odoo import fields, models, exceptions, api, tools
import logging
import pytz
from odoo import models
from .redis_connection import redis_connection
__author__ = 'zd'
r = redis_connection()
_logger = logging.getLogger(__name__)
......@@ -14,6 +16,101 @@ class CommonCommon(models.Model):
_name = 'common.common'
_description = u'公用基础类'
def get_local_time(self, local_time=None, user_obj=False):
"""获取Odoo时区的时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
datetime: Odoo时区的时间
"""
if not local_time:
local_time = datetime.datetime.now()
try:
# 获取Odoo配置的时区
if not user_obj:
user_obj = self.env.user
user_tz = user_obj.tz or 'UTC'
timezone_offset = self.env['common.common'].sudo().get_time_zone(user_tz)
local_time = local_time + datetime.timedelta(hours=int(timezone_offset))
return local_time.strftime('%Y-%m-%d %H:%M:%S'), timezone_offset
except Exception as e:
# 如果出现任何错误,返回UTC时间
logging.warning(f"获取Odoo时区失败,使用UTC时间: {str(e)}")
return self.get_utc_time(), '+0'
def get_local_rfc3339_time(self, local_time=None, user_obj=False):
"""获取Odoo本地时区的RFC3339格式时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
str: RFC3339格式的时间字符串
"""
if not local_time:
local_time = datetime.datetime.now()
# 获取Odoo配置的时区
if not user_obj:
user_obj = self.env.user
user_tz = user_obj.tz or 'UTC'
timezone_offset = self.env['common.common'].sudo().get_time_zone(user_tz)
local_time = local_time + datetime.timedelta(hours=int(timezone_offset))
local_tz = pytz.timezone(user_tz)
# 确保时间是本地时区
if local_time.tzinfo is None:
local_time = local_tz.localize(local_time)
# 转换为RFC3339格式
rfc3339_time = local_time.isoformat(timespec='seconds')
logging.info('rfc3339_time:%s' % rfc3339_time)
return rfc3339_time
def get_rfc339_time(self, utc_time=None):
if not utc_time:
# 获取当前时间的UTC时间
utc_time = datetime.datetime.utcnow()
# 创建+8时区的对象
target_timezone = pytz.timezone('Asia/Shanghai')
# 将UTC时间转换为目标时区时间
local_time = utc_time.replace(
tzinfo=pytz.utc).astimezone(target_timezone)
# 格式化为RFC 3339格式
rfc3339_time = local_time.isoformat(timespec='seconds')
return rfc3339_time
# 定义一个方法,将时间的时区转为UTC时间
def get_utc_rfc339_time(self, local_time=None):
"""获取Odoo本地时区的RFC3339格式时间
Args:
local_time: 本地时间,如果不提供则使用当前时间
Returns:
str: RFC3339格式的时间字符串
"""
if not local_time:
# 获取当前时间的UTC时间
local_time = datetime.datetime.now()
# 将本地时间转换为UTC时间
utc_time = local_time.astimezone(pytz.utc)
# 格式化为RFC 3339格式
# rfc3339_time = utc_time.isoformat(timespec='seconds')
logging.info('utc_time:%s' % utc_time)
if not local_time:
# 获取当前时间的UTC时间
local_time = datetime.datetime.now()
# 将本地时间转换为UTC时间
utc_time = local_time.astimezone(pytz.utc)
# 格式化为RFC 3339格式
rfc3339_time = utc_time.isoformat(timespec='seconds')
return rfc3339_time
# 定义一个方法,将时间的时区转为UTC时间
def get_utc_time(self, local_time=None):
if not local_time:
# 获取当前时间的UTC时间
local_time = datetime.datetime.now()
# 将本地时间转换为UTC时间
utc_time = local_time.astimezone(pytz.utc)
# 格式化为RFC 3339格式
# rfc3339_time = utc_time.isoformat(timespec='seconds')
return utc_time.strftime('%Y-%m-%d %H:%M:%S')
def get_format_time(self, parse_time):
"""
把时间加上8小时
......
# -*- coding: utf-8 -*-
# © <2016> <ToproERP hy>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, Warning
import logging
import json
import xlrd
import base64
import pdfplumber
from io import BytesIO
from datetime import datetime, timedelta
import json
import logging
import re
from datetime import datetime, timedelta
from io import BytesIO
import pdfplumber
import xlrd
from odoo import models
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__)
import html
......@@ -106,8 +107,9 @@ class OrderStateChangeRule(models.Model):
return data_arr
def upload_cds_attachment(self, bl_obj, name, data):
file_obj = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '海关CDS申报单(import和授权方式检查拉齐等)'),
('bl_id', '=', bl_obj.id)], limit=1)
file_obj = self.env['cc.clearance.file'].sudo().search(
[('file_name', '=', '海关CDS申报单(import和授权方式检查拉齐等)'),
('bl_id', '=', bl_obj.id)], limit=1)
file_obj.file = base64.encodebytes(data)
file_obj.attachment_name = name
file_obj.is_upload = False
......@@ -116,7 +118,7 @@ class OrderStateChangeRule(models.Model):
def upload_pod_attachment(self, bl_obj, name, data):
"""尾程交接POD(待大包数量和箱号) 文件上传与同步"""
file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'),
('bl_id', 'in', bl_obj.ids)])
('bl_id', 'in', bl_obj.ids)])
# 最大重试次数
max_retries = 2
......@@ -165,7 +167,8 @@ class OrderStateChangeRule(models.Model):
timezone_offset = self.env['common.common'].sudo().get_time_zone(tz)
# print(timezone_offset)
utc_time = local_time - timedelta(hours=int(timezone_offset))
sql = "select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no, ' ', ''), '-', ''), '/', '')) = '{0}' order by create_date desc limit 1".format(order_no.replace(' ', '').replace('-', '').replace('/', ''))
sql = "select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no, ' ', ''), '-', ''), '/', '')) = '{0}' order by create_date desc limit 1".format(
order_no.replace(' ', '').replace('-', '').replace('/', ''))
self._cr.execute(sql)
result = self._cr.fetchall()
bl_obj = self.env['cc.bl'].sudo().search([('id', '=', result[0][0])]) if result else False
......@@ -177,7 +180,9 @@ class OrderStateChangeRule(models.Model):
if redis_conn == 'no':
raise ValidationError('未连接redis')
else:
redis_conn.lpush('mail_push_package_list', json.dumps({'id': bl_obj.id, 'utc_time': utc_time.strftime("%Y-%m-%d %H:%M:%S")}))
redis_conn.lpush('mail_push_package_list', json.dumps(
{'id': bl_obj.id, 'user_login': users_obj.login,
'utc_time': utc_time.strftime("%Y-%m-%d %H:%M:%S")}))
except Exception as err:
logging.error('fetch_mail_dlv_attachment--error:%s' % str(err))
......@@ -254,7 +259,8 @@ class OrderStateChangeRule(models.Model):
# 调整时区
utc_time = local_time - timedelta(hours=timezone_offset)
sql = "select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no, ' ', ''), '-', ''), '/', '')) = '{0}' " \
"and transport_tool_name='{1}' order by create_date desc limit 1".format(order_no.replace(' ', '').replace('-', '').replace('/', ''), voyage_name)
"and transport_tool_name='{1}' order by create_date desc limit 1".format(
order_no.replace(' ', '').replace('-', '').replace('/', ''), voyage_name)
self._cr.execute(sql)
result = self._cr.fetchall()
print(result)
......@@ -265,7 +271,8 @@ class OrderStateChangeRule(models.Model):
if redis_conn == 'no':
raise ValidationError('未连接redis')
else:
redis_conn.lpush('mail_push_package_list', json.dumps({'id': bl_obj.id, 'utc_time': utc_time.strftime("%Y-%m-%d %H:%M:%S")}))
redis_conn.lpush('mail_push_package_list', json.dumps(
{'id': bl_obj.id, 'utc_time': utc_time.strftime("%Y-%m-%d %H:%M:%S")}))
except Exception as err:
logging.error('fetch_mail_dlv--error:%s' % str(err))
......
......@@ -25,14 +25,14 @@
<field name="inherit_id" ref="ccs_base.form_cc_bl_view"/>
<field name="arch" type="xml">
<button name="%(ccs_base.action_batch_input_ship_package_wizard)d" position="after">
<button name="callback_track" string="Sync Package Status" type="object"/>
<button name="action_callback_track" string="Sync Package Status" type="object"/>
</button>
<button name="%(ccs_base.action_batch_input_bl_status_wizard)d" position="before">
<button name="batch_action_sync" string="Sync CC Attachment" type="object"/>
</button>
<button name="%(ccs_base.action_batch_input_bl_status_wizard)d" position="after">
<!--增加同步提单状态的按钮-->
<button name="callback_track_bl" string="Sync Bill Of Loading Status" type="object"/>
<button name="action_callback_track_bl" string="Sync Bill Of Loading Status" type="object"/>
</button>
<button name="action_show_ship_package" position="replace">
......@@ -73,7 +73,7 @@
<field name="state">code</field>
<field name="code">
if records:
records.callback_track()
records.action_callback_track()
</field>
</record>
......@@ -85,7 +85,7 @@
<field name="state">code</field>
<field name="code">
if records:
records.callback_track_bl()
records.action_callback_track_bl()
</field>
</record>
......
......@@ -8,12 +8,12 @@ import redis
import config
# 默认字符gbk
logging.basicConfig(filename='./push_data_logger.log', level=logging.INFO)
# logging.basicConfig(filename='./push_data_logger.log', level=logging.INFO)
# 设置文件字符为utf-8
# logging.basicConfig(handlers=[logging.FileHandler('logs/mail_push.log', 'a', 'utf-8')],
# format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
logging.basicConfig(handlers=[logging.FileHandler('logs/mail_push.log', 'a', 'utf-8')],
format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
class Order_dispose(object):
......@@ -40,7 +40,8 @@ class Order_dispose(object):
bl_record = bl_obj.browse(data['id'])
# utc_time = datetime.strptime(data['utc_time'], "%Y-%m-%d %H:%M:%S")
utc_time = data.get('utc_time')
bl_record.mail_auto_push(utc_time, ship_packages, action_type)
user_login = data.get('user_login')
bl_record.mail_auto_push(utc_time, ship_packages, action_type, user_login, config.pda_db_user)
except Exception as ex:
logging.error('mail_auto_push error:%s' % str(ex))
return res_data
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论