提交 84438fd6 authored 作者: 郑笛's avatar 郑笛

完成翻译功能

上级 2e915111
......@@ -17,6 +17,7 @@
'data': [
'security/account_security.xml',
'security/ir.model.access.csv',
'data/data.xml',
'views/menu_view.xml',
'views/cc_node_view.xml',
'views/cc_process_view.xml',
......
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- 代理-->
<!--{'http': 'http://localhost:10809', 'https': 'http://localhost:10809'}-->
<!--公司代理:{'https': 'socks5://192.168.0.254:1080'}-->
<record id="proxy_url" model="ir.config_parameter">
<field name="key">proxy_url</field>
<field name="value">{'https': 'socks5://192.168.0.254:1080'}</field>
</record>
</data>
</odoo>
\ No newline at end of file
......@@ -398,6 +398,16 @@ msgstr "ID"
msgid "ITEM DESCRIPTION"
msgstr "商品描述"
#. module: ccs_base
#: model:ir.model.fields,field_description:ccs_base.field_cc_bl_line__item_description_translate
msgid "ITEM DESCRIPTION(EN)"
msgstr "商品描述(英文)"
#. module: ccs_base
#: model:ir.model.fields,field_description:ccs_base.field_cc_bl_line__receipient_county_translate
msgid "RECEIPIENT COUNTY(EN)"
msgstr "收件国家(英文)"
#. module: ccs_base
#: model:ir.model.fields,field_description:ccs_base.field_cc_bl_line__item_hs_code
#: model:ir.model.fields,field_description:ccs_base.field_cc_customers_declaration_order_line__item_hs_code
......@@ -906,3 +916,8 @@ msgid ""
"[Customers] Not yet! Click the Create button in the top left corner and the "
"sofa is yours!"
msgstr "[客户] 还没有!点击左上角的“创建”按钮,沙发就是你的了!"
#. module: ccs_base
#: model:ir.actions.server,name:ccs_base.bl_line_translate_server_action
msgid "Translate"
msgstr "翻译"
# 导入odoo
import ast
import base64
import re
from datetime import timedelta
from pygtrans import Translate
import xlrd
import pytz
from odoo import models, fields, api, _
......@@ -61,6 +63,7 @@ class CcBLLine(models.Model):
receipient_city = fields.Char(string='RECEIPIENT CITY')
# 收件人县
receipient_county = fields.Char(string='RECEIPIENT COUNTY')
receipient_county_translate = fields.Char(string='RECEIPIENT COUNTY(EN)')
# 收件人邮编
receipient_postcode = fields.Char(string='RECEPIENT POSTCODE')
# 收件人邮件
......@@ -77,6 +80,7 @@ class CcBLLine(models.Model):
sku_number = fields.Char(string='SKU NUMBER')
# 项目描述
item_description = fields.Char(string='ITEM DESCRIPTION')
item_description_translate = fields.Char(string='ITEM DESCRIPTION(EN)')
# 项目HS代码
item_hs_code = fields.Char(string='ITEM HS CODE')
# 项目数量
......@@ -98,6 +102,28 @@ class CcBLLine(models.Model):
# 高度
height = fields.Float(string='HEIGHT')
# 翻译
def action_bl_line_translate(self):
# http代理:proxies={'http': 'http://localhost:10809', 'https': 'http://localhost:10809'}
# socks5代理:proxies={'https': 'socks5://192.168.0.254:1080'}
proxy_url = self.env['ir.config_parameter'].sudo().get_param('proxy_url')
client = Translate(proxies=ast.literal_eval(proxy_url)) if proxy_url else Translate()
# 判断是否包含中文
charge_zh = lambda x='ddd': sum([1 if u'\u4e00' <= i <= u'\u9fff' else 0 for i in x]) > 0
for item in self:
if not item.item_description_translate and item.item_description:
if charge_zh(item.item_description):
result = client.translate(item.item_description, target='en')
item.item_description_translate = result.translatedText.replace('&#39;', "'").replace('&quot;', '"')
else:
item.item_description_translate = item.item_description
if not item.receipient_county_translate and item.receipient_county:
if charge_zh(item.receipient_county):
result = client.translate(item.receipient_county, target='en')
item.receipient_county_translate = result.translatedText.replace('&#39;', "'").replace('&quot;', '"')
else:
item.receipient_county_translate = item.receipient_county
# 创建一个业务对象,继承自models.Model, 用于管理业务数据.业务数据包括提单号、提单日期、提单总件数、提单总金额、所属客户、提单明细、清关进度明细、状态[待确认、清关中、已完成]
class CcBL(models.Model):
......@@ -268,7 +294,7 @@ class CcBL(models.Model):
'receipient_add_2': email_lines[0].receipient_add_2,
'receipient_add_3': email_lines[0].receipient_add_3,
'receipient_city': email_lines[0].receipient_city,
'receipient_county': email_lines[0].receipient_county,
'receipient_county': email_lines[0].receipient_county_translate,
'receipient_postcode': email_lines[0].receipient_postcode,
'sender_name': email_lines[0].sender_name,
'shipper_add_1': email_lines[0].shipper_add_1,
......@@ -290,7 +316,7 @@ class CcBL(models.Model):
'net_weight': email_line.net_weight,
'currency': email_line.currency,
'sku_number': email_line.sku_number,
'item_description': email_line.item_description,
'item_description': email_line.item_description_translate,
'item_hs_code': email_line.item_hs_code,
'item_quantity': email_line.item_quantity,
'unit_value': email_line.unit_value,
......
......@@ -23,6 +23,7 @@
<field optional="show" name="receipient_add_3" string="RECEIPIENT ADD 3"/>
<field optional="show" name="receipient_city" string="RECEIPIENT CITY"/>
<field optional="show" name="receipient_county" string="RECEIPIENT COUNTY"/>
<field optional="show" name="receipient_county_translate"/>
<field optional="show" name="receipient_postcode" string="RECEPIENT POSTCODE"/>
<field optional="show" name="recepient_email" string="RECEPIENT EMAIL"/>
<field optional="show" name="phone_number" string="PHONE NUMBER"/>
......@@ -31,6 +32,7 @@
<field optional="show" name="currency" string="Currency"/>
<field optional="show" name="sku_number" string="SKU NUMBER"/>
<field optional="show" name="item_description" string="ITEM DESCRIPTION"/>
<field optional="show" name="item_description_translate"/>
<field optional="show" name="item_hs_code" string="ITEM HS CODE"/>
<field optional="show" name="item_quantity" string="ITEM QUANTITY"/>
<field optional="show" name="unit_value" string="UNIT VALUE"/>
......@@ -105,4 +107,16 @@
</p>
</field>
</record>
<record id="bl_line_translate_server_action" model="ir.actions.server">
<field name="name">Translate</field>
<field name="model_id" ref="model_cc_bl_line"/>
<field name="binding_model_id" ref="model_cc_bl_line"/>
<field name="state">code</field>
<field name="code">
if records:
action = records.action_bl_line_translate()
</field>
</record>
</odoo>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论