Child table columns and width

I’ve got a custom doctype called “Lease Agreement” and within that is a child table in a field labeled “product_location”.

I’m attempting to tweak lease_agreement.json to specify which columns I want displayed and to also set the column widths of the child table.

After saving the json file I’ve tried bench build/migrate/clear-cache/clear-website-cache to no avail.

Any suggestions on how to get this to update would be appreciated.

Cheers!

 {
            "fieldname": "product_location",
            "fieldtype": "Table",
            "label": "Product Location",
            "options": "Lease Product Location",
            "fields": [
                {
                    "fieldname": "product",
                    "fieldtype": "Link",
                    "label": "Product",
                    "options": "Item",
                    "in_list_view": 1,
                    "width": 150
                },
                {
                    "fieldname": "location",
                    "fieldtype": "Link",
                    "label": "Location",
                    "options": "Location",
                    "in_list_view": 1,
                    "width": 150
                },
                {
                    "fieldname": "keys",
                    "fieldtype": "Int",
                    "label": "Keys",
                    "in_list_view": 1,
                    "width": 80
                },
                {
                    "fieldname": "term",
                    "fieldtype": "Select",
                    "label": "Term",
                    "options": "Annual\nMonthly",
                    "in_list_view": 1,
                    "width": 100
                },
                {
                    "fieldname": "date",
                    "fieldtype": "Date",
                    "label": "Commencement Date",
                    "in_list_view": 1,
                    "width": 100
                },
                {
                    "fieldname": "cancel_product",
                    "fieldtype": "Date",
                    "label": "Termination Date",
                    "in_list_view": 1,
                    "width": 100
                }
            ],
            "min_rows": 6
        },

How I want the table to look (done in code, not using the table settings within the form)

How the table currently looks for most users

Hi,
After modifying the lease_agreement.json file, run the this line in terminal, this line will reload the doctype and apply the changes

bench reload-doctype lease_agreement

After making this also still the change didn’t appeared you can try to restart the bench

bench restart

Hope this will help you out.

Thank you.

Thanks for the suggestion :slight_smile:

Unfortunately I get an error for some reason, bench can’t see the custom doctype. This command works for the standard modules, but not ones in my custom app.

Instead I restarted my server. The JSON changes for the child table didn’t take affect.

bench reload-doctype lease_agreement
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/bench/frappe/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/bench/frappe/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/bench/frappe/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/bench/frappe/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/bench/frappe/apps/frappe/frappe/commands/site.py", line 596, in reload_doctype
    frappe.reload_doctype(doctype, force=context.force)
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 1256, in reload_doctype
    reload_doc(
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 1282, in reload_doc
    return frappe.modules.reload_doc(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/bench/frappe/apps/frappe/frappe/modules/utils.py", line 196, in reload_doc
    return import_files(module, dt, dn, force=force, reset_permissions=reset_permissions)
  File "/home/bench/frappe/apps/frappe/frappe/modules/import_file.py", line 53, in import_files
    return import_file(
  File "/home/bench/frappe/apps/frappe/frappe/modules/import_file.py", line 60, in import_file
    path = get_file_path(module, dt, dn)
  File "/home/bench/frappe/apps/frappe/frappe/modules/import_file.py", line 70, in get_file_path
    path = os.path.join(get_module_path(module), os.path.join(dt, dn, f"{dn}.json"))
  File "/home/bench/frappe/apps/frappe/frappe/modules/utils.py", line 185, in get_module_path
    return frappe.get_module_path(module)
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 1339, in get_module_path
    app = get_module_app(module)
  File "/home/bench/frappe/apps/frappe/frappe/modules/utils.py", line 262, in get_module_app
    frappe.throw(_("Module {} not found").format(module), exc=frappe.DoesNotExistError)
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 523, in throw
    msgprint(
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 491, in msgprint
    _raise_exception()
  File "/home/bench/frappe/apps/frappe/frappe/__init__.py", line 443, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.DoesNotExistError: Module  not found

Hi,
If the custom doctype is not being recognized by the bench command, you can try specifying the app name before the command. For example, if the custom doctype is in the app called “custom_app”, you can run:

bench --site sitename --app custom_app clear-cache

If still This problem getting repeated then the JSON are not saved properly. So, check on that and try to bench migrate cmd to update the DB even try to clearing the cache after the migration is complete though the change reflected properly.

Hope this will help you out.

Thank you.

Thanks again.

Unfortunately none of those suggestions yield the result I’m after :frowning: is it possible that something is missing from my hooks.py file that points to the changes I’m making in lease_agreement.json?

Keeping in mind that this is a custom doctype in a custom app?

Hi,
Here is an example of how to add a custom app and custom doctype to your hooks.py file:

# Import the necessary classes from frappe
from frappe import _

# Add your custom app to installed apps
app_include_js = "/assets/my_custom_app/js/my_custom_app.js"
app_include_css = "/assets/my_custom_app/css/my_custom_app.css"
app_name = "my_custom_app"

# Add your custom doctype to the doctype list
doctype_js = {
    "Lease Agreement": "public/js/lease_agreement.js"
}

# Define your custom translations
# Note: Change the "en" translation to the appropriate language code
trans_dict = {
    "Lease Agreement": _("Lease Agreement")
}

After you make changes to your hooks.py file, run the following command to restart the bench server and apply the changes:

$ bench restart

Hope this will help you out.

Thank you.

1 Like

I don’t know if this is telling… but I made a change to the title of the field by editing the doctype. Upon saving these changes the lease_agreement.json file reverted to the standard field definitions (with the updated title), removing all of my field options:

  {
   "fieldname": "product_location",
   "fieldtype": "Table",
   "label": "Product Location TEST",
   "options": "Lease Product Location"
  },