public static SalesInvoiceBuilder WithSalesExternalB2CInvoiceDefaults(this SalesInvoiceBuilder @this, Organisation internalOrganisation) { var faker = @this.Session.Faker(); var customer = internalOrganisation.ActiveCustomers.Where(v => v.GetType().Name == typeof(Person).Name).FirstOrDefault(); var salesInvoiceItem_Default = new SalesInvoiceItemBuilder(@this.Session).WithDefaults().Build(); var salesInvoiceItem_Product = new SalesInvoiceItemBuilder(@this.Session).WithProductItemDefaults().Build(); var salesInvoiceItem_Part = new SalesInvoiceItemBuilder(@this.Session).WithPartItemDefaults().Build(); var salesInvoiceType = new SalesInvoiceTypes(@this.Session).SalesInvoice; var paymentMethod = faker.Random.ListItem(@this.Session.Extent <PaymentMethod>()); @this.WithCustomerReference(faker.Random.String(16).ToUpper(CultureInfo.CurrentCulture)); @this.WithBilledFrom(internalOrganisation); @this.WithBilledFromContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault()); @this.WithDescription(faker.Lorem.Sentence()); @this.WithComment(faker.Lorem.Sentence()); @this.WithInternalComment(faker.Lorem.Sentence()); @this.WithBillToCustomer(customer); @this.WithShipToCustomer(customer); @this.WithSalesInvoiceType(salesInvoiceType); @this.WithTotalListPrice(faker.Random.Decimal()); @this.WithAssignedPaymentMethod(paymentMethod); @this.WithSalesInvoiceItem(salesInvoiceItem_Default); @this.WithSalesInvoiceItem(salesInvoiceItem_Product); @this.WithSalesInvoiceItem(salesInvoiceItem_Part); @this.WithAdvancePayment(faker.Random.Decimal()); @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaultsForPaymentNetDays().Build()); @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build()); @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build()); @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build()); return(@this); }
public static SalesInvoiceBuilder WithSalesInternalInvoiceDefaults(this SalesInvoiceBuilder @this, Organisation internalOrganisation) { var faker = @this.Session.Faker(); var internalOrganisations = @this.Session.Extent <Organisation>(); var otherInternalOrganization = internalOrganisations.Except(new List <Organisation> { internalOrganisation }).FirstOrDefault(); var endCustomer = faker.Random.ListItem(internalOrganisation.ActiveCustomers); var salesInvoiceItem_Default = new SalesInvoiceItemBuilder(@this.Session).WithDefaults().Build(); var salesInvoiceItem_Product = new SalesInvoiceItemBuilder(@this.Session).WithProductItemDefaults().Build(); var salesInvoiceItem_Part = new SalesInvoiceItemBuilder(@this.Session).WithPartItemDefaults().Build(); var salesInvoiceType = new SalesInvoiceTypes(@this.Session).SalesInvoice; var paymentMethod = faker.Random.ListItem(@this.Session.Extent <PaymentMethod>()); @this.WithCustomerReference(faker.Random.String(16).ToUpper(CultureInfo.CurrentCulture)); @this.WithBilledFrom(internalOrganisation); @this.WithBilledFromContactMechanism(internalOrganisation.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault()); @this.WithBilledFromContactPerson(internalOrganisation.CurrentContacts.FirstOrDefault()); @this.WithDescription(faker.Lorem.Sentence()); @this.WithComment(faker.Lorem.Sentence()); @this.WithInternalComment(faker.Lorem.Sentence()); @this.WithBillToCustomer(otherInternalOrganization.CurrentContacts.FirstOrDefault()); @this.WithBillToContactMechanism(otherInternalOrganization.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault()); @this.WithBillToContactPerson(otherInternalOrganization.CurrentContacts.FirstOrDefault()); @this.WithBillToEndCustomer(endCustomer); @this.WithBillToEndCustomerContactMechanism(endCustomer.CurrentPartyContactMechanisms.Select(v => v.ContactMechanism).FirstOrDefault()); @this.WithBillToEndCustomerContactPerson(endCustomer.CurrentContacts.FirstOrDefault()); @this.WithShipToEndCustomer(endCustomer); @this.WithShipToEndCustomerAddress(endCustomer.ShippingAddress); @this.WithShipToEndCustomerContactPerson(endCustomer.CurrentContacts.FirstOrDefault()); @this.WithShipToCustomer(otherInternalOrganization); @this.WithShipToAddress(otherInternalOrganization.ShippingAddress); @this.WithShipToContactPerson(otherInternalOrganization.CurrentContacts.FirstOrDefault()); @this.WithSalesInvoiceType(salesInvoiceType); @this.WithTotalListPrice(faker.Random.Decimal()); @this.WithPaymentMethod(paymentMethod); @this.WithSalesInvoiceItem(salesInvoiceItem_Default); @this.WithSalesInvoiceItem(salesInvoiceItem_Product); @this.WithSalesInvoiceItem(salesInvoiceItem_Part); @this.WithAdvancePayment(faker.Random.Decimal()); @this.WithPaymentDays(faker.Random.Int(7, 30)); @this.WithIsRepeatingInvoice(faker.Random.Bool()); @this.WithSalesTerm(new IncoTermBuilder(@this.Session).WithDefaults().Build()); @this.WithSalesTerm(new InvoiceTermBuilder(@this.Session).WithDefaults().Build()); @this.WithSalesTerm(new OrderTermBuilder(@this.Session).WithDefaults().Build()); return(@this); }
public void GivenSalesInvoice_WhenDeriving_ThenRequiredRelationsMustExist() { var customer = new OrganisationBuilder(this.DatabaseSession).WithName("customer").Build(); var mechelen = new CityBuilder(this.DatabaseSession).WithName("Mechelen").Build(); ContactMechanism billToContactMechanism = new PostalAddressBuilder(this.DatabaseSession).WithGeographicBoundary(mechelen).WithAddress1("Haverwerf 15").Build(); new CustomerRelationshipBuilder(this.DatabaseSession) .WithCustomer(customer) .WithInternalOrganisation(Singleton.Instance(this.DatabaseSession).DefaultInternalOrganisation) .Build(); this.DatabaseSession.Commit(); var builder = new SalesInvoiceBuilder(this.DatabaseSession); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithSalesInvoiceType(new SalesInvoiceTypes(this.DatabaseSession).SalesInvoice); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithBillToCustomer(customer); builder.Build(); Assert.IsTrue(this.DatabaseSession.Derive().HasErrors); this.DatabaseSession.Rollback(); builder.WithBillToContactMechanism(billToContactMechanism); var invoice = builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); Assert.AreEqual(invoice.CurrentInvoiceStatus.SalesInvoiceObjectState, new SalesInvoiceObjectStates(this.DatabaseSession).ReadyForPosting); Assert.AreEqual(invoice.CurrentObjectState, new SalesInvoiceObjectStates(this.DatabaseSession).ReadyForPosting); Assert.AreEqual(invoice.CurrentObjectState, invoice.LastObjectState); builder.WithBilledFromInternalOrganisation(new InternalOrganisations(this.DatabaseSession).FindBy(InternalOrganisations.Meta.Name, "internalOrganisation")); builder.Build(); Assert.IsFalse(this.DatabaseSession.Derive().HasErrors); }