add code to compute fee based on the number of documents
This commit is contained in:
parent
8c85cfaacc
commit
e8435bf309
|
@ -14,9 +14,13 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
|
||||
class ExtraFees(BaseResource):
|
||||
|
@ -28,3 +32,20 @@ class ExtraFees(BaseResource):
|
|||
@classmethod
|
||||
def get_connector_slug(cls):
|
||||
return 'extra-fees'
|
||||
|
||||
@endpoint(methods=['post'])
|
||||
def compute(self, request, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
|
||||
nb_documents = 0
|
||||
for basket_item in data['data']:
|
||||
try:
|
||||
nb_documents += int(basket_item['request_data']['nb_documents'])
|
||||
except KeyError:
|
||||
# basket item not associated with any document, no fee
|
||||
pass
|
||||
|
||||
# compute fee
|
||||
postage_fee = 3 + nb_documents * 1
|
||||
|
||||
return {'data': [{'subject': force_text(_('Postage')), 'amount': str(postage_fee)}]}
|
||||
|
|
Loading…
Reference in New Issue