Commit 25140792 authored by Jean-Baptiste's avatar Jean-Baptiste

bugfix: fix nested-post by using depth=2 for CustomerInvoice

parent 4a306b42
# -*- coding: utf-8 -*-
from django.conf import settings
from django.db import models
from djangoldp.models import Model
from djangoldp_project.models import Customer
from djangoldp_project.models import Project
from django.db.models import Sum
import datetime
from decimal import Decimal
from django.db import models
from django.db.models import Sum
from djangoldp.models import Model
from djangoldp_project.models import Customer
from djangoldp_project.models import Project
class FreelanceInvoice(Model):
# customer = models.ForeignKey(User, on_delete=models.CASCADE)
# provider = models.ForeignKey(User, on_delete=models.CASCADE)
STATES = (
('pending', 'en attente'),
('sent', 'envoyé'),
('paid', 'payé')
('pending', 'en attente'),
('sent', 'envoyé'),
('paid', 'payé')
)
TVA_RATES = (
(0.0, 'exonération de TVA'),
(20.0, '20%')
(0.0, 'exonération de TVA'),
(20.0, '20%')
)
freelanceFullname = models.CharField(max_length=255)
identifier = models.CharField(max_length=255)
......@@ -29,7 +31,7 @@ class FreelanceInvoice(Model):
uploadUrl = models.URLField
creationDate = models.DateField(auto_now_add=True)
modificationDate = models.DateField(auto_now=True)
invoicingDate = models.DateField(default = datetime.date.today)
invoicingDate = models.DateField(default=datetime.date.today)
class Meta:
permissions = (
......@@ -41,13 +43,12 @@ class FreelanceInvoice(Model):
return '{} ({} / {})'.format(self.freelanceFullname, self.identifier, self.title)
class CustomerInvoice(Model):
customer = models.ForeignKey(Customer, on_delete=models.DO_NOTHING, null=True)
project = models.ForeignKey(Project, on_delete=models.DO_NOTHING, null=True)
STATES = (
('pending', 'en attente'),
('paid', 'réglée')
('pending', 'en attente'),
('paid', 'réglée')
)
identifier = models.CharField(max_length=255)
title = models.CharField(max_length=255)
......@@ -55,7 +56,7 @@ class CustomerInvoice(Model):
tvaRate = models.DecimalField(max_digits=4, decimal_places=2)
creationDate = models.DateField(auto_now_add=True)
modificationDate = models.DateField(auto_now=True)
invoicingDate = models.DateField(default = datetime.date.today)
invoicingDate = models.DateField(default=datetime.date.today)
def htAmount(self):
if self.batches is None:
......@@ -69,6 +70,7 @@ class CustomerInvoice(Model):
return Decimal(self.tvaAmount() + self.htAmount())
class Meta:
depth = 2
permissions = (
('view_invoice', 'Read'),
('control_invoice', 'Control'),
......@@ -77,6 +79,7 @@ class CustomerInvoice(Model):
def __str__(self):
return '{} - {} ({})'.format(self.identifier, self.title, self.htAmount())
# Lot =========================================================
class Batch(Model):
invoice = models.ForeignKey(CustomerInvoice, on_delete=models.CASCADE, related_name='batches')
......@@ -85,6 +88,7 @@ class Batch(Model):
modificationDate = models.DateField(auto_now=True)
class Meta:
serializer_fields = ['@id', 'invoice', 'title', 'htAmount', 'tasks']
permissions = (
('view_batch', 'Read'),
('control_batch', 'Control'),
......@@ -99,7 +103,6 @@ class Batch(Model):
amount = Decimal(0.0)
return amount
Batch._meta.serializer_fields = ['@id', 'invoice', 'title', 'htAmount', 'tasks']
class Task(Model):
batch = models.ForeignKey(Batch, on_delete=models.CASCADE, related_name='tasks')
......@@ -108,12 +111,5 @@ class Task(Model):
creationDate = models.DateField(auto_now_add=True)
modificationDate = models.DateField(auto_now=True)
class Meta:
permissions = (
('view_batch', 'Read'),
('control_batch', 'Control'),
)
def __str__(self):
return '{} - {} ({} € HT)'.format(self.batch.title, self.title, self.htAmount)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment