Ejemplo n.º 1
0
        public void GivenBasePriceForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated()
        {
            var vatRate21   = new VatRateBuilder(this.Session).WithRate(21).Build();
            var virtualGood = new NonUnifiedGoodBuilder(this.Session)
                              .WithProductIdentification(new ProductNumberBuilder(this.Session)
                                                         .WithIdentification("v101")
                                                         .WithProductIdentificationType(new ProductIdentificationTypes(this.Session).Good).Build())
                              .WithName("virtual gizmo")
                              .WithVatRate(vatRate21)
                              .WithUnitOfMeasure(new UnitsOfMeasure(this.Session).Piece)
                              .Build();

            var physicalGood = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            virtualGood.AddVariant(physicalGood);

            this.Session.Derive();

            var basePrice = new BasePriceBuilder(this.Session)
                            .WithDescription("baseprice")
                            .WithPrice(10)
                            .WithProduct(virtualGood)
                            .WithFromDate(DateTime.UtcNow)
                            .Build();

            this.Session.Derive();

            Assert.Equal(1, physicalGood.VirtualProductPriceComponents.Count);
            Assert.Contains(basePrice, physicalGood.VirtualProductPriceComponents);
            Assert.False(virtualGood.ExistVirtualProductPriceComponents);
        }
Ejemplo n.º 2
0
        public void GivenBasePriceForVirtualProduct_WhenDeriving_ThenProductVirtualProductPriceComponentIsUpdated()
        {
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var virtualGood = new GoodBuilder(this.DatabaseSession)
                .WithName("virtual gizmo")
                .WithVatRate(vatRate21)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var physicalGood = new GoodBuilder(this.DatabaseSession)
                .WithName("real gizmo")
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            virtualGood.AddVariant(physicalGood);

            this.DatabaseSession.Derive(true);

            var basePrice = new BasePriceBuilder(this.DatabaseSession)
                .WithDescription("baseprice")
                .WithPrice(10)
                .WithProduct(virtualGood)
                .WithFromDate(DateTime.UtcNow)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(1, physicalGood.VirtualProductPriceComponents.Count);
            Assert.Contains(basePrice, physicalGood.VirtualProductPriceComponents);
            Assert.IsFalse(virtualGood.ExistVirtualProductPriceComponents);
        }
Ejemplo n.º 3
0
        public void GivenBasePrice_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var vatRate21 = new VatRateBuilder(this.Session).WithRate(21).Build();
            var good      = new Goods(this.Session).FindBy(M.Good.Name, "good1");

            var colorFeature = new ColourBuilder(this.Session)
                               .WithVatRate(vatRate21)
                               .WithName("black")
                               .Build();

            this.Session.Derive();
            this.Session.Commit();

            var builder = new BasePriceBuilder(this.Session);

            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithPrice(1);
            builder.Build();

            Assert.True(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithProduct(good);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithProductFeature(colorFeature);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);

            this.Session.Rollback();

            builder.WithFromDate(DateTime.UtcNow);
            builder.Build();

            Assert.False(this.Session.Derive(false).HasErrors);
        }
Ejemplo n.º 4
0
        public void GivenWorkEffortAndPartsUsed_WhenInvoiced_ThenPartsAreInvoiced()
        {
            var organisation = new Organisations(this.Session).Extent().First(o => o.IsInternalOrganisation);

            var customerEmail = new PartyContactMechanismBuilder(this.Session)
                                .WithContactMechanism(new EmailAddressBuilder(this.Session).WithElectronicAddressString($"*****@*****.**").Build())
                                .WithContactPurpose(new ContactMechanismPurposes(this.Session).BillingAddress)
                                .WithUseAsDefault(true)
                                .Build();

            var customer = new PersonBuilder(this.Session).WithLastName("Customer").WithPartyContactMechanism(customerEmail).Build();

            new CustomerRelationshipBuilder(this.Session).WithCustomer(customer).WithInternalOrganisation(organisation).Build();

            var employee = new PersonBuilder(this.Session).WithFirstName("Good").WithLastName("Worker").Build();

            new EmploymentBuilder(this.Session).WithEmployee(employee).WithEmployer(organisation).Build();

            var yesterday = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(-1));

            var today      = DateTimeFactory.CreateDateTime(this.Session.Now());
            var laterToday = DateTimeFactory.CreateDateTime(today.AddHours(4));

            var tomorrow = DateTimeFactory.CreateDateTime(this.Session.Now().AddDays(1));

            var part1 = this.CreatePart("P1");

            new InventoryItemTransactionBuilder(this.Session)
            .WithPart(part1)
            .WithReason(new InventoryTransactionReasons(this.Session).IncomingShipment)
            .WithQuantity(11)
            .Build();

            var part1BasePriceYesterday = new BasePriceBuilder(this.Session)
                                          .WithDescription("baseprice part1")
                                          .WithPrice(9)
                                          .WithPart(part1)
                                          .WithFromDate(yesterday)
                                          .WithThroughDate(today)
                                          .Build();

            var part1BasePriceToday = new BasePriceBuilder(this.Session)
                                      .WithDescription("baseprice part1")
                                      .WithPrice(10)
                                      .WithPart(part1)
                                      .WithFromDate(today)
                                      .WithThroughDate(tomorrow)
                                      .Build();

            var part1BasePriceTomorrow = new BasePriceBuilder(this.Session)
                                         .WithDescription("baseprice part1")
                                         .WithPrice(11)
                                         .WithPart(part1)
                                         .WithFromDate(tomorrow)
                                         .Build();

            var workOrder = new WorkTaskBuilder(this.Session).WithName("Task").WithCustomer(customer).Build();

            this.Session.Derive(true);

            var timeEntryToday = new TimeEntryBuilder(this.Session)
                                 .WithRateType(new RateTypes(this.Session).StandardRate)
                                 .WithFromDate(today)
                                 .WithThroughDate(laterToday)
                                 .WithWorkEffort(workOrder)
                                 .WithBillingRate(12)
                                 .Build();

            employee.TimeSheetWhereWorker.AddTimeEntry(timeEntryToday);

            new WorkEffortInventoryAssignmentBuilder(this.Session).WithAssignment(workOrder).WithInventoryItem(part1.InventoryItemsWherePart.First).WithQuantity(3).Build();

            this.Session.Derive(true);

            workOrder.Complete();

            this.Session.Derive(true);

            workOrder.Invoice();

            this.Session.Derive(true);

            var salesInvoice = customer.SalesInvoicesWhereBillToCustomer.First;

            Assert.Equal(2, salesInvoice.InvoiceItems.Length);
            Assert.Equal(10, workOrder.WorkEffortBillingsWhereWorkEffort.First.InvoiceItem.ActualUnitPrice);
            Assert.Equal(30, workOrder.WorkEffortBillingsWhereWorkEffort.First.InvoiceItem.TotalBasePrice);
        }
Ejemplo n.º 5
0
        public void GivenBasePrice_WhenDeriving_ThenRequiredRelationsMustExist()
        {
            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("gizmo")
                .WithSku("10101")
                .WithVatRate(vatRate21)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .Build();

            var colorFeature = new ColourBuilder(this.DatabaseSession)
                .WithName("golden")
                .WithVatRate(vatRate21)
                .WithLocalisedName(new LocalisedTextBuilder(this.DatabaseSession)
                                            .WithText("black")
                                            .WithLocale(Singleton.Instance(this.DatabaseSession).DefaultLocale)
                                            .Build())
                .Build();

            this.DatabaseSession.Derive(true);
            this.DatabaseSession.Commit();

            var builder = new BasePriceBuilder(this.DatabaseSession);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithPrice(1);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithProduct(good);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithProductFeature(colorFeature);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithFromDate(DateTime.UtcNow);
            builder.Build();

            Assert.IsTrue(this.DatabaseSession.Derive().HasErrors);

            this.DatabaseSession.Rollback();

            builder.WithDescription("description");
            builder.Build();

            Assert.IsFalse(this.DatabaseSession.Derive().HasErrors);
        }