Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 854d733e

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 854d733e4adfa524aeaf748b1c1c1f1645fbb91f
  • Vorgänger 1c934069
  • Nachfolger 45823f3f

Records: Workflow-Methoden angepasst und vereinheitlicht

Unterschiede anzeigen:

SL/Controller/DeliveryOrder.pm
use SL::DB::Warehouse;
use SL::DB::Helper::RecordLink qw(set_record_link_conversions);
use SL::DB::Helper::TypeDataProxy;
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
use SL::DB::DeliveryOrder;
use SL::DB::DeliveryOrder::TypeData qw(:types);
use SL::DB::Order::TypeData qw(:types);
......
);
}
sub action_add_from_order {
sub action_add_from_record {
my ($self) = @_;
# this interfers with init_order
$self->{converted_from_oe_id} = delete $::form->{id};
$self->type_data->validate;
my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load;
my $target_type = $::form->{type};
my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type);
$self->order($delivery_order);
my $from_type = $::form->{from_type};
my $from_id = $::form->{from_id};
$self->action_add;
}
sub action_add_from_reclamation {
my ($self) = @_;
unless ($from_type && $from_id) {
$self->js->flash('error', t8("Can't create new record."));
$self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
$self->js->flash('error', t8("No 'from_id' was given.")) unless ($from_id);
return $self->js->render();
}
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
my $target_type = $reclamation->is_sales ? 'rma_delivery_order'
: 'supplier_delivery_order';
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
$self->{converted_from_reclamation_id} = $::form->{from_id};
my $record = SL::Model::Record->get_record($from_type, $from_id);
my $delivery_order = SL::Model::Record->new_from_workflow($record, $self->type);
$self->order($delivery_order);
$self->action_add;
......
$self->redirect_to(@redirect_params);
}
sub action_save_and_new_record {
my ($self) = @_;
my $to_type = $::form->{to_type};
my $to_controller = get_object_name_from_type($to_type);
$self->save();
flash_later('info', $self->type_data->text('saved'));
$self->redirect_to(
controller => $to_controller,
action => 'add_from_record',
type => $to_type,
from_id => $self->order->id,
from_type => $self->order->type,
);
}
# save the order and redirect to the frontend subroutine for a new
# delivery order
sub action_save_and_delivery_order {
SL/Controller/Order.pm
use SL::DB::ValidityToken;
use SL::DB::Helper::RecordLink qw(set_record_link_conversions RECORD_ID RECORD_ITEM_ID);
use SL::DB::Helper::TypeDataProxy;
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
use SL::Model::Record;
use SL::DB::Order::TypeData qw(:types);
use SL::DB::Reclamation::TypeData qw(:types);
......
);
}
sub action_add_from_reclamation {
sub action_add_from_record {
my ($self) = @_;
my $from_type = $::form->{from_type};
my $from_id = $::form->{from_id};
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
my %params;
my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE()
: PURCHASE_ORDER_TYPE();
my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
$self->{converted_from_reclamation_id} = $order->{ RECORD_ID() };
$_ ->{converted_from_reclamation_items_id} = $_ ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
unless ($from_type && $from_id) {
$self->js->flash('error', t8("Can't create new record."));
$self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
$self->js->flash('error', t8("No 'from_id' was given.")) unless ($from_id);
return $self->js->render();
}
my $record = SL::Model::Record->get_record($from_type, $from_id);
my $order = SL::Model::Record->new_from_workflow($record, $self->type);
$self->order($order);
if (ref($record) eq 'SL::DB::Reclamation') {
$self->{converted_from_reclamation_id} = $order->{ RECORD_ID() };
$_ ->{converted_from_reclamation_items_id} = $_ ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted };
}
$self->recalc();
$self->pre_render();
......
$self->render(
'order/form',
title => $self->type_data->text('edit'),
title => $self->type_data->text('add'),
%{$self->{template_args}}
);
}
......
$_[0]->render(\ !!$has_active_periodic_invoices, { type => 'text' });
}
sub action_save_and_new_record {
my ($self) = @_;
my $to_type = $::form->{to_type};
my $to_controller = get_object_name_from_type($to_type);
$self->save();
flash_later('info', $self->type_data->text('saved'));
$self->redirect_to(
controller => $to_controller,
action => 'add_from_record',
type => $to_type,
from_id => $self->order->id,
from_type => $self->order->type,
);
}
# save the order and redirect to the frontend subroutine for a new
# delivery order
sub action_save_and_delivery_order {
......
);
}
sub action_save_and_supplier_delivery_order {
my ($self) = @_;
$self->save_and_redirect_to(
controller => 'controller.pl',
action => 'DeliveryOrder/add_from_order',
type => 'supplier_delivery_order',
);
}
# save the order and redirect to the frontend subroutine for a new reclamation
sub action_save_and_reclamation {
my ($self) = @_;
# can't use save_and_redirect_to, because id is set!
$self->save();
my $to_type = $self->order->is_sales ? SALES_RECLAMATION_TYPE()
: PURCHASE_RECLAMATION_TYPE();
$self->redirect_to(
controller => 'Reclamation',
action => 'add_from_order',
type => $to_type,
from_id => $self->order->id,
);
}
# save the order and redirect to the frontend subroutine for a new
# invoice
sub action_save_and_invoice {
SL/Controller/Reclamation.pm
use SL::DB::ValidityToken;
use SL::DB::Helper::RecordLink qw(RECORD_ID RECORD_TYPE_REF RECORD_ITEM_ID RECORD_ITEM_TYPE_REF);
use SL::DB::Helper::TypeDataProxy;
use SL::DB::Helper::Record qw(get_object_name_from_type get_class_from_type);
use SL::Helper::CreatePDF qw(:all);
use SL::Helper::PrintOptions;
......
only => [qw(
save save_as_new print preview_pdf send_email
save_and_show_email_dialog
workflow_save_and_sales_or_purchase_reclamation
save_and_order
save_and_delivery_order
save_and_new_record
save_and_credit_note
)]);
......
only => [qw(
save save_as_new print preview_pdf send_email
save_and_show_email_dialog
workflow_save_and_sales_or_purchase_reclamation
save_and_order
save_and_delivery_order
save_and_new_record
save_and_credit_note
)]);
......
only => [qw(
save save_as_new print preview_pdf send_email
save_and_show_email_dialog
workflow_save_and_sales_or_purchase_reclamation
save_and_order
save_and_delivery_order
save_and_new_record
save_and_credit_note
)]);
......
);
}
sub action_add_from_order {
sub action_add_from_record {
my ($self) = @_;
my $from_type = $::form->{from_type};
my $from_id = $::form->{from_id};
unless ($::form->{from_id}) {
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
unless ($from_type && $from_id) {
$self->js->flash('error', t8("Can't create new record."));
$self->js->flash('error', t8("No 'from_type' was given.")) unless ($from_type);
$self->js->flash('error', t8("No 'from_id' was given.")) unless ($from_id);
return $self->js->render();
}
my $order = SL::DB::Order->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type);
$self->reclamation($reclamation);
$self->reinit_after_new_reclamation();
if (!$::form->{form_validity_token}) {
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
}
$self->render(
'reclamation/form',
title => $self->type_data->text('add'),
%{$self->{template_args}},
);
}
sub action_add_from_delivery_order {
my ($self) = @_;
unless ($::form->{from_id}) {
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
return $self->js->render();
}
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type);
my $record = SL::Model::Record->get_record($from_type, $from_id);
my $reclamation = SL::Model::Record->new_from_workflow($record, $self->type);
$self->reclamation($reclamation);
$self->reinit_after_new_reclamation();
if (!$::form->{form_validity_token}) {
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
}
$self->render(
'reclamation/form',
title => $self->type_data->text('add'),
%{$self->{template_args}},
);
}
sub action_add_from_sales_invoice {
my ($self) = @_;
unless ($::form->{from_id}) {
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
return $self->js->render();
}
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load;
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type);
$self->reclamation($reclamation);
$self->reinit_after_new_reclamation();
if (!$::form->{form_validity_token}) {
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
}
$self->render(
'reclamation/form',
title => $self->type_data->text('add'),
%{$self->{template_args}},
);
}
sub action_add_from_purchase_invoice {
my ($self) = @_;
unless ($::form->{from_id}) {
$self->js->flash('error', t8("Can't create new reclamation. No 'from_id' was given."));
return $self->js->render();
if ($record->type eq SALES_RECLAMATION_TYPE()) { # check for direct delivery
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
if ($::form->{use_shipto}) {
my $custom_shipto = $record->shipto->clone('SL::DB::Reclamation');
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
} else {
# remove any custom shipto if not wanted
$self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
}
}
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 $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
$self->reclamation($reclamation);
$self->reinit_after_new_reclamation();
if (!$::form->{form_validity_token}) {
......
$self->redirect_to(@redirect_params);
}
sub action_save_and_order {
my ($self) = @_;
my $to_type = $self->reclamation->is_sales ? SALES_ORDER_TYPE()
: PURCHASE_ORDER_TYPE();
$self->save();
flash_later('info', t8('The reclamation has been saved'));
$self->redirect_to(
controller => 'Order',
action => 'add_from_reclamation',
type => $to_type,
from_id => $self->reclamation->id,
);
}
# workflow from purchase to sales reclamation
sub action_save_and_sales_reclamation {
sub action_save_and_new_record {
my ($self) = @_;
my $to_type = $::form->{to_type};
my $to_controller = get_object_name_from_type($to_type);
$self->save();
flash_later('info', t8('The reclamation has been saved'));
$self->redirect_to(
controller => 'Reclamation',
action => 'add_from_reclamation',
from_id => $self->reclamation->id,
type => SALES_RECLAMATION_TYPE(),
);
}
# workflow from sales to purchase reclamation
sub action_save_and_purchase_reclamation {
my ($self) = @_;
$self->save();
flash_later('info', t8('The reclamation has been saved'));
$self->redirect_to(
controller => 'Reclamation',
action => 'add_from_reclamation',
from_id => $self->reclamation->id,
type => PURCHASE_RECLAMATION_TYPE(),
);
}
# save the reclamation and redirect to the frontend subroutine for a new
# delivery order
sub action_save_and_delivery_order {
my ($self) = @_;
my $to_type = $self->reclamation->is_sales ? 'rma_delivery_order'
: 'supplier_delivery_order';
$self->save();
flash_later('info', t8('The reclamation has been saved'));
$self->redirect_to(
controller => 'controller.pl',
action => 'DeliveryOrder/add_from_reclamation',
controller => $to_controller,
action => 'add_from_record',
type => $to_type,
from_id => $self->reclamation->id,
from_type => $self->reclamation->type,
);
}
......
delete $::form->{form_validity_token};
}
# sales → purchase or purchase → sales
sub action_add_from_reclamation {
my ($self) = @_;
my $destination_type = $::form->{destination_type};
my $source_reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load;
$self->reclamation(
SL::DB::Reclamation->new_from(
$source_reclamation,
destination_type => $::form->{type},
));
# check for direct delivery
# copy shipto in custom shipto (custom shipto will be copied by new_from() in case)
if (!$self->type_data->properties('is_customer')) {
if ($::form->{use_shipto}) {
my $custom_shipto = $source_reclamation->shipto->clone('SL::DB::Reclamation');
$self->reclamation->custom_shipto($custom_shipto) if $custom_shipto;
} else {
# remove any custom shipto if not wanted
$self->reclamation->custom_shipto(SL::DB::Shipto->new(module => 'RC', custom_variables => []));
}
}
$self->reinit_after_new_reclamation();
if (!$::form->{form_validity_token}) {
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_RECLAMATION_SAVE())->token;
}
$self->render(
'reclamation/form',
title => $self->type_data->text('add'),
%{$self->{template_args}}
);
}
sub reinit_after_new_reclamation {
my ($self) = @_;
bin/mozilla/do.pl
sub save_and_reclamation {
my $form = $main::form;
my $id = $form->{id};
my $type = $form->{type};
# save the delivery order
......
$type eq 'sales_delivery_order' ? 'sales_reclamation'
: 'purchase_reclamation';
$form->{callback} =
'controller.pl?action=Reclamation/add_from_delivery_order' .
'&type=' . $to_reclamation_type .
'&from_id=' . $form->escape($form->{id});
'controller.pl?action=Reclamation/add_from_record'
. '&type=' . $to_reclamation_type
. '&from_id=' . $form->escape($id)
. '&from_type=' . $form->escape($type)
;
$form->redirect;
}
bin/mozilla/io.pl
sub sales_reclamation {
my $id = $::form->{id};
my $type = $::form->{type};
require SL::Controller::Reclamation;
my $c = SL::Controller::Reclamation->new();
$c->redirect_to(
controller => 'Reclamation',
action => 'add_from_sales_invoice',
from_id => $id,
type => 'sales_reclamation',
action => 'add_from_record',
type => 'sales_reclamation',
from_id => $id,
from_type => $type,
);
}
sub purchase_reclamation {
my $id = $::form->{id};
my $type = $::form->{type};
require SL::Controller::Reclamation;
my $c = SL::Controller::Reclamation->new();
$c->redirect_to(
controller => 'Reclamation',
action => 'add_from_purchase_invoice',
from_id => $id,
type => 'purchase_reclamation',
action => 'add_from_record',
type => 'purchase_reclamation',
from_id => $id,
from_type => $type,
);
}

Auch abrufbar als: Unified diff