mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-15 02:33:22 +00:00
Remove ajax_select from accounting
This commit is contained in:
parent
afdc6b69df
commit
ab63ba1c54
@ -0,0 +1,60 @@
|
|||||||
|
import { AjaxSelect } from "#core:core/components/ajax-select-base";
|
||||||
|
import { registerComponent } from "#core:utils/web-components";
|
||||||
|
import type { TomOption } from "tom-select/dist/types/types";
|
||||||
|
import type { escape_html } from "tom-select/dist/types/utils";
|
||||||
|
import {
|
||||||
|
type ClubAccountSchema,
|
||||||
|
type CompanySchema,
|
||||||
|
accountingSearchClubAccount,
|
||||||
|
accountingSearchCompany,
|
||||||
|
} from "#openapi";
|
||||||
|
|
||||||
|
@registerComponent("club-account-ajax-select")
|
||||||
|
export class ClubAccountAjaxSelect extends AjaxSelect {
|
||||||
|
protected valueField = "id";
|
||||||
|
protected labelField = "name";
|
||||||
|
protected searchField = ["code", "name"];
|
||||||
|
|
||||||
|
protected async search(query: string): Promise<TomOption[]> {
|
||||||
|
const resp = await accountingSearchClubAccount({ query: { search: query } });
|
||||||
|
if (resp.data) {
|
||||||
|
return resp.data.results;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderOption(item: ClubAccountSchema, sanitize: typeof escape_html) {
|
||||||
|
return `<div class="select-item">
|
||||||
|
<span class="select-item-text">${sanitize(item.name)}</span>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderItem(item: ClubAccountSchema, sanitize: typeof escape_html) {
|
||||||
|
return `<span>${sanitize(item.name)}</span>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@registerComponent("company-ajax-select")
|
||||||
|
export class CompanyAjaxSelect extends AjaxSelect {
|
||||||
|
protected valueField = "id";
|
||||||
|
protected labelField = "name";
|
||||||
|
protected searchField = ["code", "name"];
|
||||||
|
|
||||||
|
protected async search(query: string): Promise<TomOption[]> {
|
||||||
|
const resp = await accountingSearchCompany({ query: { search: query } });
|
||||||
|
if (resp.data) {
|
||||||
|
return resp.data.results;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderOption(item: CompanySchema, sanitize: typeof escape_html) {
|
||||||
|
return `<div class="select-item">
|
||||||
|
<span class="select-item-text">${sanitize(item.name)}</span>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected renderItem(item: CompanySchema, sanitize: typeof escape_html) {
|
||||||
|
return `<span>${sanitize(item.name)}</span>`;
|
||||||
|
}
|
||||||
|
}
|
@ -61,10 +61,10 @@
|
|||||||
<script>
|
<script>
|
||||||
$( function() {
|
$( function() {
|
||||||
var target_type = $('#id_target_type');
|
var target_type = $('#id_target_type');
|
||||||
var user = $('#id_user_wrapper');
|
var user = $('user-ajax-select');
|
||||||
var club = $('#id_club_wrapper');
|
var club = $('club-ajax-select');
|
||||||
var club_account = $('#id_club_account_wrapper');
|
var club_account = $('club-account-ajax-select');
|
||||||
var company = $('#id_company_wrapper');
|
var company = $('company-ajax-select');
|
||||||
var other = $('#id_target_label');
|
var other = $('#id_target_label');
|
||||||
var need_link = $('#id_need_link_full');
|
var need_link = $('#id_need_link_full');
|
||||||
function update_targets () {
|
function update_targets () {
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from ajax_select.fields import AutoCompleteSelectField
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import PermissionDenied, ValidationError
|
from django.core.exceptions import PermissionDenied, ValidationError
|
||||||
@ -39,6 +38,13 @@ from accounting.models import (
|
|||||||
Operation,
|
Operation,
|
||||||
SimplifiedAccountingType,
|
SimplifiedAccountingType,
|
||||||
)
|
)
|
||||||
|
from accounting.widgets.select import (
|
||||||
|
AutoCompleteSelectClubAccount,
|
||||||
|
AutoCompleteSelectCompany,
|
||||||
|
)
|
||||||
|
from club.models import Club
|
||||||
|
from club.widgets.select import AutoCompleteSelectClub
|
||||||
|
from core.models import User
|
||||||
from core.views import (
|
from core.views import (
|
||||||
CanCreateMixin,
|
CanCreateMixin,
|
||||||
CanEditMixin,
|
CanEditMixin,
|
||||||
@ -47,6 +53,7 @@ from core.views import (
|
|||||||
TabedViewMixin,
|
TabedViewMixin,
|
||||||
)
|
)
|
||||||
from core.views.forms import SelectDate, SelectFile
|
from core.views.forms import SelectDate, SelectFile
|
||||||
|
from core.views.widgets.select import AutoCompleteSelectUser
|
||||||
from counter.models import Counter, Product, Selling
|
from counter.models import Counter, Product, Selling
|
||||||
|
|
||||||
# Main accounting view
|
# Main accounting view
|
||||||
@ -334,12 +341,30 @@ class OperationForm(forms.ModelForm):
|
|||||||
"invoice": SelectFile,
|
"invoice": SelectFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
user = AutoCompleteSelectField("users", help_text=None, required=False)
|
user = forms.ModelChoiceField(
|
||||||
club_account = AutoCompleteSelectField(
|
help_text=None,
|
||||||
"club_accounts", help_text=None, required=False
|
required=False,
|
||||||
|
widget=AutoCompleteSelectUser,
|
||||||
|
queryset=User.objects.all(),
|
||||||
|
)
|
||||||
|
club_account = forms.ModelChoiceField(
|
||||||
|
help_text=None,
|
||||||
|
required=False,
|
||||||
|
widget=AutoCompleteSelectClubAccount,
|
||||||
|
queryset=ClubAccount.objects.all(),
|
||||||
|
)
|
||||||
|
club = forms.ModelChoiceField(
|
||||||
|
help_text=None,
|
||||||
|
required=False,
|
||||||
|
widget=AutoCompleteSelectClub,
|
||||||
|
queryset=Club.objects.all(),
|
||||||
|
)
|
||||||
|
company = forms.ModelChoiceField(
|
||||||
|
help_text=None,
|
||||||
|
required=False,
|
||||||
|
widget=AutoCompleteSelectCompany,
|
||||||
|
queryset=Company.objects.all(),
|
||||||
)
|
)
|
||||||
club = AutoCompleteSelectField("clubs", help_text=None, required=False)
|
|
||||||
company = AutoCompleteSelectField("companies", help_text=None, required=False)
|
|
||||||
need_link = forms.BooleanField(
|
need_link = forms.BooleanField(
|
||||||
label=_("Link this operation to the target account"),
|
label=_("Link this operation to the target account"),
|
||||||
required=False,
|
required=False,
|
||||||
@ -817,8 +842,12 @@ class LabelDeleteView(CanEditMixin, DeleteView):
|
|||||||
|
|
||||||
|
|
||||||
class CloseCustomerAccountForm(forms.Form):
|
class CloseCustomerAccountForm(forms.Form):
|
||||||
user = AutoCompleteSelectField(
|
user = forms.ModelChoiceField(
|
||||||
"users", label=_("Refound this account"), help_text=None, required=True
|
label=_("Refound this account"),
|
||||||
|
help_text=None,
|
||||||
|
required=True,
|
||||||
|
widget=AutoCompleteSelectUser,
|
||||||
|
queryset=User.objects.all(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
45
accounting/widgets/select.py
Normal file
45
accounting/widgets/select.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
from django.forms import Select, SelectMultiple
|
||||||
|
|
||||||
|
from accounting.models import ClubAccount, Company
|
||||||
|
from accounting.schemas import ClubAccountSchema, CompanySchema
|
||||||
|
from core.views.widgets.select import AutoCompleteSelectMixin
|
||||||
|
|
||||||
|
|
||||||
|
class AutoCompleteSelectClubAccount(AutoCompleteSelectMixin, Select):
|
||||||
|
component_name = "club-account-ajax-select"
|
||||||
|
model = ClubAccount
|
||||||
|
schema = ClubAccountSchema
|
||||||
|
|
||||||
|
js = [
|
||||||
|
"webpack/accounting/components/ajax-select-index.ts",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AutoCompleteSelectMultipleClubAccount(AutoCompleteSelectMixin, SelectMultiple):
|
||||||
|
component_name = "club-account-ajax-select"
|
||||||
|
model = ClubAccount
|
||||||
|
schema = ClubAccountSchema
|
||||||
|
|
||||||
|
js = [
|
||||||
|
"webpack/accounting/components/ajax-select-index.ts",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AutoCompleteSelectCompany(AutoCompleteSelectMixin, Select):
|
||||||
|
component_name = "company-ajax-select"
|
||||||
|
model = Company
|
||||||
|
schema = CompanySchema
|
||||||
|
|
||||||
|
js = [
|
||||||
|
"webpack/accounting/components/ajax-select-index.ts",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class AutoCompleteSelectMultipleCompany(AutoCompleteSelectMixin, SelectMultiple):
|
||||||
|
component_name = "company-ajax-select"
|
||||||
|
model = Company
|
||||||
|
schema = CompanySchema
|
||||||
|
|
||||||
|
js = [
|
||||||
|
"webpack/accounting/components/ajax-select-index.ts",
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user