From 8f1b018f0ab952a02e98c07323dd6c745fa02813 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 17 Sep 2020 23:22:37 +1000 Subject: [PATCH] Add table for price breaks for selling a part --- .../migrations/0049_partsellpricebreak.py | 30 +++++++++++++++++++ InvenTree/part/models.py | 16 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 InvenTree/part/migrations/0049_partsellpricebreak.py diff --git a/InvenTree/part/migrations/0049_partsellpricebreak.py b/InvenTree/part/migrations/0049_partsellpricebreak.py new file mode 100644 index 0000000000..1d49dcbfac --- /dev/null +++ b/InvenTree/part/migrations/0049_partsellpricebreak.py @@ -0,0 +1,30 @@ +# Generated by Django 3.0.7 on 2020-09-17 13:22 + +import InvenTree.fields +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0007_colortheme'), + ('part', '0048_auto_20200902_1404'), + ] + + operations = [ + migrations.CreateModel( + name='PartSellPriceBreak', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', InvenTree.fields.RoundingDecimalField(decimal_places=5, default=1, max_digits=15, validators=[django.core.validators.MinValueValidator(1)])), + ('cost', InvenTree.fields.RoundingDecimalField(decimal_places=5, max_digits=10, validators=[django.core.validators.MinValueValidator(0)])), + ('currency', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='common.Currency')), + ('part', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='salepricebreaks', to='part.Part')), + ], + options={ + 'unique_together': {('part', 'quantity')}, + }, + ), + ] diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f1b0890cba..a3c707bfec 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -46,6 +46,8 @@ from order import models as OrderModels from company.models import SupplierPart from stock import models as StockModels +import common.models + class PartCategory(InvenTreeTree): """ PartCategory provides hierarchical organization of Part objects. @@ -1227,6 +1229,20 @@ class PartAttachment(InvenTreeAttachment): related_name='attachments') +class PartSellPriceBreak(common.models.PriceBreak): + """ + Represents a price break for selling this part + """ + + part = models.ForeignKey( + Part, on_delete=models.CASCADE, + related_name='salepricebreaks' + ) + + class Meta: + unique_together = ('part', 'quantity') + + class PartStar(models.Model): """ A PartStar object creates a relationship between a User and a Part.