Skip to content

Commit

Permalink
[FIX] partner_autocomplete : Suggestions available in tax field for GST
Browse files Browse the repository at this point in the history
Suggestions can now be accessed by entering a GST number in the Tax
ID field of the contact form.

Add the option of allowing completion even with an 'insufficient
credit' error.

closes #143532

X-original-commit: 2e47f94
Signed-off-by: Louis Baudoux (lba) <lba@odoo.com>
  • Loading branch information
deda-odoo committed Nov 25, 2023
1 parent 050cca4 commit eec7d8b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Expand Up @@ -36,8 +36,7 @@ export function usePartnerAutocomplete() {
return checkVATNumber(sanitizeVAT(value));
}

async function checkGSTNumber(value) {
// Lazyload jsvat only if the component is being used.
function isGSTNumber(value) {
// Check if the input is a valid GST number.
let isGST = false;
if (value && value.length === 15) {
Expand All @@ -55,10 +54,16 @@ export function usePartnerAutocomplete() {
return isGST;
}

async function isTAXNumber(value) {
const isVAT = await isVATNumber(value);
const isGST = isGSTNumber(value);
return isVAT || isGST;
}

async function autocomplete(value) {
value = value.trim();

const isVAT = await isVATNumber(value) || await checkGSTNumber(value);
const isVAT = await isTAXNumber(value);
let odooSuggestions = [];
let clearbitSuggestions = [];
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -186,6 +191,15 @@ export function usePartnerAutocomplete() {
else {
notification.add(company_data.error_message);
}
if (company_data.city !== undefined) {
company.city = company_data.city;
}
if (company_data.street !== undefined) {
company.street = company_data.street;
}
if (company_data.zip !== undefined) {
company.zip = company_data.zip;
}
company_data = company;
}

Expand Down Expand Up @@ -328,5 +342,5 @@ export function usePartnerAutocomplete() {
notification.add(title);
}
}
return { autocomplete, getCreateData, isVATNumber };
return { autocomplete, getCreateData, isTAXNumber };
}
Expand Up @@ -21,7 +21,7 @@ export class PartnerAutoCompleteCharField extends CharField {

async validateSearchTerm(request) {
if (this.props.name == 'vat') {
return this.partner_autocomplete.isVATNumber(request);
return this.partner_autocomplete.isTAXNumber(request);
}
else {
return request && request.length > 2;
Expand Down

0 comments on commit eec7d8b

Please sign in to comment.