Page 1 of 1

error on BinLocationCollection.Read

PostPosted: Wed Aug 03, 2016 11:24 pm
by perry
Hi,
I think even this maybe a bug but still is technical/programming related.

It took me all day to debug this, so I would like to share my pain :twisted:.

Details: (Jiwa: 7.0.157)
I get "Object reference not set to an instance of an object." on
Code: Select all
 _Inventory = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
_Inventory.Read(_InventoryID)


error as below:
Code: Select all
   at JiwaFinancials.Jiwa.JiwaInventory.BinLocationCollection.Read()
   at JiwaFinancials.Jiwa.JiwaInventory.Inventory.Read(String RecID)
   at Lonicera.Jiwa.Standard.EDI.BL.OrderLine..ctor(Int64 EDIOrderLineID, Int64 EDIOrderID, Int32 OrderLineNo, String OrderItemCode, String OrderItemCodeType, String OrderItemCode2, String OrderItemCodeType2, String OrderItemDescription, Decimal OrderQty, Decimal OrderPackSize, Decimal OrderPrice, Decimal OrderTaxRate, String JiwaPartNo, String JiwaBarCode, Decimal JiwaQtyAvailable, Decimal JiwaQtyAssigned, Decimal JiwaPrice, Decimal JiwaPriceOverwrite, String ManuallySelectedPartNo, Boolean DonotImportThisLine, Boolean LineUpdated, Int32 QuantityDecimalPlaces, String InventoryID, String _JiwaInvoiceID, String _JiwaInvoiceLineID, OrderLines Lines)
   at Lonicera.Jiwa.Standard.EDI.BL.OrderLines.Read()
   at Lonicera.Jiwa.Standard.EDI.BL.Order.Read(String RecID)


the problem:
Code: Select all
_SalesOrder = JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaSales.SalesOrder.SalesOrder)(Nothing)

RaiseEvent ProcessStart(Me, _SalesOrder, New System.EventArgs())

With _SalesOrder
   .CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)
   '.Warehouse.IN_LogicalID = WarehouseID 
   .OrderNo = Me.CustomerPONo
   .Reference = Me.EDIOrderReferenceNo
   .ExpectedDeliveryDate = Me.RequestedDeliveryDate
   .SalesOrderHistorys(1).Notes = Me.Comments
End With
'JiwaApplication.Manager.Instance.Database.CurrentLogicalWarehouseID
'JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.IN_LogicalID
           
For Each line As BL.OrderLine In _OrderLines

   If Not line.DonotImportThisLine Then
      With _SalesOrder.SalesOrderLines
         .AddInventoryItem(line.InventoryID, JiwaSales.SalesOrder.SalesOrderLineCollection.SalesOrderLineInventorySeedTypes.e_SalesOrderLineInventoryID, NewKey)
         If line.JiwaQtyAssigned = 0 Then
            .Item(NewKey).QuantityOrdered = line.OrderQty
         Else
            .Item(NewKey).QuantityOrdered = line.JiwaQtyAssigned
         End If

         .Item(NewKey).DiscountedPrice = line.JiwaPriceOverwrite

         line.AssignMapping(_SalesOrder.RecID, NewKey)
      End With
   End If
Next
Me.OrderApproved = True

RaiseEvent ProcessEnding(Me, _SalesOrder, New System.EventArgs())
_SalesOrder.Save()

Me.Save()

RaiseEvent ProcessEnd(Me, _SalesOrder, New System.EventArgs())


I was using below to create order in a different warehouse.
Code: Select all
.Warehouse.IN_LogicalID = WarehouseID 

Code was done pre v7.0.8x, so I dont remember why I didnt set logicalID in .CreateNew()...

so, after the code above, below variables actually hold different value. i.e. one is the current logical warehouse ID, the other become warehouse that order resides in
Code: Select all
'JiwaApplication.Manager.Instance.Database.CurrentLogicalWarehouseID
'JiwaApplication.Manager.Instance.CurrentLogicalWarehouse.IN_LogicalID


now you get the error if you do Inventory.Read(InventoryID) on any item. This also happens to other plugins triggered by above code(e.g. line added/updated etc etc).

Fix:
Code: Select all
SalesOrder.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)


This is an unusual scenario but I think the error on BinLocationCollection.Read() may still be a bug.

Re: error on BinLocationCollection.Read

PostPosted: Thu Aug 11, 2016 8:13 pm
by Mike.Sheen
Hi Perry,

So If I am to understand this correctly, your problem is that setting the warehouse by performing

Code: Select all
.Warehouse.IN_LogicalID = WarehouseID


where the WarehouseID is different to the current warehouse, you get the "Object reference not set to an instance of an object" exception when subsequently creating a new inventory business logic and reading:

Code: Select all
 _Inventory = JiwaFinancials.Jiwa.JiwaApplication.Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of JiwaFinancials.Jiwa.JiwaInventory.Inventory)(Nothing)
_Inventory.Read(_InventoryID)


But to work around that you found that rather than doing this, passing the warehouseID as a parameter of the CreateNew for the sales order, i.e.:

Code: Select all
.CreateNew(JiwaSales.SalesOrder.SalesOrder.NewSalesOrderTypes.e_NewSalesOrder, Debtor.DebtorID, True,,,, WarehouseID)


Then the exception does not occur. Is that correct?

Re: error on BinLocationCollection.Read

PostPosted: Fri Aug 12, 2016 12:45 pm
by perry
Yes, 100%

Re: error on BinLocationCollection.Read  Topic is solved

PostPosted: Sat Nov 12, 2016 12:04 pm
by Mike.Sheen
Hi Perry,

This is because the Warehouse of the Sales Order is actually a reference to the Current Logical Warehouse of the system. Setting the properties of that will cause problems when other objects need to reference the current warehouse (As Inventory does to read certain things) if the values are inconsistent - so by setting the SalesOrder.Warehouse.IN_LogicalID you've introduced inconsistency as that warehouse object sits inside a logical warehouse collection which sits inside a physical warehouse inside a physical warehouse collection.

We should really make those properties read-only so you can't introduce inconsistency, or at least have the sales order Warehouse property be a copy of the current logical warehouse when instantiated rather than a reference to it.

I've logged DEV-5657 to address this.

Mike