This repository has been archived on 2021-11-24. You can view files and clone it, but cannot push or open issues or pull requests.
phone_app/app/models/p_commercial.rb
2021-08-23 10:26:02 +02:00

32 lines
621 B
Ruby

class PCommercial < ApplicationRecord
validates :code, :presence => true
#validates :firstname, :presence => true
belongs_to :p_commercial_cat
def long_name
self.code.to_s+" "+self.firstname.to_s + " " + self.name.to_s
end
def member_label
self.long_name
end
has_many :p_customers
has_many :p_customer_sheets
has_many :p_documents
has_many :p_commercial_objectives
def ca_ht
self.p_documents.where(:p_document_type_id => [4,7]).sum(:cache_total_ht)
end
def ca_ttc
self.p_documents.where(:p_document_type_id => [4,7]).sum(:cache_total_ttc)
end
end