Skip to content

Commit

Permalink
Merge branch 'IMP_details_fields_typing_formatting'
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Dec 29, 2023
2 parents 3991116 + 4e20500 commit 0c2ccdd
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

- Continuous integration enabled
- Using component library
- Fix: Animated error image
- Animated error image
- Localized formatting for installation details fields
- Added missing translations for enum values from ERP

## 0.3.0 (2023-12-22)

Expand Down
51 changes: 43 additions & 8 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,54 @@
AfterValidator(stdnum.eu.vat.validate),
]

# TODO: Use an enum
# TODO: Use Enums for those literals

Role = Literal[
'customer',
'staff',
]

# TODO: Use an enum
InvoiceConcept = Literal[
'market',
'specific_retribution',
'services',
]

BillingMode = Literal[
'atr',
'index',
]

RepresentationType = Literal[
'directa_cnmc',
'indirecta_cnmc',
]

ProductionTechnology = Literal[
'FV', # Photovoltaic
'H', # Hidraulic
'E', # Eolic
]

DeviationIncluded = Literal[
'included',
'not_included',
]

ContractStatus = Literal[
'esborrany',
'validar',
'pendent',
'activa',
'cancelada',
'contracte',
'novapolissa',
'modcontractual',
'impagament',
'tall',
'baixa',
]

class SignatureResult(BaseModel):
signed_version: str # TODO: Restrict to iso datetime

Expand Down Expand Up @@ -81,18 +116,18 @@ class InstallationDetails(BaseModel):
postal_code: str
province: str
rated_power: int
technology: str | bool # TODO: restrict to enum
type: str # TODO: restrict to enum
technology: ProductionTechnology | bool | None # TODO: restrict to enum # TODO: Remove bool when fixed in ERP
type: str # TODO: Rename to installaton_type_code

class ContractDetails(BaseModel):
billing_mode: str
cost_deviation: str
billing_mode: BillingMode
cost_deviation: DeviationIncluded
discharge_date: datetime.date
iban: str
proxy_fee: float
reduction_deviation: int
representation_type: str # TODO: restrict to enum
status: str # TODO: restrict to enum
representation_type: RepresentationType
status: ContractStatus

class InstallationDetailsResult(BaseModel):
installation_details: InstallationDetails
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/i18n/locale-es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,42 @@ INSTALLATION_DETAIL:
NAME: Nombre
POSTAL_CODE: Código postal
PROVINCE: Provincia
RATED_POWER: Potencia nominal [kW]
RATED_POWER: Potencia nominal
TECHNOLOGY: Tecnología
CIL: CIL
TYPE: Código de instalación tipo
ERROR_LOADING_DATA: Error cargando los datos
BACK_TO_INSTALLATIONS: Volver a la lista de instalaciones
TECHNOLOGY_PHOTOVOLTAIC: Fotovoltáica
TECHNOLOGY_HYDRO: Hidroeléctrica
TECHNOLOGY_WIND: Eólica
CONTRACT_DETAIL:
CONTRACT_DETAILS_TITLE: Detalles del contrato
BILLING_MODE: Modo de facturación
COST_DEVIATION: Coste de los desvíos
DISCHARGE_DATE: Fecha del alta
IBAN: IBAN
PROXY_FEE: Retribución para el servicio de representación [€/MWh]
PROXY_FEE: Retribución para el servicio de representación
REDUCTION_DEVIATION: Reducción de los desvíos por efecto cartera
REPRESENTATION_TYPE: Tipo de representación
STATUS: Estado del contrato
BILLING_MODE_INDEX: Indexada
BILLING_MODE_ATR: ATR
COST_DEVIATION_INCLUDED: Incluido
STATUS_ACTIVE: Activo
COST_DEVIATION_NOT_INCLUDED: No incluido
REPRESENTATION_TYPE_DIRECT: Indirecta a Mercado y Directa ante la CNMC
REPRESENTATION_TYPE_INDIRECT: Indirecta a Mercado y Indirecta ante la CNMC
CONTRACT_STATUS_DRAFT: Borrador
CONTRACT_STATUS_VALIDATION: Validándose
CONTRACT_STATUS_PENDING: Pendiente
CONTRACT_STATUS_ACTIVE: Activo
CONTRACT_STATUS_CANCELLED: Cancelado
CONTRACT_STATUS_ACTIVATION: Proceso de activación
CONTRACT_STATUS_NEW_CONTRACT: Proceso nuevo contrato
CONTRACT_STATUS_MODIFICATION: Modificación contractual
CONTRACT_STATUS_UNPAID: Impago
CONTRACT_STATUS_CUT: Corte
CONTRACT_STATUS_ENDED: Baja
INVOICES:
INVOICES_TITLE: Facturas
TABLE_TITLE: '{{n}} facturas'
Expand Down
67 changes: 48 additions & 19 deletions frontend/src/pages/DetailInstallationPage/detailInstallationData.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ export const contractFields = [
'discharge_date',
'status',
]
export default function transformContractDetails(contractData) {
export function transformInstallationDetails(data) {
const t = i18n.t
const productionTecnologyOptions = {
FV: t('INSTALLATION_DETAIL.TECHNOLOGY_PHOTOVOLTAIC'),
H: t('INSTALLATION_DETAIL.TECHNOLOGY_HYDRO'),
E: t('INSTALLATION_DETAIL.TECHNOLOGY_WIND'),
}
return {
...data,
rated_power: format.units(data.rated_power, 'kW', 0),
technology: format.enumeration(data.technology, productionTecnologyOptions),
}
}
export default function transformContractDetails(contract) {
const t = i18n.t
const billingModeOptions = {
index: t('CONTRACT_DETAIL.BILLING_MODE_INDEX'),
Expand All @@ -36,26 +49,42 @@ export default function transformContractDetails(contractData) {
directa_cnmc: t('CONTRACT_DETAIL.REPRESENTATION_TYPE_DIRECT'),
indirecta_cnmc: t('CONTRACT_DETAIL.REPRESENTATION_TYPE_INDIRECT'),
}

if (contractData.cost_deviation == 'included') {
contractData.reduction_deviation += ' %'
const contractStatusOptions = {
esborrany: t('CONTRACT_DETAIL.CONTRACT_STATUS_DRAFT'),
validar: t('CONTRACT_DETAIL.CONTRACT_STATUS_VALIDATION'),
pendent: t('CONTRACT_DETAIL.CONTRACT_STATUS_PENDING'),
activa: t('CONTRACT_DETAIL.CONTRACT_STATUS_ACTIVE'),
cancelada: t('CONTRACT_DETAIL.CONTRACT_STATUS_CANCELLED'),
contracte: t('CONTRACT_DETAIL.CONTRACT_STATUS_ACTIVATION'),
novapolissa: t('CONTRACT_DETAIL.CONTRACT_STATUS_NEW_CONTRACT'),
modcontractual: t('CONTRACT_DETAIL.CONTRACT_STATUS_MODIFICATION'),
impagament: t('CONTRACT_DETAIL.CONTRACT_STATUS_UNPAID'),
tall: t('CONTRACT_DETAIL.CONTRACT_STATUS_CUT'),
baixa: t('CONTRACT_DETAIL.CONTRACT_STATUS_ENDED'),
}
if (contractData.cost_deviation != 'included') {
contractData.reduction_deviation = 'N/A'
const costDeviationIncludedOptions = {
included: t('CONTRACT_DETAIL.COST_DEVIATION_INCLUDED'),
not_included: t('CONTRACT_DETAIL.COST_DEVIATION_NOT_INCLUDED'),
}
if (contractData.cost_deviation == 'included') {
contractData.cost_deviation = t('CONTRACT_DETAIL.COST_DEVIATION_INCLUDED')
return {
...contract,
reduction_deviation:
contract.cost_deviation === 'included'
? format.percent(contract.reduction_deviation, 0)
: 'N/A',
cost_deviation: format.enumeration(
contract.cost_deviation,
costDeviationIncludedOptions,
),
billing_mode: format.enumeration(contract.billing_mode, billingModeOptions),
representation_type: format.enumeration(
contract.representation_type,
representationTypeOptions,
),
discharge_date: format.date(contract.discharge_date),
proxy_fee: format.units(contract.proxy_fee, '€/MWh', 2),
status: format.enumeration(contract.status, contractStatusOptions),
}
contractData.billing_mode = format.enumeration(
contractData.billing_mode,
billingModeOptions,
)
contractData.representation_type = format.enumeration(
contractData.representation_type,
representationTypeOptions,
)

contractData.status = t('CONTRACT_DETAIL.STATUS_ACTIVE')

return contractData
return contract
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { describe, expect, it } from 'vitest'
import i18n from '../../i18n/i18n'

import transformContractDetails from './detailInstallationData'
import transformContractDetails, {
transformInstallationDetails,
} from './detailInstallationData'

describe('transformContractDetails', () => {
let previousLanguage
beforeEach(() => {
previousLanguage = i18n.language
i18n.changeLanguage('es')
})
afterEach(() => {
i18n.changeLanguage(previousLanguage)
})
it('Add `%` to reduction_deviation if cost_deviation is `included`', () => {
const contractData = {
cost_deviation: 'included',
Expand Down Expand Up @@ -57,3 +68,73 @@ describe('transformContractDetails', () => {
)
})
})

describe('transformInstallationDetails', () => {
let previousLanguage
beforeEach(() => {
previousLanguage = i18n.language
i18n.changeLanguage('es')
})
afterEach(() => {
i18n.changeLanguage(previousLanguage)
})
it('technology, when no value', () => {
const contractData = {}
const result = transformInstallationDetails(contractData)
expect(result['technology']).toEqual('-')
})
it('technology, replace E by Eólica', () => {
const contractData = {
technology: 'E',
}
const result = transformInstallationDetails(contractData)
expect(result['technology']).toEqual('Eólica')
})
it('technology, replace PV by Fotovoltáica', () => {
const contractData = {
technology: 'FV',
}
const result = transformInstallationDetails(contractData)
expect(result['technology']).toEqual('Fotovoltáica')
})
it('technology, replace H by Hidroeléctrica', () => {
const contractData = {
technology: 'H',
}
const result = transformInstallationDetails(contractData)
expect(result['technology']).toEqual('Hidroeléctrica')
})
it('rated_power, not given', () => {
const contractData = {}
const result = transformInstallationDetails(contractData)
expect(result['rated_power']).toEqual('-- kW')
})
it('rated_power, null', () => {
const contractData = {
rated_power: null,
}
const result = transformInstallationDetails(contractData)
expect(result['rated_power']).toEqual('-- kW')
})
it('rated_power, integer', () => {
const contractData = {
rated_power: 100,
}
const result = transformInstallationDetails(contractData)
expect(result['rated_power']).toEqual('100 kW')
})
it('rated_power, thousand separator', () => {
const contractData = {
rated_power: 1000,
}
const result = transformInstallationDetails(contractData)
expect(result['rated_power']).toEqual('1.000 kW')
})
it('rated_power, decimals', () => {
const contractData = {
rated_power: 10.55,
}
const result = transformInstallationDetails(contractData)
expect(result['rated_power']).toEqual('11 kW')
})
})
7 changes: 5 additions & 2 deletions frontend/src/pages/DetailInstallationPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import ErrorSplash from '../../components/ErrorSplash'
import NavigationButtons from '../../components/NavigationButtons'
import { contractFields } from './detailInstallationData'
import { installationFields } from './detailInstallationData'
import transformContractDetails from './detailInstallationData'
import transformContractDetails, {
transformInstallationDetails,
} from './detailInstallationData'

export default function DetailInstallationPage(params) {
const { contract_number } = useParams()
Expand All @@ -36,7 +38,8 @@ export default function DetailInstallationPage(params) {
setError(e)
return
}
setInstallationDetail(result?.installation_details)
const installationData = transformInstallationDetails(result?.installation_details)
setInstallationDetail(installationData)
const contractData = transformContractDetails(result?.contract_details)
setContractDetail(contractData)
}
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/services/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,17 @@ function percent(amount, decimals) {
return `${localized}`
}

export { euros, percent, date, enumeration }
export default { euros, percent, date, enumeration }
function units(amount, unit, decimals) {
const asFloat = parseFloat(amount)
if (isNaN(asFloat)) return `-- ${unit}`
const language = i18n.language
const localized = asFloat.toLocaleString(language, {
maximumFractionDigits: decimals ?? 2,
minimumFractionDigits: decimals ?? 2,
useGrouping: true,
})
return `${localized} ${unit}`
}

export { euros, units, percent, date, enumeration }
export default { euros, units, percent, date, enumeration }
Loading

0 comments on commit 0c2ccdd

Please sign in to comment.