示例#1
0
        public void TestPurchaseQuantityIsAMultipleOfPackSize()
        {
            IZppSimulator zppSimulator = new global::Master40.SimulationMrp.impl.ZppSimulator();

            zppSimulator.StartTestCycle();

            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            IDbTransactionData persistedTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            List <T_PurchaseOrderPart> tPurchaseOrderParts = persistedTransactionData
                                                             .PurchaseOrderPartGetAll().GetAllAs <T_PurchaseOrderPart>();

            foreach (var tPurchaseOrderPart in tPurchaseOrderParts)
            {
                M_ArticleToBusinessPartner articleToBusinessPartner =
                    dbMasterDataCache.M_ArticleToBusinessPartnerGetAllByArticleId(
                        new Id(tPurchaseOrderPart.ArticleId))[0];
                Quantity multiplier = new Quantity(1);
                while (multiplier.GetValue() * articleToBusinessPartner.PackSize <
                       tPurchaseOrderPart.Quantity)
                {
                    multiplier.IncrementBy(new Quantity(1));
                }

                Quantity expectedPurchaseQuantity = new Quantity(multiplier.GetValue() *
                                                                 articleToBusinessPartner.PackSize);
                Assert.True(tPurchaseOrderPart.GetQuantity().Equals(expectedPurchaseQuantity),
                            $"Quantity of PurchaseOrderPart ({tPurchaseOrderPart}) ist not a multiple of packSize.");
            }
        }
示例#2
0
        /**
         * SE:I --> satisfy by orders PuOP
         */
        public EntityCollector Satisfy(Demand demand, Quantity demandedQuantity)
        {
            EntityCollector entityCollector = new EntityCollector();
            M_Article       article         = demand.GetArticle();
            DueTime         dueTime         = demand.GetStartTimeBackward();

            if (article.ToBuild)
            {
                throw new MrpRunException(
                          "You try to create a purchaseOrderPart for a articleToBuild.");
            }

            // currently only one businessPartner per article TODO: This could be changing
            M_ArticleToBusinessPartner articleToBusinessPartner =
                _dbMasterDataCache.M_ArticleToBusinessPartnerGetAllByArticleId(article.GetId())[0];
            M_BusinessPartner businessPartner =
                _dbMasterDataCache.M_BusinessPartnerGetById(new Id(articleToBusinessPartner
                                                                   .BusinessPartnerId));
            T_PurchaseOrder purchaseOrder = new T_PurchaseOrder();

            // [Name],[DueTime],[BusinessPartnerId]
            purchaseOrder.DueTime         = dueTime.GetValue();
            purchaseOrder.BusinessPartner = businessPartner;
            purchaseOrder.Name            = $"PurchaseOrder{article.Name} for " +
                                            $"businessPartner {purchaseOrder.BusinessPartner.Id}";

            // init a new purchaseOderPart
            T_PurchaseOrderPart tPurchaseOrderPart = new T_PurchaseOrderPart();

            // [PurchaseOrderId],[ArticleId],[Quantity],[State],[ProviderId]
            tPurchaseOrderPart.PurchaseOrder   = purchaseOrder;
            tPurchaseOrderPart.PurchaseOrderId = purchaseOrder.Id;
            tPurchaseOrderPart.Article         = article;
            tPurchaseOrderPart.ArticleId       = article.Id;
            tPurchaseOrderPart.Quantity        =
                CalculateQuantity(articleToBusinessPartner, demandedQuantity) *
                articleToBusinessPartner
                .PackSize;
            if (tPurchaseOrderPart.Quantity < demandedQuantity.GetValue())
            {
                throw new MrpRunException("You cannot purchase less than you need!");
            }

            tPurchaseOrderPart.State = State.Created;

            PurchaseOrderPart purchaseOrderPart =
                new PurchaseOrderPart(tPurchaseOrderPart, null);

            T_DemandToProvider demandToProvider = new T_DemandToProvider()
            {
                DemandId   = demand.GetId().GetValue(),
                ProviderId = purchaseOrderPart.GetId().GetValue(),
                Quantity   = demandedQuantity.GetValue()
            };

            entityCollector.Add(purchaseOrderPart);
            entityCollector.Add(demandToProvider);
            return(entityCollector);
        }