8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 03:43:12 +00:00

Compute job price

This commit is contained in:
Maxime Bombar 2018-09-08 14:04:44 +02:00
parent 4d308010d9
commit f47e1835b3
3 changed files with 59 additions and 5 deletions

View file

@ -23,8 +23,10 @@ from .validators import (
from .settings import ( from .settings import (
MAX_PRINTFILE_SIZE, MAX_PRINTFILE_SIZE,
ALLOWED_TYPES, ALLOWED_TYPES,
PRICES,
) )
import math
""" """
- ```user_printing_path``` is a function that returns the path of the uploaded file, used with the FileField. - ```user_printing_path``` is a function that returns the path of the uploaded file, used with the FileField.
@ -63,6 +65,12 @@ class JobWithOptions(RevMixin, models.Model):
Parent class : User Parent class : User
Methods:
```_compute_price``` compute the printing price
```_update_price``` update printing price
""" """
STATUS_AVAILABLE = ( STATUS_AVAILABLE = (
('Printable', 'Printable'), ('Printable', 'Printable'),
@ -122,4 +130,32 @@ class JobWithOptions(RevMixin, models.Model):
def _update_price(self): def _update_price(self):
self.price = 0.0 self.price = self._compute_price()
def _compute_price(self):
pages = int(self.pages)
price_paper = PRICES[self.format]
price_stapling = 0.0
nb_staples = 0
if self.disposition == 'Booklet':
sheets = int((pages+3)/4)
pages = 2 * sheets
elif self.disposition == 'TwoSided':
sheets = int(pages/2.+0.5)
else:
sheets = pages
if self.format == 'A3':
pages*=2
price_ink = price_paper*sheets + PRICES[self.color]*pages
if self.stapling:
nb_staples = 2 - int('Top' in self.stapling)
price_stapling = nb_staples * PRICES['Staples']
total_price = math.floor(self.count * (price_ink + price_stapling))
return float(total_price)/100

View file

@ -11,3 +11,20 @@ Define variables, to be changed into a configuration table.
MAX_PRINTFILE_SIZE = 25 * 1024 * 1024 # 25 MB MAX_PRINTFILE_SIZE = 25 * 1024 * 1024 # 25 MB
ALLOWED_TYPES = ['application/pdf'] ALLOWED_TYPES = ['application/pdf']
## Config
## Depreciation
depr = 2.16
PRICES = {
'Depreciation': depr,
'A3': 0.670,
'A4': 2.1504,
'Color': 9.0 + depr,
'Greyscale': 0.9 + depr,
'Staples': 1.3333,
}

View file

@ -99,6 +99,7 @@ def new_job(request):
job.user = request.user job.user = request.user
job.status = 'Running' job.status = 'Running'
job.file = old_job.file job.file = old_job.file
job._update_price()
job.save() job.save()
i+=1 i+=1
# raise ValidationError("'%(plop)s'", code='plop', params = {'plop': request.method}) # raise ValidationError("'%(plop)s'", code='plop', params = {'plop': request.method})