Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ac05693f

Von Tamino Steinert vor etwa 2 Jahren hinzugefügt

  • ID ac05693fdbaf88eae7ff1c959d785066b4235031
  • Vorgänger 4f78e190
  • Nachfolger 5e8868e4

TypeData: nutzte Konstanten anstatt String für Typen

Unterschiede anzeigen:

SL/Controller/Reclamation.pm
use SL::DB::DeliveryOrder;
use SL::DB::Invoice;
use SL::Model::Record;
use SL::DB::Order::TypeData qw(:types);
use SL::DB::Reclamation::TypeData qw(:types);
use List::Util qw(first sum0);
use List::UtilsBy qw(sort_by uniq_by);
......
}
my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
my $target_type = $order->is_sales ? 'sales_reclamation'
: 'purchase_reclamation';
my $target_type = $order->is_sales ? SALES_RECLAMATION_TYPE()
: PURCHASE_RECLAMATION_TYPE();
my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type);
$self->reclamation($reclamation);
......
}
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
my $target_type = $delivery_order->is_sales ? 'sales_reclamation'
: 'purchase_reclamation';
my $target_type = $delivery_order->is_sales ? SALES_RECLAMATION_TYPE()
: PURCHASE_RECLAMATION_TYPE();
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type);
$self->reclamation($reclamation);
......
}
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
my $target_type = 'sales_reclamation';
my $target_type = SALES_RECLAMATION_TYPE();
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
$self->reclamation($reclamation);
......
require SL::DB::PurchaseInvoice;
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load;
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice
my $target_type = 'purchase_reclamation';
my $target_type = PURCHASE_RECLAMATION_TYPE();
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type);
$self->reclamation($reclamation);
......
sub action_save_and_order {
my ($self) = @_;
my $to_type = $self->reclamation->is_sales ? 'sales_order'
: 'purchase_order';
my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
: PURCHASE_ORDER_TYPE();
$self->save_with_render_error();
flash_later('info', t8('The reclamation has been saved'));
......
controller => 'Reclamation',
action => 'add_from_reclamation',
from_id => $self->reclamation->id,
type => sales_reclamation_type(),
type => SALES_RECLAMATION_TYPE(),
);
}
......
controller => 'Reclamation',
action => 'add_from_reclamation',
from_id => $self->reclamation->id,
type => purchase_reclamation_type(),
type => PURCHASE_RECLAMATION_TYPE(),
);
}
......
#
sub init_valid_types {
[ sales_reclamation_type(), purchase_reclamation_type() ];
$_[0]->type_data->valid_types;
}
sub init_type {
......
sub init_cv {
my ($self) = @_;
my $cv = (any { $self->type eq $_ } (sales_reclamation_type())) ? 'customer'
: (any { $self->type eq $_ } (purchase_reclamation_type())) ? 'vendor'
my $cv = (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())) ? 'customer'
: (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())) ? 'vendor'
: die "Not a valid type for reclamation";
return $cv;
......
language_id => t8('Language'),
department_id => t8('Department'),
globalproject_id => t8('Project Number'),
cv_record_number => ($self->type eq 'sales_reclamation' ? t8('Customer Record Number') : t8('Vendor Record Number')),
cv_record_number => ($self->type eq SALES_RECLAMATION_TYPE() ? t8('Customer Record Number') : t8('Vendor Record Number')),
transaction_description => t8('Description'),
notes => t8('Notes'),
intnotes => t8('Internal Notes'),
......
sub init_part_picker_classification_ids {
my ($self) = @_;
my $attribute = 'used_for_' . ($self->type eq sales_reclamation_type() ? 'sale' : 'purchase');
my $attribute = 'used_for_' . ($self->type eq SALES_RECLAMATION_TYPE() ? 'sale' : 'purchase');
return [ map { $_->id } @{ SL::DB::Manager::PartClassification->get_all(where => [ $attribute => 1 ]) } ];
}
......
# check for direct delivery
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
if ($::form->{type} eq purchase_reclamation_type()) {
if ($::form->{type} eq PURCHASE_RECLAMATION_TYPE()) {
if ($::form->{use_shipto}) {
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
......
sub => sub { $_[0]->closed ? t8('Yes') : t8('No') },
},
);
if ($self->type eq sales_reclamation_type()) {
if ($self->type eq SALES_RECLAMATION_TYPE()) {
$column_defs{customer_id} = ({
raw_data => sub { $_[0]->customervendor->presenter->customer(display => 'table-cell', callback => $callback) },
sub => sub { $_[0]->customervendor->name },
......
},
sub => sub { $_[0]->contact ? $_[0]->contact->cp_name : '' },
});
} elsif ($self->type eq purchase_reclamation_type()) {
} elsif ($self->type eq PURCHASE_RECLAMATION_TYPE()) {
$column_defs{vendor_id} = ({
raw_data => sub { $_[0]->customervendor->presenter->vendor(display => 'table-cell', callback => $callback) },
sub => sub { $_[0]->customervendor->name },
......
{ output => 0 },
models => $self->models
),
title => $self->type eq sales_reclamation_type() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
title => $self->type eq SALES_RECLAMATION_TYPE() ? t8('Sales Reclamations') : t8('Purchase Reclamations'),
allow_pdf_export => 1,
allow_csv_export => 1,
);
......
sub _setup_edit_action_bar {
my ($self, %params) = @_;
my $deletion_allowed = ($self->type eq sales_reclamation_type()
my $deletion_allowed = ($self->type eq SALES_RECLAMATION_TYPE()
&& $::instance_conf->get_sales_reclamation_show_delete)
|| ($self->type eq purchase_reclamation_type()
|| ($self->type eq PURCHASE_RECLAMATION_TYPE()
&& $::instance_conf->get_purchase_reclamation_show_delete);
for my $bar ($::request->layout->get('actionbar')) {
......
$::instance_conf->get_reclamation_warn_duplicate_parts,
$::instance_conf->get_reclamation_warn_no_reqdate,
],
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
],
action => [
t8('Save and Purchase Reclamation'),
call => [ 'kivi.Reclamation.purchase_reclamation_check_for_direct_delivery' ],
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
],
action => [
t8('Save and Order'),
......
$::instance_conf->get_reclamation_warn_duplicate_parts,
$::instance_conf->get_reclamation_warn_no_reqdate,
],
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
],
action => [
t8('Save and Supplier Delivery Order'),
......
$::instance_conf->get_reclamation_warn_duplicate_parts,
$::instance_conf->get_reclamation_warn_no_reqdate,
],
only_if => (any { $self->type eq $_ } (purchase_reclamation_type())),
only_if => (any { $self->type eq $_ } (PURCHASE_RECLAMATION_TYPE())),
],
action => [
t8('Save and Credit Note'),
......
$::instance_conf->get_reclamation_warn_duplicate_parts,
$::instance_conf->get_reclamation_warn_no_reqdate,
],
only_if => (any { $self->type eq $_ } (sales_reclamation_type())),
only_if => (any { $self->type eq $_ } (SALES_RECLAMATION_TYPE())),
],
], # end of combobox "Workflow"
......
# t8("Edit Purchase Reclamation");
$action = ucfirst(lc($action));
return $self->type eq sales_reclamation_type() ? t8("$action Sales Reclamation")
: $self->type eq purchase_reclamation_type() ? t8("$action Purchase Reclamation")
return $self->type eq SALES_RECLAMATION_TYPE() ? t8("$action Sales Reclamation")
: $self->type eq PURCHASE_RECLAMATION_TYPE() ? t8("$action Purchase Reclamation")
: '';
}
......
return $texts;
}
sub sales_reclamation_type {
'sales_reclamation';
}
sub purchase_reclamation_type {
'purchase_reclamation';
}
sub save_history {
my ($self, $addition) = @_;
......
}
sub init_type_data {
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $_[0]->type);
SL::DB::Helper::TypeDataProxy->new('SL::DB::Reclamation', $::form->{type});
}
1;

Auch abrufbar als: Unified diff