From 756b09fb57be195681090c9f33cf0cecee1c5dc0 Mon Sep 17 00:00:00 2001 From: aledguedes Date: Fri, 14 Aug 2026 17:05:28 -0300 Subject: [PATCH 1/5] Refactor OEM codes models, service and compatibility UI Introduce unified OemCode model and manufacturer helpers; replace legacy ProductOemCode with OemCode in product responses. Add ManufacturerSummaryResponse, ManufacturerOptionsQuery and ProductSummaryResponse models. Implement OemCodeService with endpoints for listing, options and product-scoped OEMs. Revamp compatibility tab template and component to support search, manufacturer filters, selection, pagination and new outputs/events. Wire OEM fetching and manufacturer-by-product options in ProductWorkspace; add unit sale service usage in ProductCreate. Minor API-model field adjustments and small logging added. Improves OEM UI/UX and backend integration. --- .../additional-codes-product.model.ts | 1 + .../equivalent/equivalent-products.model.ts | 1 + .../manufaturer-summary-response.model.ts | 5 + .../mnufacturer-options-query.model.ts | 6 + .../oem-codes/oem-codes-product.model.ts | 7 +- .../core/models/oem-codes/oem-codes.model.ts | 11 + .../models/products/product-create.model.ts | 1 + .../models/products/product-response.model.ts | 4 +- .../products/product-summary-response.ts | 6 + .../vehicle-application-product.model.ts | 1 + src/app/core/services/code-oem-service.ts | 43 ++ src/app/core/services/manufacture-service.ts | 6 + .../compatibility-tab/compatibility-tab.html | 387 +++++++++++++----- .../compatibility-tab/compatibility-tab.ts | 258 +++++++++--- .../catalog/product-create/product-create.ts | 26 +- .../product-workspace/product-workspace.html | 6 +- .../product-workspace/product-workspace.ts | 86 ++-- 17 files changed, 651 insertions(+), 204 deletions(-) create mode 100644 src/app/core/models/manufactureres/manufaturer-summary-response.model.ts create mode 100644 src/app/core/models/manufactureres/mnufacturer-options-query.model.ts create mode 100644 src/app/core/models/oem-codes/oem-codes.model.ts create mode 100644 src/app/core/models/products/product-summary-response.ts create mode 100644 src/app/core/services/code-oem-service.ts diff --git a/src/app/core/models/additional-codes/additional-codes-product.model.ts b/src/app/core/models/additional-codes/additional-codes-product.model.ts index c01d660..644be4e 100644 --- a/src/app/core/models/additional-codes/additional-codes-product.model.ts +++ b/src/app/core/models/additional-codes/additional-codes-product.model.ts @@ -2,4 +2,5 @@ export interface ProductAdditionalCodeSummary { id: string; code: string; active: boolean; + type: string; // remover possivelmente } diff --git a/src/app/core/models/equivalent/equivalent-products.model.ts b/src/app/core/models/equivalent/equivalent-products.model.ts index 58799a6..39d8c6f 100644 --- a/src/app/core/models/equivalent/equivalent-products.model.ts +++ b/src/app/core/models/equivalent/equivalent-products.model.ts @@ -5,4 +5,5 @@ export interface ProductEquivalent { observation: string | null; product: EntityReference; equivalent_product: EntityReference; + status?: boolean; // remover após produtos equivalentes } diff --git a/src/app/core/models/manufactureres/manufaturer-summary-response.model.ts b/src/app/core/models/manufactureres/manufaturer-summary-response.model.ts new file mode 100644 index 0000000..cf24122 --- /dev/null +++ b/src/app/core/models/manufactureres/manufaturer-summary-response.model.ts @@ -0,0 +1,5 @@ +export interface ManufacturerSummaryResponse { + id: string; + name: string; + slug: string; +} diff --git a/src/app/core/models/manufactureres/mnufacturer-options-query.model.ts b/src/app/core/models/manufactureres/mnufacturer-options-query.model.ts new file mode 100644 index 0000000..bfe2804 --- /dev/null +++ b/src/app/core/models/manufactureres/mnufacturer-options-query.model.ts @@ -0,0 +1,6 @@ +export interface ManufacturerOptionsQuery { + search: string | null; + page: number | null; + per_page: number | null; + manufacturer_id: string | null; +} diff --git a/src/app/core/models/oem-codes/oem-codes-product.model.ts b/src/app/core/models/oem-codes/oem-codes-product.model.ts index f74ae8e..97a5ef4 100644 --- a/src/app/core/models/oem-codes/oem-codes-product.model.ts +++ b/src/app/core/models/oem-codes/oem-codes-product.model.ts @@ -3,9 +3,6 @@ import { EntityReference } from '../generals/entity-reference'; export interface ProductOemCode { id: string; oem_code: string; - manufacturer?: EntityReference; - product?: EntityReference; - created_at: string; - updated_at: string; - is_primary: boolean; + manufacturer: EntityReference; + product: EntityReference; } diff --git a/src/app/core/models/oem-codes/oem-codes.model.ts b/src/app/core/models/oem-codes/oem-codes.model.ts new file mode 100644 index 0000000..f986b7c --- /dev/null +++ b/src/app/core/models/oem-codes/oem-codes.model.ts @@ -0,0 +1,11 @@ +import { ProductSummaryResponse } from '../products/product-summary-response'; +import { ManufacturerSummaryResponse } from '../manufactureres/manufaturer-summary-response.model'; + +export interface OemCode { + id: string; + label: string; + product: ProductSummaryResponse; + manufacturer: ManufacturerSummaryResponse; + created_at: string; + updated_at: string; +} diff --git a/src/app/core/models/products/product-create.model.ts b/src/app/core/models/products/product-create.model.ts index 5c41cbb..0ce6aae 100644 --- a/src/app/core/models/products/product-create.model.ts +++ b/src/app/core/models/products/product-create.model.ts @@ -140,6 +140,7 @@ export function toProductGeneralFormData(source: ProductGeneralFormSource): Prod } export function toCreateProductPayload(source: ProductGeneralFormSource): CreateProductPayload { + console.log('[CHEGAMOS AQUI PAYLOAD]', source); return { category_id: source.category_id, manufacturer_id: source.manufacturer_id, diff --git a/src/app/core/models/products/product-response.model.ts b/src/app/core/models/products/product-response.model.ts index 1e065c5..e71e142 100644 --- a/src/app/core/models/products/product-response.model.ts +++ b/src/app/core/models/products/product-response.model.ts @@ -1,7 +1,6 @@ import { ProductVehicleApplication } from '../vehicle-application/vehicle-application-product.model'; import { ProductEquivalent } from '../equivalent/equivalent-products.model'; import { EntityReference } from '../generals/entity-reference'; -import { ProductOemCode } from '../oem-codes/oem-codes-product.model'; import { ProductStatus } from '../status/status-product.model'; import { ProductSupplier } from '../suppliers/suppliers-product.model'; import { ProductPricing } from '../pricing/pricing-product-model'; @@ -10,6 +9,7 @@ import { ProductUnitSale } from '../units-sale/unit-sale-product.model'; import { ProductPartOrigin } from '../part-origin/part-origin-product.model'; import { ProductAdditionalCodeSummary } from '../additional-codes/additional-codes-product.model'; import { ProductTag } from '../tags/tags-product.model'; +import { OemCode } from '../oem-codes/oem-codes.model'; export interface ProductSummaryResponse { id: string; @@ -56,7 +56,7 @@ export interface ProductResponse extends ProductSummaryResponse { part_origin: ProductPartOrigin | null; tags: ProductTag[]; - oem_codes: ProductOemCode[]; + oem_codes: OemCode[]; suppliers: ProductSupplier[]; equivalents: ProductEquivalent[]; applications: ProductVehicleApplication[]; diff --git a/src/app/core/models/products/product-summary-response.ts b/src/app/core/models/products/product-summary-response.ts new file mode 100644 index 0000000..caad5e6 --- /dev/null +++ b/src/app/core/models/products/product-summary-response.ts @@ -0,0 +1,6 @@ +export interface ProductSummaryResponse { + id: string; + name: string; + slug: string; + internal_code: string; +} diff --git a/src/app/core/models/vehicle-application/vehicle-application-product.model.ts b/src/app/core/models/vehicle-application/vehicle-application-product.model.ts index 6c9a78f..4487b5c 100644 --- a/src/app/core/models/vehicle-application/vehicle-application-product.model.ts +++ b/src/app/core/models/vehicle-application/vehicle-application-product.model.ts @@ -10,4 +10,5 @@ export interface ProductVehicleApplication { details: string | null; created_at?: string; updated_at?: string; + status?: boolean; // remover possivelmente } diff --git a/src/app/core/services/code-oem-service.ts b/src/app/core/services/code-oem-service.ts new file mode 100644 index 0000000..e0b8a92 --- /dev/null +++ b/src/app/core/services/code-oem-service.ts @@ -0,0 +1,43 @@ +import { inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { environment } from '../../../environments/environment'; +import { PaginatedResponse } from '../models/pagination/pagination.model'; +import { GeneralOptionQuery } from '../models/generals/general-option-query.model'; +import { buildHttpParams } from './build-http-params'; +import { getAllResponse } from '../models/generals/general-responses-list.model'; +import { OemCode } from '../models/oem-codes/oem-codes.model'; +import { ManufacturerOptionsQuery } from '../models/manufactureres/mnufacturer-options-query.model'; + +@Injectable({ + providedIn: 'root', +}) +export class OemCodeService { + private http = inject(HttpClient); + private api = environment.apiUrl; + private flag = 'product-oem-codes'; + + getAll() { + return this.http.get>(`${this.api}/${this.flag}`); + } + + getOptions(filters: GeneralOptionQuery) { + const params = buildHttpParams(filters); + return this.http.get>(`${this.api}/${this.flag}/options`, { + params, + }); + } + + getByProduct(productId: string, filters: ManufacturerOptionsQuery) { + const params = buildHttpParams(filters); + return this.http.get>( + `${this.api}/${this.flag}/product/${productId}/options`, + { + params, + }, + ); + } + + getById(id: string) { + return this.http.get>(`${this.api}/${this.flag}/${id}`); + } +} diff --git a/src/app/core/services/manufacture-service.ts b/src/app/core/services/manufacture-service.ts index 6c2a82b..c365dd9 100644 --- a/src/app/core/services/manufacture-service.ts +++ b/src/app/core/services/manufacture-service.ts @@ -29,4 +29,10 @@ export class ManufacturerService { getById(id: string) { return this.http.get(`${this.api}/${this.flag}/${id}`); } + + getManufacturerByProduct(productId: string) { + return this.http.get( + `${this.api}/${this.flag}/product/${productId}`, + ); + } } diff --git a/src/app/features/catalog/components/product-form/compatibility-tab/compatibility-tab.html b/src/app/features/catalog/components/product-form/compatibility-tab/compatibility-tab.html index 80257ab..97c8ebc 100644 --- a/src/app/features/catalog/components/product-form/compatibility-tab/compatibility-tab.html +++ b/src/app/features/catalog/components/product-form/compatibility-tab/compatibility-tab.html @@ -1,94 +1,243 @@
- @switch (activeTab()) { @case ('oem') { - + + @if (activeTab() === 'oem') {
-
+ +

- - {{ getModule('oem').label }} + + Códigos OEM Registrados

-

{{ getModule('oem').description }}

+ +

+ Selecione um ou mais códigos de montadoras de referência para vincular a este produto +

- @if (!isReadOnly()) { - - Adicionar Código OEM - +
+ + + {{ selectedOemCodeIds().length }} de {{ oemTotalItens() }} selecionados + +
+
+ + +
+
+ +
+
+ +
+ + + + @if (oemSearchQuery()) { + + } +
+ + + @if (!isReadOnly()) { +
+ + + +
+ } +
+ + + @if (manufacturerByProductFilter().length > 0) { +
+ + Filtrar por: + + + + + @for (mfr of manufacturerByProductFilter(); track mfr.id) { + + } +
}
-
+ +
- - - - - + + + + + + + - @for (oem of oemPaginated(); track oem.id) { - - - + + - + + + + + + + + - } @empty { - } @@ -96,35 +245,35 @@

} - } @case ('codigos') { + } + + @if (activeTab() === 'codigos') {

- - {{ getModule('codigos').label }} + + Códigos do Produto (Product Codes)

+

- {{ getModule('codigos').description }} + EAN, DUN, Código do fabricante, Código paralelo e Código interno auxiliar

@@ -135,7 +284,9 @@

+

Fabricante de ReferênciaCódigo OEMPrincipalSituaçãoAções + Seleção + Código OEMFabricante / MontadoraData RegistroStatus do Vínculo
{{ oem.manufacturer?.name }} - {{ oem.oem_code }} + @for (oem of oemCodes(); track oem.id) { @let selected = isOemSelected(oem.id); + +
+ - @if (oem.is_primary) { + + + +
+ + {{ oem.label }} + + + @if (selected) { + + + Selecionado + + } +
+
- - Principal + {{ oem.manufacturer.name || 'Montadora' }} - } @else if (!isReadOnly()) { - - } @else { - - - } + {{ oem.created_at ? (oem.created_at | date: 'dd/MM/yyyy') : '01/08/2026' }} + + @if (selected) { - Ativo + + Vinculado ao Produto - - @if (!isReadOnly()) { - + Não Vinculado + }
- Nenhum código OEM cadastrado. + +
+ + +

+ Nenhum código OEM encontrado para o filtro aplicado. +

+ + +
Ações + @for (codeItem of productCodesPaginated(); track codeItem.id) { + - +
- {{ codeItem.code }} + {{ codeItem.type }} {{ codeItem.code }} - - Ativo - - @if (!isReadOnly()) {