示例#1
0
class RequestReport(TabularListView):
    model = RequestItem
    title = _(u"Requests by unit")
    list_fields = [{'name': 'request__complied_date'},
                   {'name': 'request__request_unit'},
                   {'name': 'material__item_code'},
                   {'name': 'material__description'},
                   {'name': 'material__measure_unit'},
                   {'name': 'total_cost', 'style': 'text-align: right;', 'pdf_style': 'text-align: right;'},]
    totals = [{'field': 'total_cost', 'label': _(u'Sum of total cost: %s'), 'function': lambda x,y: x+y},]
    groups = [{'group_field': 'request__request_unit', 'totals': [{'field': 'total_cost', 'label': _(u'Total cost for %(key)s: %(value)s'), 'function': lambda x,y: x+y}]}]
    
    request_unit = forms.ModelChoiceField(queryset=OrganizationalUnit.objects.all(), required=False, empty_label=_(u'All units'))
    start_date = forms.DateField(label=_(u'Start date'))
    end_date = forms.DateField(label=_(u'End date'))
    
    def filter(self, queryset):
        if not self.is_valid():
            return None
        
        if self.cleaned_data['request_unit']:
            queryset = queryset.filter(request__request_unit=self.cleaned_data['request_unit'])
            
        queryset = queryset.filter(request__complied_date__gte=self.cleaned_data['start_date']) \
                           .filter(request__complied_date__lte=self.cleaned_data['end_date']) \
                           .filter(request__request_status='A')
        queryset = queryset.order_by('request__request_unit', 'request__complied_date', 'material')

        return queryset
示例#2
0
    def __init__(self, *args, **kwargs):
        super(CharacterForm, self).__init__(*args, **kwargs)

        classes = models.typeclasses.objects.filter(category="CATE_CHARACTER")
        self.fields['typeclass'] = forms.ModelChoiceField(queryset=classes)

        # models
        choices = [("", "---------")]

        model_records = models.character_models.objects.all()
        model_keys = set([obj.key for obj in model_records])
        choices.extend([(model_key, model_key) for model_key in model_keys])

        self.fields['model'] = forms.ChoiceField(choices=choices)
示例#3
0
    def __init__(self, *args, **kwargs):
        super(QuestRewardListForm, self).__init__(*args, **kwargs)

        # providers must be object_creators
        quests = models.quests.objects.all()
        self.fields['provider'] = forms.ModelChoiceField(queryset=quests)

        # available objects are common objects, foods or equipments
        choices = [("", "---------")]

        objects = models.common_objects.objects.all()
        choices.extend([(obj.key, obj.key) for obj in objects])

        foods = models.foods.objects.all()
        choices.extend([(obj.key, obj.key) for obj in foods])

        equipments = models.equipments.objects.all()
        choices.extend([(obj.key, obj.key) for obj in equipments])

        self.fields['object'] = forms.ChoiceField(choices=choices)
示例#4
0
    def __init__(self, *args, **kwargs):
        super(CreatorLootListForm, self).__init__(*args, **kwargs)

        # providers must be object_creators
        object_creators = models.world_objects.objects.filter(
            typeclass="CLASS_OBJECT_CREATOR")
        self.fields['provider'] = forms.ModelChoiceField(
            queryset=object_creators)

        # available objects are common objects, foods or equipments
        choices = [("", "---------")]

        objects = models.common_objects.objects.all()
        choices.extend([(obj.key, obj.key) for obj in objects])

        foods = models.foods.objects.all()
        choices.extend([(obj.key, obj.key) for obj in foods])

        equipments = models.equipments.objects.all()
        choices.extend([(obj.key, obj.key) for obj in equipments])

        self.fields['object'] = forms.ChoiceField(choices=choices)
示例#5
0
    def __init__(self, *args, **kwargs):
        super(WorldObjectsForm, self).__init__(*args, **kwargs)

        classes = models.typeclasses.objects.filter(category="CATE_OBJECT")
        self.fields['typeclass'] = forms.ModelChoiceField(queryset=classes)
示例#6
0
    def __init__(self, *args, **kwargs):
        super(ExitLocksForm, self).__init__(*args, **kwargs)

        locked_exits = models.world_exits.objects.filter(
            typeclass="CLASS_LOCKED_EXIT")
        self.fields['key'] = forms.ModelChoiceField(queryset=locked_exits)
示例#7
0
    def __init__(self, *args, **kwargs):
        super(ObjectCreatorsForm, self).__init__(*args, **kwargs)

        object_creators = models.world_objects.objects.filter(
            typeclass="CLASS_OBJECT_CREATOR")
        self.fields['key'] = forms.ModelChoiceField(queryset=object_creators)
示例#8
0
class InventoryReport(TabularListView):
    app_label = 'spat'
    title = _(u"Asset inventory report")
    page_size = "A4 landscape"
    list_fields = [{
        'name': 'unit',
        'width': '12%',
        'label': _('Unit')
    }, {
        'name': 'asset_code',
        'style': 'text-align: right;',
        'pdf_style': 'text-align: right;',
        'width': '4%',
        'label': _('Asset code')
    }, {
        'name': 'description',
        'width': '77%',
        'label': _('Description')
    }, {
        'name': 'value',
        'style': 'text-align: right;',
        'pdf_style': 'text-align: right;',
        'width': '7%',
        'label': _('Value')
    }]

    analitical_groups = [{
        'group_field':
        'value',
        'totals': [{
            'field':
            'unit',
            'label':
            _(u"Total for Organizational Unit %(value)s: %(key)s"),
            'function':
            lambda x, y: x + y
        }]
    }]

    groups = analitical_groups
    totals = [{
        'field': 'value',
        'label': 'Total inventory: (%s)',
        'function': lambda x, y: x + y
    }]

    year_month = forms.CharField(
        label=_(u"Year month"),
        max_length=6,
        min_length=6,
        help_text=
        _(u"Format: yyyymm where yyyy is the four digits year and mm is the two-digits month"
          ))
    report_mode = forms.ChoiceField(label=_(u"Report mode"),
                                    choices=(('S', 'Synthetic'),
                                             ('A', 'Analytical')),
                                    widget=forms.RadioSelect)
    unit = forms.ModelChoiceField(queryset=OrganizationalUnit.objects.all(),
                                  required=False,
                                  empty_label=_(u"All units"),
                                  label=_("Organizational unit"))

    def get_queryset(self):
        self.form_load_data()
        if not self.is_valid():
            return None

        year_month = self.cleaned_data['year_month']
        report_mode = self.cleaned_data['report_mode']
        unit = self.cleaned_data['unit']

        result = []
        inventory = get_object_or_404(Inventory, year_month=year_month)

        detail_set = inventory.inventorydetail_set.all()
        if unit is not None:
            detail_set = inventory.inventorydetail_set.filter(unit=unit)

        if report_mode == 'A':
            self.groups = self.analitical_groups
            for detail in detail_set:
                result.append({
                    'unit': detail.unit.name,
                    'asset_code': detail.asset.asset_code,
                    'description': detail.asset_description,
                    'value': detail.asset_value
                })
        else:
            self.groups = []
            for unit_rec in detail_set.values('unit__name').annotate(
                    total_value=Sum('asset_value')):
                result.append({
                    'unit': unit_rec['unit__name'],
                    'asset_code': '****',
                    'description': unit_rec['unit__name'],
                    'value': unit_rec['total_value'],
                })

        return result
示例#9
0
class SheetEvolutionReport(TabularListView):
    title = _(u"Sheet evolution report")
    app_label = 'spat'
    page_size = 'A4 landscape'
    year_month_start = forms.CharField(label=_(u"Start year/month"),
                                       min_length=6,
                                       max_length=6)
    year_month_end = forms.CharField(label=_(u"End year/month"),
                                     min_length=6,
                                     max_length=6)
    unit = forms.ModelChoiceField(queryset=OrganizationalUnit.objects.all(),
                                  required=False,
                                  empty_label=_(u"All units"),
                                  label=_("Organizational unit"))

    def get_queryset(self):
        self.form_load_data()
        if not self.is_valid():
            return None

        start = self.cleaned_data['year_month_start']
        end = self.cleaned_data['year_month_end']
        unit = self.cleaned_data['unit']

        return self.get_data(start=start, end=end, unit=unit)

    def get_data(self, start, end, unit=None):
        start_year = int(start[:4])
        start_month = int(start[4:])
        end_year = int(end[:4])
        end_month = int(end[4:])

        stt = datetime.datetime.strptime(
            "%s-%s-01" % (
                start_year,
                start_month,
            ), '%Y-%m-%d')
        ett = datetime.datetime.strptime("%s-%s-01" % (
            end_year,
            end_month,
        ), '%Y-%m-%d')

        if stt >= ett:
            raise Exception("Start date must be less than end date.")

        months = []
        queryset = []
        clear_line = {
            'unit_id': None,
            'unit_name': None,
        }

        while stt <= ett:
            year_month = "%04d%02d" % (start_year, start_month)
            months.append(year_month)
            clear_line[year_month] = 0
            start_month += 1
            if start_month > 12:
                start_year += 1
                start_month = 1
            stt = datetime.datetime.strptime(
                "%s-%s-01" % (
                    start_year,
                    start_month,
                ), '%Y-%m-%d')

        if unit is None:
            unit_set = OrganizationalUnit.objects.all()
        else:
            unit_set = [unit]

        for unit in unit_set:
            unit_line = clear_line.copy()
            unit_line['unit_id'] = unit.id
            unit_line['unit_name'] = unit.name
            queryset.append(unit_line)

        for detail in InventoryDetail.objects.filter(inventory_id__in=months,
                                                     unit__in=unit_set):
            unit_line = [
                r for r in queryset if r['unit_id'] == detail.unit_id
            ][0]
            unit_line[detail.inventory_id] += detail.asset_value

        self.list_fields = [
            'unit_name'
        ] + [{
            'name': m,
            'style': 'text-align:right;',
            'pdf_style': 'text-align:right;',
            'label': _("%(year)s-%(month)s" % {
                'year': m[:4],
                'month': m[4:]
            })
        } for m in months]
        self.totals = [{
            'field': m,
            'label': '%s',
            'function': lambda x, y: x + y
        } for m in months]
        self.get_list_fields()  # Force list field processing

        return queryset
示例#10
0
class InventoryReport(TabularListView):
    app_label = 'smat'
    page_size = "A4 landscape"
    title = _(u"Inventory report")
    template_name = 'smat/reports/inventory_report.html'
    template_name_pdf = 'smat/reports/inventory_report_pdf.html'
    total = {'before': 0, 'input': 0, 'output': 0, 'after': 0}

    material_class = forms.ModelChoiceField(label=_(u'Material class'), queryset=MaterialClass.objects.all(), required=False, empty_label=_(u'All classes'))
    start_date = forms.DateField(label=_(u'Start date'))
    end_date = forms.DateField(label=_(u'End date'))

    def get_queryset(self):
        self.form_load_data()
        if not self.is_valid():
            return None
        
        start_date = self.cleaned_data['start_date']
        end_date = self.cleaned_data['end_date']
        
        result = []
        self.total = {'before': 0, 'input': 0, 'output': 0, 'after': 0}
        materials = Material.objects.all().order_by('material_class', 'description')

        if self.cleaned_data['material_class']  is not None:
            materials = materials.filter(material_class=self.cleaned_data['material_class'])
            
        last_mc = None
        mc_total = {'before': 0, 'input': 0, 'output': 0, 'after': 0}
        
        for m in materials:
            if last_mc is None:
                last_mc = m.material_class
            
            if last_mc != m.material_class:
                result.append({'group_description': _(u'Totals for %s') % last_mc, 'group_total': mc_total.copy()})
                mc_total = {'before': 0, 'input': 0, 'output': 0, 'after': 0}
                last_mc = m.material_class

            row = {'item_code': m.item_code, 'description': m.description, 'measure_unit': m.measure_unit} 
            clusters = m.materialcluster_set
            clusters = clusters.exclude(Q(creation_date__lt=start_date) & Q(last_change__lt=end_date) & Q(quantity__lte=0))
            clusters = clusters.exclude(creation_date__gt=end_date)
            movements = None 
            for cl in clusters.order_by('creation_date'):
                movs = cl.materialmovement_set.exclude(mov_date__lt=start_date).exclude(mov_date__gt=end_date)
                if movements is None:
                    movements = movs
                else:
                    movements = movements | movs
            if movements is not None:
                for m in movements.order_by('mov_date'):
                    if 'physical' not in row:
                        row['physical'] = {'before': m.qty_before_mov, 'input': 0, 'output': 0, 'after': m.qty_before_mov}  
                        row['financial'] = {'before': m.qty_before_mov * m.unit_cost, 'input': 0, 'output': 0, 'after': m.qty_before_mov * m.unit_cost}
                        self.total['before'] += m.qty_before_mov * m.unit_cost
                        self.total['after'] += m.qty_before_mov * m.unit_cost
                        mc_total['before'] += m.qty_before_mov * m.unit_cost
                        mc_total['after'] += m.qty_before_mov * m.unit_cost
                    if m.type == 'E':
                        row['physical']['input'] += m.quantity
                        row['physical']['after'] += m.quantity
                        row['financial']['input'] += m.quantity * m.unit_cost
                        row['financial']['after'] += m.quantity * m.unit_cost
                        self.total['input'] += m.quantity * m.unit_cost
                        self.total['after'] += m.quantity * m.unit_cost
                        mc_total['input'] += m.quantity * m.unit_cost
                        mc_total['after'] += m.quantity * m.unit_cost
                    else:
                        row['physical']['output'] += m.quantity
                        row['physical']['after'] -= m.quantity
                        row['financial']['output'] += m.quantity * m.unit_cost
                        row['financial']['after'] -= m.quantity * m.unit_cost
                        self.total['output'] += m.quantity * m.unit_cost
                        self.total['after'] -= m.quantity * m.unit_cost
                        mc_total['output'] += m.quantity * m.unit_cost
                        mc_total['after'] -= m.quantity * m.unit_cost
                if 'physical' in row:
                    result.append(row)

        result.append({'group_description': _(u'Totals for %s') % last_mc, 'group_total': mc_total.copy()})

        return result