Skip to content

Commit

Permalink
Merge branch 'development' of github.com:OneSila/OneSilaHeadless into…
Browse files Browse the repository at this point in the history
… development
  • Loading branch information
Sascha Dobbelaere committed Jun 16, 2024
2 parents d1d5a35 + dfd2a46 commit d728610
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 26 deletions.
18 changes: 18 additions & 0 deletions OneSila/core/migrations/0098_alter_multitenantuser_timezone.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions OneSila/core/migrations/0099_alter_multitenantuser_timezone.py

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions OneSila/core/migrations/0100_alter_multitenantuser_timezone.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion OneSila/core/schema/core/types/input.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from strawberry_django import NodeInput, input, partial
from typing import List
from strawberry import input as strawberry_input
from strawberry import input as strawberry_input
2 changes: 1 addition & 1 deletion OneSila/inventory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Inventory(models.Model):
objects = InventoryManager()

class Meta:
search_terms = ['product__sku', 'stocklocation__name']
search_terms = ['product__sku', 'stocklocation__name', 'product__supplier__name']
unique_together = ('product', 'stocklocation')
verbose_name_plural = "inventories"

Expand Down
5 changes: 3 additions & 2 deletions OneSila/inventory/schema/types/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@


@filter(InventoryLocation)
class InventoryLocationFilter(SearchFilterMixin):
class InventoryLocationFilter(SearchFilterMixin, ExcluideDemoDataFilterMixin):
search: str | None
exclude_demo_data: Optional[bool]
id: auto
name: auto
location: InternalShippingAddressFilter
location: Optional[InternalShippingAddressFilter]


@filter(Inventory)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.2 on 2024-06-12 18:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('products', '0023_alter_producttranslation_language'),
]

operations = [
migrations.RemoveField(
model_name='product',
name='base_product',
),
migrations.AddField(
model_name='product',
name='base_products',
field=models.ManyToManyField(blank=True, related_name='supplier_products', to='products.product'),
),
]
9 changes: 5 additions & 4 deletions OneSila/products/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Product(models.Model):

# Supplier Product Fields
supplier = models.ForeignKey('contacts.Company', on_delete=models.CASCADE, null=True, blank=True)
base_product = models.ForeignKey('self', on_delete=models.CASCADE, related_name='supplier_products', null=True, blank=True)
base_products = models.ManyToManyField('self', symmetrical=False, related_name='supplier_products', blank=True)

#Manufacturer product fields
production_time = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
Expand Down Expand Up @@ -319,11 +319,11 @@ class SupplierProduct(Product):

class Meta:
proxy = True
search_terms = ['sku', 'supplier__name']
search_terms = ['sku', 'supplier__name', 'translations__name']

def save(self, *args, **kwargs):
if self.base_product.type not in [self.SIMPLE, self.DROPSHIP]:
raise IntegrityError(_("SupplierProduct can only be attached to a SIMPLE or DROPSHIP product. Not a {}".format(self.type)))
if self.id and not all(bp.type in [self.SIMPLE, self.DROPSHIP] for bp in self.base_products.all()):
raise IntegrityError(_("SupplierProduct can only be attached to SIMPLE or DROPSHIP products."))

if self.supplier and not self.supplier.is_supplier:
self.supplier.is_supplier = True
Expand All @@ -332,6 +332,7 @@ def save(self, *args, **kwargs):
self.for_sale = False

super().save(*args, **kwargs)

class SupplierPrices(models.Model):
supplier_product = models.ForeignKey(SupplierProduct, on_delete=models.CASCADE, related_name='details')

Expand Down
5 changes: 3 additions & 2 deletions OneSila/products/schema/types/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from contacts.schema.types.filters import SupplierFilter
from core.schema.core.types.types import auto
from core.schema.core.types.filters import filter, SearchFilterMixin, ExcluideDemoDataFilterMixin
from core.schema.core.types.filters import filter, SearchFilterMixin, ExcluideDemoDataFilterMixin, lazy

from products.models import Product, BundleProduct, UmbrellaProduct, \
SimpleProduct, ProductTranslation, UmbrellaVariation, BundleVariation, BillOfMaterial, SupplierProduct, DropshipProduct, ManufacturableProduct, \
Expand Down Expand Up @@ -85,7 +85,8 @@ class SupplierProductFilter(SearchFilterMixin):
id: auto
sku: auto
supplier: Optional[SupplierFilter]
base_product: Optional[ProductFilter]
base_products: Optional[lazy['ProductFilter', "products.schema.types.filters"]]



@filter(BillOfMaterial)
Expand Down
9 changes: 5 additions & 4 deletions OneSila/products/schema/types/input.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from decimal import Decimal

from core.schema.core.types.types import auto
from typing import List, Optional
from core.schema.core.types.input import NodeInput, input, partial
from core.schema.core.types.types import Annotated, lazy

from products.models import Product, BundleProduct, UmbrellaProduct, SimpleProduct, \
ProductTranslation, UmbrellaVariation, BundleVariation, BillOfMaterial, SupplierProduct, DropshipProduct, ManufacturableProduct, SupplierPrices
from units.schema.types.types import UnitType


@input(Product, fields="__all__")
Expand All @@ -15,7 +14,7 @@ class ProductInput:

@partial(Product, fields="__all__")
class ProductPartialInput(NodeInput):
pass
base_products: Optional[List[Annotated['ProductPartialInput', lazy("products.schema.types.input")]]]


@input(BundleProduct, fields="__all__")
Expand Down Expand Up @@ -104,13 +103,15 @@ class SupplierProductInput:
quantity: int
unit_price: float
unit: NodeInput
base_products: Optional[List[ProductPartialInput]]


@partial(SupplierProduct, fields="__all__")
class SupplierProductPartialInput(NodeInput):
quantity: int | None
unit_price: float | None
unit: NodeInput | None
base_products: Optional[List[ProductPartialInput]]


@input(BillOfMaterial, fields="__all__")
Expand Down
9 changes: 4 additions & 5 deletions OneSila/products/schema/types/types.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from decimal import Decimal

from strawberry.relay.utils import to_base64
from strawberry_django.relay import resolve_model_id

from contacts.schema.types.types import CompanyType
from core.schema.core.types.types import relay, type, GetQuerysetMultiTenantMixin, field
from core.schema.core.types.types import relay, type, GetQuerysetMultiTenantMixin, field, Annotated, lazy

from typing import List, Optional

Expand All @@ -24,7 +22,8 @@
@type(Product, filters=ProductFilter, order=ProductOrder, pagination=True, fields="__all__")
class ProductType(relay.Node, GetQuerysetMultiTenantMixin):
vat_rate: Optional[VatRateType]
base_product: Optional["ProductType"]
base_products: List[Annotated['ProductType', lazy("products.schema.types.types")]]

supplier: Optional[CompanyType]

@field()
Expand Down Expand Up @@ -114,7 +113,7 @@ def name(self, info) -> str | None:
@type(SupplierProduct, filters=SupplierProductFilter, order=SupplierProductOrder, pagination=True, fields="__all__")
class SupplierProductType(relay.Node, GetQuerysetMultiTenantMixin):
supplier: Optional[CompanyType]
base_product: ProductType
base_products: List[Annotated['ProductType', lazy("products.schema.types.types")]]

@field()
def name(self, info) -> str | None:
Expand Down
7 changes: 4 additions & 3 deletions OneSila/purchasing/demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ class SupplierProductGenerator(PrivateDataGenerator):
def prep_baker_kwargs(self, seed):
kwargs = super().prep_baker_kwargs(seed)
multi_tenant_company = kwargs['multi_tenant_company']

product = Product.objects.filter(type=Product.SIMPLE, multi_tenant_company=multi_tenant_company).order_by('?').first()
supplier = Supplier.objects.filter(is_supplier=True, multi_tenant_company=multi_tenant_company).order_by('?').first()

kwargs.update({
'base_product': product,
'supplier': supplier
})

Expand All @@ -51,6 +48,10 @@ def post_generate_instance(self, instance, **kwargs):
multi_tenant_company=multi_tenant_company,
)

products = list(Product.objects.filter(type__in=[Product.SIMPLE, Product.DROPSHIP], multi_tenant_company=multi_tenant_company).order_by('?')[:3])
instance.base_products.set(products)
instance.save()

@registry.register_private_app
class PurchaseOrderGenerator(PrivateDataGenerator):
model = PurchaseOrder
Expand Down
10 changes: 10 additions & 0 deletions OneSila/purchasing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def reference(self):
def __str__(self):
return self.reference()

def save(self, *args, **kwargs):

# if we buy from someone it mean it become a customer if is not already
if not self.supplier.is_supplier:
self.supplier.is_supplier = True
self.supplier.save()


super().save(*args, **kwargs)

class Meta:
ordering = ('-created_at',)
search_terms = ['supplier__name', 'order_reference']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.2 on 2024-06-13 10:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('contacts', '0016_company_currency'),
('sales_prices', '0003_alter_salespricelistitem_salesprice'),
]

operations = [
migrations.AlterField(
model_name='salespricelist',
name='customers',
field=models.ManyToManyField(to='contacts.company'),
),
]
2 changes: 1 addition & 1 deletion OneSila/sales_prices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SalesPriceList(models.Model):
vat_included = models.BooleanField(default=False)
auto_update = models.BooleanField(default=True)

customers = models.ManyToManyField('contacts.Customer')
customers = models.ManyToManyField('contacts.Company')

objects = SalesPriceListManager()

Expand Down
4 changes: 2 additions & 2 deletions OneSila/sales_prices/schema/types/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from contacts.schema.types.types import CustomerType
from contacts.schema.types.types import CompanyType
from core.schema.core.types.types import relay, type, GetQuerysetMultiTenantMixin

from typing import List, Optional
Expand All @@ -22,7 +22,7 @@ class SalesPriceType(relay.Node, GetQuerysetMultiTenantMixin):
@type(SalesPriceList, filters=SalesPriceListFilter, order=SalesPriceListOrder, pagination=True, fields="__all__")
class SalesPriceListType(relay.Node, GetQuerysetMultiTenantMixin):
currency: CurrencyType
customers: List[CustomerType]
customers: List[CompanyType]
salespricelistitem_set: List['SalesPriceListItemType']


Expand Down
2 changes: 1 addition & 1 deletion OneSila/taxes/demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

@registry.register_private_app
def populate_vat_rates(multi_tenant_company):
if not VatRate.objects.filter(multitenant_company=multi_tenant_company).exists():
if not VatRate.objects.filter(multi_tenant_company=multi_tenant_company).exists():
rate = baker.make(VatRate, multi_tenant_company=multi_tenant_company, name='Standard Rate', rate=20)
registry.create_demo_data_relation(rate)

0 comments on commit d728610

Please sign in to comment.