Skip to content

Commit

Permalink
Merge pull request #212 from City-of-Helsinki/develop
Browse files Browse the repository at this point in the history
Release 20210202
  • Loading branch information
Tomi Järvi authored Feb 2, 2021
2 parents 9d98a6d + 8ba216f commit 1c3aa43
Show file tree
Hide file tree
Showing 17 changed files with 240 additions and 140 deletions.
6 changes: 0 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,5 @@ indent_size = 4
indent_style = space
indent_size = 2

# Override spacing for some files
# previously configured file extensions
[.travis.yml]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
67 changes: 67 additions & 0 deletions .github/workflows/mvj-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: MVJ CI

on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]

jobs:
build:
env:
DATABASE_URL: 'postgis://postgres:postgres@localhost/github_actions'

runs-on: ubuntu-18.04
strategy:
matrix:
python: [3.6, 3.7]

services:
postgres:
image: postgis/postgis:10-2.5
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install postgis prerequisites
run: sudo apt-get install gdal-bin

- name: Install dependencies
run: |
pip install -U pip
pip install codecov -r requirements.txt -r requirements-dev.txt
- name: Check and run migrations
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
run: |
python manage.py makemigrations --dry-run --check
python manage.py migrate
- name: Run black, flake8 and isort
run: |
black --check .
flake8
isort . --check-only --diff
- name: Run tests
run: |
pytest -ra -vvv --doctest-modules --cov=.
./run-type-checks
- name: Run codecov
run: codecov
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Build status](https://travis-ci.org/City-of-Helsinki/mvj.svg?branch=master)](https://travis-ci.org/City-of-Helsinki/mvj)
[![codecov](https://codecov.io/gh/City-of-Helsinki/mvj/branch/master/graph/badge.svg)](https://codecov.io/gh/City-of-Helsinki/mvj)

# mvj
Expand Down
63 changes: 0 additions & 63 deletions azure-pipelines.yml

This file was deleted.

4 changes: 3 additions & 1 deletion laske_export/document/sales_order.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.core.exceptions import ValidationError
from django.core.validators import MaxLengthValidator
from django.utils.translation import ugettext_lazy as _

from leasing.enums import ContactType

Expand Down Expand Up @@ -71,7 +73,7 @@ class Party(FieldGroup):

def from_contact(self, contact): # NOQA C901 'Party.from_contact' is too complex
if not contact:
return
raise ValidationError(_("Contact information cannot be null."))

self.customer_ovt = contact.electronic_billing_address
self.info_customer_ovt = contact.electronic_billing_address
Expand Down
9 changes: 9 additions & 0 deletions laske_export/tests/test_party.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from django.core.exceptions import ValidationError

from laske_export.document.sales_order import Party
from leasing.enums import ContactType
Expand Down Expand Up @@ -478,3 +479,11 @@ def test_party_from_contact_person_with_long_care_of(
assert party.info_name2 == expected2, "info_name2"
assert party.info_name3 == expected3, "info_name3"
assert party.info_name4 == expected4, "info_name4"


@pytest.mark.django_db
def test_invalid_party_contact():
party = Party()

with pytest.raises(ValidationError):
party.from_contact(None)
3 changes: 3 additions & 0 deletions leasing/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,15 @@ class InvoiceRowInline(FieldPermissionsAdminMixin, admin.TabularInline):

class InvoiceAdmin(FieldPermissionsModelAdmin):
list_display = (
"number",
"lease",
"due_date",
"billing_period_start_date",
"billing_period_end_date",
"total_amount",
"sent_to_sap_at",
)
search_fields = ("number", "lease__identifier__identifier")
inlines = [InvoiceRowInline, InvoicePaymentInline]
raw_id_fields = ("lease", "invoiceset", "credited_invoice", "interest_invoice_for")

Expand Down
21 changes: 21 additions & 0 deletions leasing/fixtures/land_use_agreement_definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,26 @@
"fields": {
"name": "Kiinteistö"
}
},
{
"model": "leasing.LandUseAgreementDefinition",
"pk": 2,
"fields": {
"name": "Kaavayksikkö"
}
},
{
"model": "leasing.LandUseAgreementDefinition",
"pk": 3,
"fields": {
"name": "Määräala"
}
},
{
"model": "leasing.LandUseAgreementDefinition",
"pk": 4,
"fields": {
"name": "Muu"
}
}
]
16 changes: 15 additions & 1 deletion leasing/fixtures/land_use_agreement_status.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@
"model": "leasing.LandUseAgreementStatus",
"pk": 1,
"fields": {
"name": "Lorem"
"name": "Valmisteilla"
}
},
{
"model": "leasing.LandUseAgreementStatus",
"pk": 2,
"fields": {
"name": "Voimassa"
}
},
{
"model": "leasing.LandUseAgreementStatus",
"pk": 3,
"fields": {
"name": "Päättynyt"
}
}
]
46 changes: 46 additions & 0 deletions leasing/migrations/0027_change_rent_base_fields_required.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import enumfields.fields
from django.db import migrations, models

import leasing.enums


def forwards_func(apps, schema_editor):
ContractRent = apps.get_model("leasing", "ContractRent") # noqa: N806

contract_rents_with_missing_data_qs = ContractRent.objects.exclude(
base_amount__isnull=False
) | ContractRent.objects.exclude(base_amount_period__isnull=False)

for contract_rent in contract_rents_with_missing_data_qs:
if not contract_rent.base_amount:
contract_rent.base_amount = contract_rent.amount
if not contract_rent.base_amount_period:
contract_rent.base_amount_period = contract_rent.period
contract_rent.save()


class Migration(migrations.Migration):

dependencies = [
("leasing", "0026_land_use_agreement_estate_remove_unique"),
]

operations = [
migrations.RunPython(forwards_func, migrations.RunPython.noop),
migrations.AlterField(
model_name="contractrent",
name="base_amount",
field=models.DecimalField(
decimal_places=2, max_digits=10, verbose_name="Base amount"
),
),
migrations.AlterField(
model_name="contractrent",
name="base_amount_period",
field=enumfields.fields.EnumField(
enum=leasing.enums.PeriodType,
max_length=30,
verbose_name="Base amount period",
),
),
]
12 changes: 2 additions & 10 deletions leasing/models/rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,20 +879,12 @@ class ContractRent(TimeStampedSafeDeleteModel):

# In Finnish: Vuokranlaskennan perusteena oleva vuokra
base_amount = models.DecimalField(
verbose_name=_("Base amount"),
null=True,
blank=True,
max_digits=10,
decimal_places=2,
verbose_name=_("Base amount"), max_digits=10, decimal_places=2,
)

# In Finnish: Yksikkö
base_amount_period = EnumField(
PeriodType,
verbose_name=_("Base amount period"),
null=True,
blank=True,
max_length=30,
PeriodType, verbose_name=_("Base amount period"), max_length=30,
)

# In Finnish: Uusi perusvuosi vuokra
Expand Down
11 changes: 0 additions & 11 deletions leasing/report/lease/lease_statistic_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,17 +502,6 @@ def get_data(self, input_data):
Q(end_date__isnull=True) | Q(end_date__gte=datetime.date.today())
)

# Skip the leases where have not set the period type of base amount in contact rents
# The report fails because contract rents contain items where isn't defined the period type for the base amount
# TODO: Review this with the specialist
no_period = []
for lease in qs:
for rent in lease.rents.all():
for cr in rent.contract_rents.all():
if not cr.base_amount_period:
no_period.append(lease.id)
qs = qs.exclude(id__in=no_period)

return qs

def generate_report(self, user, input_data):
Expand Down
9 changes: 9 additions & 0 deletions leasing/serializers/rent.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ class Meta:
"end_date",
)

def to_internal_value(self, data):
if "amount" in data and "base_amount" not in data:
data["base_amount"] = data["amount"]

if "period" in data and "base_amount_period" not in data:
data["base_amount_period"] = data["period"]

return super().to_internal_value(data)


class IndexAdjustedRentSerializer(serializers.ModelSerializer):
id = serializers.IntegerField(required=False)
Expand Down
Loading

0 comments on commit 1c3aa43

Please sign in to comment.