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

Commit b00e7f3

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #7 from AlexisCaffa/quantity
quantity field added to Preference model
2 parents 564da84 + 3bbbc59 commit b00e7f3

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
v5.1.0
5+
------
6+
* ``quantity`` field implemented on Preference model.
7+
48
v5.0.4
59
------
610
* Improve the documentation.
17 Bytes
Binary file not shown.

django_mercadopago/locale/es/LC_MESSAGES/django.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ msgstr "título"
5858
msgid "price"
5959
msgstr "precio"
6060

61+
msgid "quantity"
62+
msgstr "cantidad"
63+
6164
msgid "mercadopago id"
6265
msgstr "id mercadopago"
6366

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('mp', '0016_update_model_meta'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='preference',
16+
name='quantity',
17+
field=models.PositiveIntegerField(
18+
default=1,
19+
verbose_name='quantity'
20+
),
21+
),
22+
]

django_mercadopago/models.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def create(
8585
price,
8686
reference,
8787
account,
88+
quantity=1,
8889
category='services',
8990
extra_fields=None,
9091
host=settings.MERCADOPAGO['base_host'],
@@ -99,6 +100,8 @@ def create(
99100
identify this preference.
100101
:param Account account: The account for which this payment is to be
101102
created.
103+
:param quantity: The quantity for this preference.
104+
:type quantity: integer
102105
:param dict extra_fields: Extra infromation to be sent with the
103106
preference creation (including payer). See the documentation[1] for
104107
details on avaiable fields.
@@ -126,7 +129,7 @@ def create(
126129
'currency_id': 'ARS',
127130
'description': description,
128131
'category_id': category,
129-
'quantity': 1,
132+
'quantity': quantity,
130133
# In case we get something like Decimal:
131134
'unit_price': float(price),
132135
}
@@ -153,6 +156,7 @@ def create(
153156
preference = Preference(
154157
title=title,
155158
price=price,
159+
quantity=quantity,
156160
mp_id=pref_result['response']['id'],
157161
payment_url=pref_result['response']['init_point'],
158162
sandbox_url=pref_result['response']['sandbox_init_point'],
@@ -189,6 +193,10 @@ class Preference(models.Model):
189193
max_digits=15,
190194
decimal_places=2,
191195
)
196+
quantity = models.PositiveIntegerField(
197+
_('quantity'),
198+
default=1,
199+
)
192200
# Doc says it's a UUID. It's not.
193201
mp_id = models.CharField(
194202
_('mercadopago id'),
@@ -222,14 +230,16 @@ def url(self):
222230
else:
223231
return self.payment_url
224232

225-
def update(self, title=None, price=None):
233+
def update(self, title=None, price=None, quantity=None):
226234
"""
227235
Updates the upstream Preference with the supplied title and price.
228236
"""
229237
if price:
230238
self.price = price
231239
if title:
232240
self.title = title
241+
if quantity:
242+
self.quantity = quantity
233243

234244
service = self.owner.service
235245
service.update_preference(
@@ -238,7 +248,7 @@ def update(self, title=None, price=None):
238248
'items': [
239249
{
240250
'title': self.title,
241-
'quantity': 1,
251+
'quantity': self.quantity,
242252
'currency_id': 'ARS',
243253
'unit_price': float(self.price),
244254
}

0 commit comments

Comments
 (0)