refactor: added missing translation functions (#18143)

* fix: Translating Error and Messages

* Update erpnext/controllers/item_variant.py

Co-Authored-By: Shivam Mishra <scmmishra@users.noreply.github.com>

* Update erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

Co-Authored-By: Shivam Mishra <scmmishra@users.noreply.github.com>
This commit is contained in:
Anurag Mishra 2019-07-03 15:15:08 +05:30 committed by Shivam Mishra
parent 8929c62113
commit 841d852f41
20 changed files with 41 additions and 36 deletions

View File

@ -5,6 +5,7 @@
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _
class AccountingPeriod(Document):
def validate(self):
@ -16,7 +17,7 @@ class AccountingPeriod(Document):
def autoname(self):
company_abbr = frappe.get_cached_value('Company', self.company, "abbr")
self.name = " - ".join([self.period_name, company_abbr])
def validate_overlap(self):
existing_accounting_period = frappe.db.sql("""select name from `tabAccounting Period`
where (
@ -33,7 +34,7 @@ class AccountingPeriod(Document):
}, as_dict=True)
if len(existing_accounting_period) > 0:
frappe.throw("Accounting Period overlaps with {0}".format(existing_accounting_period[0].get("name")))
frappe.throw(_("Accounting Period overlaps with {0}".format(existing_accounting_period[0].get("name"))))
def get_doctypes_for_closing(self):
docs_for_closing = []

View File

@ -48,7 +48,7 @@ class BankStatementTransactionEntry(Document):
def get_statement_headers(self):
if not self.bank_settings:
frappe.throw("Bank Data mapper doesn't exist")
frappe.throw(_("Bank Data mapper doesn't exist"))
mapper_doc = frappe.get_doc("Bank Statement Settings", self.bank_settings)
headers = {entry.mapped_header:entry.stmt_header for entry in mapper_doc.header_items}
return headers
@ -57,7 +57,7 @@ class BankStatementTransactionEntry(Document):
if self.bank_statement is None: return
filename = self.bank_statement.split("/")[-1]
if (len(self.new_transaction_items + self.reconciled_transaction_items) > 0):
frappe.throw("Transactions already retreived from the statement")
frappe.throw(_("Transactions already retreived from the statement"))
date_format = frappe.get_value("Bank Statement Settings", self.bank_settings, "date_format")
if (date_format is None):
@ -314,7 +314,7 @@ class BankStatementTransactionEntry(Document):
try:
reconcile_against_document(lst)
except:
frappe.throw("Exception occurred while reconciling {0}".format(payment.reference_name))
frappe.throw(_("Exception occurred while reconciling {0}".format(payment.reference_name)))
def submit_payment_entries(self):
for payment in self.new_transaction_items:
@ -414,7 +414,7 @@ def get_transaction_entries(filename, headers):
elif (filename.lower().endswith("xls")):
rows = get_rows_from_xls_file(filename)
else:
frappe.throw("Only .csv and .xlsx files are supported currently")
frappe.throw(_("Only .csv and .xlsx files are supported currently"))
stmt_headers = headers.values()
for row in rows:

View File

@ -157,7 +157,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
can_change_release_date: function(date) {
const diff = frappe.datetime.get_diff(date, frappe.datetime.nowdate());
if (diff < 0) {
frappe.throw('New release date should be in the future');
frappe.throw(__('New release date should be in the future'));
return false;
} else {
return true;

View File

@ -105,7 +105,7 @@ class PurchaseInvoice(BuyingController):
def validate_release_date(self):
if self.release_date and getdate(nowdate()) >= getdate(self.release_date):
frappe.msgprint('Release date must be in the future', raise_exception=True)
frappe.throw(_('Release date must be in the future'))
def validate_cash(self):
if not self.cash_bank_account and flt(self.paid_amount):

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from erpnext.utilities.product import get_price
@ -13,7 +14,7 @@ class SubscriptionPlan(Document):
def validate_interval_count(self):
if self.billing_interval_count < 1:
frappe.throw('Billing Interval Count cannot be less than 1')
frappe.throw(_('Billing Interval Count cannot be less than 1'))
@frappe.whitelist()
def get_plan_rate(plan, quantity=1, customer=None):
@ -26,7 +27,7 @@ def get_plan_rate(plan, quantity=1, customer=None):
customer_group = frappe.db.get_value("Customer", customer, "customer_group")
else:
customer_group = None
price = get_price(item_code=plan.item, price_list=plan.price_list, customer_group=customer_group, company=None, qty=quantity)
if not price:
return 0

View File

@ -176,7 +176,7 @@ def enqueue_multiple_variant_creation(item, args):
for key in variants:
total_variants *= len(variants[key])
if total_variants >= 600:
frappe.msgprint("Please do not create more than 500 items at a time", raise_exception=1)
frappe.throw(_("Please do not create more than 500 items at a time"))
return
if total_variants < 10:
return create_multiple_variants(item, args)

View File

@ -38,7 +38,7 @@ class Question(Document):
options = self.options
answers = [item.name for item in options if item.is_correct == True]
if len(answers) == 0:
frappe.throw("No correct answer is set for {0}".format(self.name))
frappe.throw(_("No correct answer is set for {0}".format(self.name)))
return None
elif len(answers) == 1:
return answers[0]

View File

@ -4,12 +4,13 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
class Quiz(Document):
def validate(self):
if self.passing_score > 100:
frappe.throw("Passing Score value should be between 0 and 100")
frappe.throw(_("Passing Score value should be between 0 and 100"))
def allowed_attempt(self, enrollment, quiz_name):
if self.max_attempts == 0:
@ -17,7 +18,7 @@ class Quiz(Document):
try:
if len(frappe.get_all("Quiz Activity", {'enrollment': enrollment.name, 'quiz': quiz_name})) >= self.max_attempts:
frappe.msgprint("Maximum attempts for this quiz reached!")
frappe.msgprint(_("Maximum attempts for this quiz reached!"))
return False
else:
return True
@ -56,5 +57,5 @@ def compare_list_elementwise(*args):
else:
return False
except TypeError:
frappe.throw("Compare List function takes on list arguments")
frappe.throw(_("Compare List function takes on list arguments"))

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe, json
from frappe import _
from frappe.model.document import Document
from erpnext.education.api import get_grade
from frappe.utils.pdf import get_pdf
@ -79,7 +80,7 @@ def get_attendance_count(student, academic_year, academic_term=None):
from_date, to_date = frappe.db.get_value("Academic Term", academic_term, ["term_start_date", "term_end_date"])
if from_date and to_date:
attendance = dict(frappe.db.sql('''select status, count(student) as no_of_days
from `tabStudent Attendance` where student = %s
from `tabStudent Attendance` where student = %s
and date between %s and %s group by status''',
(student, from_date, to_date)))
if "Absent" not in attendance.keys():
@ -88,4 +89,4 @@ def get_attendance_count(student, academic_year, academic_term=None):
attendance["Present"] = 0
return attendance
else:
frappe.throw("Provide the academic year and set the starting and ending date.")
frappe.throw(_("Provide the academic year and set the starting and ending date."))

View File

@ -148,7 +148,7 @@ def enroll_in_program(program_name, student=None):
# Check if self enrollment in allowed
program = frappe.get_doc('Program', program_name)
if not program.allow_self_enroll:
return frappe.throw("You are not allowed to enroll for this course")
return frappe.throw(_("You are not allowed to enroll for this course"))
student = get_current_student()
if not student:
@ -162,7 +162,7 @@ def enroll_in_program(program_name, student=None):
# Check if self enrollment in allowed
program = frappe.get_doc('Program', program_name)
if not program.allow_self_enroll:
return frappe.throw("You are not allowed to enroll for this course")
return frappe.throw(_("You are not allowed to enroll for this course"))
# Enroll in program
program_enrollment = student.enroll_in_program(program_name)
@ -185,7 +185,7 @@ def add_activity(course, content_type, content, program):
student = get_current_student()
if not student:
return frappe.throw("Student with email {0} does not exist".format(frappe.session.user), frappe.DoesNotExistError)
return frappe.throw(_("Student with email {0} does not exist".format(frappe.session.user)), frappe.DoesNotExistError)
enrollment = get_or_create_course_enrollment(course, program)
if content_type == 'Quiz':
@ -220,7 +220,7 @@ def get_quiz(quiz_name, course):
quiz = frappe.get_doc("Quiz", quiz_name)
questions = quiz.get_questions()
except:
frappe.throw("Quiz {0} does not exist".format(quiz_name))
frappe.throw(_("Quiz {0} does not exist".format(quiz_name)))
return None
questions = [{
@ -347,7 +347,7 @@ def get_or_create_course_enrollment(course, program):
if not course_enrollment:
program_enrollment = get_enrollment('program', program, student.name)
if not program_enrollment:
frappe.throw("You are not enrolled in program {0}".format(program))
frappe.throw(_("You are not enrolled in program {0}".format(program)))
return
return student.enroll_in_course(course_name=course, program_enrollment=get_enrollment('program', program, student.name))
else:

View File

@ -124,7 +124,7 @@ def create_sales_order(shopify_order, shopify_settings, company=None):
else:
so = frappe.get_doc("Sales Order", so)
frappe.db.commit()
return so
@ -252,6 +252,6 @@ def get_tax_account_head(tax):
{"parent": "Shopify Settings", "shopify_tax": tax_title}, "tax_account")
if not tax_account:
frappe.throw("Tax Account not specified for Shopify Tax {0}".format(tax.get("title")))
frappe.throw(_("Tax Account not specified for Shopify Tax {0}".format(tax.get("title"))))
return tax_account

View File

@ -30,7 +30,7 @@ class ClinicalProcedureTemplate(Document):
try:
frappe.delete_doc("Item",self.item)
except Exception:
frappe.throw("""Not permitted. Please disable the Procedure Template""")
frappe.throw(_("""Not permitted. Please disable the Procedure Template"""))
def get_item_details(self, args=None):
item = frappe.db.sql("""select stock_uom, item_name

View File

@ -298,7 +298,7 @@ var get_procedure_prescribed = function(frm){
});
}
else{
frappe.msgprint("Please select Patient to get prescribed procedure");
frappe.msgprint(__("Please select Patient to get prescribed procedure"));
}
};

View File

@ -160,7 +160,7 @@ var btn_create_vital_signs = function (frm) {
var btn_create_procedure = function (frm) {
if(!frm.doc.patient){
frappe.throw("Please select patient");
frappe.throw(__("Please select patient"));
}
frappe.route_options = {
"patient": frm.doc.patient,

View File

@ -84,7 +84,7 @@ def get_benefit_pro_rata_ratio_amount(employee, on_date, sal_struct):
pay_against_benefit_claim, max_benefit_amount = frappe.db.get_value("Salary Component", sal_struct_row.salary_component, ["pay_against_benefit_claim", "max_benefit_amount"])
except TypeError:
# show the error in tests?
frappe.throw("Unable to find Salary Component {0}".format(sal_struct_row.salary_component))
frappe.throw(_("Unable to find Salary Component {0}".format(sal_struct_row.salary_component)))
if sal_struct_row.is_flexible_benefit == 1 and pay_against_benefit_claim != 1:
total_pro_rata_max += max_benefit_amount
if total_pro_rata_max > 0:

View File

@ -15,7 +15,7 @@ frappe.ui.form.on('HR Settings', {
let policy = frm.doc.password_policy;
if (policy) {
if (policy.includes(' ') || policy.includes('--')) {
frappe.msgprint("Password policy cannot contain spaces or simultaneous hyphens. The format will be restructured automatically");
frappe.msgprint(_("Password policy cannot contain spaces or simultaneous hyphens. The format will be restructured automatically"));
}
frm.set_value('password_policy', policy.split(new RegExp(" |-", 'g')).filter((token) => token).join('-'));
}

View File

@ -120,7 +120,7 @@ def get_valid_items(search_value=''):
def publish_selected_items(items_to_publish):
items_to_publish = json.loads(items_to_publish)
if not len(items_to_publish):
frappe.throw('No items to publish')
frappe.throw(_('No items to publish'))
for item in items_to_publish:
item_code = item.get('item_code')
@ -165,7 +165,7 @@ def item_sync_preprocess(intended_item_publish_count):
frappe.db.set_value("Marketplace Settings", "Marketplace Settings", "sync_in_progress", 1)
return response
else:
frappe.throw('Unable to update remote activity')
frappe.throw(_('Unable to update remote activity'))
def item_sync_postprocess():
@ -173,7 +173,7 @@ def item_sync_postprocess():
if response:
frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'last_sync_datetime', frappe.utils.now())
else:
frappe.throw('Unable to update remote activity')
frappe.throw(_('Unable to update remote activity'))
frappe.db.set_value('Marketplace Settings', 'Marketplace Settings', 'sync_in_progress', 0)

View File

@ -645,7 +645,7 @@ def set_project_status(project, status):
set status for project and all related tasks
'''
if not status in ('Completed', 'Cancelled'):
frappe.throw('Status must be Cancelled or Completed')
frappe.throw(_('Status must be Cancelled or Completed'))
project = frappe.get_doc('Project', project)
frappe.has_permission(doc = project, throw = True)

View File

@ -68,7 +68,7 @@ class Quiz {
}).then(res => {
this.submit_btn.remove()
if (!res.message) {
frappe.throw("Something went wrong while evaluating the quiz.")
frappe.throw(__("Something went wrong while evaluating the quiz."))
}
let indicator = 'red'

View File

@ -4,6 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
import json
from six import iteritems
@ -414,7 +415,7 @@ class GSTR3BReport(Document):
if gst_details:
return gst_details[0]
else:
frappe.throw("Please enter GSTIN and state for the Company Address {0}".format(self.company_address))
frappe.throw(_("Please enter GSTIN and state for the Company Address {0}".format(self.company_address)))
def get_account_heads(self):
@ -427,7 +428,7 @@ class GSTR3BReport(Document):
if account_heads:
return account_heads
else:
frappe.throw("Please set account heads in GST Settings for Compnay {0}".format(self.company))
frappe.throw(_("Please set account heads in GST Settings for Compnay {0}".format(self.company)))
def get_missing_field_invoices(self):