1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) advanced accounting for products

This commit is contained in:
Sylvain 2022-11-10 16:22:01 +01:00
parent 7868f31a58
commit 4a9cbbb227
7 changed files with 21 additions and 3 deletions

View File

@ -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

View File

@ -118,7 +118,7 @@ export const FormImageUpload = <TFieldValues extends FieldValues, TContext exten
register={register}
label={label}
formState={formState}
rules={{ ...rules, required: rules.required && !hasImage() }}
rules={{ ...rules, required: rules?.required && !hasImage() }}
disabled={disabled}
error={error}
warning={warning}

View File

@ -23,6 +23,7 @@ import { UIRouter } from '@uirouter/angularjs';
import { SelectOption, ChecklistOption } from '../../models/select';
import { FormMultiFileUpload } from '../form/form-multi-file-upload';
import { FormMultiImageUpload } from '../form/form-multi-image-upload';
import { AdvancedAccountingForm } from '../accounting/advanced-accounting-form';
interface ProductFormProps {
product: Product,
@ -307,6 +308,10 @@ export const ProductForm: React.FC<ProductFormProps> = ({ product, title, onSucc
className="product-documents" />
</div>
<hr />
<AdvancedAccountingForm register={register} onError={onError} />
<div className="main-actions">
<FabButton type="submit" className="main-action-btn" disabled={saving}>
{!saving && t('app.admin.store.product_form.save')}

View File

@ -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<ProductStockMovement>,
advanced_accounting_attributes?: AdvancedAccounting
}

View File

@ -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

View File

@ -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 }

View File

@ -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