7 use SL::DB::MetaSetup::Part;
8 use SL::DB::Manager::Part;
10 __PACKAGE__->attr_number('lastcost', places => -2);
11 __PACKAGE__->attr_number('listprice', places => -2);
12 __PACKAGE__->attr_number('sellprice', places => -2);
14 __PACKAGE__->meta->add_relationships(
17 class => 'SL::DB::Unit',
18 column_map => { unit => 'name' },
21 type => 'one to many',
22 class => 'SL::DB::Assembly',
23 column_map => { id => 'id' },
27 __PACKAGE__->meta->initialize;
31 my $type = lc(shift || '');
33 if ($type =~ m/^part/) {
34 return !$self->assembly && $self->inventory_accno_id ? 1 : 0;
36 } elsif ($type =~ m/^service/) {
37 return !$self->inventory_accno_id && !$self->assembly ? 1 : 0;
39 } elsif ($type =~ m/^assembl/) {
40 return $self->assembly ? 1 : 0;
44 confess "Unknown type parameter '$type'";
47 sub get_sellprice_info {
51 confess "Missing part id" unless $self->id;
53 my $object = $self->load;
55 return { sellprice => $object->sellprice,
56 price_factor_id => $object->price_factor_id };
61 my %result = SL::DB::Manager::Part->get_ordered_qty($self->id);
63 return $result{ $self->id };
67 shift->unit_obj->convertible_units;
78 SL::DB::Part: Model for the 'parts' table
82 This is a standard Rose::DB::Object based model and can be used as one.
90 Tests if the current object is a part, a service or an
91 assembly. C<$type> must be one of the words 'part', 'service' or
92 'assembly' (their plurals are ok, too).
94 Returns 1 if the requested type matches, 0 if it doesn't and
95 C<confess>es if an unknown C<$type> parameter is encountered.
97 =item get_sellprice_info %params
99 Retrieves the C<sellprice> and C<price_factor_id> for a part under
100 different conditions and returns a hash reference with those two keys.
102 If C<%params> contains a key C<project_id> then a project price list
103 will be consulted if one exists for that project. In this case the
104 parameter C<country_id> is evaluated as well: if a price list entry
105 has been created for this country then it will be used. Otherwise an
106 entry without a country set will be used.
108 If none of the above conditions is met then the information from
111 =item get_ordered_qty %params
113 Retrieves the quantity that has been ordered from a vendor but that
114 has not been delivered yet. Only open purchase orders are considered.
116 =item get_uncommissioned_qty %params
118 Retrieves the quantity that has been ordered by a customer but that
119 has not been commissioned yet. Only open sales orders are considered.
125 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>