Skip to content

feat: add custom field default key#11

Merged
barredterra merged 5 commits intoversion-14from
feat-default-key
Jun 9, 2025
Merged

feat: add custom field default key#11
barredterra merged 5 commits intoversion-14from
feat-default-key

Conversation

@MarcCon
Copy link
Copy Markdown
Collaborator

@MarcCon MarcCon commented May 20, 2025

Adds a custom field for a default key in projects. If no key is selected, the key defined in the default key is fetched.

Closes #10

@MarcCon MarcCon requested a review from barredterra May 20, 2025 08:45
Copy link
Copy Markdown
Member

@barredterra barredterra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second though, the 'fetch from' brings the following problems:

  • It always overrides a manually entered, different key.
  • That could be solved by setting "fetch_if_empty": 1.
  • However, that would still require that we always set a key, making the "no key" scenario impossible.

I think we'll need a more fine-tuned mechanism here, that could be described as "fetch only once". Only when setting/changing the project, the default key should be set, never otherwise. This could be achieved by extending this script to not only set the billable % but also the default key:

project: function (frm, cdt, cdn) {
// set billable time to 0% if Project is of Type "Internal", reset to 100% otherwise
const child = locals[cdt][cdn];
frappe.db
.get_value("Project", child.project, "project_type")
.then(({ message }) => {
if (message && message.project_type == "Internal") {
frappe.model.set_value(cdt, cdn, "billable", "0%");
} else {
frappe.model.set_value(cdt, cdn, "billable", "100%");
}
});
},

@MarcCon
Copy link
Copy Markdown
Collaborator Author

MarcCon commented May 26, 2025

If I have understood correctly the key is now fetched only once when the project is set. But you can also enter your own key and overwrite the default key.

Comment thread working_time/working_time/doctype/working_time/working_time.js Outdated
@barredterra barredterra assigned barredterra and unassigned MarcCon Jun 8, 2025
@barredterra
Copy link
Copy Markdown
Member

barredterra commented Jun 9, 2025

Mergifyio backport version-15

Manual backport: cf10a7a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unnecessary / doesn't do anything

Comment thread working_time/patches.txt
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this to ensure that the custom field is created when we install the update on existing sites.

.get_value("Project", child.project, "project_type")
.get_value("Project", child.project, ["project_type", "default_key"])
.then(({ message }) => {
if (!child.key && message.default_key) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this condition to ensure we don't override existing data

@barredterra barredterra merged commit 693516f into version-14 Jun 9, 2025
@barredterra barredterra deleted the feat-default-key branch June 9, 2025 18:09
@barredterra barredterra removed their assignment Jun 9, 2025
barredterra added a commit that referenced this pull request Jun 9, 2025
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fetch default key from project

2 participants