-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(pwa): multicurrency support in expense & advance forms #4083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iamkhanraheel
wants to merge
14
commits into
frappe:develop
Choose a base branch
from
iamkhanraheel:fix/v16_changes_pwa
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c1bba6b
fix: update currency & exchange rate, update base & transaction field…
iamkhanraheel 370b469
fix: advance child table row selection as per the sanctioned amount i…
iamkhanraheel 2b0dc14
fix: update base fields value as per the exchange rate in real time
iamkhanraheel a767d69
fix(Link): reload link field options when filters change
ruchamahabal 0912671
fix: update currency in advance account filters, remove fetching defa…
iamkhanraheel cde96b3
fix: add currency filter in payable account of expense claim
iamkhanraheel f7ef13f
fix: set exchange rate to 0 if currency not set, correct typo
iamkhanraheel 1164ff8
fix: formatting
iamkhanraheel 604dc07
fix: currency not showing up in recent expenses
ruchamahabal 6972cea
fix(Link): new options don't populate when search term changes
ruchamahabal 3908367
fix: fetching exchange rate fails when expense currency changes from …
ruchamahabal 0f9ef2b
fix: don't pass currency in expense claim tables, use doc currency
ruchamahabal f18d124
fix: remove all basefield conversion & label update
iamkhanraheel 0874b5a
fix: watch for currency change only to update label, cleanup currency…
iamkhanraheel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { ref, watch } from "vue" | ||
| import { getCompanyCurrency, currencyPrecision } from "@/data/currencies" | ||
|
|
||
| const flt = (value, precision) => { | ||
| const num = parseFloat(value) || 0; | ||
| const targetPrecision = precision !== undefined ? precision : (currencyPrecision.data || 2); | ||
| return parseFloat(num.toFixed(targetPrecision)); | ||
| }; | ||
|
|
||
| export function updateCurrencyLabels({ formFields, doc, baseFields = [], transactionFields = []}) { | ||
| if (!formFields || !doc) return | ||
| const companyCurrency = ref("") | ||
| // fetch company currency initially or when company changes | ||
| const fetchCompanyCurrency = async () => { | ||
| if (!doc.company) return | ||
| companyCurrency.value = await getCompanyCurrency(doc.company) | ||
| } | ||
|
|
||
| const currencyFields = new Set([...baseFields, ...transactionFields]) | ||
| const updateLabels = () => { | ||
| if (!companyCurrency.value) return | ||
|
|
||
| formFields.forEach((field) => { | ||
| if (!field?.fieldname) return | ||
| if (!currencyFields.has(field.fieldname)) return | ||
|
|
||
| if (!field._original_label && field.label) { | ||
| field._original_label = field.label.replace(/\([^\)]*\)/g, "").trim() | ||
| } | ||
| if (baseFields.includes(field.fieldname)) { | ||
| field.label = `${field._original_label} (${companyCurrency.value})` | ||
| field.hidden = doc.currency === companyCurrency.value | ||
| } | ||
| if (transactionFields.includes(field.fieldname)) { | ||
| field.label = `${field._original_label} (${doc.currency})` | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // update labels | ||
| watch( | ||
| () => [doc.company, doc.currency], | ||
| async () => { | ||
| await fetchCompanyCurrency() | ||
| updateLabels() | ||
| }, | ||
| { immediate: true } | ||
| ) | ||
|
|
||
| return { updateLabels, companyCurrency } | ||
| } | ||
|
|
||
| // function to update base currency fields data | ||
| export function updateBaseFieldsAmount({doc, fields, exchangeRate}) { | ||
| if (!doc) return; | ||
| const exchange_rate = flt(exchangeRate || doc.exchange_rate || 1, 9); | ||
| fields.forEach(f => { | ||
| const val = flt(flt(doc[f]) * exchange_rate); | ||
| doc["base_" + f] = val; | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.