mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 20:33:11 +00:00
Compute job price
This commit is contained in:
parent
ba6cc23fed
commit
39cddb2cb5
3 changed files with 59 additions and 5 deletions
|
@ -23,8 +23,10 @@ from .validators import (
|
|||
from .settings import (
|
||||
MAX_PRINTFILE_SIZE,
|
||||
ALLOWED_TYPES,
|
||||
PRICES,
|
||||
)
|
||||
|
||||
import math
|
||||
|
||||
"""
|
||||
- ```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
|
||||
|
||||
|
||||
|
||||
Methods:
|
||||
```_compute_price``` compute the printing price
|
||||
```_update_price``` update printing price
|
||||
"""
|
||||
STATUS_AVAILABLE = (
|
||||
('Printable', 'Printable'),
|
||||
|
@ -122,4 +130,32 @@ class JobWithOptions(RevMixin, models.Model):
|
|||
|
||||
|
||||
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
|
||||
|
|
|
@ -11,3 +11,20 @@ Define variables, to be changed into a configuration table.
|
|||
|
||||
MAX_PRINTFILE_SIZE = 25 * 1024 * 1024 # 25 MB
|
||||
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,
|
||||
}
|
||||
|
|
|
@ -99,6 +99,7 @@ def new_job(request):
|
|||
job.user = request.user
|
||||
job.status = 'Running'
|
||||
job.file = old_job.file
|
||||
job._update_price()
|
||||
job.save()
|
||||
i+=1
|
||||
# raise ValidationError("'%(plop)s'", code='plop', params = {'plop': request.method})
|
||||
|
|
Loading…
Reference in a new issue