85
class account_voucher(osv.osv):
86
_inherit = "account.voucher"
88
#Copy from account_voucher
89
def action_move_line_create(self, cr, uid, ids, context=None):
90
#res = super(account_voucher, self).action_move_line_create(cr, uid, ids, context=context)
92
def _get_payment_term_lines(term_id, amount):
93
term_pool = self.pool.get('account.payment.term')
94
if term_id and amount:
95
terms = term_pool.compute(cr, uid, term_id, amount)
100
move_pool = self.pool.get('account.move')
101
move_line_pool = self.pool.get('account.move.line')
102
currency_pool = self.pool.get('res.currency')
103
tax_obj = self.pool.get('account.tax')
104
seq_obj = self.pool.get('ir.sequence')
105
for inv in self.browse(cr, uid, ids, context=context):
108
context_multi_currency = context.copy()
109
context_multi_currency.update({'date': inv.date})
113
elif inv.journal_id.sequence_id:
114
name = seq_obj.get_id(cr, uid, inv.journal_id.sequence_id.id)
116
raise osv.except_osv(_('Error !'), _('Please define a sequence on the journal !'))
117
if not inv.reference:
118
ref = name.replace('/','')
124
'journal_id': inv.journal_id.id,
125
'narration': inv.narration,
128
'period_id': inv.period_id and inv.period_id.id or False
130
move_id = move_pool.create(cr, uid, move)
132
#create the first line manually
133
company_currency = inv.journal_id.company_id.currency_id.id
134
current_currency = inv.currency_id.id
137
# TODO: is there any other alternative then the voucher type ??
138
# -for sale, purchase we have but for the payment and receipt we do not have as based on the bank/cash journal we can not know its payment or receipt
139
if inv.type in ('purchase', 'payment'):
140
credit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount, context=context_multi_currency)
141
elif inv.type in ('sale', 'receipt'):
142
debit = currency_pool.compute(cr, uid, current_currency, company_currency, inv.amount, context=context_multi_currency)
149
sign = debit - credit < 0 and -1 or 1
151
# KGB change start: take new partner_id from journal
152
new_partner_id = inv.partner_id.id #no change
153
if debit > 0 and inv.journal_id.default_debit_partner_id:
154
new_partner_id = inv.journal_id.default_debit_partner_id.id
155
if credit > 0 and inv.journal_id.default_credit_partner_id:
156
new_partner_id = inv.journal_id.default_credit_partner_id.id
157
# KGB change end: take new partner_id from journal
159
#create the first line of the voucher
161
'name': inv.name or '/',
164
'account_id': inv.account_id.id,
166
'journal_id': inv.journal_id.id,
167
'period_id': inv.period_id.id,
168
'partner_id': new_partner_id, #KGB changed inv.partner_id.id,
169
'currency_id': company_currency <> current_currency and current_currency or False,
170
'amount_currency': company_currency <> current_currency and sign * inv.amount or 0.0,
172
'date_maturity': inv.date_due
174
move_line_pool.create(cr, uid, move_line)
176
line_total = debit - credit
177
if inv.type == 'sale':
178
line_total = line_total - currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.tax_amount, context=context_multi_currency)
179
elif inv.type == 'purchase':
180
line_total = line_total + currency_pool.compute(cr, uid, inv.currency_id.id, company_currency, inv.tax_amount, context=context_multi_currency)
182
for line in inv.line_ids:
183
#create one move line per voucher line where amount is not 0.0
186
#we check if the voucher line is fully paid or not and create a move line to balance the payment and initial invoice if needed
187
if line.amount == line.amount_unreconciled:
188
amount = line.move_line_id.amount_residual or 0.00 #residual amount in company currency
190
amount = currency_pool.compute(cr, uid, current_currency, company_currency, line.untax_amount or line.amount, context=context_multi_currency)
192
'journal_id': inv.journal_id.id,
193
'period_id': inv.period_id.id,
194
'name': line.name or '/',
195
'account_id': line.account_id.id,
197
'partner_id': inv.partner_id.id,
198
'currency_id': company_currency <> current_currency and current_currency or False,
199
'analytic_account_id': line.account_analytic_id and line.account_analytic_id.id or False,
207
if line.type == 'dr':
211
if (line.type=='dr'):
213
move_line['debit'] = amount
216
move_line['credit'] = amount
218
if inv.tax_id and inv.type in ('sale', 'purchase'):
220
'account_tax_id': inv.tax_id.id,
222
if move_line.get('account_tax_id', False):
223
tax_data = tax_obj.browse(cr, uid, [move_line['account_tax_id']], context=context)[0]
224
if not (tax_data.base_code_id and tax_data.tax_code_id):
225
raise osv.except_osv(_('No Account Base Code and Account Tax Code!'),_("You have to configure account base code and account tax code on the '%s' tax!") % (tax_data.name))
226
sign = (move_line['debit'] - move_line['credit']) < 0 and -1 or 1
227
move_line['amount_currency'] = company_currency <> current_currency and sign * line.amount or 0.0
228
voucher_line = move_line_pool.create(cr, uid, move_line)
229
if line.move_line_id.id:
230
rec_ids = [voucher_line, line.move_line_id.id]
231
rec_list_ids.append(rec_ids)
233
if not currency_pool.is_zero(cr, uid, inv.currency_id, line_total):
237
if inv.payment_option == 'with_writeoff':
238
account_id = inv.writeoff_acc_id.id
239
write_off_name = inv.comment
240
elif inv.type in ('sale', 'receipt'):
241
account_id = inv.partner_id.property_account_receivable.id
243
account_id = inv.partner_id.property_account_payable.id
245
'name': write_off_name or name,
246
'account_id': account_id,
248
'partner_id': inv.partner_id.id,
250
'credit': diff > 0 and diff or 0.0,
251
'debit': diff < 0 and -diff or 0.0,
252
#'amount_currency': company_currency <> current_currency and currency_pool.compute(cr, uid, company_currency, current_currency, diff * -1, context=context_multi_currency) or 0.0,
253
#'currency_id': company_currency <> current_currency and current_currency or False,
255
move_line_pool.create(cr, uid, move_line)
256
self.write(cr, uid, [inv.id], {
261
move_pool.post(cr, uid, [move_id], context={})
262
for rec_ids in rec_list_ids:
263
if len(rec_ids) >= 2:
264
move_line_pool.reconcile_partial(cr, uid, rec_ids)
270
84
class account_move(osv.osv):
271
85
_inherit = "account.move"