GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ReservableBasket   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 21
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _compare_line_for_addition() 0 6 2
A add_product() 0 13 3
1
import datetime
2
3
from shoop.front.basket.objects import BaseBasket
4
from shoop.front.basket.order_creator import BasketOrderCreator
5
from shoop.utils.dates import parse_date
6
7
from reservations.models import Reservation, ReservableProduct
8
9
10
class ReservableBasket(BaseBasket):
11
    def _compare_line_for_addition(self, current_line_data, product, supplier, shop, extra):
12
        if product.type.identifier == "reservable":
13
            # Never add to existing reservation lines
14
            return False
15
        return super(
16
            ReservableBasket, self)._compare_line_for_addition(current_line_data, product, supplier, shop, extra)
17
18
    def add_product(self, supplier, shop, product, quantity, force_new_line=False, extra=None, parent_line=None):
19
        if not extra:
20
            extra = {}
21
        if self.request.POST.get("start", None):
0 ignored issues
show
Bug introduced by
The Instance of ReservableBasket does not seem to have a member named request.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
22
            extra["reservation_start"] = parse_date(self.request.POST.get("start"))
0 ignored issues
show
Bug introduced by
The Instance of ReservableBasket does not seem to have a member named request.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
23
            extra["persons"] = self.request.POST.get("persons", 1)
0 ignored issues
show
Bug introduced by
The Instance of ReservableBasket does not seem to have a member named request.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
24
        # TODO: enable this here once https://github.com/shoopio/shoop/issues/291 is resolved in some way
25
        # Currently setting `force_new_line` causes product not to be added at all.
26
        # Once this works, remove above override of `_compare_line_for_addition`.
27
        # if product.type.identifier == "reservable":
28
        #     force_new_line = True
29
        return super(ReservableBasket, self).add_product(
30
            supplier, shop, product, quantity, force_new_line=force_new_line, extra=extra, parent_line=parent_line)
31
32
33
class ReservableOrderCreator(BasketOrderCreator):
34
    def process_saved_order_line(self, order, order_line):
35
        if order_line.product and order_line.product.type.identifier == "reservable":
36
            # Create reservation
37
            start_date = order_line.source_line.get("reservation_start")
38
            reservable = ReservableProduct.objects.get(product=order_line.product)
0 ignored issues
show
Bug introduced by
The Class ReservableProduct does not seem to have a member named objects.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
39
            start_time = datetime.datetime.combine(start_date, reservable.check_in_time)
40
            end_date = start_date + datetime.timedelta(days=int(order_line.quantity))
41
            end_time = datetime.datetime.combine(end_date, reservable.check_out_time)
42
            Reservation.objects.create(
0 ignored issues
show
Bug introduced by
The Class Reservation does not seem to have a member named objects.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
43
                reservable=reservable,
44
                order_line=order_line,
45
                start_time=start_time,
46
                end_time=end_time,
47
                persons=order_line.source_line.get("persons", 1),
48
            )
49
            if not order_line.extra_data:
50
                order_line.extra_data = {}
51
            order_line.extra_data["reservation_start"] = order_line.source_line.get("reservation_start")
52
            order_line.extra_data["reservation_end"] = end_date.strftime("%Y-%m-%d")
53
            order_line.extra_data["persons"] = order_line.source_line.get("persons", 1)
54
            order_line.save()
55