diff --git a/README.md b/README.md index 513afa1..ab883ed 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,16 @@ To import ward data, get the ward data csv and then run the following command: --args '[ "/path/to/ward/csv" ]' ``` +# Setting up Entity Postcodes + +Assuming you have imported codepoint open, then to properly assign all + postcodes: + +```shell script +./script/pear-local_loop minion job \ + --enqueue entity_postcode_lookup +``` + ## Example PostgreSQL setup ``` diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index 9c92a71..72eee9b 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -64,6 +64,7 @@ sub post_lcc_suppliers { $v->optional('page')->number; $v->optional('sort_by'); $v->optional('sort_dir'); + $v->optional('search'); my $order_by = [ { -asc => 'organisation.name' }, @@ -85,6 +86,12 @@ sub post_lcc_suppliers { my $lcc_suppliers = $c->schema->resultset('Entity')->search( { 'sales.buyer_id' => $user->entity->id, + ( $v->param('search') ? ( + '-or' => [ + { 'organisation.name' => { 'like' => $v->param('search') . '%' } }, + { 'organisation.postcode' => { 'like' => $v->param('search') . '%' } }, + ] + ) : () ), }, { join => [ 'sales', 'organisation' ], diff --git a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm index 6b5b503..fc38ba2 100644 --- a/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm +++ b/lib/Pear/LocalLoop/Schema/Result/ViewQuantisedTransactionSQLite.pm @@ -23,4 +23,18 @@ SELECT "value", FROM "transactions" /); +__PACKAGE__->belongs_to( + "buyer", + "Pear::LocalLoop::Schema::Result::Entity", + { id => "buyer_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + +__PACKAGE__->belongs_to( + "seller", + "Pear::LocalLoop::Schema::Result::Entity", + { id => "seller_id" }, + { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, +); + 1;