提交 02db7a0f authored 作者: 伍姿英's avatar 伍姿英

Merge branch 'release/2.7.1'

......@@ -105,7 +105,8 @@ class CcBigPackage(models.Model):
'type': 'ir.actions.act_window',
'res_model': 'cc.package.good',
'view_mode': 'tree,form',
'domain': [('big_package_id', '=', self.id), ('is_cancel', '=', False)],
# 'domain': [('big_package_id', '=', self.id), ('is_cancel', '=', False)],
'domain': [('bl_line_id', 'in', self.ship_package_ids.ids), ('is_cancel', '=', False)],
}
def action_link_pallet(self):
......@@ -865,12 +866,19 @@ class CcBL(models.Model):
# 创建显示商品的action
def action_show_package_good(self):
# 返回一个action,显示商品
sql = "select id from cc_ship_package where bl_id=%s" % self.id
self._cr.execute(sql)
result = self._cr.fetchall()
ids = []
if result:
ids = [i[0] for i in result]
return {
'name': _('Goods'),
'type': 'ir.actions.act_window',
'res_model': 'cc.package.good',
'view_mode': 'tree,form',
'domain': [('bl_id', '=', self.id), ('is_cancel', '=', False)],
# 'domain': [('bl_id', '=', self.id), ('is_cancel', '=', False)],
'domain': [('bl_line_id', 'in', ids), ('is_cancel', '=', False)],
}
# 增加清关截止日期
......
......@@ -117,9 +117,18 @@ 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)])
arr = [
{
'file_name': '尾程交接POD(待大包数量和箱号)',
'file': base64.encodebytes(data),
'attachment_name': name,
'is_upload': False,
'bl_id': bl.id
} for bl in bl_obj
]
# file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'),
# ('bl_id', 'in', bl_obj.ids)])
file_objs = self.env['cc.clearance.file'].sudo().create(arr)
# 最大重试次数
max_retries = 2
for file_obj in file_objs:
......@@ -127,9 +136,9 @@ class OrderStateChangeRule(models.Model):
while retries <= max_retries:
try:
# 设置文件内容
file_obj.file = base64.encodebytes(data)
file_obj.attachment_name = name
file_obj.is_upload = False # 确保文件状态是未上传
# file_obj.file = base64.encodebytes(data)
# file_obj.attachment_name = name
# file_obj.is_upload = False # 确保文件状态是未上传
# 尝试上传操作
file_obj.action_sync()
# 检查是否上传成功,假设 is_upload 为 False 表示上传失败
......@@ -201,7 +210,8 @@ class OrderStateChangeRule(models.Model):
text_arr = self.find_final_email_text(email_body)
logging.info('data_arr: %s' % text_arr)
attachment_arr = kwargs['attachment_arr']
attachment_tuple = attachment_arr[0] if attachment_arr else []
# attachment_tuple = attachment_arr[0] if attachment_arr else []
attachment_tuple_arr = attachment_arr if attachment_arr else []
# order_obj_arr = []
try:
text_arr = [i.replace('-', '').replace(' ', '') for i in text_arr]
......@@ -210,9 +220,13 @@ class OrderStateChangeRule(models.Model):
result = self._cr.fetchall()
ids = [i[0] for i in result]
bl_objs = self.env['cc.bl'].sudo().search([('id', 'in', ids)]) if result else False
if bl_objs and attachment_tuple:
attachment_name, attachment_data = attachment_tuple
self.upload_pod_attachment(bl_objs, attachment_name, attachment_data)
if bl_objs and attachment_tuple_arr:
file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'),
('bl_id', 'in', bl_objs.ids)])
file_objs.unlink()
for attachment_tuple in attachment_tuple_arr:
attachment_name, attachment_data = attachment_tuple
self.upload_pod_attachment(bl_objs, attachment_name, attachment_data)
# redis_conn = self.env['common.common'].sudo().get_redis()
# if redis_conn == 'no':
# raise ValidationError('未连接redis')
......
......@@ -16,6 +16,7 @@
'security/ir.model.access.csv',
# data
'data/data.xml',
'data/timer.xml',
# wizard
'wizard/batch_input_ship_package_statu_wizard.xml',
'wizard/update_bl_status_wizard.xml',
......
<odoo>
<data>
<record id="cron_delete_log" model="ir.cron">
<field name="name">定时删除历史日志</field>
<field name="model_id" ref="ccs_connect_tiktok.model_ao_tt_api_log"/>
<field name="state">code</field>
<field name="code">model.cron_delete_log()</field>
<field name='interval_number'>2</field>
<field name='interval_type'>hours</field>
<field name="numbercall">-1</field>
<field name="active" eval="False"/>
</record>
</data>
</odoo>
\ No newline at end of file
......@@ -4,6 +4,7 @@ from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError, Warning
import logging
from datetime import timedelta
_logger = logging.getLogger(__name__)
......@@ -14,7 +15,7 @@ class TTErrorLog(models.Model):
_order = 'id desc'
big_bag_no = fields.Char('业务信息', index=True)
push_time = fields.Datetime('产生时间', index=True)
push_time = fields.Datetime('产生时间')
error_msg = fields.Char('失败原因')
success_bl = fields.Boolean('是否成功', default=False, index=True)
data_text = fields.Text('传输数据')
......@@ -42,3 +43,24 @@ class TTErrorLog(models.Model):
def deal_tt_error_log(self):
for item in self:
item.state = '已处理'
def cron_delete_log(self):
history_days = self.env['ir.config_parameter'].sudo().get_param('history_days') or 180
history_limit_log = self.env['ir.config_parameter'].sudo().get_param('history_limit_log') or 10000
history_limit_log = int(history_limit_log)
history_days = int(history_days)
current_date = datetime.utcnow()
# 计算180天之前的日期
past_date = current_date - timedelta(days=history_days)
sql = 'select id from ao_tt_api_log where create_date < %s order by create_date asc limit %s;'
self._cr.execute(sql, (past_date, history_limit_log))
result = self._cr.fetchall()
tk_log_ids = []
if result:
tk_log_ids = [i[0] for i in result]
if tk_log_ids:
log_ids = '(%s)' % str(tk_log_ids)[1:-1]
delete_api_log_sql = 'delete from ao_tt_api_log where id in %s' % log_ids
self._cr.execute(delete_api_log_sql)
self._cr.commit()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论