2018-04-16 14:32:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.contrib import admin
|
2022-05-12 02:44:15 +00:00
|
|
|
|
2019-04-30 06:35:40 +00:00
|
|
|
from import_export.admin import ImportExportModelAdmin
|
2022-05-12 02:44:15 +00:00
|
|
|
from import_export.fields import Field
|
|
|
|
from import_export.resources import ModelResource
|
|
|
|
import import_export.widgets as widgets
|
|
|
|
|
|
|
|
from build.models import Build, BuildItem
|
|
|
|
|
|
|
|
import part.models
|
|
|
|
|
|
|
|
|
|
|
|
class BuildResource(ModelResource):
|
|
|
|
"""Class for managing import/export of Build data"""
|
|
|
|
# For some reason, we need to specify the fields individually for this ModelResource,
|
2022-05-12 02:47:25 +00:00
|
|
|
# but we don't for other ones.
|
2022-05-12 02:44:15 +00:00
|
|
|
# TODO: 2022-05-12 - Need to investigate why this is the case!
|
|
|
|
|
|
|
|
pk = Field(attribute='pk')
|
|
|
|
|
|
|
|
reference = Field(attribute='reference')
|
|
|
|
|
|
|
|
title = Field(attribute='title')
|
|
|
|
|
|
|
|
part = Field(attribute='part', widget=widgets.ForeignKeyWidget(part.models.Part))
|
|
|
|
|
|
|
|
part_name = Field(attribute='part__full_name', readonly=True)
|
|
|
|
|
|
|
|
overdue = Field(attribute='is_overdue', readonly=True, widget=widgets.BooleanWidget())
|
|
|
|
|
|
|
|
completed = Field(attribute='completed', readonly=True)
|
|
|
|
|
|
|
|
quantity = Field(attribute='quantity')
|
|
|
|
|
|
|
|
status = Field(attribute='status')
|
|
|
|
|
|
|
|
batch = Field(attribute='batch')
|
|
|
|
|
|
|
|
notes = Field(attribute='notes')
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
models = Build
|
|
|
|
skip_unchanged = True
|
|
|
|
report_skipped = False
|
|
|
|
clean_model_instances = True
|
|
|
|
exclude = [
|
|
|
|
'lft', 'rght', 'tree_id', 'level',
|
|
|
|
]
|
2018-04-16 14:32:02 +00:00
|
|
|
|
|
|
|
|
2019-04-30 06:35:40 +00:00
|
|
|
class BuildAdmin(ImportExportModelAdmin):
|
2018-04-16 14:32:02 +00:00
|
|
|
|
2021-10-14 07:57:02 +00:00
|
|
|
exclude = [
|
|
|
|
'reference_int',
|
|
|
|
]
|
|
|
|
|
2019-04-30 06:35:40 +00:00
|
|
|
list_display = (
|
2020-10-19 11:40:19 +00:00
|
|
|
'reference',
|
|
|
|
'title',
|
2019-04-30 06:35:40 +00:00
|
|
|
'part',
|
|
|
|
'status',
|
|
|
|
'batch',
|
|
|
|
'quantity',
|
|
|
|
)
|
|
|
|
|
2020-09-29 13:41:50 +00:00
|
|
|
search_fields = [
|
2020-10-19 11:40:19 +00:00
|
|
|
'reference',
|
2020-09-29 13:41:50 +00:00
|
|
|
'title',
|
|
|
|
'part__name',
|
|
|
|
'part__description',
|
|
|
|
]
|
|
|
|
|
2021-12-04 09:16:53 +00:00
|
|
|
autocomplete_fields = [
|
|
|
|
'parent',
|
|
|
|
'part',
|
|
|
|
'sales_order',
|
|
|
|
'take_from',
|
|
|
|
'destination',
|
|
|
|
]
|
|
|
|
|
2019-04-30 06:35:40 +00:00
|
|
|
|
|
|
|
class BuildItemAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
list_display = (
|
|
|
|
'build',
|
|
|
|
'stock_item',
|
|
|
|
'quantity'
|
|
|
|
)
|
2018-04-17 08:29:40 +00:00
|
|
|
|
2021-12-04 09:16:53 +00:00
|
|
|
autocomplete_fields = [
|
|
|
|
'build',
|
|
|
|
'bom_item',
|
|
|
|
'stock_item',
|
|
|
|
'install_into',
|
|
|
|
]
|
|
|
|
|
2018-04-17 14:03:42 +00:00
|
|
|
|
2018-04-16 14:32:02 +00:00
|
|
|
admin.site.register(Build, BuildAdmin)
|
2019-04-30 06:35:40 +00:00
|
|
|
admin.site.register(BuildItem, BuildItemAdmin)
|