39
41
from stoqdrivers.devices.printers.interface import (ICouponPrinter,
44
_ = lambda msg: gettext.dgettext("stoqdrivers", msg)
43
47
def __init__(self, id, quantity, value):
44
48
self.id, self.quantity, self.value = id, quantity, value
71
75
def _check_coupon_is_opened(self):
72
76
if not self.is_coupon_opened:
73
raise CouponOpenError("There is no coupon opened!")
77
raise CouponOpenError(_("There is no coupon opened!"))
75
79
def _check_coupon_is_closed(self):
76
80
if self.is_coupon_opened:
77
raise CouponOpenError("There is a coupon already open")
81
raise CouponOpenError(_("There is a coupon already open"))
80
84
# ICouponPrinter implementation
93
97
taxcode, discount, charge):
94
98
self._check_coupon_is_opened()
95
99
if self.is_coupon_totalized:
96
raise ItemAdditionError("The coupon is already totalized, "
97
"you can't add items anymore.")
100
raise ItemAdditionError(_("The coupon is already totalized, "
101
"you can't add items anymore."))
98
102
self.items_quantity += 1
99
103
item_id = self.items_quantity
100
104
self._items[item_id] = CouponItem(item_id, quantity, price)
103
107
def coupon_cancel_item(self, item_id):
104
108
self._check_coupon_is_opened()
105
109
if not item_id in self._items:
106
raise CancelItemError("There is no item with this ID (%d)"
110
raise CancelItemError(_("There is no item with this ID (%d)")
108
112
elif self.is_coupon_totalized:
109
raise CancelItemError("The coupon is already totalized, "
110
"you can't cancel items anymore.")
113
raise CancelItemError(_("The coupon is already totalized, "
114
"you can't cancel items anymore."))
111
115
del self._items[item_id]
113
117
def coupon_cancel(self):
117
121
def coupon_totalize(self, discount, charge, taxcode):
118
122
self._check_coupon_is_opened()
119
123
if not self.items_quantity:
120
raise CouponTotalizeError("The coupon can't be totalized, since "
121
"there is no items added")
124
raise CouponTotalizeError(_("The coupon can't be totalized, since "
125
"there is no items added"))
122
126
elif self.is_coupon_totalized:
123
raise CouponTotalizeError("The coupon is already totalized")
127
raise CouponTotalizeError(_("The coupon is already totalized"))
125
129
for item_id, item in self._items.items():
126
130
self.totalized_value += item.get_total_value()
128
132
if not self.totalized_value:
129
raise CouponTotalizeError("Coupon totalized at zero!")
133
raise CouponTotalizeError(_("Coupon totalized at zero!"))
131
135
self.is_coupon_totalized = True
132
136
return self.totalized_value
134
138
def coupon_add_payment(self, payment_method, value, description):
135
139
if not self.is_coupon_totalized:
136
raise PaymentAdditionError("Isn't possible add payments to the "
137
"coupon since it isn't totalized")
140
raise PaymentAdditionError(_("Isn't possible add payments to the "
141
"coupon since it isn't totalized"))
138
142
self.payments_total += value
139
143
self.has_payments = True
140
144
return self.totalized_value - self.payments_total
142
146
def coupon_close(self, message=''):
143
147
self._check_coupon_is_opened()
144
148
if not self.is_coupon_totalized:
145
raise CloseCouponError("Isn't possible close the coupon "
146
"since it isn't totalized yet!")
149
raise CloseCouponError(_("Isn't possible close the coupon "
150
"since it isn't totalized yet!"))
147
151
elif not self.has_payments:
148
raise CloseCouponError("Isn't possible close the coupon since "
149
"there is no payments added.")
152
raise CloseCouponError(_("Isn't possible close the coupon "
153
"since there is no payments added."))
150
154
elif self.totalized_value > self.payments_total:
151
raise CloseCouponError("The payments total value doesn't "
152
"match the totalized value.")
155
raise CloseCouponError(_("The payments total value doesn't "
156
"match the totalized value."))
153
157
self._reset_flags()
155
159
def get_capabilities(self):