Ejemplo n.º 1
0
    def test_get_header_data(self):
        branch = get_current_branch(self.store)
        person = branch.person
        company = person.company
        main_address = person.get_main_address()
        person.email = u'foo@bar'
        person.mobile_number = u'998765432'
        with mock.patch('stoqlib.reporting.utils.get_default_store') as ds:
            ds.return_value = self.store
            data = get_header_data()

        address = ' - '.join([
            main_address.get_address_string(), main_address.postal_code,
            main_address.get_city(),
            main_address.get_state()
        ])
        contact = ' - '.join([
            format_phone_number(person.phone_number),
            format_phone_number(person.mobile_number),
            _("Fax: %s") % format_phone_number(person.fax_number), person.email
        ])
        register = ' - '.join([
            _("CNPJ: %s") % company.cnpj,
            _("State Registry: %s") % company.state_registry
        ])
        self.assertEquals(data['lines'], [address, contact, register])
Ejemplo n.º 2
0
    def _get_person_phone(self, person):
        phone_number = format_phone_number(person.phone_number)
        mobile_number = format_phone_number(person.mobile_number)
        if phone_number and mobile_number:
            return '%s | %s' % (phone_number, mobile_number)

        return phone_number or mobile_number
Ejemplo n.º 3
0
    def _get_person_phone(self, person):
        phone_number = format_phone_number(person.phone_number)
        mobile_number = format_phone_number(person.mobile_number)
        if phone_number and mobile_number:
            return '%s | %s' % (phone_number, mobile_number)

        return phone_number or mobile_number
Ejemplo n.º 4
0
def get_header_data():
    default_store = get_default_store()

    branch = get_current_branch(default_store)
    person = branch.person
    company = person.company
    main_address = person.get_main_address()

    if not person.name:  # pragma nocover
        raise DatabaseInconsistency("The person by ID %r should have a "
                                    "name at this point" % (person.id, ))

    data = {
        'title': branch.get_description(),
        'lines': [],
    }

    # Address
    if main_address:
        address_parts = []
        address_parts.append(main_address.get_address_string())
        if main_address.postal_code:
            address_parts.append(main_address.postal_code)
        if main_address.get_city():
            address_parts.append(main_address.get_city())
        if main_address.get_state():
            address_parts.append(main_address.get_state())
        if address_parts:
            data['lines'].append(' - '.join(address_parts))

    # Contact
    contact_parts = []
    if person.phone_number:
        contact_parts.append(format_phone_number(person.phone_number))
    if person.mobile_number:
        contact_parts.append(format_phone_number(person.mobile_number))
    if person.fax_number:
        contact_parts.append(_("Fax: %s") %
                             format_phone_number(person.fax_number))
    if person.email:
        contact_parts.append(person.email)
    if contact_parts:
        data['lines'].append(' - '.join(contact_parts))

    # Company details
    if company:
        company_parts = []
        if company.get_cnpj_number():
            company_parts.append(_("CNPJ: %s") % company.cnpj)
        if company.get_state_registry_number():
            company_parts.append(_("State Registry: %s") %
                                 company.state_registry)

        if company_parts:
            data['lines'].append(' - '.join(company_parts))

    return data
Ejemplo n.º 5
0
def get_header_data():
    default_store = get_default_store()

    branch = get_current_branch(default_store)
    person = branch.person
    company = person.company
    main_address = person.get_main_address()

    if not person.name:  # pragma nocover
        raise DatabaseInconsistency("The person by ID %r should have a "
                                    "name at this point" % (person.id, ))

    data = {
        'title': branch.get_description(),
        'lines': [],
    }

    # Address
    if main_address:
        address_parts = []
        address_parts.append(main_address.get_address_string())
        if main_address.postal_code:
            address_parts.append(main_address.postal_code)
        if main_address.get_city():
            address_parts.append(main_address.get_city())
        if main_address.get_state():
            address_parts.append(main_address.get_state())
        if address_parts:
            data['lines'].append(' - '.join(address_parts))

    # Contact
    contact_parts = []
    if person.phone_number:
        contact_parts.append(format_phone_number(person.phone_number))
    if person.mobile_number:
        contact_parts.append(format_phone_number(person.mobile_number))
    if person.fax_number:
        contact_parts.append(
            _("Fax: %s") % format_phone_number(person.fax_number))
    if person.email:
        contact_parts.append(person.email)
    if contact_parts:
        data['lines'].append(' - '.join(contact_parts))

    # Company details
    if company:
        company_parts = []
        if company.get_cnpj_number():
            company_parts.append(_("CNPJ: %s") % company.cnpj)
        if company.get_state_registry_number():
            company_parts.append(
                _("State Registry: %s") % company.state_registry)

        if company_parts:
            data['lines'].append(' - '.join(company_parts))

    return data
Ejemplo n.º 6
0
Archivo: utils.py Proyecto: rg3915/stoq
def get_header_data():
    default_store = get_default_store()

    person = get_current_branch(default_store).person
    company = person.company
    main_address = person.get_main_address()

    if not person.name:  # pragma nocover
        raise DatabaseInconsistency("The person by ID %r should have a " "name at this point" % (person.id,))

    data = {"title": person.name, "lines": []}

    # Address
    if main_address:
        data["lines"].append(main_address.get_address_string())

        address_parts = []
        if main_address.postal_code:
            address_parts.append(main_address.postal_code)
        if main_address.get_city():
            address_parts.append(main_address.get_city())
        if main_address.get_state():
            address_parts.append(main_address.get_state())

        if address_parts:
            data["lines"].append(" - ".join(address_parts))

    # Contact
    contact_parts = []
    if person.phone_number:
        contact_parts.append(_("Phone: %s") % format_phone_number(person.phone_number))
    if person.fax_number:
        contact_parts.append(_("Fax: %s") % format_phone_number(person.fax_number))
    if contact_parts:
        data["lines"].append(" - ".join(contact_parts))

    # Company details
    if company:
        company_parts = []
        if company.get_cnpj_number():
            company_parts.append(_("CNPJ: %s") % company.cnpj)
        if company.get_state_registry_number():
            company_parts.append(_("State Registry: %s") % company.state_registry)

        if company_parts:
            data["lines"].append(" - ".join(company_parts))

    return data
Ejemplo n.º 7
0
    def test_get_header_data(self):
        branch = get_current_branch(self.store)
        person = branch.person
        company = person.company
        main_address = person.get_main_address()
        person.email = u'foo@bar'
        person.mobile_number = u'998765432'
        with mock.patch('stoqlib.reporting.utils.get_default_store') as ds:
            ds.return_value = self.store
            data = get_header_data()

        address = ' - '.join([main_address.get_address_string(),
                              main_address.postal_code,
                              main_address.get_city(),
                              main_address.get_state()])
        contact = ' - '.join([format_phone_number(person.phone_number),
                              format_phone_number(person.mobile_number),
                              _("Fax: %s") % format_phone_number(person.fax_number),
                              person.email])
        register = ' - '.join([_("CNPJ: %s") % company.cnpj,
                               _("State Registry: %s") % company.state_registry])
        self.assertEqual(data['lines'], [address, contact, register])
Ejemplo n.º 8
0
    def testFormatPhoneNumber(self):
        self.assertEquals(format_phone_number("190"), "190")
        self.assertEquals(format_phone_number("1052"), "1052")
        self.assertEquals(format_phone_number("10325"), "103 25")

        self.assertEquals(format_phone_number("0300123456"), "0300 123-456")
        self.assertEquals(format_phone_number("03001234567"), "0300 123-4567")
        self.assertEquals(format_phone_number("0500700600"), "0500 700-600")
        self.assertEquals(format_phone_number("05007006005"), "0500 700-6005")
        self.assertEquals(format_phone_number("0800197878"), "0800 197-878")
        self.assertEquals(format_phone_number("08001234567"), "0800 123-4567")
        self.assertEquals(format_phone_number("0900197878"), "0900 197-878")
        self.assertEquals(format_phone_number("09001234567"), "0900 123-4567")

        self.assertEquals(format_phone_number("1312345678"), "(13) 1234-5678")
        self.assertEquals(format_phone_number("1512345678"), "(15) 1234-5678")
        self.assertEquals(format_phone_number("1812345678"), "(18) 1234-5678")
        self.assertEquals(format_phone_number("1912345678"), "(19) 1234-5678")

        self.assertEquals(format_phone_number("12345678"), "1234-5678")
        self.assertEquals(format_phone_number("1612345678"), "(16) 1234-5678")
        self.assertEquals(format_phone_number("01612345678"), "(16) 1234-5678")
        self.assertEquals(format_phone_number("(16)12345678"),
                          "(16) 1234-5678")
        self.assertEquals(format_phone_number("(016)12345678"),
                          "(16) 1234-5678")
        self.assertEquals(format_phone_number("11123456789"),
                          "(11) 12345-6789")
        self.assertEquals(format_phone_number("011123456789"),
                          "(11) 12345-6789")
Ejemplo n.º 9
0
    def test_format_phone_number(self):
        self.assertEqual(format_phone_number("190"), "190")
        self.assertEqual(format_phone_number("1052"), "1052")
        self.assertEqual(format_phone_number("10325"), "103 25")

        self.assertEqual(format_phone_number("991236789"), "99123-6789")
        self.assertEqual(format_phone_number("0300123456"), "0300 123-456")
        self.assertEqual(format_phone_number("03001234567"), "0300 123-4567")
        self.assertEqual(format_phone_number("0500700600"), "0500 700-600")
        self.assertEqual(format_phone_number("05007006005"), "0500 700-6005")
        self.assertEqual(format_phone_number("0800197878"), "0800 197-878")
        self.assertEqual(format_phone_number("08001234567"), "0800 123-4567")
        self.assertEqual(format_phone_number("0900197878"), "0900 197-878")
        self.assertEqual(format_phone_number("09001234567"), "0900 123-4567")

        self.assertEqual(format_phone_number("1312345678"), "(13) 1234-5678")
        self.assertEqual(format_phone_number("1512345678"), "(15) 1234-5678")
        self.assertEqual(format_phone_number("1812345678"), "(18) 1234-5678")
        self.assertEqual(format_phone_number("1912345678"), "(19) 1234-5678")

        self.assertEqual(format_phone_number("12345678"), "1234-5678")
        self.assertEqual(format_phone_number("1612345678"), "(16) 1234-5678")
        self.assertEqual(format_phone_number("01612345678"), "(16) 1234-5678")
        self.assertEqual(format_phone_number("(16)12345678"), "(16) 1234-5678")
        self.assertEqual(format_phone_number("(016)12345678"), "(16) 1234-5678")
        self.assertEqual(format_phone_number("11123456789"), "(11) 12345-6789")
        self.assertEqual(format_phone_number("011123456789"), "(11) 12345-6789")
Ejemplo n.º 10
0
def test_format_phone_number():
    assert formatters.format_phone_number("1231234") == "123-1234"