def setup_slaves(self): marker('SelectPaymentMethodSlave') self.pm_slave = SelectPaymentMethodSlave(store=self.store, payment_type=Payment.TYPE_IN) self.attach_slave('select_method_holder', self.pm_slave) marker('CashChangeSlave') self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard) self.attach_slave('cash_change_holder', self.cash_change_slave) self.cash_change_slave.received_value.connect( 'activate', lambda entry: self.wizard.go_to_next())
class BaseMethodSelectionStep(object): """Base class for method selection when doing client sales Classes using this base class should have a select_method_holder EventBox and a cash_change_holder EventBox in the glade file """ # # Private API # def _update_next_step(self, method): if method and method.method_name == u'money': self.wizard.enable_finish() if self.wizard.need_create_payment(): self.cash_change_slave.enable_cash_change() else: self.cash_change_slave.disable_cash_change() else: self.wizard.disable_finish() self.cash_change_slave.disable_cash_change() # # Public API # def get_selected_method(self): return self.pm_slave.get_selected_method() def setup_cash_payment(self, total=None): money_method = PaymentMethod.get_by_name(self.store, u'money') total = total or self.wizard.get_total_to_pay() return money_method.create_inpayment(self.model.group, self.model.branch, total) # # WizardStep hooks # def post_init(self): if not self.wizard.need_create_payment(): for widget in [self.select_method_holder, self.subtotal_expander]: widget.hide() self._update_next_step(self.pm_slave.get_selected_method()) def setup_slaves(self): marker('SelectPaymentMethodSlave') self.pm_slave = SelectPaymentMethodSlave(store=self.store, payment_type=Payment.TYPE_IN) self.pm_slave.connect('method-changed', self.on_payment_method_changed) self.attach_slave('select_method_holder', self.pm_slave) marker('CashChangeSlave') self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard) self.attach_slave('cash_change_holder', self.cash_change_slave) self.cash_change_slave.received_value.connect( 'activate', lambda entry: self.wizard.go_to_next()) def next_step(self): if not self.wizard.need_create_payment(): return selected_method = self.get_selected_method() if selected_method.method_name == u'money': if not self.cash_change_slave.can_finish(): warning(_(u"Invalid value, please verify if it was " "properly typed.")) self.cash_change_slave.received_value.select_region( 0, len(self.cash_change_slave.received_value.get_text())) self.cash_change_slave.received_value.grab_focus() return self # We have to modify the payment, so the fiscal printer can # calculate and print the payback, if necessary. payment = self.setup_cash_payment() total = self.cash_change_slave.get_received_value() payment.base_value = total # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'store_credit': client = self.model.client total = self.wizard.get_total_amount() assert client.can_purchase(selected_method, total) step_class = PaymentMethodStep elif selected_method.method_name == 'card': providers = CreditProvider.get_card_providers(self.store) if providers.is_empty(): warning(_("You need active credit providers to use the " "card payment method.")) return self step_class = PaymentMethodStep else: step_class = PaymentMethodStep retval = CreatePaymentEvent.emit(selected_method, self.model, self.store) # None means no one catched this event if retval is None or retval == CreatePaymentStatus.UNHANDLED: # FIXME: We cannot send outstanding_value to multiple editor # since if we have a trade going on, it will be calculated wrong if selected_method.method_name == 'multiple': outstanding_value = None else: outstanding_value = self.wizard.get_total_to_pay() return step_class(self.wizard, self, self.store, self.model, selected_method, outstanding_value=outstanding_value) # finish the wizard if retval == CreatePaymentStatus.SUCCESS: return None # returning self to stay on this step return self # # Callbacks # def on_payment_method_changed(self, slave, method_name): self._update_next_step(method_name)
class BaseMethodSelectionStep(object): """Base class for method selection when doing client sales Classes using this base class should have a select_method_holder EventBox and a cash_change_holder EventBox in the glade file """ # # Private API # def _update_next_step(self, method): received_value = self.cash_change_slave.received_value if method and method.method_name == u'money': self.wizard.enable_finish() if self.wizard.need_create_payment(): self.cash_change_slave.enable_cash_change() else: # In this case, the user has already paid more than the total # sale amount. self.cash_change_slave.disable_cash_change() elif method and method.method_name == u'credit': self.wizard.enable_finish() if self.wizard.need_create_payment(): received_value.set_text(format_price(self.get_remaining_value())) self.cash_change_slave.disable_cash_change() else: self.wizard.disable_finish() if self.wizard.need_create_payment(): received_value.set_text(format_price(self.get_remaining_value())) else: self.wizard.enable_finish() self.cash_change_slave.disable_cash_change() def _create_change_payment(self): if self.cash_change_slave.credit_checkbutton.get_active(): method_name = u'credit' else: method_name = u'money' payments_value = self.model.group.get_total_confirmed_value() sale_total = self.model.get_total_sale_amount() # To have reached this far, the payments value must be greater than the # sale total assert payments_value > sale_total, (payments_value, sale_total) method = PaymentMethod.get_by_name(self.store, method_name) description = _(u'%s returned for sale %s') % (method.description, self.model.identifier) payment = method.create_payment(Payment.TYPE_OUT, payment_group=self.model.group, branch=self.model.branch, value=(payments_value - sale_total), description=description) payment.set_pending() if method_name == u'credit': payment.pay() # # Public API # # FIXME This should be on Sale domain but the domain needs to be refactored def get_remaining_value(self): sale_total = self.model.get_total_sale_amount() payments_value = self.model.group.get_total_confirmed_value() return sale_total - payments_value def get_selected_method(self): return self.pm_slave.get_selected_method() def setup_cash_payment(self, total=None): money_method = PaymentMethod.get_by_name(self.store, u'money') total = total or self.wizard.get_total_to_pay() try: return money_method.create_payment(Payment.TYPE_IN, self.model.group, self.model.branch, total) except PaymentMethodError as err: warning(str(err)) # # WizardStep hooks # def post_init(self): if not self.wizard.need_create_payment(): for widget in [self.select_method_holder, self.subtotal_expander]: widget.hide() self.pm_slave.connect('method-changed', self.on_payment_method_changed) self._update_next_step(self.pm_slave.get_selected_method()) def setup_slaves(self): marker('SelectPaymentMethodSlave') self.pm_slave = SelectPaymentMethodSlave(store=self.store, payment_type=Payment.TYPE_IN) self.attach_slave('select_method_holder', self.pm_slave) marker('CashChangeSlave') self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard) self.attach_slave('cash_change_holder', self.cash_change_slave) self.cash_change_slave.received_value.connect( 'activate', lambda entry: self.wizard.go_to_next()) def next_step(self): if not self.wizard.need_create_payment(): if self.cash_change_slave.credit_checkbutton.get_active(): self._create_change_payment() return selected_method = self.get_selected_method() if selected_method.method_name == u'money': if not self.cash_change_slave.can_finish(): warning(_(u"Invalid value, please verify if it was " "properly typed.")) self.cash_change_slave.received_value.select_region( 0, len(self.cash_change_slave.received_value.get_text())) self.cash_change_slave.received_value.grab_focus() return self # We have to modify the payment, so the fiscal printer can # calculate and print the payback, if necessary. payment = self.setup_cash_payment() if payment is None: return total = self.cash_change_slave.get_received_value() payment.base_value = total # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) try: payment = selected_method.create_payment( Payment.TYPE_IN, self.model.group, self.model.branch, total) except PaymentMethodError as err: warning(str(err)) return self # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'store_credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) step_class = PaymentMethodStep elif selected_method.method_name == 'card': providers = CreditProvider.get_card_providers(self.store) if providers.is_empty(): warning(_("You need active credit providers to use the " "card payment method.")) return self step_class = PaymentMethodStep else: step_class = PaymentMethodStep retval = CreatePaymentEvent.emit(selected_method, self.model, self.store) # None means no one catched this event if retval is None or retval == CreatePaymentStatus.UNHANDLED: # FIXME: We cannot send outstanding_value to multiple editor # since if we have a trade going on, it will be calculated wrong if selected_method.method_name == 'multiple': outstanding_value = None else: outstanding_value = self.wizard.get_total_to_pay() manager = get_plugin_manager() return step_class(self.wizard, self, self.store, self.model, selected_method, outstanding_value=outstanding_value, finish_on_total=manager.is_active('tef')) # finish the wizard if retval == CreatePaymentStatus.SUCCESS: return None # returning self to stay on this step return self # # Callbacks # def on_payment_method_changed(self, slave, method_name): self._update_next_step(method_name)
class BaseMethodSelectionStep(object): """Base class for method selection when doing client sales Classes using this base class should have a select_method_holder EventBox and a cash_change_holder EventBox in the glade file """ # # Private API # def _update_next_step(self, method): received_value = self.cash_change_slave.received_value if method and method.method_name == u'money': self.wizard.enable_finish() if self.wizard.need_create_payment(): self.cash_change_slave.enable_cash_change() else: # In this case, the user has already paid more than the total # sale amount. self.cash_change_slave.disable_cash_change() elif method and method.method_name == u'credit': self.wizard.enable_finish() if self.wizard.need_create_payment(): received_value.set_text( format_price(self.get_remaining_value())) self.cash_change_slave.disable_cash_change() else: self.wizard.disable_finish() if self.wizard.need_create_payment(): received_value.set_text( format_price(self.get_remaining_value())) else: self.wizard.enable_finish() self.cash_change_slave.disable_cash_change() def _create_change_payment(self): if self.cash_change_slave.credit_checkbutton.get_active(): method_name = u'credit' else: method_name = u'money' payments_value = self.model.group.get_total_confirmed_value() sale_total = self.model.get_total_sale_amount() # To have reached this far, the payments value must be greater than the # sale total assert payments_value > sale_total, (payments_value, sale_total) method = PaymentMethod.get_by_name(self.store, method_name) description = _(u'%s returned for sale %s') % (method.description, self.model.identifier) payment = method.create_payment(Payment.TYPE_OUT, payment_group=self.model.group, branch=self.model.branch, value=(payments_value - sale_total), description=description) payment.set_pending() if method_name == u'credit': payment.pay() # # Public API # # FIXME This should be on Sale domain but the domain needs to be refactored def get_remaining_value(self): sale_total = self.model.get_total_sale_amount() payments_value = self.model.group.get_total_confirmed_value() return sale_total - payments_value def get_selected_method(self): return self.pm_slave.get_selected_method() def setup_cash_payment(self, total=None): money_method = PaymentMethod.get_by_name(self.store, u'money') total = total or self.wizard.get_total_to_pay() try: return money_method.create_payment(Payment.TYPE_IN, self.model.group, self.model.branch, total) except PaymentMethodError as err: warning(str(err)) # # WizardStep hooks # def post_init(self): if not self.wizard.need_create_payment(): for widget in [self.select_method_holder, self.subtotal_expander]: widget.hide() self.pm_slave.connect('method-changed', self.on_payment_method_changed) self._update_next_step(self.pm_slave.get_selected_method()) def setup_slaves(self): marker('SelectPaymentMethodSlave') self.pm_slave = SelectPaymentMethodSlave(store=self.store, payment_type=Payment.TYPE_IN) self.attach_slave('select_method_holder', self.pm_slave) marker('CashChangeSlave') self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard) self.attach_slave('cash_change_holder', self.cash_change_slave) self.cash_change_slave.received_value.connect( 'activate', lambda entry: self.wizard.go_to_next()) def next_step(self): if not self.wizard.need_create_payment(): if self.cash_change_slave.credit_checkbutton.get_active(): self._create_change_payment() return selected_method = self.get_selected_method() if selected_method.method_name == u'money': if not self.cash_change_slave.can_finish(): warning( _(u"Invalid value, please verify if it was " "properly typed.")) self.cash_change_slave.received_value.select_region( 0, len(self.cash_change_slave.received_value.get_text())) self.cash_change_slave.received_value.grab_focus() return self # We have to modify the payment, so the fiscal printer can # calculate and print the payback, if necessary. payment = self.setup_cash_payment() if payment is None: return total = self.cash_change_slave.get_received_value() payment.base_value = total # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) try: payment = selected_method.create_payment( Payment.TYPE_IN, self.model.group, self.model.branch, total) except PaymentMethodError as err: warning(str(err)) return self # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'store_credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) step_class = PaymentMethodStep elif selected_method.method_name == 'card': providers = CreditProvider.get_card_providers(self.store) if providers.is_empty(): warning( _("You need active credit providers to use the " "card payment method.")) return self step_class = PaymentMethodStep else: step_class = PaymentMethodStep retval = CreatePaymentEvent.emit(selected_method, self.model, self.store) # None means no one catched this event if retval is None or retval == CreatePaymentStatus.UNHANDLED: # FIXME: We cannot send outstanding_value to multiple editor # since if we have a trade going on, it will be calculated wrong if selected_method.method_name == 'multiple': outstanding_value = None else: outstanding_value = self.wizard.get_total_to_pay() manager = get_plugin_manager() return step_class(self.wizard, self, self.store, self.model, selected_method, outstanding_value=outstanding_value, finish_on_total=manager.is_active('tef')) # finish the wizard if retval == CreatePaymentStatus.SUCCESS: return None # returning self to stay on this step return self # # Callbacks # def on_payment_method_changed(self, slave, method_name): self._update_next_step(method_name)
class BaseMethodSelectionStep(object): """Base class for method selection when doing client sales Classes using this base class should have a select_method_holder EventBox and a cash_change_holder EventBox in the glade file """ # # Private API # def _update_next_step(self, method): if method and method.method_name == u'money': self.wizard.enable_finish() if self.wizard.need_create_payment(): self.cash_change_slave.enable_cash_change() else: self.cash_change_slave.disable_cash_change() elif method and method.method_name == u'credit': self.wizard.enable_finish() self.cash_change_slave.disable_cash_change() else: self.wizard.disable_finish() self.cash_change_slave.disable_cash_change() # # Public API # def get_selected_method(self): return self.pm_slave.get_selected_method() def setup_cash_payment(self, total=None): money_method = PaymentMethod.get_by_name(self.store, u'money') total = total or self.wizard.get_total_to_pay() return money_method.create_payment(Payment.TYPE_IN, self.model.group, self.model.branch, total) # # WizardStep hooks # def post_init(self): if not self.wizard.need_create_payment(): for widget in [self.select_method_holder, self.subtotal_expander]: widget.hide() self._update_next_step(self.pm_slave.get_selected_method()) def setup_slaves(self): marker('SelectPaymentMethodSlave') self.pm_slave = SelectPaymentMethodSlave(store=self.store, payment_type=Payment.TYPE_IN) self.pm_slave.connect('method-changed', self.on_payment_method_changed) self.attach_slave('select_method_holder', self.pm_slave) marker('CashChangeSlave') self.cash_change_slave = CashChangeSlave(self.store, self.model, self.wizard) self.attach_slave('cash_change_holder', self.cash_change_slave) self.cash_change_slave.received_value.connect( 'activate', lambda entry: self.wizard.go_to_next()) def next_step(self): if not self.wizard.need_create_payment(): return selected_method = self.get_selected_method() if selected_method.method_name == u'money': if not self.cash_change_slave.can_finish(): warning(_(u"Invalid value, please verify if it was " "properly typed.")) self.cash_change_slave.received_value.select_region( 0, len(self.cash_change_slave.received_value.get_text())) self.cash_change_slave.received_value.grab_focus() return self # We have to modify the payment, so the fiscal printer can # calculate and print the payback, if necessary. payment = self.setup_cash_payment() total = self.cash_change_slave.get_received_value() payment.base_value = total # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) payment = selected_method.create_payment(Payment.TYPE_IN, self.model.group, self.model.branch, total) # Return None here means call wizard.finish, which is exactly # what we need return None elif selected_method.method_name == u'store_credit': client = self.model.client total = self.wizard.get_total_to_pay() assert client.can_purchase(selected_method, total) step_class = PaymentMethodStep elif selected_method.method_name == 'card': providers = CreditProvider.get_card_providers(self.store) if providers.is_empty(): warning(_("You need active credit providers to use the " "card payment method.")) return self step_class = PaymentMethodStep else: step_class = PaymentMethodStep retval = CreatePaymentEvent.emit(selected_method, self.model, self.store) # None means no one catched this event if retval is None or retval == CreatePaymentStatus.UNHANDLED: # FIXME: We cannot send outstanding_value to multiple editor # since if we have a trade going on, it will be calculated wrong if selected_method.method_name == 'multiple': outstanding_value = None else: outstanding_value = self.wizard.get_total_to_pay() return step_class(self.wizard, self, self.store, self.model, selected_method, outstanding_value=outstanding_value) # finish the wizard if retval == CreatePaymentStatus.SUCCESS: return None # returning self to stay on this step return self # # Callbacks # def on_payment_method_changed(self, slave, method_name): self._update_next_step(method_name)