diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 30584fd5e..ae8411993 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -73,6 +73,7 @@ class API::ProductsController < API::ApiController :low_stock_alert, :low_stock_threshold, machine_ids: [], product_files_attributes: %i[id attachment _destroy], - product_images_attributes: %i[id attachment is_main _destroy]) + product_images_attributes: %i[id attachment is_main _destroy], + advanced_accounting_attributes: %i[code analytical_section]) end end diff --git a/app/frontend/src/javascript/components/form/form-image-upload.tsx b/app/frontend/src/javascript/components/form/form-image-upload.tsx index 4e449d2cd..6fd9c243f 100644 --- a/app/frontend/src/javascript/components/form/form-image-upload.tsx +++ b/app/frontend/src/javascript/components/form/form-image-upload.tsx @@ -118,7 +118,7 @@ export const FormImageUpload = = ({ product, title, onSucc className="product-documents" /> +
+ + +
{!saving && t('app.admin.store.product_form.save')} diff --git a/app/frontend/src/javascript/models/product.ts b/app/frontend/src/javascript/models/product.ts index adaaa5b90..10a6767ef 100644 --- a/app/frontend/src/javascript/models/product.ts +++ b/app/frontend/src/javascript/models/product.ts @@ -3,6 +3,7 @@ import { ApiFilter, ApiResource, PaginatedIndex } from './api'; import { ProductCategory } from './product-category'; import { Machine } from './machine'; import { FileType, ImageType } from './file'; +import { AdvancedAccounting } from './advanced-accounting'; export type ProductSortOption = 'name-asc' | 'name-desc' | 'amount-asc' | 'amount-desc' | ''; @@ -119,4 +120,5 @@ export interface Product { thumb_attachment_url?: string, }>, product_stock_movements_attributes?: Array, + advanced_accounting_attributes?: AdvancedAccounting } diff --git a/app/models/advanced_accounting.rb b/app/models/advanced_accounting.rb index e56015812..740b186b7 100644 --- a/app/models/advanced_accounting.rb +++ b/app/models/advanced_accounting.rb @@ -6,5 +6,6 @@ class AdvancedAccounting < ApplicationRecord belongs_to :machine, foreign_type: 'Machine', foreign_key: 'accountable_id', inverse_of: :advanced_accounting belongs_to :training, foreign_type: 'Training', foreign_key: 'accountable_id', inverse_of: :advanced_accounting belongs_to :space, foreign_type: 'Space', foreign_key: 'accountable_id', inverse_of: :advanced_accounting - belongs_to :event, foreign_type: 'event', foreign_key: 'accountable_id', inverse_of: :advanced_accounting + belongs_to :event, foreign_type: 'Event', foreign_key: 'accountable_id', inverse_of: :advanced_accounting + belongs_to :product, foreign_type: 'Product', foreign_key: 'accountable_id', inverse_of: :advanced_accounting end diff --git a/app/models/product.rb b/app/models/product.rb index e7921a56a..777209525 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -20,6 +20,9 @@ class Product < ApplicationRecord has_many :product_stock_movements, dependent: :destroy accepts_nested_attributes_for :product_stock_movements, allow_destroy: true, reject_if: :all_blank + has_one :advanced_accounting, as: :accountable, dependent: :destroy + accepts_nested_attributes_for :advanced_accounting, allow_destroy: true + validates :name, :slug, presence: true validates :slug, uniqueness: { message: I18n.t('.errors.messages.slug_already_used') } validates :amount, numericality: { greater_than_or_equal_to: 0, allow_nil: true } diff --git a/app/views/api/products/_product.json.jbuilder b/app/views/api/products/_product.json.jbuilder index 961baf234..e0ebfa558 100644 --- a/app/views/api/products/_product.json.jbuilder +++ b/app/views/api/products/_product.json.jbuilder @@ -16,3 +16,9 @@ json.product_images_attributes product.product_images.order(created_at: :asc) do json.thumb_attachment_url f.attachment.thumb.url json.is_main f.is_main end + +if product.advanced_accounting + json.advanced_accounting_attributes do + json.partial! 'api/advanced_accounting/advanced_accounting', advanced_accounting: product.advanced_accounting + end +end