From d661ab59965e6da5a467c2c48c44c2d6775538fe Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Sun, 14 Jul 2019 19:41:02 +0100 Subject: [PATCH] Another possible fix for transactions under postgres --- lib/Pear/LocalLoop/Controller/Api/External.pm | 51 +++++++------------ 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index 4b13e4f..28272bd 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -80,38 +80,25 @@ sub post_lcc_suppliers { return $c->api_validation_error if $v->has_error; - my $lcc_import_ext_ref = $c->schema->resultset('ExternalReference')->find_or_create({ name => 'LCC CSV' }); - - return 0 unless $lcc_import_ext_ref; - - my $columns = [qw/ - sales.id - seller.id - organisation.id - organisation.name - organisation.street_name - organisation.town - organisation.postcode - organisation.country - /]; - - my $lcc_suppliers = $user->entity->purchases->search_related('seller',undef)->search( - undef, - { - prefetch => ['sales', 'organisation'], - columns => $columns, - group_by => $columns, - '+select' => [ - { - 'sum' => 'sales.value', - '-as' => 'total_spend', - }, - ], - '+as' => ['total_spend'], - page => $v->param('page') || 1, - rows => 10, - order_by => $order_by, - }); + my $lcc_suppliers = $c->schema->resultset('Entity')->search( + { + 'sales.buyer_id' => $user->entity->id, + }, + { + join => ['sales', 'organisation'], + group_by => ['me.id', 'organisation.id'], + '+select' => [ + { + 'sum' => 'sales.value', + '-as' => 'total_spend', + } + ], + '+as' => ['total_spend'], + page => $v->param('page') || 1, + rows => 10, + order_by => $order_by, + } + ); my @supplier_list = ( map {{