Skip to content

Commit

Permalink
Update for Issue allors#46
Browse files Browse the repository at this point in the history
- Implements SalesOrder Transfer feature
- Domain Test (WIP)
- Updates Clone Function
- Updates Derivation
  • Loading branch information
jubayerarefin committed Jul 23, 2020
1 parent 4f92b18 commit 917fbc2
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 112 deletions.
111 changes: 27 additions & 84 deletions Base/Database/Diagrams/Temp2.cd
Original file line number Diff line number Diff line change
@@ -1,120 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Interface Name="Allors.Domain.SalesOrderItem">
<Position X="3" Y="2.75" Width="3.75" />
<TypeIdentifier>
<HashCode>CAAKJDkAEiAAAAAABAgAABAAAIABgCtAEACAATCAgAk=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="_s_SalesOrderItemInventoryAssignments" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.OrderShipment">
<Position X="8.5" Y="0.5" Width="1.5" />
<AssociationLine Name="OrderItem" Type="Allors.Domain.OrderItem" FixedToPoint="true">
<Path>
<Point X="8.5" Y="1" />
<Point X="6.5" Y="1" />
</Path>
</AssociationLine>
<TypeIdentifier>
<HashCode>AAAAAACAAAAAAAAIAAAAAAAAAAAAAAAAAAAAgAAAAAA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="OrderItem" />
<Property Name="ShipmentItem" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.OrderItem" Collapsed="true">
<Position X="3.25" Y="0.5" Width="3.25" />
<TypeIdentifier>
<HashCode>ACEAAAAAAUAgCAAAAAAAAAAAgBAAAAAAQIAAIAAAgQI=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="Allors.Domain.ShipmentItem">
<Position X="12.75" Y="0.5" Width="2.25" />
<TypeIdentifier>
<HashCode>AAAAAAQAIgAAAIAAAEQIAAAAAIAgAEBSAAAAgCAAAAE=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="ReservedFromInventoryItems" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.Shipment">
<Position X="17.25" Y="0.5" Width="2" />
<Interface Name="Allors.Domain.SalesOrder" Collapsed="true">
<Position X="4.75" Y="4.25" Width="2.75" />
<TypeIdentifier>
<HashCode>CAgAAogEAAAEEAAAAAAAAYAAAkAQQCBCAhZAIQAAAEA=</HashCode>
<HashCode>Cg9BAQhAAAQAAgQRABAABAAAoEAAtBgQAIQQGzLGQoA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="ShipmentItems" />
<Property Name="TakenBy" />
<Property Name="ShipToCustomer" />
<Property Name="BillToCustomer" />
<Property Name="SalesOrderItems" />
<Property Name="BillToEndCustomer" />
<Property Name="ShipToEndCustomer" />
<Property Name="OriginFacility" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.SalesOrder" Collapsed="true">
<Position X="0.5" Y="2.75" Width="1.5" />
<Interface Name="Allors.Domain.InternalOrganisation" Collapsed="true">
<Position X="9.75" Y="5.5" Width="1.75" />
<TypeIdentifier>
<HashCode>CAoBAQhAhgCAggYRhBABACAAgEAGtAhQAAQQAWJGggQ=</HashCode>
<HashCode>WgTAAAGESRYAAAKAUExQJxMKBgmtgoIACAECgAgxSAA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="SalesOrderItems" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.SalesOrderItemInventoryAssignment">
<Position X="8.5" Y="4" Width="2.75" />
<Interface Name="Allors.Domain.PartyFinancialRelationship" Collapsed="true">
<Position X="14" Y="5.75" Width="2" />
<TypeIdentifier>
<HashCode>AAAAAAgAAAAAAAAAAAAAAACAAAAAAAgAAAAAgIAAAAA=</HashCode>
<HashCode>AEAACAABAAAABAAAEAAAAAAAAAAAAADgASCACAAgAIA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="InventoryItem" />
<Property Name="___InventoryItemTransactions" />
<Property Name="InternalOrganisation" />
<Property Name="Party" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.InventoryItem">
<Position X="12.75" Y="5.25" Width="1.5" />
<Interface Name="Allors.Domain.Party" Collapsed="true">
<Position X="10.75" Y="3.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAIIAAAIAAAAAAAAAAAAQAAAAgAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>wYAoGAAAAoAAAIAQgEgACAgAQIARAhAQFYIFQANAogA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="Facility" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.InventoryItemTransaction">
<Position X="8.5" Y="6.75" Width="2" />
<Interface Name="Allors.Domain.SalesOrderItem" Collapsed="true">
<Position X="10.75" Y="8.25" Width="3.5" />
<TypeIdentifier>
<HashCode>AAAIIAAAIAAIAAIAAACAgAAAAAgAAAAEAAAAkCAAAAA=</HashCode>
<HashCode>KACKAAkAAAAAAIAhhQhAQAiAAoABAQqAAQGiGCRAgAE=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="___InventoryItem" />
<Property Name="AssignedShipToParty" />
<Property Name="_ShipToParty" />
</ShowAsAssociation>
</Interface>
<Interface Name="Allors.Domain.Facility" Collapsed="true">
<Position X="15.5" Y="6" Width="1.5" />
<Position X="10" Y="7.25" Width="1.5" />
<TypeIdentifier>
<HashCode>ABAAgACAAAAgAAAAAAAAAAQAAAAAAAABAAAAAEAAAAA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="Allors.Domain.NonSerialisedInventoryItem">
<Position X="11.25" Y="8.5" Width="3.25" />
<TypeIdentifier>
<HashCode>AAAAAAgAAACAACAABAAAAAMAAAAAAogEAAAAAAACAAA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="Allors.Domain.SerialisedInventoryItem" Collapsed="true">
<Position X="15" Y="8.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAkAAAAgAAAAAAAAgAAAAAIAAIgAAAAAACAAAAA=</HashCode>
<FileName>Generated\domain.g.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
161 changes: 151 additions & 10 deletions Base/Database/Domain.Tests/Order/SalesOrderTransferTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2690,20 +2690,161 @@ public class SalesOrderTransferSecurityTests : DomainTest
[Fact]
public void GivenSalesOrderBuilder_WhenProvisional_ThenOrderCanTransfer()
{
var customer = new PersonBuilder(this.Session).WithFirstName("Koen").Build();
var customer = new PersonBuilder(this.Session).WithFirstName("Jubayer").Build();
var internalOrganisation = this.InternalOrganisation;

var anotherInternalOrganisation = new OrganisationBuilder(this.Session)
.WithIsInternalOrganisation(true)
.WithDoAccounting(false)
.WithName("another internalOrganisation")
.WithPreferredCurrency(new Currencies(this.Session).CurrencyByCode["EUR"])
.WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
.WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
.WithPurchaseOrderNumberPrefix("purchase orderno: ")
.WithSubAccountCounter(new CounterBuilder(this.Session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build())
//Another InternalOrg Begins
var session = this.Session;
var singleton = session.GetSingleton();

var belgium = new Countries(session).CountryByIsoCode["BE"];
var euro = belgium.Currency;

var bank = new BankBuilder(session).WithCountry(belgium).WithName("ING België").WithBic("BBRUBEBB").Build();

var ownBankAccount = new OwnBankAccountBuilder(session)
.WithBankAccount(new BankAccountBuilder(session).WithBank(bank)
.WithCurrency(euro)
.WithIban("BE24557215223438")
.WithNameOnAccount("Jubayer")
.Build())
.WithDescription("Main bank account")
.Build();

var postalAddress = new PostalAddressBuilder(session)
.WithAddress1("Kleine Nieuwedijkstraat 2")
.WithLocality("Mechelen")
.WithCountry(belgium)
.Build();

var anotherInternalOrganisation = new OrganisationBuilder(session)
.WithIsInternalOrganisation(true)
.WithDoAccounting(false)
.WithName("internalOrganisation")
.WithPreferredCurrency(new Currencies(session).CurrencyByCode["EUR"])
.WithIncomingShipmentNumberPrefix("incoming shipmentno: ")
.WithPurchaseInvoiceNumberPrefix("incoming invoiceno: ")
.WithPurchaseOrderNumberPrefix("purchase orderno: ")
.WithDefaultCollectionMethod(ownBankAccount)
.WithSubAccountCounter(new CounterBuilder(session).WithUniqueId(Guid.NewGuid()).WithValue(0).Build())
.Build();

anotherInternalOrganisation.AddPartyContactMechanism(new PartyContactMechanismBuilder(session)
.WithUseAsDefault(true)
.WithContactMechanism(postalAddress)
.WithContactPurpose(new ContactMechanismPurposes(session).GeneralCorrespondence)
.WithContactPurpose(new ContactMechanismPurposes(session).BillingAddress)
.WithContactPurpose(new ContactMechanismPurposes(session).ShippingAddress)
.Build());

var facility = new FacilityBuilder(session)
.WithFacilityType(new FacilityTypes(session).Warehouse)
.WithName("facility")
.WithOwner(anotherInternalOrganisation)
.Build();

singleton.Settings.DefaultFacility = facility;

var collectionMethod = new PaymentMethods(session).Extent().First;

new StoreBuilder(session)
.WithName("store")
.WithBillingProcess(new BillingProcesses(session).BillingForShipmentItems)
.WithInternalOrganisation(anotherInternalOrganisation)
.WithOutgoingShipmentNumberPrefix("shipmentno: ")
.WithSalesInvoiceNumberPrefix("invoiceno: ")
.WithSalesOrderNumberPrefix("orderno: ")
.WithDefaultShipmentMethod(new ShipmentMethods(session).Ground)
.WithDefaultCarrier(new Carriers(session).Fedex)
.WithCreditLimit(500)
.WithPaymentGracePeriod(10)
.WithDefaultCollectionMethod(collectionMethod)
.WithIsImmediatelyPicked(false)
.WithAutoGenerateShipmentPackage(false)
.WithIsImmediatelyPacked(true)
.Build();

new ProductCategoryBuilder(session).WithName("Primary Category").Build();

anotherInternalOrganisation.CreateB2BCustomer(session.Faker());
anotherInternalOrganisation.CreateB2CCustomer(session.Faker());
anotherInternalOrganisation.CreateSupplier(session.Faker());
anotherInternalOrganisation.CreateSubContractor(session.Faker());

var purchaser = new PersonBuilder(session).WithFirstName("Mr").WithLastName("Purchaser").WithUserName("anotherPurchaser").Build();
var orderProcessor = new PersonBuilder(session).WithFirstName("Mr").WithLastName("OrderProcessor").WithUserName("anotherOrderProcessor").Build();

// Adding newly created persons to EmployeeUserGroup as employees do not have any permission when created
var employeesUserGroup = new UserGroups(session).Employees;
employeesUserGroup.AddMember(purchaser);
employeesUserGroup.AddMember(orderProcessor);

new UserGroups(session).Creators.AddMember(purchaser);
new UserGroups(session).Creators.AddMember(orderProcessor);

new EmploymentBuilder(session).WithFromDate(session.Now()).WithEmployee(purchaser).WithEmployer(anotherInternalOrganisation).Build();

new EmploymentBuilder(session).WithFromDate(session.Now()).WithEmployee(orderProcessor).WithEmployer(anotherInternalOrganisation).Build();

var good1 = new NonUnifiedGoodBuilder(session)
.WithProductIdentification(new ProductNumberBuilder(session)
.WithIdentification("1")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
.WithName("good1")
.WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
.WithPart(new NonUnifiedPartBuilder(session)
.WithProductIdentification(new PartNumberBuilder(session)
.WithIdentification("1")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
.WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
.Build();

var good2 = new NonUnifiedGoodBuilder(session)
.WithProductIdentification(new ProductNumberBuilder(session)
.WithIdentification("2")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
.WithName("good2")
.WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
.WithPart(new NonUnifiedPartBuilder(session)
.WithProductIdentification(new PartNumberBuilder(session)
.WithIdentification("2")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
.WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
.Build();

var good3 = new NonUnifiedGoodBuilder(session)
.WithProductIdentification(new ProductNumberBuilder(session)
.WithIdentification("3")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Good).Build())
.WithName("good3")
.WithUnitOfMeasure(new UnitsOfMeasure(session).Piece)
.WithPart(new NonUnifiedPartBuilder(session)
.WithProductIdentification(new PartNumberBuilder(session)
.WithIdentification("3")
.WithProductIdentificationType(new ProductIdentificationTypes(session).Part).Build())
.WithInventoryItemKind(new InventoryItemKinds(session).NonSerialised).Build())
.Build();

var catMain = new ProductCategoryBuilder(session).WithName("main cat").Build();

new ProductCategoryBuilder(session)
.WithName("cat for good1")
.WithPrimaryParent(catMain)
.WithProduct(good1)
.Build();

new ProductCategoryBuilder(session)
.WithName("cat for good2")
.WithPrimaryParent(catMain)
.WithProduct(good2)
.WithProduct(good3)
.Build();

session.Derive();
session.Commit();

//Another InternalOrg Ends

new CustomerRelationshipBuilder(this.Session).WithFromDate(this.Session.Now()).WithCustomer(customer).WithInternalOrganisation(internalOrganisation).Build();

var mechelen = new CityBuilder(this.Session).WithName("Mechelen").Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ namespace Allors.Domain

public partial class PartyFinancialRelationship
{
public void BaseOnPreDerive(ObjectOnPreDerive method)
{
var (iteration, changeSet, derivedObjects) = method;

iteration.AddDependency(this, this.Party.SalesOrdersWhereBillToCustomer);
iteration.AddDependency(this, this.Party.SalesInvoicesWhereBillToCustomer);
}

public void BaseOnDerive(ObjectOnDerive method)
{
var party = this.Party;
Expand Down
1 change: 0 additions & 1 deletion Base/Database/Domain/Base/Invoice/SalesInvoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public void BaseOnPreDerive(ObjectOnPreDerive method)

if (iteration.IsMarked(this) || changeSet.IsCreated(this) || changeSet.HasChangedRoles(this))
{

if (this.ExistBillToCustomer)
{
var customerRelationships = this.BillToCustomer.CustomerRelationshipsWhereCustomer;
Expand Down
11 changes: 11 additions & 0 deletions Base/Database/Domain/Base/Order/SalesOrderTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ public void BaseOnDerive(ObjectOnDerive method)
else
{
this.To = this.From.Clone(this.From.Meta.SalesOrderItems);
this.To.TakenBy = this.InternalOrganisation;

// TODO: Make sure 'from' customer is also a customer in 'to' internal organisation
if (!this.To.TakenBy.ActiveCustomers.Contains(this.To.BillToCustomer))
{
new CustomerRelationshipBuilder(this.Strategy.Session)
.WithInternalOrganisation(this.To.TakenBy)
.WithCustomer(this.To.BillToCustomer)
.Build();
}

this.From.SalesOrderState = new SalesOrderStates(this.strategy.Session).Transferred;
}
}
Expand Down
14 changes: 0 additions & 14 deletions Base/Database/Domain/Base/Relation/PartyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ public static void BaseOnBuild(this Party @this, ObjectOnBuild method)
}
}

public static void BaseOnPreDerive(this Party @this, ObjectOnPreDerive method)
{
var (iteration, changeSet, derivedObjects) = method;

if (iteration.IsMarked(@this) || changeSet.IsCreated(@this) || changeSet.HasChangedRoles(@this))
{
foreach (PartyFinancialRelationship partyFinancialRelationship in @this.PartyFinancialRelationshipsWhereParty)
{
iteration.AddDependency(partyFinancialRelationship, @this);
iteration.Mark(partyFinancialRelationship);
}
}
}

public static void BaseOnDerive(this Party @this, ObjectOnDerive method)
{
@this.DerivedRoles.BillingAddress = null;
Expand Down
Loading

0 comments on commit 917fbc2

Please sign in to comment.