Parcourir la source

Save tax codes on the basket and order for reference (#4136)

* Add tax codes to basket and order

* Rename to tax_code
master
Viggo de Vries il y a 2 ans
Parent
révision
5edac196f4
Aucun compte lié à l'adresse e-mail de l'auteur

+ 4
- 0
src/oscar/apps/basket/abstract_models.py Voir le fichier

@@ -281,6 +281,7 @@ class AbstractBasket(models.Model):
281 281
             "quantity": quantity,
282 282
             "price_excl_tax": stock_info.price.excl_tax,
283 283
             "price_currency": stock_info.price.currency,
284
+            "tax_code": stock_info.price.tax_code,
284 285
         }
285 286
         if stock_info.price.is_tax_known:
286 287
             defaults["price_incl_tax"] = stock_info.price.incl_tax
@@ -709,6 +710,9 @@ class AbstractLine(models.Model):
709 710
     price_incl_tax = models.DecimalField(
710 711
         _("Price incl. Tax"), decimal_places=2, max_digits=12, null=True
711 712
     )
713
+    tax_code = models.CharField(
714
+        _("VAT rate code"), max_length=64, blank=True, null=True
715
+    )
712 716
 
713 717
     # Track date of first addition
714 718
     date_created = models.DateTimeField(

+ 18
- 0
src/oscar/apps/basket/migrations/0012_line_code.py Voir le fichier

@@ -0,0 +1,18 @@
1
+# Generated by Django 3.2.19 on 2023-07-10 08:31
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('basket', '0011_json_basket_option'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='line',
15
+            name='tax_code',
16
+            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='VAT rate code'),
17
+        ),
18
+    ]

+ 13
- 1
src/oscar/apps/order/abstract_models.py Voir le fichier

@@ -86,6 +86,9 @@ class AbstractOrder(models.Model):
86 86
     shipping_excl_tax = models.DecimalField(
87 87
         _("Shipping charge (excl. tax)"), decimal_places=2, max_digits=12, default=0
88 88
     )
89
+    shipping_tax_code = models.CharField(
90
+        _("Shipping VAT rate code"), max_length=64, blank=True, null=True
91
+    )
89 92
 
90 93
     # Not all lines are actually shipped (such as downloads), hence shipping
91 94
     # address is not mandatory.
@@ -606,6 +609,10 @@ class AbstractLine(models.Model):
606 609
         null=True,
607 610
     )
608 611
 
612
+    tax_code = models.CharField(
613
+        _("VAT rate code"), max_length=64, blank=True, null=True
614
+    )
615
+
609 616
     # Partners often want to assign some status to each line to help with their
610 617
     # own business processes.
611 618
     status = models.CharField(_("Status"), max_length=255, blank=True)
@@ -925,6 +932,9 @@ class AbstractLinePrice(models.Model):
925 932
     shipping_excl_tax = models.DecimalField(
926 933
         _("Shipping (excl. tax)"), decimal_places=2, max_digits=12, default=0
927 934
     )
935
+    tax_code = models.CharField(
936
+        _("VAT rate code"), max_length=64, blank=True, null=True
937
+    )
928 938
 
929 939
     class Meta:
930 940
         abstract = True
@@ -1291,10 +1301,12 @@ class AbstractSurcharge(models.Model):
1291 1301
     incl_tax = models.DecimalField(
1292 1302
         _("Surcharge (inc. tax)"), decimal_places=2, max_digits=12, default=0
1293 1303
     )
1294
-
1295 1304
     excl_tax = models.DecimalField(
1296 1305
         _("Surcharge (excl. tax)"), decimal_places=2, max_digits=12, default=0
1297 1306
     )
1307
+    tax_code = models.CharField(
1308
+        _("VAT rate code"), max_length=64, blank=True, null=True
1309
+    )
1298 1310
 
1299 1311
     @property
1300 1312
     def tax(self):

+ 33
- 0
src/oscar/apps/order/migrations/0014_tax_code.py Voir le fichier

@@ -0,0 +1,33 @@
1
+# Generated by Django 3.2.19 on 2023-07-10 08:44
2
+
3
+from django.db import migrations, models
4
+
5
+
6
+class Migration(migrations.Migration):
7
+
8
+    dependencies = [
9
+        ('order', '0013_json_option_value'),
10
+    ]
11
+
12
+    operations = [
13
+        migrations.AddField(
14
+            model_name='line',
15
+            name='tax_code',
16
+            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='VAT rate code'),
17
+        ),
18
+        migrations.AddField(
19
+            model_name='lineprice',
20
+            name='tax_code',
21
+            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='VAT rate code'),
22
+        ),
23
+        migrations.AddField(
24
+            model_name='order',
25
+            name='shipping_tax_code',
26
+            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='Shipping VAT rate code'),
27
+        ),
28
+        migrations.AddField(
29
+            model_name='surcharge',
30
+            name='tax_code',
31
+            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='VAT rate code'),
32
+        ),
33
+    ]

+ 6
- 0
src/oscar/apps/order/utils.py Voir le fichier

@@ -152,6 +152,7 @@ class OrderCreator(object):
152 152
             "total_excl_tax": total.excl_tax,
153 153
             "shipping_incl_tax": shipping_charge.incl_tax,
154 154
             "shipping_excl_tax": shipping_charge.excl_tax,
155
+            "shipping_tax_code": shipping_charge.tax_code,
155 156
             "shipping_method": shipping_method.name,
156 157
             "shipping_code": shipping_method.code,
157 158
         }
@@ -177,7 +178,9 @@ class OrderCreator(object):
177 178
                     code=charge.surcharge.code,
178 179
                     excl_tax=charge.price.excl_tax,
179 180
                     incl_tax=charge.price.incl_tax,
181
+                    tax_code=charge.price.tax_code,
180 182
                 )
183
+
181 184
         return order
182 185
 
183 186
     def create_line_models(self, order, basket_line, extra_line_fields=None):
@@ -193,6 +196,7 @@ class OrderCreator(object):
193 196
             raise exceptions.UnableToPlaceOrder(
194 197
                 "Basket line #%d has no stockrecord" % basket_line.id
195 198
             )
199
+
196 200
         partner = stockrecord.partner
197 201
         line_data = {
198 202
             "order": order,
@@ -214,6 +218,7 @@ class OrderCreator(object):
214 218
             # Reporting details
215 219
             "unit_price_incl_tax": basket_line.unit_price_incl_tax,
216 220
             "unit_price_excl_tax": basket_line.unit_price_excl_tax,
221
+            "tax_code": basket_line.tax_code,
217 222
         }
218 223
         extra_line_fields = extra_line_fields or {}
219 224
         if hasattr(settings, "OSCAR_INITIAL_LINE_STATUS"):
@@ -259,6 +264,7 @@ class OrderCreator(object):
259 264
                 quantity=quantity,
260 265
                 price_incl_tax=price_incl_tax,
261 266
                 price_excl_tax=price_excl_tax,
267
+                tax_code=basket_line.tax_code,
262 268
             )
263 269
 
264 270
     # pylint: disable=unused-argument

+ 5
- 1
src/oscar/apps/partner/prices.py Voir le fichier

@@ -27,6 +27,9 @@ class Base(object):
27 27
     #: Price tax
28 28
     tax = None
29 29
 
30
+    # Code used to store the vat rate reference
31
+    tax_code = None
32
+
30 33
     #: Retail price
31 34
     retail = None
32 35
 
@@ -58,11 +61,12 @@ class FixedPrice(Base):
58 61
 
59 62
     exists = True
60 63
 
61
-    def __init__(self, currency, excl_tax, tax=None):
64
+    def __init__(self, currency, excl_tax, tax=None, tax_code=None):
62 65
         super().__init__()
63 66
         self.currency = currency
64 67
         self.excl_tax = excl_tax
65 68
         self.tax = tax
69
+        self.tax_code = tax_code
66 70
 
67 71
     @property
68 72
     def incl_tax(self):

+ 3
- 1
src/oscar/core/prices.py Voir le fichier

@@ -17,9 +17,10 @@ class Price(object):
17 17
         currency (str): 3 character currency code
18 18
     """
19 19
 
20
-    def __init__(self, currency, excl_tax, incl_tax=None, tax=None):
20
+    def __init__(self, currency, excl_tax, incl_tax=None, tax=None, tax_code=None):
21 21
         self.currency = currency
22 22
         self.excl_tax = excl_tax
23
+        self.tax_code = tax_code
23 24
         if incl_tax is not None:
24 25
             self.incl_tax = incl_tax
25 26
             self.is_tax_known = True
@@ -72,6 +73,7 @@ class Price(object):
72 73
             currency=self.currency,
73 74
             incl_tax=self.incl_tax + other.incl_tax,
74 75
             excl_tax=self.excl_tax + other.excl_tax,
76
+            tax_code=self.tax_code,
75 77
         )
76 78
 
77 79
     def __radd__(self, other):

Chargement…
Annuler
Enregistrer