예제 #1
0
 def test_list_contacts(self):
     ''' 
         Verify that the list contacts method returns the list of the user clients
         as a list of (id, contact) tuples
     
      '''
     user1 = helpers.create_dummy_user(11)
     user2 = helpers.create_dummy_user(12)
     
     create_dummy_client(1, user1)
     create_dummy_client(2, user2)
     create_dummy_client(3, user1)
     create_dummy_client(4, user2)
     create_dummy_client(5, user1)
     create_dummy_client(6, user2)
     create_dummy_client(7, user1)
      
     client_manager_1 = ClientManager(user1)
     client_manager_2 = ClientManager(user2)
      
     clients_1 = client_manager_1.list_clients()
     clients_2 = client_manager_2.list_clients()
      
     self.assertEqual(len(clients_1), 4)
     self.assertEqual(len(clients_2), 3)
     
예제 #2
0
def add_dummy_contact(index, client, user, client_manager = None):
    """ add a dummy client contact """

    if client_manager == None:
        client_manager = ClientManager(user.user)

    return client_manager.add_client_contact(
        client = client, 
        name = 'name_%i' % index,
        email = '*****@*****.**' % index
    )
예제 #3
0
    def post(self):
        form = ClientForm(data=self.request.POST)
        if form.is_valid():
            client_manager = ClientManager(self._user_session.get_user())

            name = form["name"].data
            address = form["address"].data
            email = form["email"].data
            default_currency_id = form["default_currency"].data
            default_language_id = form["default_language"].data

            client_manager.add_client(name, address, email, default_currency_id, default_language_id)
        else:
            self.get(form)
예제 #4
0
    def create(self, client_id, invoice_no, invoice_date, sale_date, currency_id = None, language_id = None):
        '''
            Create a new invoice
        '''
        self._invoice_items = []
        
        client = ClientManager.find_by_id(client_id)
        
        if currency_id is None:
            currency = client.default_currency
        else:
            currency = CurrencyManager.find_by_id(currency_id)
        
        if language_id is None:
            language = client.default_language
        else:
            language = LanguageManager.find_by_id(language_id)
        
        self._invoice = InvoiceEntity.create(
                                       user = self._user,
                                       client = client,
                                       currency = currency,
                                       language = language,
                                       invoice_no = invoice_no,
                                       invoice_date = invoice_date,
                                       sale_date = sale_date
                                    )

        return self._invoice
예제 #5
0
def create_dummy_client(index, user, client_manager = None, language = None, currency = None):
    """ Create a dummy client """
    
    if client_manager == None:
        client_manager = ClientManager(user)
    
    if currency is None:
        currency = create_dummy_currency(index)
        
    if language is None:
        language = create_dummy_language(index)
    
    return client_manager.add_client(
        name = 'client_%i' %index,
        address = 'address_%i' % index,
        email = '*****@*****.**' % index,
        default_currency_id = currency.key().id(),
        default_language_id = language.key().id(),
    )
예제 #6
0
 def _execute(self):
     client_manager = ClientManager(self._user_session.get_user())
     clients = client_manager.list_clients()
     json = self.jsonize_jqgrid(clients)
     return self.render_content(json)
예제 #7
0
    def initialize(self, request, response):
        """ Override to inizialize the session """
        super(CreateInvoiceHandler, self).initialize(request, response)

        self._client_manager = ClientManager(self._user)
        self._invoice_manager = InvoiceManager(self._user)
예제 #8
0
class CreateInvoiceHandler(BaseProtectedHandler):
    """ Create a new invoice """

    def initialize(self, request, response):
        """ Override to inizialize the session """
        super(CreateInvoiceHandler, self).initialize(request, response)

        self._client_manager = ClientManager(self._user)
        self._invoice_manager = InvoiceManager(self._user)

    def get(self, invoice_form=None, invoice_item_forms=[InvoiceItemForm(index=1)]):
        if invoice_form == None:
            # Initialize the Invoice form

            clients = self._client_manager.listify_clients()
            currencies = CurrencyManager.listify_currencies()
            languages = LanguageManager.listify_languages()

            invoice_form = InvoiceForm(clients, currencies, languages)

        return render_template(
            self, "invoice_create.html", {"invoice_form": invoice_form, "invoice_item_forms": invoice_item_forms}
        )

    def post(self):
        commit = False

        clients = self._client_manager.listify_clients()
        currencies = CurrencyManager.listify_currencies()
        languages = LanguageManager.listify_languages()
        invoice_form = InvoiceForm(data=self.request.POST, clients=clients, currencies=currencies, languages=languages)

        items = invoice_form.fields["items"].to_python(self.request.POST["invoice-items"]) or 0
        max_item_index = int(self.request.POST["h-last-invoice-item-index"]) or 0

        invoice_item_forms = [
            InvoiceItemForm(index + 1, self.request.POST)
            for index in range(0, max_item_index)
            if self.request.POST.has_key("%i_invoice_item-description" % (index + 1))
        ]

        if items > max_item_index:
            commit = False
        elif items == 0:
            commit = False
        elif invoice_form.is_valid():
            # Validates the invoice items
            commit = True
            for form in invoice_item_forms:
                if not form.is_valid():
                    commit = False
                    break

        if commit:
            self._invoice_manager.create(
                client_id=invoice_form.cleaned_data["client"],
                currency_id=invoice_form.cleaned_data["currency"],
                invoice_no=invoice_form.cleaned_data["invoice_no"],
                invoice_date=invoice_form.cleaned_data["invoice_date"],
                sale_date=invoice_form.cleaned_data["sale_date"],
            )
            for invoice_item in invoice_item_forms:
                self._invoice_manager.add_invoice_item(
                    description=invoice_item.cleaned_data["description"],
                    quantity=invoice_item.cleaned_data["quantity"],
                    unit_price=invoice_item.cleaned_data["unit_price"],
                )

            self._invoice_manager.save()
        else:
            self.get(invoice_form, invoice_item_forms)