26
# Add useful methode on bank statement handling
27
##############################################################################
28
AccountBankStatement.class_eval do
29
############################################################################
30
# Import invoices into the given bank statements
32
# - invoices : A valid dict of AccountInvoice instance
33
# - statement : A valid AccountBankStatement instance
35
# date (Default today) : date used into the first screen of the wizard (date
39
# - The AccountBankStatement as a instance of the class¨
41
# statement = AccountBankStatement.import_invoice(invoices,statement)
43
# TODO implement journals
44
# TODO filter acc_move_line_ids to take the right one
45
# TODO Remove self to use it from an instance of the class
46
def import_invoice(invoices, options={},*args)
47
o = {:date => false, :journals => []}.merge(options)
49
o[:date] = Date.parse(str=o[:date]).to_s
51
o[:date] = Date.today.to_s
54
# Parse the given journal ids if provided
56
o[:journals].each do |journal|
57
journal_ids.push journal.id
59
invoice_move_line_ids=[]
61
self.balance_start=inv_total
63
# # For each invoices, add the right account.move.line and compute total
64
invoices.each do |inv|
66
unless inv.class == AccountInvoice :
67
raise "!!! --- HELPER ERROR :import_invoice received a #{inv.class.to_s} instead of AccountInvoice"
69
# Take the move ids from concerned invoice
70
# TODO add journal support and (journal_ids.include? move_line.journal_id or journal_ids == []
71
# TODO : Debug the problem of undefined method `[]' for nil:NilClass (NoMethodError)
72
# pp inv.move_id.line_id
73
# inv.move_id.line_id.each do |move_line|
75
# # if move_line.reconcile_id == false
76
# if move_line.account_id.reconcile == true
77
# invoice_move_line_ids.push move_line.id
81
inv.move_id.line_id.each do |move_line|
82
if move_line.attributes['reconcile_id'] == false and move_line.account_id.reconcile == true
83
invoice_move_line_ids.push move_line.id
84
inv_total = inv_total + move_line.amount_currency
28
if Object.const_defined?'AccountBankStatement':
30
# Add useful methode on bank statement handling
31
##############################################################################
32
AccountBankStatement.class_eval do
33
############################################################################
34
# Import invoices into the given bank statements
36
# - invoices : A valid dict of AccountInvoice instance
37
# - statement : A valid AccountBankStatement instance
39
# date (Default today) : date used into the first screen of the wizard (date
43
# - The AccountBankStatement as a instance of the class¨
45
# statement = AccountBankStatement.import_invoice(invoices,statement)
47
# TODO implement journals
48
# TODO filter acc_move_line_ids to take the right one
49
# TODO Remove self to use it from an instance of the class
50
def import_invoice(invoices, options={},*args)
51
o = {:date => false, :journals => []}.merge(options)
53
o[:date] = Date.parse(str=o[:date]).to_s
55
o[:date] = Date.today.to_s
58
# Parse the given journal ids if provided
60
o[:journals].each do |journal|
61
journal_ids.push journal.id
63
invoice_move_line_ids=[]
65
self.balance_start=inv_total
67
# # For each invoices, add the right account.move.line and compute total
68
invoices.each do |inv|
69
unless inv.class == AccountInvoice :
70
raise "!!! --- HELPER ERROR :import_invoice received a #{inv.class.to_s} instead of AccountInvoice"
72
# Take the move ids from concerned invoice
73
# TODO add journal support and (journal_ids.include? move_line.journal_id or journal_ids == []
74
# TODO : Debug the problem of undefined method `[]' for nil:NilClass (NoMethodError)
75
# pp inv.move_id.line_id
76
# inv.move_id.line_id.each do |move_line|
78
# # if move_line.reconcile_id == false
79
# if move_line.account_id.reconcile == true
80
# invoice_move_line_ids.push move_line.id
84
inv.move_id.line_id.each do |move_line|
85
if (not move_line.attributes['reconcile_id']) && move_line.account_id.reconcile
86
invoice_move_line_ids.push move_line.id
87
inv_total = inv_total + move_line.amount_currency
91
# Save the start and end values
92
self.balance_end_real=inv_total
95
unless self.class == AccountBankStatement :
96
raise "!!! --- HELPER ERROR :import_invoice received a #{self.class.to_s} instead of AccountBankStatement"
100
wizard = self.old_wizard_step('populate_statement_from_inv')
101
# Set the wizard with given values
102
step_dict = wizard.datas.merge({:date=>o[:date]})
103
step_dict=step_dict.merge({:journal_id=> [[[],[],journal_ids]]})
104
# Search the invoices and update values
105
res=wizard.go(step_dict)
106
step_dict=res.datas.merge(step_dict)
107
# Update the step_dict with invoice we want
108
step_dict=step_dict.merge({:lines=> [[[],[],invoice_move_line_ids]]})
109
# Ask to populate the statement with given invoice linked account move
110
res=wizard.finish(step_dict)
111
# step_dict = step_dict.merge({:writeoff_acc_id => @journal.default_debit_account_id.id, :writeoff_journal_id=>@journal.id})
114
############################################################################
115
# Create an statement with given informations
118
# journal : A valid AccountJournal instance
119
# currency_code (Default : EUR) : An ISO code for currency
120
# name (Default : computed by OpenERP sequence) : A valid name if you wanna set it
123
# - The created AccountBankStatement as a instance of the class¨
125
# statement = AccountBankStatement.create_statement_with_currency({currency_code =>'CHF'})
126
def self.create_statement_with_currency(options={}, *args)
127
o = {:currency_code=>'EUR', :journal=>false, :name=>false}.merge(options)
130
currency_id = ResCurrency.find(:first, :domain=>[['code','=',o[:currency_code]]]).id
132
# Look for the asked cash journal currency
133
journal = AccountJournal.find(:first, :domain=>[['type','=','cash'],['currency','=',currency_id]])
135
raise "!!! --- HELPER ERROR : create_statement_with_currency #{o[:currency_code]} currency not found"
138
journal = o[:journal]
140
toreturn = AccountBankStatement.new()
141
toreturn.journal_id = journal.id
144
toreturn.name=o[:name]
88
# Save the start and end values
89
self.balance_end_real=inv_total
92
unless self.class == AccountBankStatement :
93
raise "!!! --- HELPER ERROR :import_invoice received a #{self.class.to_s} instead of AccountBankStatement"
97
wizard = self.old_wizard_step('populate_statement_from_inv')
98
# Set the wizard with given values
99
step_dict = wizard.datas.merge({:date=>o[:date]})
100
step_dict=step_dict.merge({:journal_id=> [[[],[],journal_ids]]})
101
# Search the invoices and update values
102
res=wizard.go(step_dict)
103
step_dict=res.datas.merge(step_dict)
104
# Update the step_dict with invoice we want
105
step_dict=step_dict.merge({:lines=> [[[],[],invoice_move_line_ids]]})
106
# Ask to populate the statement with given invoice linked account move
107
res=wizard.finish(step_dict)
108
# step_dict = step_dict.merge({:writeoff_acc_id => @journal.default_debit_account_id.id, :writeoff_journal_id=>@journal.id})
111
############################################################################
112
# Create an statement with given informations
115
# journal : A valid AccountJournal instance
116
# currency_code (Default : EUR) : An ISO code for currency
117
# name (Default : computed by OpenERP sequence) : A valid name if you wanna set it
120
# - The created AccountBankStatement as a instance of the class¨
122
# statement = AccountBankStatement.create_statement_with_currency({currency_code =>'CHF'})
123
def self.create_statement_with_currency(options={}, *args)
124
o = {:currency_code=>'EUR', :journal=>false, :name=>false}.merge(options)
127
currency_id = ResCurrency.find(:first, :domain=>[['code','=',o[:currency_code]]]).id
129
# Look for the asked cash journal currency
130
journal = AccountJournal.find(:first, :domain=>[['type','=','cash'],['currency','=',currency_id]])
132
raise "!!! --- HELPER ERROR : create_statement_with_currency #{o[:currency_code]} currency not found"
135
journal = o[:journal]
137
toreturn = AccountBankStatement.new()
138
toreturn.journal_id = journal.id
141
toreturn.name=o[:name]
b'\\ No newline at end of file'
152
puts "WARNING : Account Helpers can't be initialized -> account module isn't installed !!!"
154
rescue Exception => e