|
@@ -91,6 +91,37 @@ class Document(models.Model):
|
|
|
def get_total_goods(self):
|
|
|
return self.good_set.aggregate(sum=Sum('price'))['sum'] or 0
|
|
|
|
|
|
+ def compare(self, other_doc):
|
|
|
+ """ Compare this document to another one
|
|
|
+
|
|
|
+ :type other_doc: Document
|
|
|
+ :rtype: dict
|
|
|
+ """
|
|
|
+ service_records = []
|
|
|
+ for service in self.service_set.subscribables():
|
|
|
+ other_service = Service.objects.similar_to(service).filter(
|
|
|
+ document=other_doc).first()
|
|
|
+
|
|
|
+ if other_service:
|
|
|
+ deltas = service.compare(other_service)
|
|
|
+ else:
|
|
|
+ deltas = {}
|
|
|
+
|
|
|
+ service_records.append({
|
|
|
+ 'service': service,
|
|
|
+ 'other_service': other_service,
|
|
|
+ 'deltas': deltas,
|
|
|
+ })
|
|
|
+
|
|
|
+ comparison = {
|
|
|
+ 'services': service_records,
|
|
|
+ 'total_recuring_costs': self.get_total_recuring_costs() - other_doc.get_total_recuring_costs(),
|
|
|
+ 'total_goods': self.get_total_goods() - other_doc.get_total_goods(),
|
|
|
+ }
|
|
|
+
|
|
|
+ return comparison
|
|
|
+
|
|
|
+
|
|
|
class AbstractItem(models.Model):
|
|
|
name = models.CharField('Nom', max_length=130)
|
|
|
description = models.TextField('description', blank=True)
|