Retrieving customised inventory prices in bulk  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Re: Retrieving customised inventory prices in bulk

Postby Mike.Sheen » Mon Jul 25, 2022 4:53 pm

mls wrote:
Hey Mike, does it make sense to you to use a stateful SalesQuote (or SalesOrder) to solve this problem?


It's a novel approach... and it would work but there are some potential pitfalls - but they may not be an issue for your use case. Specifically what I'm thinking of is the quantity price breaks - ideally you want to get a list of prices for a customer your list of products and it return all the prices for each product - so multiple prices per product if there were quantity price breaks.

You could emulate that and achieve the 80/20 rule by doing what many web stores do and show prices as qty 1 : $x, qty 5 - 10: $y, qty 10+ : $z and using your novel stateful quote idea you'd add the same part 3 times to the quote, and with the respective quantities of 1, 6 and 11.

Or maybe your use case there is no quantity price breaks.

Try it and see how it works for you - if so, great!

If you're feeling generous, post back here how it worked out for you.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Retrieving customised inventory prices in bulk

Postby mls » Mon Apr 10, 2023 4:00 am

Hi, I'm getting a strange error when I try to create a SalesOrder through the API, am hoping to get some advice.

My request:

POST /SalesOrders

Body: { "DebtorID": "$DebtorID", "BranchID": "$BranchID"}

Here's the error I get, no matter which BranchID I try...and even when I omit BranchID from my request:

{
"ResponseStatus": {
"ErrorCode": "RecordNotFoundException",
"Message": "Branch with an ID of '' was not found.",
"StackTrace": "[SalesOrderPOSTRequest: 6/04/2023 6:18:50 AM]:\n[REQUEST: {SystemSettings:{},CashSales:{},JobCosting:{},DebtorID:001dfae3b68b4be18a68,CustomFieldValues:[],Notes:[],Documents:[],Payments:[],Lines:[],Histories:[],ASNs:[]}]\nJiwaFinancials.Jiwa.JiwaApplication.Exceptions.RecordNotFoundException: Branch with an ID of '' was not found.\r\n at JiwaFinancials.Jiwa.JiwaApplication.Entities.Sales.Branch.ReadRecord(String BranchIDToRead)\r\n at BusinessLogicPlugin.SalesOrder_CreateEnd(Object sender, EventArgs e)\r\n at JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance.OnCreateEnd()\r\n at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.CreateNew(NewSalesOrderTypes NewSalesOrderType, String DebtorSeed, Boolean DebtorSeedIsID, String InvoiceHistoryID, String JobID, String QuoteHistoryID, String LogicalWarehouseID)\r\n at JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder.DTO_Deserialise(SalesOrder SalesOrder)\r\n at JiwaFinancials.Jiwa.JiwaServiceModel.SalesOrderServices.Post(SalesOrderPOSTRequest request) in c:\\ProgramData\\Jiwa Financials\\Jiwa 7\\7.2.1\\SYSTEM\\SRV-SY4-DB01\\REDPOINT_DEV\\Plugins\\Admin\\Compile\\REST API\\REST API.cs:line 22252\r\n at lambda_method(Closure , Object , Object )\r\n at ServiceStack.Host.ServiceRunner`1.<ExecuteAsync>d__13.MoveNext()",
"Errors": []
}
}


Any ideas what might be causing this? I'm fairly sure this code was working when I last tried it (late last year) and I'm stumped.

Thanks,
Michael
mls
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Tue Jul 05, 2022 5:50 am
Topics Solved: 1

Re: Retrieving customised inventory prices in bulk

Postby SBarnes » Mon Apr 10, 2023 8:14 am

Usually something like the below will work for a sales order the Branch ID is not required at all

Code: Select all
{
    "DebtorID": "DebtorIDGoesHere",
    "Lines":[
        {
            "PartNo":"PartNoGoesHere" //This can be inventory Id instead
            "QuantityOrdered":1
        }
    ]
}


The code that deserialises the branch looks like the below, it is the Branch.ReadRecord that is throwing the error, so if the BranchID is given in any way, even an empty string it will fail as an empty string isn't null/nothing.


Code: Select all
                         If SalesOrder.BranchID IsNot Nothing Then
                            If SalesOrderStatus = SalesOrderStatuses.e_SalesOrderClosed Then
                                Throw New Exception("Cannot modify a closed order.")
                            Else
                                Branch.ReadRecord(SalesOrder.BranchID)
                            End If
                        ElseIf SalesOrder.BranchName IsNot Nothing Then
                            If SalesOrderStatus = SalesOrderStatuses.e_SalesOrderClosed Then
                                Throw New Exception("Cannot modify a closed order.")
                            Else
                                Branch.ReadRecordFromDescription(SalesOrder.BranchName)
                            End If
                        ElseIf SalesOrder.BranchDescription IsNot Nothing Then
                            If SalesOrderStatus = SalesOrderStatuses.e_SalesOrderClosed Then
                                Throw New Exception("Cannot modify a closed order.")
                            Else
                                Branch.ReadRecordFromDescription(SalesOrder.BranchDescription)
                            End If
                        End If
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Retrieving customised inventory prices in bulk

Postby mls » Mon Apr 10, 2023 10:09 am

Yeah, my original request didn't have the BranchID as I thought it wasn't required.

In any case, I get exactly the same error when I try a request in the format you suggested -- I've tested with both PartNo and InventoryID
mls
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Tue Jul 05, 2022 5:50 am
Topics Solved: 1

Re: Retrieving customised inventory prices in bulk

Postby SBarnes » Mon Apr 10, 2023 10:33 am

Using postman I was able to get the following body and post to create and a sales order on a demo database

Code: Select all
https://BaseURLHere/SalesOrders?apikey=APIKeyHere



Code: Select all
{
    "DebtorID": "00000000080000000002",
    "Lines":[
        {
            "PartNo":"8100044"
            "QuantityOrdered":1
        }
    ]
}


My advice would be to try a clean demo database and see if it works.

Also provide the details of exactly the post you are sending and the body.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Retrieving customised inventory prices in bulk

Postby mls » Mon Apr 10, 2023 10:46 am

Here are the curl requests I am sending

Code: Select all
curl \
   -H 'Content-Type: application/json' \
   -H "Authorization: Bearer <API KEY>" \
   -X POST <API BASE>/SalesOrders \
   -d '{"DebtorID":"<DebtorID>","Lines":[{"InventoryID": "<InventoryID>", "QuantityOrdered":1}]}'

curl \
   -H 'Content-Type: application/json' \
   -H "Authorization: Bearer <API KEY>" \
   -X POST <API BASE>/SalesOrders \
   -d '{"DebtorID":"<DebtorID>","Lines":[{"PartNo": "<PartNo>", "QuantityOrdered":1}]}'


The DebtorID, InventoryID and PartNo I am sending are all correct...they are all pulled directly from Jiwa.

The error message is the same as I mentioned before: Branch with an ID of '' was not found.
mls
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Tue Jul 05, 2022 5:50 am
Topics Solved: 1

Re: Retrieving customised inventory prices in bulk

Postby SBarnes » Mon Apr 10, 2023 10:57 am

And what happens if you make the same calls from postman with the debtor id and part no / inventory id hard coded in the body, because if you get the same error then I would suspect the error about reading the branch id is possibly being caused by some other plugin that is firing in the business logic rather than the REST API itself given that from what I can tell you aren't providing the branch id in any way.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Retrieving customised inventory prices in bulk

Postby mls » Mon Apr 10, 2023 11:02 am

I don't know what you mean by hardcoded in the body. I am using a real DebtorID/InventoryID that I am stripping out of the examples I post here.

I do get different errors if I change my request:

- send an incorrect DebtorID => "Debtor Not Found"
- omit the DebtorID field => "AccountNo, SenderEDIAddress or DebtorID was not supplied. This must be supplied for new sales orders."
mls
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Tue Jul 05, 2022 5:50 am
Topics Solved: 1

Re: Retrieving customised inventory prices in bulk

Postby SBarnes » Mon Apr 10, 2023 11:07 am

Yeah that is standard for the api but getting the branch id error when you don't even supply it is not, hence my suggestion it might be the side effect of another plugin, what I would suggest you do is raise the issue with the Jiwa customer so that it can be investigated unless Mike or Scott from Jiwa might have another suggestion.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Retrieving customised inventory prices in bulk

Postby mls » Mon Apr 10, 2023 11:10 am

I'll try that. Thanks for your help!

Michael
mls
Occasional Contributor
Occasional Contributor
 
Posts: 16
Joined: Tue Jul 05, 2022 5:50 am
Topics Solved: 1

PreviousNext

Return to REST API

Who is online

Users browsing this forum: No registered users and 2 guests