[FIX] account: tax totals currency issue
The tax totals widget is formatting data using the old props instead of the new. When viewing an invoice the currency is correct, but when scrolling through records or changing currencies, the currency in the widget is not correct. To replicate: 1. Create 2 invoices, one in EUR, one in USD, ideally both with tax 2. Scroll through the record form views using the next/previous pager buttons 3. Observe the currency is not correct (display USD instead of EUR, and EUR instead of USD) This fix modifies the way the record data (props.value) is formatted, and ensures using the correct currency (nextProps) instead of the old one (props) OPW-3244079 closes odoo/odoo#118241 X-original-commit: 15a610acddf4ea19082a88aaf1eee231aa1fe91f Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com> Signed-off-by: Ayob Habib (ayh) <ayh@odoo.com>
This commit is contained in:
@@ -79,7 +79,7 @@ class TaxGroupComponent extends Component {
|
||||
return;
|
||||
}
|
||||
this.props.taxGroup.tax_group_amount = newValue;
|
||||
this.props.taxGroup.formatted_tax_group_amount = this.props.taxGroup.formatted_tax_group_amount.replace(oldValue.toString(), newValue.toString());
|
||||
|
||||
this.props.onChangeTaxGroup({
|
||||
oldValue,
|
||||
newValue: newValue,
|
||||
@@ -106,17 +106,17 @@ TaxGroupComponent.template = "account.TaxGroupComponent";
|
||||
**/
|
||||
export class TaxTotalsComponent extends Component {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.totals = this.props.record.data[this.props.name];
|
||||
this.readonly = this.props.readonly;
|
||||
this.totals = {};
|
||||
this.formatData(this.props);
|
||||
onWillUpdateProps((nextProps) => {
|
||||
// We only reformat tax groups if there are changed
|
||||
this.totals = nextProps.record.data[nextProps.name];
|
||||
this.readonly = nextProps.readonly;
|
||||
this._computeTotalsFormat();
|
||||
this.formatData(nextProps);
|
||||
});
|
||||
}
|
||||
|
||||
get readonly() {
|
||||
return this.props.readonly;
|
||||
}
|
||||
|
||||
get currencyId() {
|
||||
const recordCurrency = this.props.record.data.currency_id;
|
||||
return recordCurrency && recordCurrency[0];
|
||||
@@ -132,52 +132,46 @@ export class TaxTotalsComponent extends Component {
|
||||
|
||||
/**
|
||||
* This method is the main function of the tax group widget.
|
||||
* It is called by the TaxGroupComponent and receives the
|
||||
* newer tax value.
|
||||
* It is called by the TaxGroupComponent and receives the newer tax value.
|
||||
*
|
||||
* It is responsible for calculating taxes based on tax groups and triggering
|
||||
* an event to notify the ORM of a change.
|
||||
* It is responsible for triggering an event to notify the ORM of a change.
|
||||
*/
|
||||
_onChangeTaxValueByTaxGroup({ oldValue, newValue, taxGroupId }) {
|
||||
_onChangeTaxValueByTaxGroup({ oldValue, newValue }) {
|
||||
if (oldValue === newValue) return;
|
||||
this.totals.amount_total = this.totals.amount_untaxed + newValue;
|
||||
this.props.record.update({ [this.props.name]: this.totals });
|
||||
}
|
||||
|
||||
_format(amount) {
|
||||
return formatMonetary(amount, { currencyId: this.currencyId });
|
||||
}
|
||||
formatData(props) {
|
||||
let totals = props.record.data[this.props.name];
|
||||
const currencyFmtOpts = { currencyId: props.record.data.currency_id && props.record.data.currency_id[0] };
|
||||
|
||||
_computeTotalsFormat() {
|
||||
if (!this.totals) {
|
||||
return;
|
||||
}
|
||||
let amount_untaxed = this.totals.amount_untaxed;
|
||||
let amount_untaxed = totals.amount_untaxed;
|
||||
let amount_tax = 0;
|
||||
let subtotals = [];
|
||||
for (let subtotal_title of this.totals.subtotals_order) {
|
||||
for (let subtotal_title of totals.subtotals_order) {
|
||||
let amount_total = amount_untaxed + amount_tax;
|
||||
subtotals.push({
|
||||
'name': subtotal_title,
|
||||
'amount': amount_total,
|
||||
'formatted_amount': this._format(amount_total),
|
||||
'formatted_amount': formatMonetary(amount_total, currencyFmtOpts),
|
||||
});
|
||||
let group = this.totals.groups_by_subtotal[subtotal_title];
|
||||
let group = totals.groups_by_subtotal[subtotal_title];
|
||||
for (let i in group) {
|
||||
amount_tax = amount_tax + group[i].tax_group_amount;
|
||||
}
|
||||
}
|
||||
this.totals.subtotals = subtotals;
|
||||
totals.subtotals = subtotals;
|
||||
let amount_total = amount_untaxed + amount_tax;
|
||||
this.totals.amount_total = amount_total;
|
||||
this.totals.formatted_amount_total = this._format(amount_total);
|
||||
for (let group_name of Object.keys(this.totals.groups_by_subtotal)) {
|
||||
let group = this.totals.groups_by_subtotal[group_name];
|
||||
for (let i in group) {
|
||||
group[i].formatted_tax_group_amount = this._format(group[i].tax_group_amount);
|
||||
group[i].formatted_tax_group_base_amount = this._format(group[i].tax_group_base_amount);
|
||||
totals.amount_total = amount_total;
|
||||
totals.formatted_amount_total = formatMonetary(amount_total, currencyFmtOpts);
|
||||
for (let group_name of Object.keys(totals.groups_by_subtotal)) {
|
||||
let group = totals.groups_by_subtotal[group_name];
|
||||
for (let key in group) {
|
||||
group[key].formatted_tax_group_amount = formatMonetary(group[key].tax_group_amount, currencyFmtOpts);
|
||||
group[key].formatted_tax_group_base_amount = formatMonetary(group[key].tax_group_base_amount, currencyFmtOpts);
|
||||
}
|
||||
}
|
||||
this.totals = totals;
|
||||
}
|
||||
}
|
||||
TaxTotalsComponent.template = "account.TaxTotalsField";
|
||||
|
||||
Reference in New Issue
Block a user