forked from substancelab/rconomic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CurrentInvoiceProxy to Debtor allowing us to to debtor.current_in…
…voices.build and get a CurrentInvoice initialized with required values from debtor
- Loading branch information
Showing
12 changed files
with
126 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,43 @@ | ||
module Economic | ||
class CurrentInvoiceProxy | ||
attr_reader :session | ||
attr_reader :owner | ||
|
||
def initialize(session) | ||
@session = session | ||
def initialize(owner) | ||
@owner = owner | ||
end | ||
|
||
def session | ||
owner.session | ||
end | ||
|
||
# Returns a new, unpersisted Economic::CurrentInvoice | ||
def build(values = {}) | ||
invoice = Economic::CurrentInvoice.new(values) | ||
invoice.session = session | ||
def build(properties = {}) | ||
invoice = Economic::CurrentInvoice.new(:session => session) | ||
|
||
initialize_properties_with_values_from_owner(invoice) if owner.is_a?(Debtor) | ||
invoice.update_properties(properties) | ||
invoice.partial = false | ||
|
||
invoice | ||
end | ||
|
||
private | ||
|
||
# Initialize properties in invoice with values from owner | ||
def initialize_properties_with_values_from_owner(invoice) | ||
invoice.debtor_handle = owner.handle | ||
|
||
invoice.debtor_name ||= owner.name | ||
invoice.debtor_address ||= owner.address | ||
invoice.debtor_postal_code ||= owner.postal_code | ||
invoice.debtor_city ||= owner.city | ||
|
||
invoice.term_of_payment_handle ||= owner.term_of_payment_handle | ||
invoice.layout_handle ||= owner.layout_handle | ||
invoice.currency_handle ||= owner.currency_handle | ||
|
||
invoice | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters