Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7 from AlexisCaffa/quantity
Browse files Browse the repository at this point in the history
quantity field added to Preference model
  • Loading branch information
Hugo Osvaldo Barrera authored Jan 23, 2019
2 parents 564da84 + 3bbbc59 commit b00e7f3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

v5.1.0
------
* ``quantity`` field implemented on Preference model.

v5.0.4
------
* Improve the documentation.
Expand Down
Binary file modified django_mercadopago/locale/es/LC_MESSAGES/django.mo
Binary file not shown.
3 changes: 3 additions & 0 deletions django_mercadopago/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ msgstr "título"
msgid "price"
msgstr "precio"

msgid "quantity"
msgstr "cantidad"

msgid "mercadopago id"
msgstr "id mercadopago"

Expand Down
22 changes: 22 additions & 0 deletions django_mercadopago/migrations/0017_preference_quantity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('mp', '0016_update_model_meta'),
]

operations = [
migrations.AddField(
model_name='preference',
name='quantity',
field=models.PositiveIntegerField(
default=1,
verbose_name='quantity'
),
),
]
16 changes: 13 additions & 3 deletions django_mercadopago/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def create(
price,
reference,
account,
quantity=1,
category='services',
extra_fields=None,
host=settings.MERCADOPAGO['base_host'],
Expand All @@ -99,6 +100,8 @@ def create(
identify this preference.
:param Account account: The account for which this payment is to be
created.
:param quantity: The quantity for this preference.
:type quantity: integer
:param dict extra_fields: Extra infromation to be sent with the
preference creation (including payer). See the documentation[1] for
details on avaiable fields.
Expand Down Expand Up @@ -126,7 +129,7 @@ def create(
'currency_id': 'ARS',
'description': description,
'category_id': category,
'quantity': 1,
'quantity': quantity,
# In case we get something like Decimal:
'unit_price': float(price),
}
Expand All @@ -153,6 +156,7 @@ def create(
preference = Preference(
title=title,
price=price,
quantity=quantity,
mp_id=pref_result['response']['id'],
payment_url=pref_result['response']['init_point'],
sandbox_url=pref_result['response']['sandbox_init_point'],
Expand Down Expand Up @@ -189,6 +193,10 @@ class Preference(models.Model):
max_digits=15,
decimal_places=2,
)
quantity = models.PositiveIntegerField(
_('quantity'),
default=1,
)
# Doc says it's a UUID. It's not.
mp_id = models.CharField(
_('mercadopago id'),
Expand Down Expand Up @@ -222,14 +230,16 @@ def url(self):
else:
return self.payment_url

def update(self, title=None, price=None):
def update(self, title=None, price=None, quantity=None):
"""
Updates the upstream Preference with the supplied title and price.
"""
if price:
self.price = price
if title:
self.title = title
if quantity:
self.quantity = quantity

service = self.owner.service
service.update_preference(
Expand All @@ -238,7 +248,7 @@ def update(self, title=None, price=None):
'items': [
{
'title': self.title,
'quantity': 1,
'quantity': self.quantity,
'currency_id': 'ARS',
'unit_price': float(self.price),
}
Expand Down

0 comments on commit b00e7f3

Please sign in to comment.