Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions mhr-api/migrations/versions/0001_rebase_2024-10.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,13 +898,17 @@ def upgrade():
sa.Column('phone_extension', sa.String(length=10), nullable=True),
sa.Column('terms_accepted', sa.String(length=1), nullable=True),
sa.Column('address_id', sa.Integer(), nullable=True),
sa.Column('confirm_requirements', sa.String(length=1), nullable=True),
sa.Column('location_address_id', sa.Integer(), nullable=True),
sa.Column('party_type', postgresql.ENUM('OWNER_BUS', 'OWNER_IND', 'SUBMITTING', 'EXECUTOR', 'ADMINISTRATOR', 'TRUSTEE', 'TRUST', 'MANUFACTURER', 'CONTACT', name='mhr_party_type'), nullable=False),
sa.ForeignKeyConstraint(['address_id'], ['addresses.id'], ),
sa.ForeignKeyConstraint(['location_address_id'], ['addresses.id'], ),
sa.ForeignKeyConstraint(['party_type'], ['mhr_party_types.party_type'], ),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('mhr_qualified_suppliers', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_mhr_qualified_suppliers_address_id'), ['address_id'], unique=False)
batch_op.create_index(batch_op.f('ix_mhr_qualified_suppliers_location_address_id'), ['location_address_id'], unique=False)

op.create_table('mhr_registration_reports',
sa.Column('id', sa.Integer(), sa.Sequence('mhr_registration_report_id_seq'), nullable=False),
Expand Down Expand Up @@ -3760,33 +3764,7 @@ def downgrade():
op.drop_table('mhr_registration_reports')
with op.batch_alter_table('mhr_qualified_suppliers', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_qualified_suppliers_address_id'))
op.drop_table('mhr_qualified_suppliers')
with op.batch_alter_table('mhr_owner_groups', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_owner_groups_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_owner_groups_change_registration_id'))
op.drop_table('mhr_owner_groups')
with op.batch_alter_table('mhr_locations', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_locations_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_locations_exception_plan'))
batch_op.drop_index(batch_op.f('ix_mhr_locations_change_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_locations_address_id'))
op.drop_table('mhr_locations')
with op.batch_alter_table('mhr_documents', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_documents_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_documents_document_registration_number'))
batch_op.drop_index(batch_op.f('ix_mhr_documents_document_id'))
batch_op.drop_index(batch_op.f('ix_mhr_documents_change_registration_id'))
op.drop_table('mhr_documents')
with op.batch_alter_table('mhr_descriptions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_descriptions_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_descriptions_change_registration_id'))
op.drop_table('mhr_descriptions')
with op.batch_alter_table('mhr_registration_reports', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_registration_reports_registration_id'))
batch_op.drop_index(batch_op.f('ix_mhr_registration_reports_create_ts'))
op.drop_table('mhr_registration_reports')
with op.batch_alter_table('mhr_qualified_suppliers', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_qualified_suppliers_address_id'))
batch_op.drop_index(batch_op.f('ix_mhr_qualified_suppliers_location_address_id'))
op.drop_table('mhr_qualified_suppliers')
with op.batch_alter_table('mhr_owner_groups', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_mhr_owner_groups_registration_id'))
Expand Down
8 changes: 4 additions & 4 deletions mhr-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mhr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "mhr-api"
version = "2.0.2"
version = "2.0.3"
description = ""
authors = ["dlovett <doug@daxiom.com>"]
license = "BSD 3"
Expand Down Expand Up @@ -42,8 +42,8 @@ pytz = "^2022.7.1"
alembic-utils = "^0.8.3"
datedelta = "^1.4"
flask-jwt-oidc = "^0.7.0"
registry-schemas = { git = "https://github.com/bcgov/registry-schemas.git", tag = "1.8.11" }
flask-babel = "^4.0.0"
registry-schemas = {git = "https://github.com/bcgov/registry-schemas.git", rev = "1.8.12"}


[tool.poetry.group.test.dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
# Manually replace after script runs: actual signature is too long and truncated, causing an alembic error.
# Actual signature is:
# match_individual_name(lastname character varying, firstname character varying, sim_quotient_last real DEFAULT 0.29, sim_quotient_first real DEFAULT 0.4, sim_quotient_default real DEFAULT 0.50)
# signature="match_individual_name(lastname character varying, firstname character varying, sq_last real DEFAULT 0.29, sq_first real DEFAULT 0.4, sq_def real DEFAULT 0.50)",
match_individual_name = PGFunction(
schema="public",
signature="match_individual_name(lastname character varying, firstname character varying, sq_last real DEFAULT 0.29, sq_first real DEFAULT 0.4, sq_default real DEFAULT 0.50)",
signature="match_individual_name(lastname character varying, firstname character varying, sq_last real, sq_first real, sq_def real)",
definition=r"""
RETURNS integer[]
LANGUAGE plpgsql
Expand Down
21 changes: 20 additions & 1 deletion mhr-api/src/mhr_api/models/mhr_qualified_supplier.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ class MhrQualifiedSupplier(db.Model): # pylint: disable=too-many-instance-attri
phone_number = db.mapped_column("phone_number", db.String(20), nullable=True)
phone_extension = db.mapped_column("phone_extension", db.String(10), nullable=True)
terms_accepted = db.mapped_column("terms_accepted", db.String(1), nullable=True)
confirm_requirements = db.mapped_column("confirm_requirements", db.String(1), nullable=True)

# parent keys
address_id = db.mapped_column("address_id", db.Integer, db.ForeignKey("addresses.id"), nullable=True, index=True)
location_address_id = db.mapped_column(
"location_address_id", db.Integer, db.ForeignKey("addresses.id"), nullable=True, index=True
)
party_type = db.mapped_column(
"party_type",
PG_ENUM(MhrPartyTypes, name="mhr_party_type"),
Expand All @@ -51,11 +55,13 @@ class MhrQualifiedSupplier(db.Model): # pylint: disable=too-many-instance-attri
)
# Relationships - Addressess
address = db.relationship("Address", foreign_keys=[address_id], uselist=False)
location_address = db.relationship("Address", foreign_keys=[location_address_id], uselist=False)

@property
def json(self) -> dict:
"""Return the party as a json object."""
party = {
"confirmRequirements": bool(self.confirm_requirements and self.confirm_requirements == "Y"),
"termsAccepted": bool(self.terms_accepted and self.terms_accepted == "Y"),
"partyType": self.party_type,
"address": self.address.json,
Expand All @@ -77,6 +83,8 @@ def json(self) -> dict:
party["phoneExtension"] = self.phone_extension
if self.authorization_name:
party["authorizationName"] = self.authorization_name
if self.location_address_id and self.location_address:
party["locationAddress"] = self.location_address.json
return party

def save(self):
Expand Down Expand Up @@ -111,8 +119,15 @@ def update(self, json_data: dict):
self.phone_number = json_data["phoneNumber"].strip() if json_data.get("phoneNumber") else None
self.phone_extension = json_data["phoneExtension"].strip() if json_data.get("phoneExtension") else None
self.terms_accepted = "Y" if json_data.get("termsAccepted") else None
if json_data.get("address") != self.address.json:
if json_data.get("address") and json_data.get("address") != self.address.json:
self.address = Address.create_from_json(json_data["address"])
if json_data.get("confirmRequirements"):
self.confirm_requirements = "Y"
if json_data.get("locationAddress") and (
not self.location_address
or (self.location_address and self.location_address.json != json_data.get("locationAddress"))
):
self.location_address = Address.create_from_json(json_data["locationAddress"])
db.session.add(self)
db.session.commit()

Expand Down Expand Up @@ -174,4 +189,8 @@ def create_from_json(json_data, account_id: str, party_type: str):
if json_data.get("termsAccepted"):
supplier.terms_accepted = "Y"
supplier.address = Address.create_from_json(json_data["address"])
if json_data.get("confirmRequirements"):
supplier.confirm_requirements = "Y"
if json_data.get("locationAddress"):
supplier.location_address = Address.create_from_json(json_data["locationAddress"])
return supplier
6 changes: 3 additions & 3 deletions mhr-api/src/mhr_api/models/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
REG_FILTER_CLIENT_REF_COLLAPSE,
REG_FILTER_DATE,
REG_FILTER_DATE_COLLAPSE,
REG_FILTER_DOCUMENT_ID,
REG_FILTER_DOCUMENT_ID_COLLAPSE,
REG_FILTER_MHR,
REG_FILTER_REG_TYPE,
REG_FILTER_REG_TYPE_COLLAPSE,
Expand All @@ -51,18 +53,16 @@
REG_FILTER_SUBMITTING_NAME_COLLAPSE,
REG_FILTER_USERNAME,
REG_FILTER_USERNAME_COLLAPSE,
REG_FILTER_DOCUMENT_ID,
REG_FILTER_DOCUMENT_ID_COLLAPSE,
REG_ORDER_BY_CLIENT_REF,
REG_ORDER_BY_DATE,
REG_ORDER_BY_DOCUMENT_ID,
REG_ORDER_BY_EXPIRY_DAYS,
REG_ORDER_BY_MHR_NUMBER,
REG_ORDER_BY_OWNER_NAME,
REG_ORDER_BY_REG_TYPE,
REG_ORDER_BY_STATUS,
REG_ORDER_BY_SUBMITTING_NAME,
REG_ORDER_BY_USERNAME,
REG_ORDER_BY_DOCUMENT_ID,
UPDATE_BATCH_REG_REPORT,
)
from mhr_api.models.type_tables import (
Expand Down
6 changes: 5 additions & 1 deletion mhr-api/src/mhr_api/utils/registration_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,13 @@ def validate_permit(
)
if registration and group_name and group_name == MANUFACTURER_GROUP:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the ticket description the removal of the restriction applies only to dealers. MANUFACTURER_GROUP applies to QS manufactures, which I do not think has changed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely correct, only Dealers are changing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! I will update it.

error_msg += validate_manufacturer_permit(registration.mhr_number, json_data, current_location)
# When the group name is DEALERSHIP_GROUP, json_data["qsLocation"] is qualified supplier json.
qs = json_data.get("qsLocation", {})
if (
registration
and group_name
and group_name == DEALERSHIP_GROUP
and qs.get("confirmRequirements", False) == False
and current_location
and current_location.get("locationType", "") != MhrLocationTypes.MANUFACTURER
):
Expand Down Expand Up @@ -912,7 +915,8 @@ def validate_transfer_dealer(registration: MhrRegistration, json_data, reg_type:
if not json_data.get("supplier"):
error_msg += QS_DEALER_INVALID
return error_msg
if not validator_utils.is_valid_dealer_transfer_owner(registration, json_data.get("supplier")):
qs: dict = json_data.get("supplier")
if qs.get("confirmRequirements", False) == False and not validator_utils.is_valid_dealer_transfer_owner(registration, qs):
error_msg += DEALER_TRANSFER_OWNER_INVALID
if json_data.get("supplier"): # Added just for this validation.
del json_data["supplier"]
Expand Down
13 changes: 7 additions & 6 deletions mhr-api/test_data/postgres_create_first.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
-- Place any general or common use statements here.
DELETE FROM mhr_drafts WHERE id = 0;

INSERT INTO mhr_drafts(id, draft_number, account_id, registration_type, create_ts, draft, mhr_number, update_ts, user_id)
VALUES (0, 'CONV-1', '0', 'MHREG', now() at time zone 'UTC', '{}',null, null, 'TESTUSER')
;

INSERT INTO mhr_extra_registrations(id, account_id, mhr_number, removed_ind)
VALUES (200000000, 'PS12345', 'TEST01', null)
;
Expand Down Expand Up @@ -35,3 +29,10 @@ INSERT INTO user_profiles(id, payment_confirmation, search_selection_confirmatio
registrations_table, misc_preferences, service_agreements)
VALUES (190000001, 'Y', 'Y', 'Y', 'Y', null, null, '{"agreementType": "DEFAULT", "version": "v1", "latestVersion": true, "accepted": true, "acceptedDateTime": "2023-08-11T22:07:37+00:00", "acceptAgreementRequired": true}')
;

DELETE FROM mhr_drafts WHERE id = 0 AND NOT EXISTS (SELECT id FROM mhr_registrations WHERE draft_id = 0 AND id < 200000000);

INSERT INTO mhr_drafts(id, draft_number, account_id, registration_type, create_ts, draft, mhr_number, update_ts, user_id)
SELECT 0, 'CONV-1', '0', 'MHREG', now() at time zone 'UTC', '{}',null, null, 'TESTUSER'
WHERE NOT EXISTS (SELECT id FROM mhr_registrations WHERE draft_id = 0 AND id < 190000000)
;
4 changes: 2 additions & 2 deletions mhr-api/test_data/postgres_test_reset.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DELETE FROM mhr_registrations WHERE id >= 200000000;
DELETE FROM mhr_drafts WHERE id >= 200000000;
DELETE FROM mhr_extra_registrations WHERE id >= 200000000;
DELETE FROM addresses WHERE id BETWEEN 190000000 AND 191000000;
DELETE FROM user_profiles WHERE id BETWEEN 190000000 AND 191000000;
DELETE FROM users WHERE id BETWEEN 190000000 AND 191000000;
DELETE FROM user_profiles WHERE id BETWEEN 190000000 AND 191000000;
DELETE FROM users WHERE id BETWEEN 190000000 AND 191000000;

-- Delete test data end
Loading
Loading