Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
1381 Widoki

Hi,

I need to have a form view that shows all Journals and balance for each one.

But here, the balance is calculated based on the journal's payments not journal items.

Each 'Inbound' payment is considered a Debit and each 'Outbound' payment is considered a Credit.

Balance is Debit minus Credit.

Here is my code:


from odoo import fields, models, api

from odoo.exceptions import UserError,ValidationError


class JournalLine(models.TransientModel):

 _name = 'journal.line'
move_id = fields.Many2one( comodel_name='journal', string='Journal' )
journal_name = fields.Char( string="Journal" )
sum_debit = fields.Float( string='Debit', default=0.00 )
sum_credit = fields.Float( string='Credit', default=0.00 )
balance = fields.Float( string='Balance', default=0.00 )
currency_id = fields.Many2one( 'res.currency', string='Currency' )


class Journal(models.TransientModel): 

_name = 'journal'
line_ids = fields.One2many( 'journal.line', 'move_id', string='Journal lines', default=lambda self: self._compute_journal_lines() )


def _compute_journal_lines(self): 

​comodel_obj = self.env['journal.line'] 

​journals = self.env['account.journal'].search([('active','=',True)]) 

​domain = [] 

​for journal in journals: 

​lines = {} 

​domain = [('journal_id', '=', journal.id),('state','=','posted')] ​payment_ids = self.env['account.payment'].search(domain) 

​sum_debit = 0.00 

​sum_credit = 0.00 

​balance = 0.00 

​if payment_ids: 

​for payment in payment_ids: 

​if payment.payment_type == 'inbound': 

​sum_debit += payment.debit 

​else: 

​sum_credit += payment.credit 

​line = { 

​'move_id': self.id, 

​'journal_name': journal.name, 

​'currency_id': journal.currency_id.id, 

​'sum_debit': sum_debit, 

​'sum_credit': sum_credit, 

​'balance': sum_debit - sum_credit 

​} 

​new_record = comodel_obj.create(line) 

​self.write({ 'line_ids': [(4, new_record.id)] })

But the code does not work and in the form view, It shows nothing.

As I debug the code, I see all line_ids are produced successfully but I think binding it to the Journal is the main problem.

Can someone help me out?


Awatar
Odrzuć
Najlepsza odpowiedź

in odoo 16 this is a standard report

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
kwi 24
1554
1
maj 23
3415
1
mar 23
3344
3
lip 23
2182
1
cze 23
1806