Issue with translated strings passed in a new document created programatically

Hi all,

I am trying to create a customer automatically from the server and I’m getting an error message when I’m connected in French:

Translation: Type cannot be “Individual”. It should be one of “”, “Company”, “Individual”

Here is my code:

customer =  frappe.get_doc({
                        "doctype": "Customer",
                        "customer_name": doc.patient_name,
                        "customer_type": _('Individual'),
                        "customer_group": _('Individual'),
                        "territory": _('All Territories')

And the error message

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 56, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 19, in handle
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 42, in execute_cmd
    ret =, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 907, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 124, in insert
    doc = frappe.get_doc(doc).insert()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 214, in insert
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 667, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 892, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 875, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 661, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/maia/maia/maia/doctype/patient/", line 59, in after_insert
  File "/home/frappe/frappe-bench/apps/maia/maia/maia/doctype/patient/", line 93, in create_customer_from_patient
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 194, in insert
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 402, in _validate
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/", line 537, in _validate_selects
    value, comma_options))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 316, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red')
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 306, in msgprint
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 279, in _raise_exception
    raise raise_exception, encode(msg)
ValidationError:  Type ne peut pas être "Individuel". Il devrait être l'un des "", "Société", "Individuel"

It seems like Frappe cannot validate the matching of two translated strings, since it works fine in English.

Has anyone encountered this already ?

Thanks for any help!

For people getting the same issue, the solution was not far…

The customer type is an option and should not be translated, whereas the customer group and territory should be passed as translated strings:

customer =  frappe.get_doc({
                        "doctype": "Customer",
                        "customer_name": doc.patient_name,
                        "customer_type": 'Individual',
                        "customer_group": _('Individual'),
                        "territory": _('All Territories')
1 Like

The error message sent me in the wrong direction because it translates everything anyway :wink:

1 Like