def test_send(self, localnow): localnow.return_value = localdate(2013, 1, 1) package = self.create_workorder_package() package.destination_branch = self.create_branch() workorder1 = self.create_workorder() workorder2 = self.create_workorder() with mock.patch('stoqlib.domain.workorder.get_current_branch') as gcb: gcb.return_value = self.create_branch() with self.assertRaisesRegexp( ValueError, ("This package's source branch is <Branch u'[0-9a-f-]+'> " "and you are in <Branch u'[0-9a-f-]+'>. It's not possible " "to send a package outside the source branch")): package.send() with self.assertRaisesRegexp(ValueError, "There're no orders to send"): package.send() for order in [workorder1, workorder2]: self.assertNotEqual(order.branch, None) self.assertEqual(order.branch, order.current_branch) package.add_order(order) self.assertEqual(package.status, WorkOrderPackage.STATUS_OPENED) self.assertEqual(package.send_date, None) package.send() self.assertEqual(package.status, WorkOrderPackage.STATUS_SENT) self.assertEqual(package.send_date, localdate(2013, 1, 1)) for order in [workorder1, workorder2]: self.assertEqual(order.current_branch, None)
def test_confirm(self): editor = OutPaymentEditor(self.store) self.assertFalse(editor.validate_confirm()) editor.description.update('Payment name') self.assertFalse(editor.validate_confirm()) editor.value.update(100) self.assertFalse(editor.validate_confirm()) editor.due_date.update(localdate(2015, 1, 1).date()) self.assertTrue(editor.validate_confirm()) editor.repeat.update(INTERVALTYPE_WEEK) self.assertFalse(editor.validate_confirm()) editor.end_date.update(localdate(2014, 1, 10).date()) self.assertFalse(editor.validate_confirm()) editor.end_date.update(localdate(2015, 1, 10).date()) self.assertTrue(editor.validate_confirm()) editor.main_dialog.confirm() model = editor.retval self.check_editor(editor, 'editor-payment-confirm', [model.group] + list(model.group.payments))
def _create_domain(self): self.clean_domain([Commission, SaleItem, Sale]) branches = self.store.find(Branch) sale = self.create_sale(branch=branches[0]) sale_item = self.create_sale_item(sale=sale) self.create_storable(sale_item.sellable.product, branches[0], 10) self.create_payment(payment_type=Payment.TYPE_IN, group=sale.group) sale.order(self.current_user) sale.confirm(self.current_user) sale_item.sellable.code = u'1' sale_item.sellable.description = u'Luvas' sale.open_date = localdate(2012, 1, 1).date() sale.confirm_date = localdate(2012, 1, 1).date() sale = self.create_sale(branch=branches[1]) sale_item = self.create_sale_item(sale=sale) self.create_storable(sale_item.sellable.product, branches[1], 10) self.create_payment(payment_type=Payment.TYPE_IN, group=sale.group) sale.order(self.current_user) sale.confirm(self.current_user) sale_item.sellable.code = u'2' sale_item.sellable.description = u'Botas' sale.open_date = localdate(2012, 2, 2).date() sale.confirm_date = localdate(2012, 2, 2).date()
def test_receive(self, localnow): localnow.return_value = localdate(2013, 1, 1) package = self.create_workorder_package( source_branch=self.create_branch()) package.destination_branch = get_current_branch(self.store) workorder1 = self.create_workorder(current_branch=package.source_branch) workorder2 = self.create_workorder(current_branch=package.source_branch) # Mimic WorkOrderPackage.send for order in [workorder1, workorder2]: package.add_order(order) order.current_branch = None package.status = WorkOrderPackage.STATUS_SENT with mock.patch('stoqlib.domain.workorder.get_current_branch') as gcb: gcb.return_value = self.create_branch() with self.assertRaisesRegexp( ValueError, ("This package's destination branch is <Branch u'[0-9a-f-]+'> " "and you are in <Branch u'[0-9a-f-]+'>. It's not possible " "to receive a package outside the destination branch")): package.receive() self.assertEqual(package.receive_date, None) package.receive() self.assertEqual(package.status, WorkOrderPackage.STATUS_RECEIVED) self.assertEqual(package.receive_date, localdate(2013, 1, 1)) for order in [workorder1, workorder2]: self.assertEqual(order.current_branch, package.destination_branch)
def test_receive(self, localnow): localnow.return_value = localdate(2013, 1, 1) package = self.create_workorder_package( source_branch=self.create_branch()) package.destination_branch = get_current_branch(self.store) workorder1 = self.create_workorder( current_branch=package.source_branch) workorder2 = self.create_workorder( current_branch=package.source_branch) # Mimic WorkOrderPackage.send for order in [workorder1, workorder2]: package.add_order(order) order.current_branch = None package.status = WorkOrderPackage.STATUS_SENT with mock.patch('stoqlib.domain.workorder.get_current_branch') as gcb: gcb.return_value = self.create_branch() with self.assertRaisesRegexp( ValueError, ("This package's destination branch is <Branch u'[0-9a-f-]+'> " "and you are in <Branch u'[0-9a-f-]+'>. It's not possible " "to receive a package outside the destination branch")): package.receive() self.assertEqual(package.receive_date, None) package.receive() self.assertEqual(package.status, WorkOrderPackage.STATUS_RECEIVED) self.assertEqual(package.receive_date, localdate(2013, 1, 1)) for order in [workorder1, workorder2]: self.assertEqual(order.current_branch, package.destination_branch)
def test_send(self, localnow): localnow.return_value = localdate(2013, 1, 1) package = self.create_workorder_package() package.destination_branch = self.create_branch() workorder1 = self.create_workorder() workorder2 = self.create_workorder() with mock.patch('stoqlib.domain.workorder.get_current_branch') as gcb: gcb.return_value = self.create_branch() with self.assertRaisesRegexp( ValueError, ("This package's source branch is <Branch u'[0-9a-f-]+'> " "and you are in <Branch u'[0-9a-f-]+'>. It's not possible " "to send a package outside the source branch")): package.send() with self.assertRaisesRegexp( ValueError, "There're no orders to send"): package.send() for order in [workorder1, workorder2]: self.assertNotEqual(order.branch, None) self.assertEqual(order.branch, order.current_branch) package.add_order(order) self.assertEqual(package.status, WorkOrderPackage.STATUS_OPENED) self.assertEqual(package.send_date, None) package.send() self.assertEqual(package.status, WorkOrderPackage.STATUS_SENT) self.assertEqual(package.send_date, localdate(2013, 1, 1)) for order in [workorder1, workorder2]: self.assertEqual(order.current_branch, None)
def test_get_birthday_interval_query(self): start = localdatetime(2000, 3, 1) end = localdatetime(2000, 3, 25) query = Individual.get_birthday_query(start, end) start_year = DateTrunc(u'year', Date(start)) age_in_year = Age(Individual.birth_date, DateTrunc(u'year', Individual.birth_date)) test_query = ( start_year + age_in_year + Case(condition=age_in_year < Age(Date(start), start_year), result=Interval(u'1 year'), else_=Interval(u'0 year'))) test_query = And(test_query >= Date(start), test_query <= Date(end)) self.assertEquals(query, test_query) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 0) client1 = self.create_client(u'Junio C. Hamano') client1.person.individual.birth_date = localdate(1972, 10, 15) client2 = self.create_client(u'Richard Stallman') client2.person.individual.birth_date = localdate(1989, 3, 7) client3 = self.create_client(u'Linus Torvalds') client3.person.individual.birth_date = localdate(2000, 3, 4) client4 = self.create_client(u'Guido van Rossum') client4.person.individual.birth_date = localdate(2005, 3, 20) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 3) self.assertTrue(client2.person.individual in individuals) self.assertTrue(client3.person.individual in individuals) self.assertTrue(client4.person.individual in individuals)
def test_is_late(self, localtoday): localtoday.return_value = localdate(2012, 1, 1) workorder = self.create_workorder() self.assertEqual(workorder.estimated_finish, None) for status in WorkOrder.statuses.keys(): workorder.status = status # If we have no estimated_finish, we are not late self.assertFalse(workorder.is_late()) # datetime.today will expand to 2012, so this is in the future workorder.estimated_finish = localdate(2013, 1, 1) for status in WorkOrder.statuses.keys(): workorder.status = status self.assertFalse(workorder.is_late()) # datetime.today will expand to 2012, so this is in the past workorder.estimated_finish = localdate(2011, 1, 1) for status in WorkOrder.statuses.keys(): workorder.status = status if status in [ WorkOrder.STATUS_WORK_FINISHED, WorkOrder.STATUS_DELIVERED ]: self.assertFalse(workorder.is_late()) else: self.assertTrue(workorder.is_late())
def test_get_birthday_date_query(self): start = localdate(2000, 3, 4) query = Individual.get_birthday_query(start) start_year = DateTrunc(u'year', Date(start)) age_in_year = Age(Individual.birth_date, DateTrunc(u'year', Individual.birth_date)) test_query = ( start_year + age_in_year + Case(condition=age_in_year < Age(Date(start), start_year), result=Interval(u'1 year'), else_=Interval(u'0 year')) ) test_query = (test_query == Date(start)) self.assertEquals(query, test_query) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 0) client1 = self.create_client(u'Junio C. Hamano') client1.person.individual.birth_date = localdate(1972, 10, 15) client2 = self.create_client(u'Richard Stallman') client2.person.individual.birth_date = localdate(1989, 3, 4) client3 = self.create_client(u'Linus Torvalds') client3.person.individual.birth_date = localdate(2000, 3, 4) client4 = self.create_client(u'Guido van Rossum') client4.person.individual.birth_date = localdate(2005, 3, 4) individuals = list(self.store.find(Individual, test_query)) self.assertEquals(len(individuals), 3) self.assertTrue(client2.person.individual in individuals) self.assertTrue(client3.person.individual in individuals) self.assertTrue(client4.person.individual in individuals)
def _create_domain(self): address = self.create_address() service_item = self.create_sale_item() service_item.sale.identifier = 10 service_item.sale.status = Sale.STATUS_CONFIRMED transporter = self.create_transporter(name=u'Hall') delivery = Delivery(transporter=transporter, address=address, invoice=service_item.sale.invoice, open_date=localdate(2012, 1, 1).date(), store=self.store) delivery.tracking_code = u'45' service_item = self.create_sale_item() service_item.sale.identifier = 20 service_item.sale.status = Sale.STATUS_CONFIRMED transporter = self.create_transporter(name=u'Torvalds') delivery = Delivery(transporter=transporter, address=address, invoice=service_item.sale.invoice, open_date=localdate(2012, 2, 2).date(), send_date=localdate(2012, 3, 3).date(), receive_date=localdate(2012, 4, 4).date(), store=self.store) delivery.tracking_code = u'78' delivery.status = Delivery.STATUS_RECEIVED
def test_estimated_finish(self, localtoday_): workorder = self.create_workorder() slave = WorkOrderOpticalSlave(self.store, workorder) localtoday_.return_value = localdate(2014, 1, 1) res = slave.estimated_finish.emit("validate", localdate(2013, 1, 1)) self.assertEquals(unicode(res), u'Estimated finish date cannot be in the past.')
def _create_domain(self): branch = get_current_branch(self.store) sale = self.create_sale(branch=branch) sale_item = self.create_sale_item(sale=sale) sale_item.quantity = 66 sale_item.quantity_decreased = 23 sale_item.sellable.description = u'Schrubbery' sale_item.sale.identifier = 42 sale.status = sale.STATUS_ORDERED sale.open_date = localdate(2013, 12, 11) sale2 = self.create_sale(branch=branch) sale_item2 = self.create_sale_item(sale=sale2) sale_item2.quantity = 29 sale_item2.quantity_decreased = 29 sale_item2.sellable.description = u'Holy Grail' sale_item2.sale.identifier = 73 sale2.open_date = localdate(2013, 12, 11) sale2.status = sale2.STATUS_QUOTE self.branch2 = self.create_branch(u'The Meaning of Life') sale3 = self.create_sale(branch=self.branch2) sale_item3 = self.create_sale_item(sale=sale3) sale_item3.quantity = 41 sale_item3.quantity_decreased = 1 sale_item3.sellable.description = u'The Funniest Joke in this Code' sale_item3.sale.identifier = 99 sale3.open_date = localdate(2013, 12, 11) sale3.status = sale3.STATUS_QUOTE
def _create_domain(self): self.clean_domain([Commission, SaleItem, Sale]) branches = self.store.find(Branch) sale = self.create_sale(branch=branches[0]) sale_item = self.create_sale_item(sale=sale) self.create_storable(sale_item.sellable.product, branches[0], 10) self.create_payment(payment_type=Payment.TYPE_IN, group=sale.group) sale.order() sale.confirm() sale_item.sellable.code = u'1' sale_item.sellable.description = u'Luvas' sale.open_date = localdate(2012, 1, 1).date() sale.confirm_date = localdate(2012, 1, 1).date() sale = self.create_sale(branch=branches[1]) sale_item = self.create_sale_item(sale=sale) self.create_storable(sale_item.sellable.product, branches[0], 10) self.create_payment(payment_type=Payment.TYPE_IN, group=sale.group) sale.order() sale.confirm() sale_item.sellable.code = u'2' sale_item.sellable.description = u'Botas' sale.open_date = localdate(2012, 2, 2).date() sale.confirm_date = localdate(2012, 2, 2).date()
def test_find_pending(self): wo1 = self.create_workorder() wo1.status = WorkOrder.STATUS_OPENED wo2 = self.create_workorder() wo2.status = WorkOrder.STATUS_WORK_WAITING wo3 = self.create_workorder() wo3.status = WorkOrder.STATUS_WORK_IN_PROGRESS wo4 = self.create_workorder() wo4.status = WorkOrder.STATUS_WORK_FINISHED # Those 2 should not appear on the results wo5 = self.create_workorder() wo5.status = WorkOrder.STATUS_DELIVERED wo6 = self.create_workorder() wo6.status = WorkOrder.STATUS_CANCELLED work_orders = set(wov.work_order for wov in WorkOrderView.find_pending(self.store)) self.assertEqual(work_orders, set([wo1, wo2, wo3, wo4])) wo1.estimated_finish = localdate(2013, 1, 1) wo2.estimated_finish = localdate(2013, 2, 1) wo3.estimated_finish = localdate(2013, 3, 1) wo4.estimated_finish = localdate(2013, 4, 1) wo5.estimated_finish = localdate(2013, 1, 1) wo6.estimated_finish = localdate(2013, 2, 1) # Filtering by start date only work_orders = set( wov.work_order for wov in WorkOrderView.find_pending(self.store, start_date=localdate(2013, 1, 1)) ) self.assertEqual(work_orders, set([wo1, wo2, wo3, wo4])) work_orders = set( wov.work_order for wov in WorkOrderView.find_pending(self.store, start_date=localdate(2013, 1, 2)) ) self.assertEqual(work_orders, set([wo2, wo3, wo4])) # Filtering by end date only work_orders = set( wov.work_order for wov in WorkOrderView.find_pending(self.store, end_date=localdate(2013, 1, 2)) ) self.assertEqual(work_orders, set([wo1])) work_orders = set( wov.work_order for wov in WorkOrderView.find_pending(self.store, end_date=localdate(2013, 4, 2)) ) self.assertEqual(work_orders, set([wo1, wo2, wo3, wo4])) # Filtering by both start and end dates work_orders = set( wov.work_order for wov in WorkOrderView.find_pending( self.store, start_date=localdate(2013, 1, 1), end_date=localdate(2013, 4, 2) ) ) self.assertEqual(work_orders, set([wo1, wo2, wo3, wo4])) work_orders = set( wov.work_order for wov in WorkOrderView.find_pending( self.store, start_date=localdate(2013, 3, 1), end_date=localdate(2013, 4, 2) ) ) self.assertEqual(work_orders, set([wo3, wo4]))
def test_create_repeated_with_temporary_identifier(self): payment = self.create_payment() payment.description = u'temporary' payments = Payment.create_repeated(self.store, payment, INTERVALTYPE_MONTH, localdate(2012, 1, 1).date(), localdate(2012, 3, 1).date(), temporary_identifiers=True) (self.assertTrue(p.identifier < 0) for p in payments)
def test_optical_sales(self): app = self.create_app(SalesApp, u'sales') for sales in app.results: sales.open_date = localdate(2012, 1, 1) sales.confirm_date = localdate(2012, 2, 3) sales.close_date = localdate(2012, 4, 5) self.check_app(app, u'sales-optical-plugin') self.window.hide_app(empty=True)
def _create_domain(self, localnow): self.clean_domain([WorkOrder]) localnow.return_value = localdate(2014, 1, 1) work_order = self.create_workorder() work_order.open_date = localdate(2014, 1, 1) work_order.identifier = 123 work_order.approve() work_order.work() work_order.add_sellable(self.create_sellable(), quantity=1) work_order.finish()
def test_expire_date_validate(self, localtoday_): localtoday_.return_value = localdate(2020, 1, 5) wizard = OpticalSaleQuoteWizard(self.store) step = wizard.get_current_step() res = step.expire_date.emit('validate', localdate(2013, 1, 1).date()) self.assertEquals( unicode(res), u"The expire date must be set to today or a future date.")
def test_prescription_date(self, localtoday_): localtoday_.return_value = localdate(2014, 1, 1) not_late_date = localdate(2013, 6, 1).date() late_date = localdate(2012, 1, 1).date() workorder = self.create_workorder() slave = WorkOrderOpticalSlave(self.store, workorder) slave.prescription_date.set_date(localdate(2014, 1, 1)) slave.prescription_date.set_date(not_late_date) slave.prescription_date.set_date(late_date) slave.prescription_date.set_date(None)
def test_estimated_finish(self, localtoday_): workorder = self.create_workorder() workorder.open_date = localdate(2015, 4, 2) slave = WorkOrderOpticalSlave(self.store, workorder) #localtoday_.return_value = localdate(2014, 1, 1) res = slave.estimated_finish.emit("validate", localdate(2015, 4, 1)) self.assertEqual(str(res), u'Estimated finish date cannot be in the past.') # Can be edited without changing the estimated_finish res2 = slave.estimated_finish.emit("validate", localdate(2015, 4, 2)) self.assertEqual(res2, None)
def _on_results__row_activated(self, results, item): chart_type_name = item.chart_class.__name__ if chart_type_name == 'YearlyPayments': start = localdate(item.year, 1, 1).date() end = localdate(item.year, 12, 31).date() chart_type_name = 'MonthlyPayments' elif chart_type_name == 'MonthlyPayments': start = localdate(item.year, item.month, 1).date() end = start + relativedelta(days=31) chart_type_name = 'DailyPayments' else: return self._show_one(chart_type_name, start, end)
def test_show(self): till = self.create_till() till.open_till(self.current_user) till.close_till(self.current_user, "Observation...") till.opening_date = localdate(2014, 5, 6).date() till.closing_date = localdate(2014, 5, 6).date() till.responsible_open_id = self.create_user().id till.initial_cash_amount = Decimal(5656.64) till.final_cash_amount = Decimal(246823.22) model = self.store.find(TillClosedView, id=till.id).one() dialog = TillDetailsDialog(self.store, model) self.check_dialog(dialog, 'till-details-dialog-show')
def test_create_for_another_branch(self, current_branch): branch = self.create_branch() with self.sysparam(SYNCHRONIZED_MODE=True): editor = OutPaymentEditor(self.store) current_branch.return_value = branch editor.description.update('Payment name') editor.value.update(100) editor.due_date.update(localdate(2015, 1, 1).date()) editor.repeat.update(INTERVALTYPE_MONTH) editor.end_date.update(localdate(2016, 1, 10).date()) editor.main_dialog.confirm() self.assertEquals(editor.model.identifier, -1)
def test_show(self): till = self.create_till() till.open_till() till.close_till(u"Observation...") till.opening_date = localdate(2014, 5, 6).date() till.closing_date = localdate(2014, 5, 6).date() till.responsible_open_id = self.create_user().id till.initial_cash_amount = Decimal(5656.64) till.final_cash_amount = Decimal(246823.22) model = self.store.find(TillClosedView, id=till.id).one() dialog = TillDetailsDialog(self.store, model) self.check_dialog(dialog, 'till-details-dialog-show')
def test_installments(self): sysparam(self.store).update_parameter(u'ALLOW_OUTDATED_OPERATIONS', u'1') wizard = PurchaseWizard(self.store) method = PaymentMethod.get_by_name(self.store, u'bill') order = self.create_purchase_order() order.identifier = 12345 slave = BillMethodSlave(wizard, None, self.store, order, method, Decimal(200), localdate(2012, 01, 01).date()) self.check_slave(slave, 'slave-bill-method-1-installments') slave.installments_number.update(2) self.check_slave(slave, 'slave-bill-method-2-installments')
def _show_client_birthdays_by_date(self, date): from stoqlib.gui.search.personsearch import ClientSearch with api.new_store() as store: y, m, d = map(int, date.split('-')) date = localdate(y, m, d).date() run_dialog(ClientSearch, self.app, store, birth_date=date)
def test_show(self): # 5 items in sale for first salesperson sale1 = self.create_sale() self.add_product(sale1, quantity=5) sale1.order() self.add_payments(sale1, method_type=u'check') sale1.confirm() sale1.confirm_date = localdate(2011, 1, 1).date() sale1.salesperson.person.name = u'salesperson1' # 3 items in sale for first salesperson sale2 = self.create_sale() sale2.salesperson = sale1.salesperson self.add_product(sale2, quantity=3) sale2.order() self.add_payments(sale2, method_type=u'money') sale2.confirm() sale2.confirm_date = sale1.confirm_date # 15 items for another salesperson sale3 = self.create_sale() self.add_product(sale3, quantity=15) sale3.order() self.add_payments(sale3, method_type=u'bill') sale3.confirm() sale3.confirm_date = sale1.confirm_date sale3.salesperson.person.name = u'salesperson2' dialog = SalesPersonSalesSearch(self.store) dialog.date_filter.select(DateSearchFilter.Type.USER_DAY) dialog.date_filter.start_date.update(sale1.confirm_date) self.click(dialog.search.search_button) self.check_dialog(dialog, 'sales-person-sales-show')
def test_synchronized_mode(self): # This is a non editable parameter with self.sysparam(SYNCHRONIZED_MODE=True): current = api.get_current_branch(self.store) other_branch = self.create_branch() # One sale on one branch sale1 = self.create_sale(branch=current) self.add_product(sale1) sale1.order() self.add_payments(sale1, method_type=u'check') sale1.confirm() sale1.confirm_date = localdate(2011, 1, 1).date() sale1.salesperson.person.name = u'salesperson1' # And another one on a second branch sale2 = self.create_sale(branch=other_branch) sale2.salesperson = sale1.salesperson self.add_product(sale2) sale2.order() self.add_payments(sale2, method_type=u'money') sale2.confirm() sale2.confirm_date = sale1.confirm_date dialog = SalesPersonSalesSearch(self.store) dialog.date_filter.select(DateSearchFilter.Type.USER_INTERVAL) dialog.date_filter.start_date.update(sale1.confirm_date) dialog.date_filter.end_date.update(sale1.confirm_date) self.click(dialog.search.search_button) self.check_dialog(dialog, 'sales-person-sales-synchronized-show')
def test_sale_return_payment_step_partially_paid(self, info): sale = self.create_sale() sale.identifier = 1234 self.add_product(sale, price=50, quantity=6) payments = self.add_payments(sale, method_type=u'check', installments=3, date=localdate(2012, 1, 1).date()) sale.order() sale.confirm() payments[0].pay() returned_sale = sale.create_sale_return_adapter() returned_sale.reason = u'reason' returned_sale.invoice.invoice_number = 1 list(returned_sale.returned_items)[0].quantity = 1 wizard = SaleReturnWizard(self.store, returned_sale) self.click(wizard.next_button) self.click(wizard.next_button) step = wizard.get_current_step() info.assert_called_once_with( ("The client's debt has changed. " "Use this step to adjust the payments."), ("The debt before was $200.00 and now is $150.00. " "Cancel some unpaid installments and create new ones.")) self.assertVisible(step.slave, ['remove_button']) self.assertEqual(step.slave.total_value.read(), returned_sale.total_amount_abs + returned_sale.paid_total) self.check_wizard(wizard, 'wizard-sale-return-payment-step-partially-paid')
def _show_search_by_date(self, date, app_name): y, m, d = map(int, date.split('-')) date = localdate(y, m, d).date() self.app.window.hide_app(empty=True) shell_app = self.app.window.run_application( app_name, refresh=False) shell_app.search_for_date(date)
def test_edit_optical_details(self, run_dialog, new_store): new_store.return_value = self.store product = self.create_product() work_order = self.create_workorder() work_order.identifier = 666 work_order.open_date = localdate(2014, 01, 31) work_order.sellable = product.sellable app = self.create_app(ServicesApp, u'services') app.search.refresh() for wo_view in app.search.results: if wo_view.work_order == work_order: break self.assertIsNotNone(wo_view) app.search.results.select(wo_view) action = app.uimanager.get_action( '/menubar/AppMenubarPH/OrderMenu/OpticalDetails') with contextlib.nested( mock.patch.object(self.store, 'commit'), mock.patch.object(self.store, 'close')): self.activate(action) run_dialog.assert_called_once_with(OpticalWorkOrderEditor, None, self.store, work_order)
def test_create(self): # Allow creating purchases in the past. sysparam.set_bool(self.store, 'ALLOW_OUTDATED_OPERATIONS', True) with self.sysparam(MANDATORY_CHECK_NUMBER=True): self.wizard = PurchaseWizard(self.store) purchase_branch = self.create_branch() purchase_order = PurchaseOrder(branch=purchase_branch, station=self.current_station, store=self.store) sellable = self.create_sellable() purchase_order.add_item(sellable=sellable) self.wizard.model.identifier = 12345 self.wizard.model.open_date = localdate(2010, 1, 3).date() self._check_start_step('wizard-purchase-start-step') self._check_item_step('wizard-purchase-item-step') payment_step = self.wizard.get_current_step() payment_step.slave.bank_first_check_number.set_text('12') self._check_payment_step('wizard-purchase-payment-step') purchase = self.wizard.model models = [purchase] models.extend(purchase.get_items()) models.extend(purchase.payments) models.append(purchase.group) self.check_wizard(self.wizard, 'wizard-purchase-finish-step', models=models) self.click(self.wizard.next_button)
def test_synchronized_mode(self): # This is a non editable parameter with self.sysparam(SYNCHRONIZED_MODE=True): current = api.get_current_branch(self.store) other_branch = self.create_branch() # One sale on one branch sale1 = self.create_sale(branch=current) self.add_product(sale1) sale1.order() self.add_payments(sale1, method_type=u'check') sale1.confirm() sale1.confirm_date = localdate(2011, 01, 01).date() sale1.salesperson.person.name = u'salesperson1' # And another one on a second branch sale2 = self.create_sale(branch=other_branch) sale2.salesperson = sale1.salesperson self.add_product(sale2) sale2.order() self.add_payments(sale2, method_type=u'money') sale2.confirm() sale2.confirm_date = sale1.confirm_date dialog = SalesPersonSalesSearch(self.store) dialog.date_filter.select(DateSearchFilter.Type.USER_INTERVAL) dialog.date_filter.start_date.update(sale1.confirm_date) dialog.date_filter.end_date.update(sale1.confirm_date) self.click(dialog.search.search_button) self.check_dialog(dialog, 'sales-person-sales-synchronized-show')
def testChangeDueDateSale(self, warning): sale = self.create_sale() sale.client = self.create_client() sale.identifier = 9123 payment = self.add_payments(sale, date=localdate(2001, 1, 1).date())[0] editor = PaymentDueDateChangeDialog(self.store, payment, sale) self.check_editor(editor, 'editor-payment-change-due-date-sale') today = localtoday().date() yesterday = today - relativedelta(days=1) # By default, we cannot set a due date to the past editor.due_date.update(yesterday) self.assertNotSensitive(editor.main_dialog, ['ok_button']) # Now we should be able to confirm the dialog editor.due_date.update(today) self.assertSensitive(editor.main_dialog, ['ok_button']) # Ok button is enabled, but should show a warning self.click(editor.main_dialog.ok_button) warning.assert_called_once_with('You can not change the due date ' 'without a reason!') warning.reset_mock() editor.change_reason.update('Just because') self.click(editor.main_dialog.ok_button) self.assertEquals(warning.call_count, 0) self.assertEquals(payment.due_date.date(), today)
def test_show(self): # 5 items in sale for first salesperson sale1 = self.create_sale() self.add_product(sale1, quantity=5) sale1.order() self.add_payments(sale1, method_type=u'check') sale1.confirm() sale1.confirm_date = localdate(2011, 01, 01).date() sale1.salesperson.person.name = u'salesperson1' # 3 items in sale for first salesperson sale2 = self.create_sale() sale2.salesperson = sale1.salesperson self.add_product(sale2, quantity=3) sale2.order() self.add_payments(sale2, method_type=u'money') sale2.confirm() sale2.confirm_date = sale1.confirm_date # 15 items for another salesperson sale3 = self.create_sale() self.add_product(sale3, quantity=15) sale3.order() self.add_payments(sale3, method_type=u'bill') sale3.confirm() sale3.confirm_date = sale1.confirm_date sale3.salesperson.person.name = u'salesperson2' dialog = SalesPersonSalesSearch(self.store) dialog.date_filter.select(DateSearchFilter.Type.USER_DAY) dialog.date_filter.start_date.update(sale1.confirm_date) self.click(dialog.search.search_button) self.check_dialog(dialog, 'sales-person-sales-show')
def test_create(self): # Allow creating purchases in the past. sysparam.set_bool(self.store, 'ALLOW_OUTDATED_OPERATIONS', True) self.wizard = PurchaseWizard(self.store) purchase_branch = self.create_branch() purchase_order = PurchaseOrder(branch=purchase_branch) sellable = self.create_sellable() purchase_order.add_item(sellable=sellable) self.wizard.model.identifier = 12345 self.wizard.model.open_date = localdate(2010, 1, 3).date() self._check_start_step('wizard-purchase-start-step') self._check_item_step('wizard-purchase-item-step') self._check_payment_step('wizard-purchase-payment-step') purchase = self.wizard.model models = [purchase] models.extend(purchase.get_items()) models.extend(purchase.payments) models.append(purchase.group) self.check_wizard(self.wizard, 'wizard-purchase-finish-step', models=models) self.click(self.wizard.next_button)
def test_sale_return_payment_step_partially_paid(self, info): sale = self.create_sale() sale.identifier = 1234 self.add_product(sale, price=50, quantity=6) payments = self.add_payments(sale, method_type=u'check', installments=3, date=localdate(2012, 1, 1).date()) sale.order() sale.confirm() payments[0].pay() returned_sale = sale.create_sale_return_adapter() returned_sale.reason = u'reason' returned_sale.invoice_number = 1 list(returned_sale.returned_items)[0].quantity = 1 wizard = SaleReturnWizard(self.store, returned_sale) self.click(wizard.next_button) self.click(wizard.next_button) step = wizard.get_current_step() info.assert_called_once_with( ("The client's debt has changed. " "Use this step to adjust the payments."), ("The debt before was $200.00 and now is $150.00. " "Cancel some unpaid installments and create new ones.")) self.assertVisible(step.slave, ['remove_button']) self.assertEqual(step.slave.total_value.read(), returned_sale.total_amount_abs + returned_sale.paid_total) self.check_wizard(wizard, 'wizard-sale-return-payment-step-partially-paid')
def test_edit_optical_details(self, run_dialog, new_store): new_store.return_value = self.store product = self.create_product() work_order = self.create_workorder() work_order.identifier = 666 work_order.open_date = localdate(2014, 1, 31) work_order.sellable = product.sellable app = self.create_app(ServicesApp, u'services') app.search.refresh() for wo_view in app.search.results: if wo_view.work_order == work_order: break self.assertIsNotNone(wo_view) app.search.results.select(wo_view) action = app.uimanager.get_action( '/menubar/AppMenubarPH/OrderMenu/OpticalDetails') with contextlib.nested(mock.patch.object(self.store, 'commit'), mock.patch.object(self.store, 'close')): self.activate(action) run_dialog.assert_called_once_with(OpticalWorkOrderEditor, None, self.store, work_order)
def test_show_with_returns_and_comments(self, print_report): date = localdate(2010, 12, 10).date() sale = self._create_sale() returned_sale = sale.create_sale_return_adapter( self.current_branch, self.current_user, self.current_station) returned_sale.return_(self.current_user) returned_sale.return_date = date # payments[0] is the sale's payment created on self._create_sale returned_payment = returned_sale.group.payments.find( Payment.identifier != 999).one() returned_payment.identifier = 666 returned_payment.due_date = date returned_payment.paid_date = date comment = self.create_sale_comment(sale) comment.date = date model = self.store.find(SaleView, id=sale.id).one() dialog = SaleDetailsDialog(self.store, model) self.click(dialog.print_return_report) self.check_editor(dialog, 'dialog-sale-details-with-returns')
def add_payments(self, obj, method_type=u'money', installments=1, date=None): from stoqlib.domain.payment.payment import Payment from stoqlib.domain.purchase import PurchaseOrder from stoqlib.domain.sale import Sale from stoqlib.domain.stockdecrease import StockDecrease assert installments > 0 if not date: date = localnow() elif isinstance(date, datetime.date): date = localdate(date.year, date.month, date.day) if isinstance(obj, (Sale, StockDecrease)): if isinstance(obj, Sale): value = obj.get_total_sale_amount() else: value = obj.get_total_cost() payment_type = Payment.TYPE_IN elif isinstance(obj, PurchaseOrder): value = obj.get_purchase_total() payment_type = Payment.TYPE_OUT else: # pragma: nocover raise ValueError(obj) method = self.get_payment_method(method_type) payments = method.create_payments( payment_type=payment_type, group=obj.group, branch=obj.branch, value=value, due_dates=self.create_installment_dates(date, installments)) for p in payments: p.open_date = date return payments
def add_payments(self, obj, method_type=u'money', installments=1, date=None): from stoqlib.domain.payment.payment import Payment from stoqlib.domain.purchase import PurchaseOrder from stoqlib.domain.sale import Sale from stoqlib.domain.stockdecrease import StockDecrease assert installments > 0 if not date: date = localnow() elif isinstance(date, datetime.date): date = localdate(date.year, date.month, date.day) if isinstance(obj, (Sale, StockDecrease)): if isinstance(obj, Sale): value = obj.get_total_sale_amount() else: value = obj.get_total_cost() payment_type = Payment.TYPE_IN elif isinstance(obj, PurchaseOrder): value = obj.get_purchase_total() payment_type = Payment.TYPE_OUT else: raise ValueError(obj) method = self.get_payment_method(method_type) payments = method.create_payments( payment_type=payment_type, group=obj.group, branch=obj.branch, value=value, due_dates=self.create_installment_dates(date, installments)) for p in payments: p.open_date = date return payments
def test_create(self): # Allow creating purchases in the past. sysparam(self.store).update_parameter(u"ALLOW_OUTDATED_OPERATIONS", u"1") self.wizard = PurchaseWizard(self.store) purchase_branch = self.create_branch() purchase_order = PurchaseOrder(branch=purchase_branch) sellable = self.create_sellable() purchase_order.add_item(sellable=sellable) self.wizard.model.identifier = 12345 self.wizard.model.open_date = localdate(2010, 1, 3).date() self._check_start_step('wizard-purchase-start-step') self._check_item_step('wizard-purchase-item-step') self._check_payment_step('wizard-purchase-payment-step') purchase = self.wizard.model models = [purchase] models.extend(purchase.get_items()) models.extend(purchase.payments) models.append(purchase.group) self.check_wizard(self.wizard, 'wizard-purchase-finish-step', models=models) self.click(self.wizard.next_button)
def test_show(self): date = localdate(2012, 1, 1).date() supplier = self.create_supplier() # New purchase order = self.create_purchase_order() order.identifier = 123 order.supplier = supplier order.open_date = date # Product purchase_item = self.create_purchase_order_item(order) purchase_item.ipi_value = 80 # New receiving receiving_order = self.create_receiving_order(purchase_order=order) self.create_receiving_order_item(receiving_order, purchase_item=purchase_item) # Payments payment = self.add_payments(order, date=date)[0] payment.identifier = 999 payment.group.payer = supplier.person dialog = PurchaseDetailsDialog(self.store, order) self.check_editor(dialog, 'dialog-purchase-details')
def _create_sale(self): today = localdate(2010, 12, 1) client = self.create_client() # new sale sale = self.create_sale(branch=get_current_branch(self.store)) sale.identifier = 123 sale.client = client sale.open_date = today sale.discount_value = Decimal('15') sale.surcharge_value = Decimal('8') # Product item_ = self.create_sale_item(sale, product=True) self.create_storable(item_.sellable.product, sale.branch, 1) # Service item = self.create_sale_item(sale, product=False) item.estimated_fix_date = today # Payments payment = self.add_payments(sale, date=today)[0] payment.identifier = 999 payment.group.payer = client.person sale.order() sale.confirm() sale.group.pay() payment.paid_date = today return sale
def _create_sale(self): today = localdate(2010, 12, 1).date() client = self.create_client() # new sale sale = self.create_sale(branch=get_current_branch(self.store)) sale.identifier = 123 sale.client = client sale.open_date = today sale.discount_value = Decimal('15') sale.surcharge_value = Decimal('8') # Product item_ = self.create_sale_item(sale, product=True) self.create_storable(item_.sellable.product, sale.branch, 1) # Service item = self.create_sale_item(sale, product=False) item.estimated_fix_date = today # Payments payment = self.add_payments(sale, date=today)[0] payment.identifier = 999 payment.group.payer = client.person sale.order() sale.confirm() sale.group.pay() payment.paid_date = today return sale
def _create_domain(self): branch = get_current_branch(self.store) sale = self.create_sale(branch=branch) sale_item = self.create_sale_item(sale=sale) sale_item.quantity = 66 sale_item.quantity_decreased = 23 sale_item.sellable.description = u'Schrubbery' sale_item.sale.identifier = 42 sale.status = sale.STATUS_ORDERED sale.open_date = localdate(2013, 12, 11) sale2 = self.create_sale(branch=branch) sale_item2 = self.create_sale_item(sale=sale2) sale_item2.quantity = 29 sale_item2.quantity_decreased = 29 sale_item2.sellable.description = u'Holy Grail' sale_item2.sale.identifier = 73 sale2.open_date = localdate(2013, 12, 11) sale2.status = sale2.STATUS_QUOTE self.branch2 = self.create_branch(u'The Meaning of Life') sale3 = self.create_sale(branch=self.branch2) sale_item3 = self.create_sale_item(sale=sale3) sale_item3.quantity = 41 sale_item3.quantity_decreased = 1 sale_item3.sellable.description = u'The Funniest Joke in this Code' sale_item3.sale.identifier = 99 sale3.open_date = localdate(2013, 12, 11) sale3.status = sale3.STATUS_QUOTE # With work order sale4 = self.create_sale(branch=branch) sale4.identifier = 43 sale_item4 = self.create_sale_item(sale=sale4) sale_item4.quantity = 33 sale_item4.quantity_decreased = 33 sale_item4.description = u'Knights who say Ni' sale4.open_date = localdate(2014, 6, 12) sale4.status = sale4.STATUS_QUOTE work_order = self.create_workorder(branch=branch) work_order.identifier = 44 work_order_item = self.create_work_order_item() work_order_item.sale_item = sale_item4 work_order_item.sellable = sale_item4.sellable work_order_item.order = work_order work_order.sale = sale4
def test_complete(self): station = self.create_station() today = localdate(2007, 1, 1) reduction_date = localdatetime(2007, 1, 1, 23, 59) day = FiscalDayHistory(store=self.store, emission_date=today, station=station, serial=u'Stoqlib test serial', serial_id=1, coupon_start=1, coupon_end=23, crz=18, cro=25, period_total=Decimal("456.00"), total=Decimal("123141.00"), reduction_date=reduction_date) for code, value, type in [(u'2500', Decimal("123.00"), u'ICMS'), (u'F', Decimal("789.00"), u'ICMS')]: FiscalDayTax(fiscal_day_history=day, code=code, value=value, type=type, store=self.store) branch = get_current_branch(self.store) user = self.create_employee() branch.manager = user manager = branch.manager.person company = branch.person.company address = branch.person.get_main_address() start = today + relativedelta(day=1) end = today + relativedelta(day=31) s = SintegraFile() s.add_header(company.get_cnpj_number(), u'110042490114', branch.get_description(), address.get_city(), address.get_state(), branch.person.get_fax_number_number(), start, end) # if we don't a street number, use zero for sintegra s.add_complement_header(address.street, address.streetnumber or 0, address.complement, address.district, address.get_postal_code_number(), manager.name, branch.person.get_phone_number_number()) for item in self.store.find(FiscalDayHistory): s.add_fiscal_coupon(item.emission_date, item.serial, item.serial_id, item.coupon_start, item.coupon_end, item.cro, item.crz, item.period_total, item.total) for tax in item.taxes: s.add_fiscal_tax(item.emission_date, item.serial, tax.code, tax.value) s.close() try: compare_sintegra_file(s, 'sintegra') except AssertionError as e: self.fail(e)