浏览代码

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 2 年前
父节点
当前提交
5edac196f4
没有帐户链接到提交者的电子邮件

+ 4
- 0
src/oscar/apps/basket/abstract_models.py 查看文件

281
             "quantity": quantity,
281
             "quantity": quantity,
282
             "price_excl_tax": stock_info.price.excl_tax,
282
             "price_excl_tax": stock_info.price.excl_tax,
283
             "price_currency": stock_info.price.currency,
283
             "price_currency": stock_info.price.currency,
284
+            "tax_code": stock_info.price.tax_code,
284
         }
285
         }
285
         if stock_info.price.is_tax_known:
286
         if stock_info.price.is_tax_known:
286
             defaults["price_incl_tax"] = stock_info.price.incl_tax
287
             defaults["price_incl_tax"] = stock_info.price.incl_tax
709
     price_incl_tax = models.DecimalField(
710
     price_incl_tax = models.DecimalField(
710
         _("Price incl. Tax"), decimal_places=2, max_digits=12, null=True
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
     # Track date of first addition
717
     # Track date of first addition
714
     date_created = models.DateTimeField(
718
     date_created = models.DateTimeField(

+ 18
- 0
src/oscar/apps/basket/migrations/0012_line_code.py 查看文件

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 查看文件

86
     shipping_excl_tax = models.DecimalField(
86
     shipping_excl_tax = models.DecimalField(
87
         _("Shipping charge (excl. tax)"), decimal_places=2, max_digits=12, default=0
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
     # Not all lines are actually shipped (such as downloads), hence shipping
93
     # Not all lines are actually shipped (such as downloads), hence shipping
91
     # address is not mandatory.
94
     # address is not mandatory.
606
         null=True,
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
     # Partners often want to assign some status to each line to help with their
616
     # Partners often want to assign some status to each line to help with their
610
     # own business processes.
617
     # own business processes.
611
     status = models.CharField(_("Status"), max_length=255, blank=True)
618
     status = models.CharField(_("Status"), max_length=255, blank=True)
925
     shipping_excl_tax = models.DecimalField(
932
     shipping_excl_tax = models.DecimalField(
926
         _("Shipping (excl. tax)"), decimal_places=2, max_digits=12, default=0
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
     class Meta:
939
     class Meta:
930
         abstract = True
940
         abstract = True
1291
     incl_tax = models.DecimalField(
1301
     incl_tax = models.DecimalField(
1292
         _("Surcharge (inc. tax)"), decimal_places=2, max_digits=12, default=0
1302
         _("Surcharge (inc. tax)"), decimal_places=2, max_digits=12, default=0
1293
     )
1303
     )
1294
-
1295
     excl_tax = models.DecimalField(
1304
     excl_tax = models.DecimalField(
1296
         _("Surcharge (excl. tax)"), decimal_places=2, max_digits=12, default=0
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
     @property
1311
     @property
1300
     def tax(self):
1312
     def tax(self):

+ 33
- 0
src/oscar/apps/order/migrations/0014_tax_code.py 查看文件

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 查看文件

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

+ 5
- 1
src/oscar/apps/partner/prices.py 查看文件

27
     #: Price tax
27
     #: Price tax
28
     tax = None
28
     tax = None
29
 
29
 
30
+    # Code used to store the vat rate reference
31
+    tax_code = None
32
+
30
     #: Retail price
33
     #: Retail price
31
     retail = None
34
     retail = None
32
 
35
 
58
 
61
 
59
     exists = True
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
         super().__init__()
65
         super().__init__()
63
         self.currency = currency
66
         self.currency = currency
64
         self.excl_tax = excl_tax
67
         self.excl_tax = excl_tax
65
         self.tax = tax
68
         self.tax = tax
69
+        self.tax_code = tax_code
66
 
70
 
67
     @property
71
     @property
68
     def incl_tax(self):
72
     def incl_tax(self):

+ 3
- 1
src/oscar/core/prices.py 查看文件

17
         currency (str): 3 character currency code
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
         self.currency = currency
21
         self.currency = currency
22
         self.excl_tax = excl_tax
22
         self.excl_tax = excl_tax
23
+        self.tax_code = tax_code
23
         if incl_tax is not None:
24
         if incl_tax is not None:
24
             self.incl_tax = incl_tax
25
             self.incl_tax = incl_tax
25
             self.is_tax_known = True
26
             self.is_tax_known = True
72
             currency=self.currency,
73
             currency=self.currency,
73
             incl_tax=self.incl_tax + other.incl_tax,
74
             incl_tax=self.incl_tax + other.incl_tax,
74
             excl_tax=self.excl_tax + other.excl_tax,
75
             excl_tax=self.excl_tax + other.excl_tax,
76
+            tax_code=self.tax_code,
75
         )
77
         )
76
 
78
 
77
     def __radd__(self, other):
79
     def __radd__(self, other):

正在加载...
取消
保存