Skip to content

Commit

Permalink
refactor(Demand)
Browse files Browse the repository at this point in the history
- AbstractDemand
- DemandPosition
  • Loading branch information
wmakeev committed Jul 23, 2021
1 parent 9da5f3f commit cd2d33f
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 10 deletions.
29 changes: 29 additions & 0 deletions src/model/AbstractDemand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type {
DocumentWithPositions,
DocumentWithPositionsPatch,
EntityRef,
HasVat,
HasVatPatch
} from '.'

export type DemandMetaType = 'demand' | 'retaildemand'

export type AbstractDemandFields = {
customerOrder: EntityRef<'customerorder'>

// TODO facture: IDREF
// TODO invoicesOutUuid: IDREF
// TODO paymentsUuid: IDREF
// TODO salesReturnsUuid: IDREF
// TODO shipmentOut: ShipmentOut
}

export type AbstractDemand<
T extends DemandMetaType
> = DocumentWithPositions<T> & HasVat

export type AbstractDemandPatch<
T extends DemandMetaType
> = DocumentWithPositionsPatch<T> &
HasVatPatch &
Partial<Pick<AbstractDemandFields, 'customerOrder'>>
13 changes: 11 additions & 2 deletions src/model/Demand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import type { DocumentWithPositions, HasVat, MetaType } from '.'
import type { AbstractDemand, AbstractDemandPatch } from './AbstractDemand'

export type Demand = DocumentWithPositions<'demand'> & HasVat
export type DemandFields = {
// TODO extension: DemandExtension
// TODO overhead: MoneyAmount
// TODO overheadDistribution: OverheadDistribution
}

export type Demand = AbstractDemand<'demand'>

export type DemandPatch = AbstractDemandPatch<'demand'>
// & Partial<Pick<DemandFields, ''>>
15 changes: 15 additions & 0 deletions src/model/DemandPosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Position, PositionPatch } from './Position'

export type DemandPositionFields = {
/**
* НДС
*/
vat: number

overhead: number
}

export type DemandPosition = Position<'demandposition'> & DemandPositionFields

export type DemandPositionPatch = PositionPatch<'demandposition'> &
Partial<Pick<DemandPositionFields, 'vat' | 'overhead'>>
3 changes: 2 additions & 1 deletion src/model/MetaType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
CustomerOrder,
CustomerOrderPosition,
Demand,
DemandPosition,
Document,
DocumentMetaType,
Employee,
Expand Down Expand Up @@ -143,7 +144,7 @@ export type EntityByMetaType = {
customerorderposition: CustomerOrderPosition
customtemplate: Entity<'customtemplate'>
demand: Demand
demandposition: Entity<'demandposition'>
demandposition: DemandPosition
discount: Entity<'discount'>
embeddedtemplate: Entity<'embeddedtemplate'>
employee: Employee
Expand Down
9 changes: 7 additions & 2 deletions src/model/RetailDemand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { DocumentWithPositions, MetaType } from '.'
import type { AbstractDemand, DocumentWithPositions, MetaType } from '.'
import type { AbstractDemandPatch } from './AbstractDemand'

export interface RetailDemand extends DocumentWithPositions<'retaildemand'> {
export type RetailDemandFields = {
readonly cashSum: number

readonly noCashSum: number
}

export type RetailDemand = AbstractDemand<'retaildemand'> & RetailDemandFields

export type RetailDemandPatch = AbstractDemandPatch<'retaildemand'>
2 changes: 2 additions & 0 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './Counterparty'
export * from './CustomerOrder'
export * from './CustomerOrderPosition'
export * from './Demand'
export * from './DemandPosition'
export * from './Discount'
export * from './Document'
export * from './DocumentWithPositions'
Expand Down Expand Up @@ -54,6 +55,7 @@ export * from './RetailDemand'
export * from './State'
export * from './TaxSystem'
export * from './Id'
export * from './AbstractDemand'

// Utility types
export * from './utils'
Expand Down
6 changes: 2 additions & 4 deletions src/model/reports/counterparty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { MetaType } from '..'
import type { CollectionRef } from '../CollectionRef'
import type { EntityRef } from '../EntityRef'
import type { CollectionRef, EntityRef } from '..'

export interface CounterpartyReportItem extends EntityRef<'counterparty'> {
counterparty: EntityRef<'counterparty'>
Expand All @@ -20,7 +18,7 @@ export interface CounterpartyReportItem extends EntityRef<'counterparty'> {
}

/**
* `/report/counterparty`
* `report/counterparty`
*/
export interface CounterpartyReport extends CollectionRef<'counterparty'> {
context: {
Expand Down
8 changes: 7 additions & 1 deletion src/model/utils/Patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import type {
CashOutPatch,
CustomerOrderPatch,
CustomerOrderPositionPatch,
Demand,
DemandPosition,
EntityPatchRef,
InvoiceInPatch,
InvoiceOutPatch,
InvoicePositionPatch,
MetaType
MetaType,
RetailDemand
} from '..'

export type PatchByMetaType = {
Expand All @@ -20,6 +23,9 @@ export type PatchByMetaType = {
invoiceposition: InvoicePositionPatch
cashin: CashInPatch
cashout: CashOutPatch
demand: Demand
demandposition: DemandPosition
retaildemand: RetailDemand
}

export type Patch<T extends MetaType> = T extends keyof PatchByMetaType
Expand Down
1 change: 1 addition & 0 deletions test/model/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ const invoiceOut: Patch<'invoiceout'> = {}
invoiceOut.positions?.[0].price
invoiceOut.customerOrder
invoiceOut.store
invoiceOut.paymentPlannedMoment
11 changes: 11 additions & 0 deletions test/model/types.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import type {
Collection,
CustomerOrder,
Document,
DocumentMetaType,
DocumentWithPositionsMetaType,
Expand,
IsExtends
} from '../../src'

const t1: IsExtends<DocumentWithPositionsMetaType, DocumentMetaType> = true

const t2 = {} as Document<DocumentWithPositionsMetaType>

let t3_1 = {} as Expand<Collection<'customerorder'>, 'state'>
const t3_2 = {} as Expand<Collection<'customerorder'>, 'state'>

// FIXME Судя по всему, коллекцию нужно переделывать на Expand<Collection<CustomerOrder>, 'state'>

// @ts-expect-error
t3_1 = [...t3_1.rows, ...t3_2.rows]

0 comments on commit cd2d33f

Please sign in to comment.