Skip to content

Commit

Permalink
增加时区设置的支持;订单备注返回时去除html标签
Browse files Browse the repository at this point in the history
  • Loading branch information
JoneXiong committed Oct 19, 2022
1 parent de5b4ce commit dd6ad38
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
20 changes: 16 additions & 4 deletions controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def check_userid(self, token):

def res_ok(self, data=None):
ret = {'code': 0, 'msg': 'success'}
if request.httprequest.headers.get('sec-ch-ua-platform')=='"Android"':
pass#ret = {'code': 1, 'msg': 'success'}
if data!=None:
ret['data'] = data
return request.make_response(
Expand All @@ -194,7 +196,7 @@ def convert_static_link(request, html):
return html.replace('src="/', 'src="{base_url}/'.format(base_url=base_url))


def dt_convert(value, return_format='%Y-%m-%d %H:%M:%S'):
def dt_convert(value, return_format='%Y-%m-%d %H:%M:%S', gmt_diff=8):
"""
UTC时间转为本地时间
"""
Expand All @@ -203,11 +205,16 @@ def dt_convert(value, return_format='%Y-%m-%d %H:%M:%S'):
if isinstance(value, datetime):
value = value.strftime(return_format)
dt = datetime.strptime(value, return_format)
pytz_timezone = pytz.timezone('Etc/GMT-8')
_diff = ''
if gmt_diff>0:
_diff = '-%s'%gmt_diff
else:
_diff = '+%s'%(0-gmt_diff)
pytz_timezone = pytz.timezone('Etc/GMT' + _diff)
dt = dt.replace(tzinfo=pytz.timezone('UTC'))
return dt.astimezone(pytz_timezone).strftime(return_format)

def dt_utc(value, return_format='%Y-%m-%d %H:%M:%S'):
def dt_utc(value, return_format='%Y-%m-%d %H:%M:%S', gmt_diff=8):
"""
本地时间转为UTC时间
"""
Expand All @@ -216,6 +223,11 @@ def dt_utc(value, return_format='%Y-%m-%d %H:%M:%S'):
if isinstance(value, datetime):
value = value.strftime(return_format)
dt = datetime.strptime(value, return_format)
pytz_timezone = pytz.timezone('Etc/GMT+8')
_diff = ''
if gmt_diff>=0:
_diff = '+%s'%gmt_diff
else:
_diff = str(gmt_diff)
pytz_timezone = pytz.timezone('Etc/GMT' + _diff)
dt = dt.replace(tzinfo=pytz.timezone('UTC'))
return dt.astimezone(pytz_timezone).strftime(return_format)
21 changes: 15 additions & 6 deletions controllers/order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import json
import re

from odoo import http
from odoo.http import request
Expand All @@ -16,6 +17,8 @@

class WxappOrder(http.Controller, BaseController):

cur_gmt_diff = 8

def _get_user(self):
user = None
if hasattr(request, 'wechat_user') and request.wechat_user:
Expand Down Expand Up @@ -130,7 +133,7 @@ def create(self, sub_domain, **kwargs):
order.action_created(order_dict)
_data = {
"amountReal": round(order.amount_total, 2),
"dateAdd": dt_convert(order.create_date),
"dateAdd": dt_convert(order.create_date, gmt_diff=entry.gmt_diff),
"id": order.id,
"orderNumber": order.name,
"customer": order.partner_id.name,
Expand Down Expand Up @@ -290,12 +293,17 @@ def statistics(self, sub_domain, token=None, **kwargs):
_logger.exception(e)
return self.res_err(-1, str(e))

def clean_html(self, content):
pattern = re.compile(r'<[^>]+>',re.S)
result = pattern.sub('', content)
return result

def _order_basic_dict(self, each_order):
ret = {
"amountReal": round(each_order.amount_total, 2),
"dateAdd": dt_convert(each_order.create_date),
"dateAdd": dt_convert(each_order.create_date, gmt_diff=self.cur_gmt_diff),
"id": each_order.id,
"remark": each_order.note,
"remark": self.clean_html(each_order.note),
"orderNumber": each_order.name,
"goodsNumber": each_order.number_goods,
"status": defs.OrderResponseStatus.attrs[each_order.customer_status],
Expand Down Expand Up @@ -323,6 +331,7 @@ def list(self, sub_domain, token=None, status=None, **kwargs):
domain = self.get_orders_domain(status, **kwargs)
orders = request.env['sale.order'].sudo().search(domain, order='id desc', limit=30)
delivery_product_id = request.env.ref('oejia_weshop.product_product_delivery_weshop').id
self.cur_gmt_diff = entry.gmt_diff
data = {
"logisticsMap": {},
"orderList": [self._order_basic_dict(each_order) for each_order in orders],
Expand Down Expand Up @@ -387,12 +396,12 @@ def detail(self, sub_domain, token=None, id=None, **kwargs):
"amountLogistics": order.logistics_price,
"amountTax": round(order.amount_tax, 2),
"amountReal": round(order.amount_total, 2),
"dateAdd": dt_convert(order.create_date),
"dateUpdate": dt_convert(order.write_date),
"dateAdd": dt_convert(order.create_date, gmt_diff=entry.gmt_diff),
"dateUpdate": dt_convert(order.write_date, gmt_diff=entry.gmt_diff),
"goodsNumber": order.number_goods,
"id": order.id,
"orderNumber": order.name,
"remark": order.note,
"remark": self.clean_html(order.note),
"status": defs.OrderResponseStatus.attrs[order.customer_status],
"statusStr": defs.OrderStatus.attrs[order.customer_status],
"type": 0,
Expand Down
1 change: 1 addition & 0 deletions models/wxapp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class WxappConfig(models.Model):
secret = fields.Char('Secret')

team_id = fields.Many2one('crm.team', string='所属销售渠道', required=True)
gmt_diff = fields.Integer('客户端时区GMT ± N', default=8)

def need_login(self):
return False
Expand Down
1 change: 1 addition & 0 deletions views/wxapp_config_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<group string="基础配置" colspan="4">
<field name="mall_name"/>
<field name="team_id"/>
<field name="gmt_diff"/>
</group>
</sheet>
</form>
Expand Down

0 comments on commit dd6ad38

Please sign in to comment.