Skip to content

Commit

Permalink
Merge pull request #289 from rafaelurben/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rafaelurben authored Jul 18, 2024
2 parents dfb06bc + fab47d1 commit afee6e9
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ "master" ]
branches: [ "master", "dev" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
branches: [ "master", "dev" ]
schedule:
- cron: '33 0 * * 5'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: KMUHelper tests

on:
push:
branches: [ "master" ]
branches: [ "master", "dev" ]
pull_request:
branches: [ "master" ]
branches: [ "master", "dev" ]

jobs:
run-tests:
Expand Down
36 changes: 36 additions & 0 deletions kmuhelper/migrations/0116_add_woocommerceid_indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 5.0.7 on 2024-07-17 22:13

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("kmuhelper", "0115_migrate_payment_receiver_address_format"),
]

operations = [
migrations.AddIndex(
model_name="customer",
index=models.Index(
fields=["woocommerceid"], name="kmuhelper_c_woocomm_b647fd_idx"
),
),
migrations.AddIndex(
model_name="order",
index=models.Index(
fields=["woocommerceid"], name="kmuhelper_o_woocomm_8db6e3_idx"
),
),
migrations.AddIndex(
model_name="product",
index=models.Index(
fields=["woocommerceid"], name="kmuhelper_p_woocomm_34f8a4_idx"
),
),
migrations.AddIndex(
model_name="productcategory",
index=models.Index(
fields=["woocommerceid"], name="kmuhelper_p_woocomm_a29e62_idx"
),
),
]
3 changes: 3 additions & 0 deletions kmuhelper/modules/integrations/woocommerce/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db import models
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _

from kmuhelper import settings

WC_STATE_DESCRIPTION = format_html(
Expand Down Expand Up @@ -60,3 +61,5 @@ def display_woocommerce_state(self):

class Meta:
abstract = True

indexes = [models.Index(fields=["woocommerceid"])]
52 changes: 42 additions & 10 deletions kmuhelper/modules/main/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,49 @@
_ = gettext_lazy


class Address:
"""Model representing an address"""

first_name: str
last_name: str
company: str
address_1: str
address_2: str
postcode: str
city: str
state: str
country: str
phone: str
email: str

def __getitem__(self, item):
return getattr(self, item)

def is_empty(self):
for field in [
"first_name",
"last_name",
"company",
"address_1",
"postcode",
"city",
]:
if getattr(self, field, "") != "":
return False
return True


class AddressModelMixin(models.Model):
"""This model mixin provides billing and shipping address fields and utility methods"""

# Billing address

@property
def addr_billing(self):
return {
field.replace("addr_billing_", ""): getattr(self, field)
for field in constants.ADDR_BILLING_FIELDS
}
def addr_billing(self) -> Address:
addr = Address()
for field in constants.ADDR_BILLING_FIELDS:
setattr(addr, field.replace("addr_billing_", ""), getattr(self, field))
return addr

addr_billing_first_name = models.CharField(
verbose_name=pgettext_lazy("address", "Vorname"),
Expand Down Expand Up @@ -91,11 +123,11 @@ def addr_billing(self):
# Shipping address

@property
def addr_shipping(self):
return {
field.replace("addr_shipping_", ""): getattr(self, field)
for field in constants.ADDR_SHIPPING_FIELDS
}
def addr_shipping(self) -> Address:
addr = Address()
for field in constants.ADDR_SHIPPING_FIELDS:
setattr(addr, field.replace("addr_shipping_", ""), getattr(self, field))
return addr

addr_shipping_first_name = models.CharField(
verbose_name=pgettext_lazy("address", "Vorname"),
Expand Down
8 changes: 4 additions & 4 deletions kmuhelper/modules/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ def email_stock_warning(self):
log("No email receiver for stock warning set.")
return None

class Meta:
class Meta(WooCommerceModelMixin.Meta):
verbose_name = _("Bestellung")
verbose_name_plural = _("Bestellungen")

Expand Down Expand Up @@ -1148,7 +1148,7 @@ def __str__(self):
s += f"({self.addr_billing_postcode} {self.addr_billing_city})"
return s

class Meta:
class Meta(WooCommerceModelMixin.Meta):
verbose_name = _("Kunde")
verbose_name_plural = _("Kunden")

Expand Down Expand Up @@ -1760,7 +1760,7 @@ def show_stock_warning(self, request):
def __str__(self):
return f"[{self.pk}] {self.article_number} - {self.clean_name()}"

class Meta:
class Meta(WooCommerceModelMixin.Meta):
verbose_name = _("Produkt")
verbose_name_plural = _("Produkte")

Expand Down Expand Up @@ -1822,7 +1822,7 @@ def clean_description(self):
def __str__(self):
return f"[{self.pk}] {self.clean_name()}"

class Meta:
class Meta(WooCommerceModelMixin.Meta):
verbose_name = _("Produktkategorie")
verbose_name_plural = _("Produktkategorien")

Expand Down
Loading

0 comments on commit afee6e9

Please sign in to comment.