Hello i need a example to create or update a new Purchase of a items
Hello i have this code
// Add customer
Movement objMovement = Movement.NewMovement(MovementType.Ordered, false);
var _with1 = objMovement;
_with1.OrderLoadType = MovementOrderLoadType.New;
_with1.DestinationID = Guid.Parse("903cba2c-d515-4558-9777-97b159f01037");
_with1.BusinessPartnerID = Guid.Parse("6303c86e-e542-4f34-a7b8-427b9fa9c35a");
_with1.MovementID = Guid.NewGuid();
_with1.MovementNumber = "MOV-123";
_with1.BackOrderNumber = "O-123";
_with1.MovementProducts("643534").Quantity = 100;
and i have this error MovementProducts is not invocable please help
Hello Bernardo. You may have the movement type incorrect. If you’re purchasing available (for rent) products then you can use the code below. For new products use MovementType.PurchaseNew, etc. You also want to pass ‘true’ into the second parameter in order to load all of the products. This is optional because sometimes you may want to edit and loading all of the products is (relatively) expensive on performance.
// Create new purchase for rent
Movement purchase = Movement.NewMovement(MovementType.PurchaseForRent, true);
// Set the destination ID
purchase.DestinationID = stockingLocationID;
// If products contain the part, set the qty and price
if (purchase.MovementProducts.Contains("ABC123"))
{
purchase.MovementProducts["ABC123"].Quantity = 100;
purchase.MovementProducts["ABC123"].PurchasePrice = (decimal)45.21;
}
// Save
purchase.Save();
Hello. This topic title is now to purchase available products. You asked this question in the other topic, which has been answered: Quantity of my inventory of an item
Thank you very much, I did not know that they did the same. I’ll prove it and I’ll tell you thanks in advance
Hi, I am trying to make a purchase of an article that I have in my product catalog, with the example code, this is my code:
string PartNumber = "4518171";
string Description = "Prueba";
string qty = "1";
string com = "Purge";
double qtyd = Convert.ToDouble(qty);
var Adj = ProductStoked.FirstOrDefault(prod => prod.PartNumber == PartNumber);
var product = Product_.FirstOrDefault(prod => prod.PartNumber == PartNumber);
// Create new purchase for rent
Movement purchase = Movement.NewMovement(MovementType.PurchaseForRent, true);
// Set the destination ID
purchase.DestinationID = Guid.Parse("B60B0A50-4678-4444-B920-31E497307B7A");
// If products contain the part, set the qty and price
if (purchase.MovementProducts.Contains(PartNumber))
{
purchase.MovementProducts[PartNumber].Quantity = qtyd;
purchase.MovementProducts[PartNumber].Comment = "Activo fijo nuevo desde SAP";
}
// Save
purchase.Save();
The error is an uncontrolled exception :
I have no idea what it may be, please urge me this
As you can see the article that I am buying if it exists in my product catalog:
thanks
Hello. The error is “Object is not valid and cannot be saved”. In order to find out what the issue is, please read this article and add checks for the BusinessRules.
Sorry, the example code they gave me I’m running as they gave it to me, I can not verify the error. The most logical thing is that if you give an example it works correctly, thank you very much
Hello. Unfortunately there’s no way to give you exact code that will work as everyone’s data is different. If you follow the example on the broken rules you’ll be able to put a breakpoint right before saving the object and see what rules are broken. You’ll also want to repeat the loop on the child collections as one of them could be invalid as well.