7 use SL::DB::MetaSetup::Part;
8 use SL::DB::Manager::Part;
10 __PACKAGE__->meta->add_relationships(
13 class => 'SL::DB::Unit',
14 column_map => { unit => 'name' },
17 type => 'one to many',
18 class => 'SL::DB::Assembly',
19 column_map => { id => 'id' },
23 __PACKAGE__->meta->initialize;
27 my $type = lc(shift || '');
29 if ($type =~ m/^part/) {
30 return !$self->assembly && $self->inventory_accno_id ? 1 : 0;
32 } elsif ($type =~ m/^service/) {
33 return !$self->inventory_accno_id && !$self->assembly ? 1 : 0;
35 } elsif ($type =~ m/^assembl/) {
36 return $self->assembly ? 1 : 0;
40 confess "Unknown type parameter '$type'";
43 sub get_sellprice_info {
47 confess "Missing part id" unless $self->id;
49 my $object = $self->load;
51 return { sellprice => $object->sellprice,
52 price_factor_id => $object->price_factor_id };
57 my %result = SL::DB::Manager::Part->get_ordered_qty($self->id);
59 return $result{ $self->id };
63 shift->unit_obj->convertible_units;
74 SL::DB::Part: Model for the 'parts' table
78 This is a standard Rose::DB::Object based model and can be used as one.
86 Tests if the current object is a part, a service or an
87 assembly. C<$type> must be one of the words 'part', 'service' or
88 'assembly' (their plurals are ok, too).
90 Returns 1 if the requested type matches, 0 if it doesn't and
91 C<confess>es if an unknown C<$type> parameter is encountered.
93 =item get_sellprice_info %params
95 Retrieves the C<sellprice> and C<price_factor_id> for a part under
96 different conditions and returns a hash reference with those two keys.
98 If C<%params> contains a key C<project_id> then a project price list
99 will be consulted if one exists for that project. In this case the
100 parameter C<country_id> is evaluated as well: if a price list entry
101 has been created for this country then it will be used. Otherwise an
102 entry without a country set will be used.
104 If none of the above conditions is met then the information from
107 =item get_ordered_qty %params
109 Retrieves the quantity that has been ordered from a vendor but that
110 has not been delivered yet. Only open purchase orders are considered.
112 =item get_uncommissioned_qty %params
114 Retrieves the quantity that has been ordered by a customer but that
115 has not been commissioned yet. Only open sales orders are considered.
121 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>