From cd663d99b7326dd9b8b95c66796c0ef24995eaa9 Mon Sep 17 00:00:00 2001
From: elforjani13 <39470382+elforjani13@users.noreply.github.com>
Date: Thu, 17 Feb 2022 19:07:58 +0200
Subject: [PATCH] fix(invoice): foreign customer.
---
.../Invoices/InvoiceForm/InvoiceFormHeaderFields.js | 6 ++++--
.../Sales/Invoices/InvoiceForm/InvoiceFormPage.js | 10 ++++++++--
.../Invoices/InvoiceForm/InvoiceFormProvider.js | 12 ++++++++----
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.js b/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.js
index 760ffcab2..31d48a57f 100644
--- a/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.js
+++ b/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormHeaderFields.js
@@ -57,7 +57,8 @@ function InvoiceFormHeaderFields({
invoiceNextNumber,
}) {
// Invoice form context.
- const { customers, isForeignCustomer } = useInvoiceFormContext();
+ const { customers, isForeignCustomer, setSelectCustomer } =
+ useInvoiceFormContext();
// Handle invoice number changing.
const handleInvoiceNumberChange = () => {
@@ -109,6 +110,7 @@ function InvoiceFormHeaderFields({
defaultSelectText={}
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
+ setSelectCustomer(customer);
}}
popoverFill={true}
allowCreate={true}
@@ -120,7 +122,7 @@ function InvoiceFormHeaderFields({
{/* ----------- Exchange rate ----------- */}
-
+
+
);
}
+export default compose(withCurrentOrganization())(InvoiceFormPage);
diff --git a/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormProvider.js b/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormProvider.js
index 488d3d21f..3e3155c63 100644
--- a/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormProvider.js
+++ b/src/containers/Sales/Invoices/InvoiceForm/InvoiceFormProvider.js
@@ -1,5 +1,5 @@
import React, { createContext, useState } from 'react';
-import { isEmpty, pick } from 'lodash';
+import { isEmpty, pick, isEqual, isUndefined } from 'lodash';
import { useLocation } from 'react-router-dom';
import DashboardInsider from 'components/Dashboard/DashboardInsider';
import { transformToEditForm, ITEMS_FILTER_ROLES_QUERY } from './utils';
@@ -20,7 +20,7 @@ const InvoiceFormContext = createContext();
/**
* Accounts chart data provider.
*/
-function InvoiceFormProvider({ invoiceId, ...props }) {
+function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
const { state } = useLocation();
const estimateId = state?.action;
@@ -70,6 +70,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
// Form submit payload.
const [submitPayload, setSubmitPayload] = useState();
+ const [selectCustomer, setSelectCustomer] = useState(null);
// Detarmines whether the form in new mode.
const isNewMode = !invoiceId;
@@ -78,9 +79,10 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
const isFeatureLoading = isWarehouesLoading || isBranchesLoading;
// Determines whether the foreign customer.
- const isForeignCustomer = false;
+ const isForeignCustomer =
+ !isEqual(selectCustomer?.currency_code, baseCurrency) &&
+ !isUndefined(selectCustomer?.currency_code);
- // Provider payload.
const provider = {
invoice,
items,
@@ -89,6 +91,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
estimateId,
invoiceId,
submitPayload,
+ selectCustomer,
branches,
warehouses,
@@ -104,6 +107,7 @@ function InvoiceFormProvider({ invoiceId, ...props }) {
createInvoiceMutate,
editInvoiceMutate,
setSubmitPayload,
+ setSelectCustomer,
isNewMode,
};