Skip to content

Commit

Permalink
Merge pull request #2 from aalexmrt/development
Browse files Browse the repository at this point in the history
Update application styles, refactor and add customer forms
  • Loading branch information
aalexmrt authored Jul 13, 2023
2 parents a9da961 + d136d8f commit 535aba3
Show file tree
Hide file tree
Showing 25 changed files with 513 additions and 1,428 deletions.
80 changes: 72 additions & 8 deletions invoices/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.forms import ModelForm, inlineformset_factory, BaseInlineFormSet
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Row, Column, Div, HTML, Button, ButtonHolder, Field
from crispy_forms.layout import Column, Div, HTML, Layout, Row
from django import forms
from django.forms import BaseInlineFormSet, inlineformset_factory, ModelForm

from invoices.models import Customer, Invoice, OrderLine, Product
from invoices.models import Address, Company, Contact, Customer, Invoice, OrderLine, Product


class InvoiceForm(ModelForm):
Expand All @@ -17,13 +17,13 @@ def __init__(self, *args, **kwargs):
self.helper.layout = Layout(
Row(
Column(
'sequence', css_class='form-group col-lg-3 col-md-3 col-sm-2 mb-0'),
'sequence', css_class='form-group col-lg-3 col-md-3 col-sm-6 mb-0'),
Column(
'number', css_class='form-group col-lg-3 col-md-3 col-sm-2 mb-0'),
'number', css_class='form-group col-lg-3 col-md-3 col-sm-6 mb-0'),
Column('issued_date',
css_class='form-group col-lg-3 col-md-3 col-sm-3 mb-0'),
Column(
'customer', css_class='form-group col-lg-3 col-md-3 col-sm-5 mb-0'),
'customer', css_class='form-group col-lg-3 col-md-3 col-sm-6 mb-0'),
css_class='form-row'
)
)
Expand All @@ -48,7 +48,7 @@ def __init__(self, *args, **kwargs):
Column(
'product', css_class='form-group col-lg-3 col-md-3 col-sm-5 mb-0'),
Column(
'quantity', css_class='form-group col-lg-3 col-md-3 col-sm-2 mb-0'),
'quantity', css_class='form-group col-lg-3 col-md-3 col-sm-3 mb-0'),
Column('unit_price',
css_class='form-group col-lg-3 col-md-3 col-sm-3 mb-0'),
Div(
Expand All @@ -70,3 +70,67 @@ class BaseInlineOrderFormSet(BaseInlineFormSet):

OrderLineFormSet = inlineformset_factory(
Invoice, OrderLine, form=OrderLineForm, formset=BaseInlineOrderFormSet, fields=('product', 'quantity', 'unit_price'), extra=1, can_delete=True)


class ContactForm(ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Row(
Column(
'name', css_class='form-group col-lg-3 col-md-3 col-sm-5 mb-0'),
Column(
'email', css_class='form-group col-lg-4 col-md-3 col-sm-3 mb-0'),
Column(
'cc_email', css_class='form-group col-lg-12 col-md-3 col-sm-3 mb-0'),
)
)

class Meta:
model = Contact
fields = ['name', 'email', 'cc_email']


class AddressForm(ModelForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Row(
Column(
'street', css_class='form-group col-lg-6 col-md-3 col-sm-5 mb-0'),
Column(
'postal_code', css_class='form-group col-lg-3 col-md-3 col-sm-3 mb-0'),
Column(
'city', css_class='form-group col-lg-3 col-md-3 col-sm-3 mb-0'),
)
)

class Meta:
model = Address
fields = ['city', 'postal_code', 'street']


class CompanyForm(ModelForm):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['customer_information_file_number'].label = 'CIF'
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.layout = Layout(
Row(
Column(
'name', css_class='form-group col-lg-3 col-md-3 col-sm-5 mb-0'),
Column(
'customer_information_file_number', css_class='form-group col-lg-2 col-md-3 col-sm-3 mb-0'),
)
)

class Meta:
model = Company
fields = ['name', 'customer_information_file_number']
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.5 on 2023-06-29 19:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('invoices', '0020_alter_mailinfo_sent_timestamp'),
]

operations = [
migrations.AlterField(
model_name='company',
name='customer_information_file_number',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='company',
name='name',
field=models.CharField(max_length=100),
),
]
33 changes: 16 additions & 17 deletions invoices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@


class Address(models.Model):
street = models.CharField(null=True, blank=True, max_length=100)
city = models.CharField(null=True, blank=True, max_length=100)
street = models.CharField(max_length=100)
city = models.CharField(max_length=100)
state = models.CharField(null=True, blank=True, max_length=100)
postal_code = models.CharField(null=True, blank=True, max_length=100)
postal_code = models.CharField(max_length=100)
country = models.CharField(null=True, blank=True, max_length=100)
alias = models.CharField(null=True, blank=True,
max_length=100, default='Default')

def __str__(self):
return f'{self.street} | {self.postal_code} | {self.city} | {self.state} - {self.alias}'
return f'{self.street}, {self.postal_code}, {self.city}'

class Meta:
ordering = ['alias']
Expand All @@ -22,7 +22,6 @@ class Contact(models.Model):
name = models.CharField(null=True, blank=True, max_length=100)
phone_number = models.CharField(null=True, blank=True, max_length=100)
email = models.CharField(null=True, blank=True, max_length=100)
# TODO: convert cc_email to a list of emails, it can be 0, 1 or more emails in this field
cc_email = models.CharField(null=True, blank=True, max_length=100)
country = models.CharField(null=True, blank=True, max_length=100)

Expand All @@ -35,14 +34,15 @@ class Company(models.Model):
Address, on_delete=models.CASCADE, null=True, blank=True)
contact = models.ForeignKey(
Contact, on_delete=models.CASCADE, null=True, blank=True)
name = models.CharField(null=True, blank=True, max_length=100)
name = models.CharField(max_length=100)
bank_account_number = models.CharField(
null=True, blank=True, max_length=100)
customer_information_file_number = models.CharField(
null=True, blank=True, max_length=100)
customer_information_file_number = models.CharField(max_length=100)
logo = models.ImageField(null=True, blank=True, upload_to='company/images')

def __str__(self):
if self.name is None:
return self.id
return self.name

class Meta:
Expand All @@ -54,15 +54,19 @@ class Issuer(models.Model):
Company, on_delete=models.CASCADE, null=True, blank=True)

def __str__(self):
return self.company.name
if self.company is None:
return str(self.id)
return str(self.company)


class Customer(models.Model):
company = models.ForeignKey(
Company, null=True, blank=True, on_delete=models.CASCADE)

def __str__(self):
return self.company.name
if self.company is None:
return str(self.id)
return str(self.company)


class MailInfo(models.Model):
Expand All @@ -79,11 +83,6 @@ def __str__(self):
return self.status


class GlobalSettingsManager(models.Manager):
def get_global_settings(self):
return self.get(pk=1)


class GlobalSettings(models.Model):
issuer = models.ForeignKey(
Issuer, null=True, blank=True, on_delete=models.CASCADE)
Expand All @@ -92,7 +91,6 @@ class GlobalSettings(models.Model):
max_digits=6, decimal_places=2, null=True, blank=True, default=0)
last_number = models.IntegerField(null=True, blank=True, default=0)
lead_zeros_format = models.IntegerField(null=True, blank=True, default=0)
objects = GlobalSettingsManager()
sequence = models.CharField(null=True, blank=True, max_length=100)
tax_value = models.DecimalField(
max_digits=6, decimal_places=2, null=True, blank=True, default=0)
Expand Down Expand Up @@ -163,7 +161,8 @@ class Invoice(models.Model):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.global_settings = GlobalSettings.objects.get_global_settings()
self.global_settings = GlobalSettings.objects.filter().first()

logging.info(f'Loaded global settings {self.global_settings}')

def save(self, *args, **kwargs):
Expand Down
19 changes: 19 additions & 0 deletions invoices/static/invoices/css/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.header {
background-color: #004ec1;
color: #fff;
padding: 0.5em;
}

.logo {
font-size: 24px;
font-weight: bold;
}

.empty-div{
width: 100%;

}
.dropdown:hover .dropdown-menu {
display: block;
margin-top: 0; /* remove the gap so it doesn't close */
}
6 changes: 0 additions & 6 deletions invoices/static/invoices/css/styles.css

This file was deleted.

Binary file added invoices/static/invoices/images/bill.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions invoices/static/invoices/images/bill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified invoices/static/invoices/images/favicon.ico
Binary file not shown.
92 changes: 49 additions & 43 deletions invoices/templates/invoices/base.html
Original file line number Diff line number Diff line change
@@ -1,57 +1,63 @@
<!DOCTYPE html>
{# Load the tag library #}
{% load bootstrap5 %}

{# Load CSS and JavaScript #}
{% bootstrap_css %}
{% bootstrap_javascript %}

{# Display django.contrib.messages as Bootstrap alerts #}
{% bootstrap_messages %}

{% load static %}

<html lang="en">
<head>
<title>Invoices App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="{% static 'invoices/images/favicon.ico' %}">
<link rel="stylesheet" href="{% static 'invoices/css/styles.css' %}">
<style>
/* Global styles */
/* Header styles */
.header {
background-color: #222;
color: #fff;
padding: 20px;
}

.logo {
font-size: 24px;
font-weight: bold;
}
</style>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{% static 'invoices/css/base.css' %}">
{% block css %}
<!-- Additional CSS files specific to each template -->
{% endblock %}
{% bootstrap_css %}
{% bootstrap_javascript %}
</head>

<body>
<header class="header">
<div class="d-flex align-items-baseline">
<div class="logo flex-grow-1 p-2">Invoices App</div>
<div class="p-2">
<nav class="navigation">
{% if request.path != '/' %}
<a class="p-4 link-primary" href="{% url 'index' %}">Home</a>
{% endif %}
<a class="btn btn-light" role="button" href="{% url 'add_invoice' %}"></a>
</nav>
</div>

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<div class="container-fluid p-2">
<a class="navbar-brand" href="{% url 'view_invoices' %}">Invoices App</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarText">
<div class="collapse navbar-collapse" id="navbarNavDarkDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Invoices
</a>
<ul class="dropdown-menu dropdown-menu-light" aria-labelledby="navbarDarkDropdownMenuLink">
<li><a class="dropdown-item" href="{% url 'add_invoice' %}">New item</a></li>
<li><a class="dropdown-item" href="{% url 'view_invoices' %}">View</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDarkDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Customers
</a>
<ul class="dropdown-menu dropdown-menu-light" aria-labelledby="navbarDarkDropdownMenuLink">
<li><a class="dropdown-item" href="{% url 'add_customer' %}">New item</a></li>
<li><a class="dropdown-item" href="{% url 'view_customers' %}">View</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</header>
<div class="container-fluid">
{% block main %}
<!--Here the content of the page-->
{% endblock %}
</div>
</nav>

{% block main %}
<!-- Here goes the content of the page -->
{% endblock %}

{% block javascript %}
<!-- Additional JavaScript files specific to each template -->
{% endblock %}

</body>
</html>
</html>
21 changes: 21 additions & 0 deletions invoices/templates/invoices/form_customer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends 'invoices/base.html' %}
{% load static %}
{% load crispy_forms_tags %}

{% block main %}
<div class="container pb-4">
<form class="my-class" method="post">
{% csrf_token %}

<h3 class="mt-4">Company details</h3>
{% crispy company_form %}
<h3 class="mt-4">Address details</h3>
{% crispy address_form %}
<h3 class="mt-4">Contact details</h3>
{% crispy contact_form %}
<div class="text-end">
<button type="submit" class="mt-4 btn btn-primary">Submit</button>
</div>
</form>
</div>
{% endblock %}
File renamed without changes.
Loading

0 comments on commit 535aba3

Please sign in to comment.