浏览代码

Merge pull request #15568 from resilient-tech/fix-customize-form-renaming

fix(Customize Form): delete translation for renaming only if label is empty
version-14
mergify[bot] 3 年前
committed by GitHub
父节点
当前提交
b81879e511
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 39 次插入11 次删除
  1. +17
    -11
      frappe/custom/doctype/customize_form/customize_form.py
  2. +22
    -0
      frappe/custom/doctype/customize_form/test_customize_form.py

+ 17
- 11
frappe/custom/doctype/customize_form/customize_form.py 查看文件

@@ -107,20 +107,26 @@ class CustomizeForm(Document):
def set_name_translation(self): def set_name_translation(self):
'''Create, update custom translation for this doctype''' '''Create, update custom translation for this doctype'''
current = self.get_name_translation() current = self.get_name_translation()
if current:
if self.label and current.translated_text != self.label:
frappe.db.set_value('Translation', current.name, 'translated_text', self.label)
frappe.translate.clear_cache()
else:
if not self.label:
if current:
# clear translation # clear translation
frappe.delete_doc('Translation', current.name) frappe.delete_doc('Translation', current.name)
return


else:
if self.label:
frappe.get_doc(dict(doctype='Translation',
source_text=self.doc_type,
translated_text=self.label,
language_code=frappe.local.lang or 'en')).insert()
if not current:
frappe.get_doc(
{
"doctype": 'Translation',
"source_text": self.doc_type,
"translated_text": self.label,
"language_code": frappe.local.lang or 'en'
}
).insert()
return

if self.label != current.translated_text:
frappe.db.set_value('Translation', current.name, 'translated_text', self.label)
frappe.translate.clear_cache()


def clear_existing_doc(self): def clear_existing_doc(self):
doc_type = self.doc_type doc_type = self.doc_type


+ 22
- 0
frappe/custom/doctype/customize_form/test_customize_form.py 查看文件

@@ -304,3 +304,25 @@ class TestCustomizeForm(unittest.TestCase):


action = [d for d in event.actions if d.label=='Test Action'] action = [d for d in event.actions if d.label=='Test Action']
self.assertEqual(len(action), 0) self.assertEqual(len(action), 0)

def test_custom_label(self):
d = self.get_customize_form("Event")

# add label
d.label = "Test Rename"
d.run_method("save_customization")
self.assertEqual(d.label, "Test Rename")

# change label
d.label = "Test Rename 2"
d.run_method("save_customization")
self.assertEqual(d.label, "Test Rename 2")

# saving again to make sure existing label persists
d.run_method("save_customization")
self.assertEqual(d.label, "Test Rename 2")

# clear label
d.label = ""
d.run_method("save_customization")
self.assertEqual(d.label, "")

正在加载...
取消
保存