-
Notifications
You must be signed in to change notification settings - Fork 43
feat(warehouse): deduct consumption from the workshop location it cam… #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jakub-przepiora
merged 9 commits into
develop
from
feat/consumption-stock-deduction-by-location
Sep 1, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
92b3fdc
feat(warehouse): deduct consumption from the workshop location it cam…
JanKolo04 26792a0
Merge branch 'develop' into feat/consumption-stock-deduction-by-location
JanKolo04 5396c89
fix(warehouse): gate consumption deduction on the Warehouses module
JanKolo04 d13c41f
Merge branch 'develop' into feat/consumption-stock-deduction-by-location
JanKolo04 a8b7dad
fix(warehouse): address CodeRabbit review on consumption-by-location
JanKolo04 c643d47
Merge branch 'develop' into feat/consumption-stock-deduction-by-location
JanKolo04 ee77bfb
Merge branch 'develop' into feat/consumption-stock-deduction-by-location
JanKolo04 d905000
fix(warehouse): address second CodeRabbit round on consumption-by-loc…
JanKolo04 d3710eb
Merge remote-tracking branch 'origin/develop' into feat/consumption-s…
jakub-przepiora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
backend/app/Http/Requests/Concerns/ValidatesLineStockLocation.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Requests\Concerns; | ||
|
|
||
| use App\Models\Warehouse; | ||
| use Illuminate\Validation\Rule; | ||
|
|
||
| /** | ||
| * The rule set behind a line's stock location, shared by create and edit. | ||
| * | ||
| * It has to match what the form actually offers (LineManagementController:: | ||
| * warehouseOptions): a live, active warehouse that may hold materials. A line | ||
| * draws components, never finished goods, and pointing one at an archived or | ||
| * finished-goods store would send every consumption deduction somewhere that | ||
| * cannot answer for it. | ||
| * | ||
| * `Rule::exists` queries the table directly and so bypasses the model's global | ||
| * TenantScope — the tenant clause below is what keeps one tenant from naming | ||
| * another tenant's warehouse by id. | ||
| */ | ||
| trait ValidatesLineStockLocation | ||
| { | ||
| /** @return array<int, mixed> */ | ||
| protected function stockLocationRules(): array | ||
| { | ||
| return [ | ||
| 'nullable', | ||
| 'integer', | ||
| Rule::exists('warehouses', 'id') | ||
| ->whereNull('deleted_at') | ||
| ->where('is_active', true) | ||
| ->whereIn('kind', [Warehouse::KIND_RAW_MATERIAL, Warehouse::KIND_MIXED]) | ||
| ->where(function ($query) { | ||
| // Mirrors TenantScope exactly: scope to the tenant when there is | ||
| // one, and to nothing when there is not. Rejecting outright on a | ||
| // null tenant would break every single-tenant install — tenancy is | ||
| // dormant there, so users and warehouses both carry a null | ||
| // tenant_id and the picker offers all of them. | ||
| $tenantId = $this->user()?->tenant_id; | ||
|
|
||
| if ($tenantId) { | ||
| $query->where('tenant_id', $tenantId); | ||
| } | ||
| }), | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Requests\Web\Admin; | ||
|
|
||
| use App\Http\Requests\Concerns\MergesCustomFieldRules; | ||
| use App\Http\Requests\Concerns\ValidatesLineStockLocation; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| class StoreLineRequest extends FormRequest | ||
| { | ||
| use MergesCustomFieldRules; | ||
| use ValidatesLineStockLocation; | ||
|
|
||
| public function authorize(): bool | ||
| { | ||
| // Route middleware already restricts admin routes to the Admin role. | ||
| return true; | ||
| } | ||
|
|
||
| protected function customFieldEntityType(): string | ||
| { | ||
| return 'line'; | ||
| } | ||
|
|
||
| /** A missing checkbox on create means "not filled in", not "unchecked". */ | ||
| protected function prepareForValidation(): void | ||
| { | ||
| $this->merge(['is_active' => $this->boolean('is_active', true)]); | ||
| } | ||
|
|
||
| public function rules(): array | ||
| { | ||
| return array_merge([ | ||
| 'code' => ['required', 'string', 'max:50', 'unique:lines,code'], | ||
| 'name' => ['required', 'string', 'max:255'], | ||
| 'description' => ['nullable', 'string'], | ||
| 'area_id' => ['nullable', 'exists:areas,id'], | ||
| // The stock location this line's consumption comes off. | ||
| 'warehouse_id' => $this->stockLocationRules(), | ||
| 'is_active' => ['boolean'], | ||
| ], $this->customFieldRules()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Requests\Web\Admin; | ||
|
|
||
| use App\Http\Requests\Concerns\MergesCustomFieldRules; | ||
| use App\Http\Requests\Concerns\ValidatesLineStockLocation; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
| use Illuminate\Validation\Rule; | ||
|
|
||
| class UpdateLineRequest extends FormRequest | ||
| { | ||
| use MergesCustomFieldRules; | ||
| use ValidatesLineStockLocation; | ||
|
|
||
| public function authorize(): bool | ||
| { | ||
| // Route middleware already restricts admin routes to the Admin role. | ||
| return true; | ||
| } | ||
|
|
||
| protected function customFieldEntityType(): string | ||
| { | ||
| return 'line'; | ||
| } | ||
|
|
||
| /** On edit an unticked checkbox really does mean "inactive". */ | ||
| protected function prepareForValidation(): void | ||
| { | ||
| $this->merge(['is_active' => $this->boolean('is_active')]); | ||
| } | ||
|
|
||
| public function rules(): array | ||
| { | ||
| return array_merge([ | ||
| 'code' => [ | ||
| 'required', 'string', 'max:50', | ||
| Rule::unique('lines', 'code')->ignore($this->route('line')?->id), | ||
| ], | ||
| 'name' => ['required', 'string', 'max:255'], | ||
| 'description' => ['nullable', 'string'], | ||
| 'area_id' => ['nullable', 'exists:areas,id'], | ||
| // The stock location this line's consumption comes off. | ||
| 'warehouse_id' => $this->stockLocationRules(), | ||
| 'is_active' => ['boolean'], | ||
| ], $this->customFieldRules()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.