def _create_source(self): direct = self._get_direct_commission() inst = self._get_installments_commission() CommissionSource(direct_value=direct, installments_value=inst, sellable=self.model, store=self.store)
def test_installments_commission_amount(self): self._payComissionWhenConfirmed() sale = self.create_sale() sellable = self.add_product(sale, price=300) sale.order() CommissionSource(sellable=sellable, direct_value=12, installments_value=5, store=self.store) method = PaymentMethod.get_by_name(self.store, u'check') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, Decimal(100)) method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, Decimal(200)) self.assertTrue(self.store.find(Commission, sale=sale).is_empty()) sale.confirm() self.assertFalse(self.store.find(Commission, sale=sale).is_empty()) commissions = self.store.find(Commission, sale=sale).order_by(Commission.value) self.assertEqual(commissions.count(), 2) for c in commissions: self.assertTrue(c.commission_type == Commission.INSTALLMENTS) # the first payment represent 1/3 of the total amount # 5% of 300: 15,00 * 1/3 => 5,00 self.assertEqual(commissions[0].value, Decimal("5.00")) # the second payment represent 2/3 of the total amount # $15 * 2/3 => 10,00 self.assertEqual(commissions[1].value, Decimal("10.00"))
def test_sales_person_report(self): sysparam(self.store).SALE_PAY_COMMISSION_WHEN_CONFIRMED = 1 salesperson = self.create_sales_person() product = self.create_product(price=100) sellable = product.sellable sale = self.create_sale() sale.salesperson = salesperson sale.add_sellable(sellable, quantity=1) self.create_storable(product, get_current_branch(self.store), stock=100) CommissionSource(sellable=sellable, direct_value=Decimal(10), installments_value=1, store=self.store) sale.order() method = PaymentMethod.get_by_name(self.store, u'money') till = Till.get_last_opened(self.store) method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, sale.get_sale_subtotal(), till=till) sale.confirm() sale.group.pay() salesperson_name = salesperson.person.name commissions = list(self.store.find(CommissionView)) commissions[0].identifier = 1 commissions[1].identifier = 139 self._diff_expected(SalesPersonReport, 'sales-person-report', commissions, salesperson_name)
def testInstallmentsCommissionAmountWithMultipleItems(self): self._payComissionWhenConfirmed() sale = self.create_sale() sellable = self.add_product(sale, price=300, quantity=3) sale.order() CommissionSource(sellable=sellable, direct_value=12, installments_value=5, store=self.store) method = PaymentMethod.get_by_name(self.store, u'check') method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, Decimal(300)) method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, Decimal(450)) method.create_payment(Payment.TYPE_IN, sale.group, sale.branch, Decimal(150)) self.assertTrue(self.store.find(Commission, sale=sale).is_empty()) sale.confirm() commissions = self.store.find(Commission, sale=sale).order_by(Commission.value) self.assertEquals(commissions.count(), 3) for c in commissions: self.failUnless(c.commission_type == Commission.INSTALLMENTS) # the first payment represent 1/3 of the total amount # 45 / 6 => 7.50 self.assertEquals(commissions[0].value, Decimal("7.50")) # the second payment represent 1/3 of the total amount # 5% of 900: 45,00 * 1/3 => 15,00 self.assertEquals(commissions[1].value, Decimal("15.00")) # the third payment represent 1/2 of the total amount # 45 / 2 => 22,50 self.assertEquals(commissions[2].value, Decimal("22.50"))
def create_commission_source(self, category=None): from stoqlib.domain.commission import CommissionSource if not category: sellable = self.create_sellable() else: sellable = None return CommissionSource(direct_value=10, category=category, sellable=sellable, installments_value=1, store=self.store)
def test_installments_commission_amount_when_sale_return(self): if True: raise SkipTest( u"See stoqlib.domain.returnedsale.ReturnedSale.return_ " u"and bug 5215.") self._payComissionWhenConfirmed() sale = self.create_sale() sellable = self.create_sellable() CommissionSource(sellable=sellable, direct_value=12, installments_value=5, store=self.store) sale.add_sellable(sellable, quantity=3, price=300) product = sellable.product self.create_storable(product, self.current_branch, 100) sale.order(self.current_user) method = PaymentMethod.get_by_name(self.store, u'check') payment1 = method.create_payment(sale.branch, self.current_station, Payment.TYPE_IN, sale.group, Decimal(300)) payment2 = method.create_payment(sale.branch, self.current_station, Payment.TYPE_IN, sale.group, Decimal(450)) payment3 = method.create_payment(sale.branch, self.current_station, Payment.TYPE_IN, sale.group, Decimal(150)) sale.confirm(self.current_user) # the commissions are created after the payment payment1.pay() payment2.pay() payment3.pay() returned_sale = sale.create_sale_return_adapter( self.current_branch, self.current_user, self.current_station) returned_sale.return_() self.assertEqual(sale.status, Sale.STATUS_RETURNED) commissions = self.store.find(Commission, sale=sale) value = sum([c.value for c in commissions]) self.assertEqual(value, Decimal(0)) self.assertEqual(commissions.count(), 4) self.assertFalse(commissions[-1].value >= 0)
def test_sales_person_report(self): sysparam.set_bool(self.store, 'SALE_PAY_COMMISSION_WHEN_CONFIRMED', True) salesperson = self.create_sales_person() product = self.create_product(price=100) sellable = product.sellable sale = self.create_sale() sale.salesperson = salesperson sale.add_sellable(sellable, quantity=1) self.create_storable(product, get_current_branch(self.store), stock=100) CommissionSource(sellable=sellable, direct_value=Decimal(10), installments_value=1, store=self.store) sale.order(self.current_user) method = PaymentMethod.get_by_name(self.store, u'money') method.create_payment(sale.branch, sale.station, Payment.TYPE_IN, sale.group, sale.get_sale_subtotal()) sale.confirm(self.current_user) sale.group.pay() salesperson = salesperson commissions = list(self.store.find(CommissionView)) commissions[0].identifier = 1 commissions[1].identifier = 139 self._diff_expected(SalesPersonReport, 'sales-person-report', commissions, salesperson) # Also test when there is no salesperson selected self._diff_expected(SalesPersonReport, 'sales-person-report-without-salesperson', commissions, None)
def _delete_source(self, source): CommissionSource.delete(source.id, store=self.store)
def _delete_source(self, source): CommissionSource.delete(source.id, store=self.store)