I have this method:
@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state')
def accounting_scenarios(self):
for record in self:
if not len(record.transporter):
raise Warning('Please Enter Transporter !')
elif not len(record.transporter.transp_transit):
raise Warning('Please assign transit account to the transporter !')
if record.state in ('awaitingraw'): #('cancel', 'done')
record.temp = record.contract_worksheet.total_alles - record.contract_worksheet.total_totals
acc_move = self.env['account.move']
move_lines = [
(0, 0, {
'name': 'name',
'debit': record.temp, # amount of debit
'credit': 0, # amount of credit
'account_id': record.transporter.transp_transit,
'date': date,
'partner_id': record.transporter, # partner if there is one
}),
(0, 0, {
'name': 'name',
'debit': 0,
'credit': record.contract_worksheet.total_alles,
'account_id': record.transporter.transp_transit,
'date': date,
'partner_id': record.transporter,
})
]
journal_id = False
if record.transporter.transp_transit:
journals = self.env['account.journal'].search([
('default_debit_account_id', '=', record.transporter.transp_transit.id)
])
if journals:
journal_id = journals[0].id
acc_move.create({
#'period_id': period_id,
'journal_id': journal_id,
'date': fields.Date.today(),
'state': 'draft',
'line_id': move_lines,
})
elif record.state in ('work_in_progress'):
record.temp2 = record.contract_worksheet.total_totals
elif record.state in ('delivered'):
record.transporter.transp_transit.debit = record.contract_worksheet.total_alles
The account
where it should look for a journal_id
is the field transp_transit
:
transp_transit = fields.Many2one('account.account', string='Transporter Transit Account')
So, this is a custom field on a res.partner
it is already defined and all that stuff.
The method doesn't throw any errors, but, for some reason, when I go to this account document, I cannot see any debit
or credit
amounts nor Journal entries on accounting.
So, what could be the reason for this? Is there something I didn't see or miss?
Any ideas?