ZuloOne
English
Sign inTry it
Menu

🤝 Counterparty roles: ICounterpartyRegistry, ICounterpartyRoles

Updated

← Developer wiki For the user: Counterparty, customer and supplier.

Counterparty (Organization 1.10.0) is the party; Customer and Supplier (Inventory) are its roles and reference it through their Counterparty field. Details shared by both sides live on the counterparty and its child lists CounterpartyAddress, CounterpartyContactInfo, CounterpartyBankAccount. Reference: 01-Organization, 04-Inventory.

ICounterpartyRegistry (Organization)#

Knows only counterparties. FindAsync(registrationNumber, taxNumber) — the oldest match by the code, else by the tax number (codes compared digits-only). EnsureAsync(hint, …) — the hint when it exists, else a found one, else a new one; it never matches by name. UpdateIdentityAsync writes only what differs and never clears a detail with an empty value. AddAddressAsync / AddContactInfoAsync are idempotent per address + purpose / kind + value. PrimaryAddressAsync, PrimaryBankAccountAsync, FindByBankAccountAsync(iban) (null when the IBAN is on several counterparties).

The primary rows write the mirrors Counterparty.Phone, Email, LegalAddress; one primary row per purpose / kind / counterparty is kept by the child dictionaries' OnAfterSave.

ICounterpartyRoles (Inventory)#

Method Use
IdentityOfCustomerAsync, IdentityOfSupplierAsync Extension points. Return Hint, Name, FullName, EntityType, RegistrationNumber, TaxRegistrationNumber, Phone, Email of a role.
AttachCustomerAsync, AttachSupplierAsync Called from the role's save handler: find or make the counterparty from the identity, write Counterparty, lift the details up.
FanOutAsync(counterparty) Called from the counterparty's save handler (Counterparty.Inventory): name, full name, tax number down to every role; blocked → roles disabled.
CustomersOfAsync, SuppliersOfAsync The roles of a counterparty.
MakeCustomerAsync, MakeSupplierAsync The missing role (commands MakeCustomer, MakeSupplier; CRM ConvertLead, WinOpportunity).
MirrorContactInfoAsync(row) An obsolete CustomerContactInfo row into the counterparty's lists.
BackfillAsync(batch) The CounterpartyBackfill job.

The round trip stops by itself. A role save lifts its details up; the counterparty save fans them down; each side writes only columns that differ, so the second pass writes nothing. A role keeps its own phone and e-mail: they go up, never down.

Extend the identity, not the attach. A higher model adds its key by a service link with the same service name (CounterpartyRoles) that overrides IdentityOf…Async and calls nextAsync<T>() first; every other method just forwards to nextAsync. LocalizationUkraine puts the role's EdrpouCode into RegistrationNumber; a tenant model may set Hint (a tenant migrated from 1C: the counterparty of the same 1C card). Inside Inventory, calls go through ScriptServices.Get<ICounterpartyRoles>(), not this, so the chain applies.

Writers that bypass handlers. A raw IDataService.InsertAsync of a customer or supplier still fires the save handlers, so it gets a counterparty. A direct SQL insert does not — run the backfill job afterwards. OData Customers goes through the handlers.

Permissions. The office contours Sales, Purchasing and Accountant get Counterparty cells (OfficeRoleGrants), the phone roles do not. A row predicate cannot reach Counterparty through Customer (no sub-selects in predicates), so an agent restricted to its customers does not read counterparties through the API at all; server-side handlers are not limited.

See also#

Was this page helpful?