Page 1 of 1

Sales Quote Line Update Optimization

PostPosted: Tue Jan 09, 2018 7:02 pm
by nsbandara
Jiwa version : 7.0.129

I'm working on a plugin that updates open sales quote entries when an inventory item is updated.

Code: Select all
        List<OpenQuotesLines> openQuoteLines = ReadOpenQuoteLines(inventory.InventoryID); //read quote ids, line keys
        if (openQuoteLines.Any())
        {
            string[] openQuotes = openQuoteLines.Select(ql => ql.InvoiceID).Distinct().ToArray();
            JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote quoteBo = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic<JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuote>(null);

            foreach (string openQuote in openQuotes)
            {
                quoteBo.Read(openQuote);

                string[] quoteLines = openQuoteLines.Where(ql => ql.InvoiceID == openQuote).Select(ql => ql.InvoiceLineID).ToArray();
                foreach (var quoteLineKey in quoteLines)
                {
                    JiwaFinancials.Jiwa.JiwaSales.SalesQuote.SalesQuoteLine quoteLine = quoteBo.SalesQuoteLines[quoteLineKey];
                       
                    quoteLine.Description = inventory.Description;
                    quoteLine.ClassificationDescription = inventory.Classification.Description;
                    quoteLine.Units = inventory.UnitMeasure;
                    quoteLine.Cat1Description = inventory.Category1.Description;
                    quoteLine.Cat2Description = inventory.Category2.Description;
                    quoteLine.Cat3Description = inventory.Category3.Description;
                    quoteLine.CostIn = inventory.LCost;
                   quoteLine.SellPriceExGST = inventory.LCost; //price update, use jiwa library to update GST calc
                }

                quoteBo.Save();
            }

        }


If there was no price update I could run a SQL command to update other fields. But since we need to update prices I had to use Jiwa library functions. Issue I'm experiencing is it gets really slow as it load whole quote entry when do the update.

My questions are
1) Is there any alternative option to do the sales quote update including item price ?
2) Does Quote.Save() support async execution?

Thanks.

Re: Sales Quote Line Update Optimization  Topic is solved

PostPosted: Tue Jan 16, 2018 12:59 pm
by Mike.Sheen
nsbandara wrote:1) Is there any alternative option to do the sales quote update including item price ?


No - using the existing quote business logic is the only way to ensure the business logic rules are enforced and all relevant fields calculated correctly.

nsbandara wrote:2) Does Quote.Save() support async execution?


No - the Save method of the quote does in fact use asynchronous calls for saving the lines, notes, documents, et cetera - but the save itself is synchronous. You could still make your code asynchronous, however - and it would result in asynchronously reading and saving all those quotes.