コード例 #1
0
ファイル: managers.py プロジェクト: Ra3bOjN1K/order_manager
    def create(self, **kwargs):
        from orders_manager.models import (Order, AdditionalService,
            ClientChild, OrderServiceExecutors, UserProfile)

        celebrate_date = kwargs.get('celebrate_date')

        order = Order()
        order.code = '{0}-{1}'.format(
            format_date(
                datetime.combine(celebrate_date, datetime.min.time()),
                pattern='%Y%m%d'
            ),
            generate_str(num_chars=3)
        )

        order.author = self._get_author(**kwargs)
        order.client_id = self._get_client_id(**kwargs)
        order.children_num = kwargs.get('children_num')
        order.celebrate_date = celebrate_date
        order.celebrate_time = kwargs.get('celebrate_time')
        order.celebrate_place = kwargs.get('celebrate_place')
        order.address = kwargs.get('address')
        order.program_id = self._get_program_id(**kwargs)
        order.duration = kwargs.get('duration')
        order.price = kwargs.get('price')
        order.discount_id = self._get_discount_id(**kwargs)
        order.total_price = kwargs.get('total_price')
        order.total_price_with_discounts = kwargs.get(
            'total_price_with_discounts')
        order.details = kwargs.get('details')
        order.executor_comment = kwargs.get('executor_comment')
        order.where_was_found = kwargs.get('where_was_found')
        order.cost_of_the_way = kwargs.get('cost_of_the_way')

        order.save()

        for child_id in self._get_client_children_ids(**kwargs):
            child = ClientChild.objects.get(id=child_id)
            order.client_children.add(child)

        for prog_executor_id in self._get_program_executors_ids(**kwargs):
            executor = UserProfile.objects.get(user__id=prog_executor_id)
            order.program_executors.add(executor)

        for item in self._get_services_to_executors(**kwargs):
            for ex in item.get('executors'):
                executor_id = ex.get('id')
                if executor_id and item.get('service_id'):
                    order_serv_obj = OrderServiceExecutors.objects.create(**{
                        'executor_id': executor_id,
                        'additional_service_id': item.get('service_id')
                    })
                    order.additional_services_executors.add(order_serv_obj)
                    order.save()

        # for service_id in self._get_additional_services(**kwargs):
        #     serv = AdditionalService.objects.get(id=service_id)
        #     order.additional_services.add(serv)

        return order
コード例 #2
0
    def create(self, **kwargs):
        from orders_manager.models import (Order, AdditionalService,
                                           ClientChild, OrderServiceExecutors,
                                           UserProfile)

        celebrate_date = kwargs.get('celebrate_date')

        order = Order()
        order.code = '{0}-{1}'.format(
            format_date(datetime.combine(celebrate_date, datetime.min.time()),
                        pattern='%Y%m%d'), generate_str(num_chars=3))

        order.author = self._get_author(**kwargs)
        order.client_id = self._get_client_id(**kwargs)
        order.children_num = kwargs.get('children_num')
        order.celebrate_date = celebrate_date
        order.celebrate_time = kwargs.get('celebrate_time')
        order.celebrate_place = kwargs.get('celebrate_place')
        order.address = kwargs.get('address')
        order.program_id = self._get_program_id(**kwargs)
        order.duration = kwargs.get('duration')
        order.price = kwargs.get('price')
        order.discount_id = self._get_discount_id(**kwargs)
        order.total_price = kwargs.get('total_price')
        order.total_price_with_discounts = kwargs.get(
            'total_price_with_discounts')
        order.details = kwargs.get('details')
        order.executor_comment = kwargs.get('executor_comment')
        order.where_was_found = kwargs.get('where_was_found')
        order.cost_of_the_way = kwargs.get('cost_of_the_way')

        order.save()

        for child_id in self._get_client_children_ids(**kwargs):
            child = ClientChild.objects.get(id=child_id)
            order.client_children.add(child)

        for prog_executor_id in self._get_program_executors_ids(**kwargs):
            executor = UserProfile.objects.get(user__id=prog_executor_id)
            order.program_executors.add(executor)

        for item in self._get_services_to_executors(**kwargs):
            for ex in item.get('executors'):
                executor_id = ex.get('id')
                if executor_id and item.get('service_id'):
                    order_serv_obj = OrderServiceExecutors.objects.create(
                        **{
                            'executor_id': executor_id,
                            'additional_service_id': item.get('service_id')
                        })
                    order.additional_services_executors.add(order_serv_obj)
                    order.save()

        # for service_id in self._get_additional_services(**kwargs):
        #     serv = AdditionalService.objects.get(id=service_id)
        #     order.additional_services.add(serv)

        return order
コード例 #3
0
ファイル: forms.py プロジェクト: Ra3bOjN1K/order_manager
    def __init__(self, *args, **kwargs):
        from orders_manager.utils.data_utils import format_date

        celebrate_date = kwargs.pop('celebrate_date', None)

        super(OrderModelForm, self).__init__(*args, **kwargs)

        self.fields['client'].widget = forms.TextInput()
        self.fields['client_children'] = forms.ModelMultipleChoiceField(
            queryset=ClientChild.objects.none(),
            widget=ClientChildrenMultipleChoiceField(),
            label='Виновник(-и) торжества:'
        )
        if celebrate_date:
            self.fields['celebrate_date'].widget = forms.TextInput(
                attrs={
                    'value': format_date(
                        celebrate_date,
                        'Дата: %d.%m.%Y   Время: %H:%M'
                    )
                }
            )
        self.fields['address'].widget = AddressMultiTextInput()
        self.fields['program'].queryset = Program.objects.all()
        self.fields['possible_program_executors'] = \
            forms.ModelMultipleChoiceField(
                queryset=UserProfile.objects.none(),
                widget=ExecutorsMultipleChoiceField(),
                label='Возможные исполнители программы:'
            )
        self.fields['additional_services'] = \
            forms.ModelMultipleChoiceField(
                queryset=AdditionalService.objects.all(),
                widget=ServicesMultipleChoiceField(),
                label='Список дополнительнх услуг:'
            )
        self.fields['possible_services_executors'] = \
            forms.ModelMultipleChoiceField(
                queryset=UserProfile.objects.none(),
                widget=ExecutorsMultipleChoiceField(),
                label='Исполнители дополнительнх услуг:'
            )
        self.fields['duration'] = forms.ChoiceField(label='Продолжительность:')
        self.fields['price'].widget = forms.TextInput(
            attrs={'readonly': True}
        )
        self.fields['total_price'].widget = forms.TextInput(
            attrs={'readonly': True},
        )
        self.fields['total_price_with_discounts'].widget = forms.TextInput(
            attrs={'readonly': True}
        )
コード例 #4
0
    def __init__(self, *args, **kwargs):
        from orders_manager.utils.data_utils import format_date

        celebrate_date = kwargs.pop('celebrate_date', None)

        super(OrderModelForm, self).__init__(*args, **kwargs)

        self.fields['client'].widget = forms.TextInput()
        self.fields['client_children'] = forms.ModelMultipleChoiceField(
            queryset=ClientChild.objects.none(),
            widget=ClientChildrenMultipleChoiceField(),
            label='Виновник(-и) торжества:')
        if celebrate_date:
            self.fields['celebrate_date'].widget = forms.TextInput(
                attrs={
                    'value':
                    format_date(celebrate_date,
                                'Дата: %d.%m.%Y   Время: %H:%M')
                })
        self.fields['address'].widget = AddressMultiTextInput()
        self.fields['program'].queryset = Program.objects.all()
        self.fields['possible_program_executors'] = \
            forms.ModelMultipleChoiceField(
                queryset=UserProfile.objects.none(),
                widget=ExecutorsMultipleChoiceField(),
                label='Возможные исполнители программы:'
            )
        self.fields['additional_services'] = \
            forms.ModelMultipleChoiceField(
                queryset=AdditionalService.objects.all(),
                widget=ServicesMultipleChoiceField(),
                label='Список дополнительнх услуг:'
            )
        self.fields['possible_services_executors'] = \
            forms.ModelMultipleChoiceField(
                queryset=UserProfile.objects.none(),
                widget=ExecutorsMultipleChoiceField(),
                label='Исполнители дополнительнх услуг:'
            )
        self.fields['duration'] = forms.ChoiceField(label='Продолжительность:')
        self.fields['price'].widget = forms.TextInput(attrs={'readonly': True})
        self.fields['total_price'].widget = forms.TextInput(
            attrs={'readonly': True}, )
        self.fields['total_price_with_discounts'].widget = forms.TextInput(
            attrs={'readonly': True})