Esempio n. 1
0
    def test_update_taxes(self):
        tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
        icms_template = ProductIcmsTemplate(store=self.store,
                                            product_tax_template=tax_template)
        icms_template.csosn = 201

        tax_template = ProductTaxTemplate(store=self.store,
                                          tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = ProductIpiTemplate(store=self.store,
                                          product_tax_template=tax_template)
        ipi_template.cst = 00

        product = self.create_product()
        product.icms_template = icms_template
        product.ipi_template = ipi_template
        decrease_item = self.create_stock_decrease_item(
            sellable=product.sellable, cost=100, quantity=1)
        with mock.patch(
                'stoqlib.lib.pluginmanager.PluginManager.is_active') as patch:
            patch.return_value = True
            editor = StockDecreaseItemEditor(self.store, decrease_item)
            slave = editor.item_slave
            icms_slave = editor.icms_slave
            ipi_slave = editor.ipi_slave
            self.assertEquals(icms_slave.v_bc_st.read(), 100)
            self.assertEquals(ipi_slave.v_bc.read(), 100)
            slave.cost.update(150)
            self.assertEquals(icms_slave.v_bc_st.read(), 150)
            self.assertEquals(ipi_slave.v_bc.read(), 150)
            slave.quantity.update(2)
            self.assertEquals(icms_slave.v_bc_st.read(), 300)
            self.assertEquals(ipi_slave.v_bc.read(), 300)
Esempio n. 2
0
 def testGetTaxModel(self):
     tax_template = ProductTaxTemplate(
         store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
     self.failIf(tax_template.get_tax_model())
     ProductIcmsTemplate(store=self.store,
                         product_tax_template=tax_template)
     self.failUnless(tax_template.get_tax_model())
Esempio n. 3
0
 def test_get_tax_model(self):
     tax_template = ProductTaxTemplate(
         store=self.store,
         tax_type=ProductTaxTemplate.TYPE_ICMS)
     self.failIf(tax_template.get_tax_model())
     ProductIcmsTemplate(
         store=self.store,
         product_tax_template=tax_template)
     self.failUnless(tax_template.get_tax_model())
Esempio n. 4
0
    def testSearch(self):
        ProductTaxTemplate(name=u'Test ICMS Tax Template',
                           tax_type=ProductTaxTemplate.TYPE_ICMS,
                           store=self.store)
        ProductTaxTemplate(name=u'Test IPI Tax Template',
                           tax_type=ProductTaxTemplate.TYPE_IPI,
                           store=self.store)

        search = TaxTemplatesSearch(self.store)

        search.search.refresh()
        self.check_search(search, 'product-tax-template')
Esempio n. 5
0
    def test_update_taxes(self):
        tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
        icms_template = ProductIcmsTemplate(store=self.store,
                                            product_tax_template=tax_template)
        icms_template.csosn = 201

        tax_template = ProductTaxTemplate(store=self.store,
                                          tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = ProductIpiTemplate(store=self.store,
                                          product_tax_template=tax_template)
        ipi_template.cst = 00

        tax_template = self.create_product_tax_template(
            tax_type=ProductTaxTemplate.TYPE_PIS)
        pis_template = self.create_product_pis_template(cst=49)
        self.assertEqual(pis_template.cst, 49)

        tax_template = self.create_product_tax_template(
            tax_type=ProductTaxTemplate.TYPE_COFINS)
        cofins_template = self.create_product_cofins_template(cst=49)
        self.assertEqual(cofins_template.cst, 49)

        product = self.create_product()
        product.set_icms_template(icms_template)
        product.set_ipi_template(ipi_template)
        product.set_pis_template(pis_template)
        product.set_cofins_template(cofins_template)
        transfer_item = self.create_transfer_order_item(
            sellable=product.sellable, stock_cost=100, quantity=1)
        with mock.patch(
                'stoqlib.lib.pluginmanager.PluginManager.is_active') as patch:
            patch.return_value = True
            editor = TransferItemEditor(self.store, transfer_item)
            slave = editor.item_slave
            icms_slave = editor.icms_slave
            ipi_slave = editor.ipi_slave
            self.assertEqual(icms_slave.v_bc_st.read(), 100)
            self.assertEqual(ipi_slave.v_bc.read(), 100)
            slave.stock_cost.update(150)
            self.assertEqual(icms_slave.v_bc_st.read(), 150)
            self.assertEqual(ipi_slave.v_bc.read(), 150)
            slave.quantity.update(2)
            self.assertEqual(icms_slave.v_bc_st.read(), 300)
            self.assertEqual(ipi_slave.v_bc.read(), 300)
Esempio n. 6
0
    def test_nfe_data(self):
        # FIXME: Improve this test after fix the properties, icms_info and ipi_info.
        loan = self.create_loan()
        product = self.create_product()
        icms_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
        icms_template = ProductIcmsTemplate(
            store=self.store, product_tax_template=icms_tax_template)

        ipi_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = ProductIpiTemplate(
            store=self.store, product_tax_template=ipi_tax_template)
        product.icms_template = icms_template
        product.ipi_template = ipi_template

        loan_item = loan.add_sellable(product.sellable)
        self.assertEquals(loan_item.icms_info, None)
        self.assertEquals(loan_item.ipi_info, None)
Esempio n. 7
0
    def test_nfe_data(self):
        loan = self.create_loan()
        product = self.create_product()
        icms_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
        icms_template = ProductIcmsTemplate(
            store=self.store, product_tax_template=icms_tax_template)

        ipi_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = ProductIpiTemplate(
            store=self.store, product_tax_template=ipi_tax_template)

        pis_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_PIS)
        pis_template = ProductPisTemplate(
            store=self.store, product_tax_template=pis_tax_template)

        cofins_tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_COFINS)
        cofins_template = ProductCofinsTemplate(
            store=self.store, product_tax_template=cofins_tax_template)
        product.icms_template = icms_template
        product.ipi_template = ipi_template
        product.pis_template = pis_template
        product.cofins_template = cofins_template

        loan_item = loan.add_sellable(product.sellable)
        self.assertIsNotNone(loan_item.icms_info)
        self.assertIsNotNone(loan_item.ipi_info)
        self.assertIsNotNone(loan_item.pis_info)
        self.assertIsNotNone(loan_item.cofins_info)

        self.assertEquals(loan_item.item_discount, 0)
        loan_item.price -= 2
        self.assertEquals(loan_item.item_discount, 2)
Esempio n. 8
0
    def test_calculate_item(self):
        # SP (São Paulo) as default state.
        branch = get_current_branch(self.store)
        address = branch.person.get_main_address()
        state = address.city_location.state
        assert state == "SP"
        # Product with NCM, EX TIPI and ICMS
        sale = self.create_sale()
        sale_item = self.create_sale_item(sale)
        sale_item.price = 150
        product = sale_item.sellable.product
        product.ncm = u'39269090'
        product.ex_tipi = u'001'

        items = sale.get_items()
        generator = IBPTGenerator(items)

        # Create ICMS tax
        tax = ProductTaxTemplate(store=self.store, name=u'Test')
        icms = ProductIcmsTemplate(store=self.store, product_tax_template=tax)
        # Values (0, 3, 4, 5, 8) - taxes codes of brazilian origin.
        # Different values represent taxes of international origin.
        icms.orig = 0
        product.icms_template = icms

        # Values used from IBPT table. Change this values when update the taxes.
        # (ncm;ex;tipo;descricao;nacionalfederal;importadosfederal;estadual;
        #  municipal;vigenciainicio;vigenciafim;chave;versao;fonte;)

        # (39269090;01;0;Ex 01 - Forma para fabricação de calçados;13.45;24.77;18.00;
        #  0.00;01/01/2015;30/06/2015;9oi3aC;15.1.C;IBPT)
        tax_values = generator._load_tax_values(sale_item)
        total_item = sale_item.quantity * sale_item.price
        # Federal tax
        expected_federal_tax = total_item * (Decimal("4.2") / 100)
        federal = generator._calculate_federal_tax(sale_item, tax_values)
        self.assertEquals(federal, expected_federal_tax)
        # State tax
        expected_state_tax = total_item * (Decimal("18") / 100)
        state_tax = generator._calculate_state_tax(sale_item, tax_values)
        self.assertEquals(state_tax, expected_state_tax)

        # With tax of international origin.
        icms.orig = 1
        # Federal tax
        expected_federal_tax = total_item * (Decimal("21.45") / 100)
        federal = generator._calculate_federal_tax(sale_item, tax_values)
        self.assertEquals(federal, expected_federal_tax)
Esempio n. 9
0
    def test_set_item_tax(self):
        icms_template = self.create_product_icms_template()

        tax_template = ProductTaxTemplate(
            store=self.store,
            tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = ProductIpiTemplate(
            store=self.store,
            product_tax_template=tax_template)

        product = self.create_product()
        product.icms_template = icms_template
        product.ipi_template = ipi_template
        sale_item = self.create_sale_item()
        sale_item.sellable.product = product
        sale_item.icms_info.set_item_tax(sale_item)
        sale_item.ipi_info.set_item_tax(sale_item)
Esempio n. 10
0
    def test_set_item_tax(self):
        icms_template = self.create_product_icms_template()

        tax_template = ProductTaxTemplate(store=self.store,
                                          tax_type=ProductTaxTemplate.TYPE_IPI)
        ipi_template = self.create_product_ipi_template(
            tax_template=tax_template,
            calculo=ProductIpiTemplate.CALC_ALIQUOTA)

        product = self.create_product()
        product.icms_template = icms_template
        product.ipi_template = ipi_template
        sale_item = self.create_sale_item(sellable=product.sellable)
        sale_item.icms_info.set_item_tax(sale_item)
        sale_item.ipi_info.set_item_tax(sale_item)
        sale_item.pis_info.set_item_tax(sale_item)
        sale_item.cofins_info.set_item_tax(sale_item)
Esempio n. 11
0
    def testIsPCredSnValid(self):
        tax_template = ProductTaxTemplate(
            store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
        icms_template = ProductIcmsTemplate(store=self.store,
                                            product_tax_template=tax_template)

        self.assertTrue(icms_template.is_p_cred_sn_valid())

        expire_date = localnow()
        icms_template.p_cred_sn_valid_until = expire_date
        self.assertTrue(icms_template.is_p_cred_sn_valid())

        expire_date = localnow() + relativedelta(days=+1)
        icms_template.p_cred_sn_valid_until = expire_date
        self.assertTrue(icms_template.is_p_cred_sn_valid())

        expire_date = localnow() + relativedelta(days=-1)
        icms_template.p_cred_sn_valid_until = expire_date
        self.assertFalse(icms_template.is_p_cred_sn_valid())
Esempio n. 12
0
    def test_check_taxes_validity(self):
        sellable = self.create_sellable()
        sellable.check_taxes_validity(self.current_branch)

        tax = ProductTaxTemplate(store=self.store, name=u'foo')
        template = ProductIcmsTemplate(store=self.store, product_tax_template=tax)
        sellable.product.set_icms_template(template)

        sellable.check_taxes_validity(self.current_branch)

        template.p_cred_sn = 10
        template.p_cred_sn_valid_until = localdate(2000, 1, 1)

        with self.assertRaises(TaxError) as e:
            sellable.check_taxes_validity(self.current_branch)
            self.assertEqual(str(e), ("You cannot sell this item before updating "
                                      "the 'ICMS tax rate credit' field on 'foo' "
                                      "Tax Class.\n"
                                      "If you don't know what this means, contact "
                                      "the system administrator."))
Esempio n. 13
0
 def test_get_tax_type_str(self):
     tax_template = ProductTaxTemplate(
         store=self.store,
         tax_type=ProductTaxTemplate.TYPE_ICMS)
     self.assertEqual(tax_template.get_tax_type_str(), u'ICMS')
Esempio n. 14
0
 def test_get_tax_type_str(self):
     tax_template = ProductTaxTemplate(
         store=self.store,
         tax_type=ProductTaxTemplate.TYPE_ICMS)
     self.assertEqual(tax_template.get_tax_type_str(), u'ICMS')
Esempio n. 15
0
 def testSetFromTemplate(self):
     tax_template = ProductTaxTemplate(
         store=self.store, tax_type=ProductTaxTemplate.TYPE_ICMS)
     icms_template = ProductIcmsTemplate(store=self.store,
                                         product_tax_template=tax_template)
     icms_template.set_from_template(icms_template)
Esempio n. 16
0
 def create_model(self, store):
     model = ProductTaxTemplate(name=u"",
                                tax_type=ProductTaxTemplate.TYPE_ICMS,
                                store=store)
     self._create_slave_model(model)
     return model