public void BaseOnDerive(ObjectOnDerive method) { var derivation = method.Derivation; var defaultLocale = this.Strategy.Session.GetSingleton().DefaultLocale; var settings = this.Strategy.Session.GetSingleton().Settings; var identifications = this.ProductIdentifications; identifications.Filter.AddEquals(M.ProductIdentification.ProductIdentificationType, new ProductIdentificationTypes(this.Strategy.Session).Good); var goodIdentification = identifications.FirstOrDefault(); if (goodIdentification == null && settings.UseProductNumberCounter) { goodIdentification = new ProductNumberBuilder(this.Strategy.Session) .WithIdentification(settings.NextProductNumber()) .WithProductIdentificationType(new ProductIdentificationTypes(this.Strategy.Session).Good).Build(); this.AddProductIdentification(goodIdentification); } this.ProductNumber = goodIdentification.Identification; if (!this.ExistProductIdentifications) { derivation.Validation.AssertExists(this, M.Good.ProductIdentifications); } if (!this.ExistVariants) { derivation.Validation.AssertExists(this, M.NonUnifiedGood.Part); } if (this.LocalisedNames.Any(x => x.Locale.Equals(defaultLocale))) { this.Name = this.LocalisedNames.First(x => x.Locale.Equals(defaultLocale)).Text; } if (this.LocalisedDescriptions.Any(x => x.Locale.Equals(defaultLocale))) { this.Description = this.LocalisedDescriptions.First(x => x.Locale.Equals(defaultLocale)).Text; } this.DeriveVirtualProductPriceComponent(); }
public void BaseOnDerive(ObjectOnDerive method) { var derivation = method.Derivation; var defaultLocale = this.Strategy.Session.GetSingleton().DefaultLocale; var settings = this.Strategy.Session.GetSingleton().Settings; if (derivation.ChangeSet.HasChangedRoles(this, new RoleType[] { this.Meta.UnitOfMeasure, this.Meta.DefaultFacility })) { this.SyncDefaultInventoryItem(); } var identifications = this.ProductIdentifications; identifications.Filter.AddEquals(M.ProductIdentification.ProductIdentificationType, new ProductIdentificationTypes(this.Strategy.Session).Good); var goodIdentification = identifications.FirstOrDefault(); if (goodIdentification == null && settings.UseProductNumberCounter) { goodIdentification = new ProductNumberBuilder(this.Strategy.Session) .WithIdentification(settings.NextProductNumber()) .WithProductIdentificationType(new ProductIdentificationTypes(this.Strategy.Session).Good).Build(); this.AddProductIdentification(goodIdentification); } this.ProductNumber = goodIdentification.Identification; if (!this.ExistProductIdentifications) { derivation.Validation.AssertExists(this, M.Good.ProductIdentifications); } if (this.LocalisedNames.Any(x => x.Locale.Equals(defaultLocale))) { this.Name = this.LocalisedNames.First(x => x.Locale.Equals(defaultLocale)).Text; } if (this.LocalisedDescriptions.Any(x => x.Locale.Equals(defaultLocale))) { this.Description = this.LocalisedDescriptions.First(x => x.Locale.Equals(defaultLocale)).Text; } foreach (SupplierOffering supplierOffering in this.SupplierOfferingsWherePart) { if (supplierOffering.FromDate <= this.Session().Now() && (!supplierOffering.ExistThroughDate || supplierOffering.ThroughDate >= this.Session().Now())) { this.AddSuppliedBy(supplierOffering.Supplier); } if (supplierOffering.FromDate > this.Session().Now() || (supplierOffering.ExistThroughDate && supplierOffering.ThroughDate < this.Session().Now())) { this.RemoveSuppliedBy(supplierOffering.Supplier); } } this.DeriveVirtualProductPriceComponent(); this.DeriveProductCharacteristics(derivation); this.DeriveQuantityOnHand(); this.DeriveAvailableToPromise(); this.DeriveQuantityCommittedOut(); this.DeriveQuantityExpectedIn(); var quantityOnHand = 0M; var totalCost = 0M; foreach (InventoryItemTransaction inventoryTransaction in this.InventoryItemTransactionsWherePart) { var reason = inventoryTransaction.Reason; if (reason.IncreasesQuantityOnHand == true) { quantityOnHand += inventoryTransaction.Quantity; var transactionCost = inventoryTransaction.Quantity * inventoryTransaction.Cost; totalCost += transactionCost; var averageCost = quantityOnHand > 0 ? totalCost / quantityOnHand : 0M; ((PartWeightedAverageDerivedRoles)this.PartWeightedAverage).AverageCost = decimal.Round(averageCost, 2); } else if (reason.IncreasesQuantityOnHand == false) { quantityOnHand -= inventoryTransaction.Quantity; totalCost = quantityOnHand * this.PartWeightedAverage.AverageCost; } } }