2
votes

How can i display journal name, credit and debit about in point of sale orders tree view. i used to made relationship between pos.order and account.bank.statement models but still not showing field value in pos Tree view Or anyother way to perform this task? ..Here is code below to display account journal name

**pos_order.py** 

    journals_id = fields.One2many('account.bank.statement','journals', string='Journal', readonly=True)
journal_id = fields.Char(related='journals_id.type', store=True, readonly=True)


**account_bank_statement.py**

class AccountBankStatement(models.Model):
_inherit = 'account.bank.statement'

journals = fields.Many2one('pos.order', string="Journals", ondelete='cascade')
1
Adding new code but not showing values please guide me.. statement_ids = fields.One2many('account.bank.statement.line', 'pos_statement_id', string='Payments', states={'draft': [('readonly', False)]}, readonly=True)debit = fields.Char(compute='_get_journals', string='Debit', store=True, readonly=True) @api.depends('statement_ids') def _get_journals(self): journals = self.env['account.journal'] res = [] for rec in self.env['pos.order']: res = journals.search(['statement_ids']) if res == statement_ids: rec.debit = statement_ids.namemajid

1 Answers

0
votes

First you cannot create a related field from one2many fied because one2many field can contains a lot of recrod how would you return them in one field.

try this: make your related field a compute field instead create a string value from the concatination of the types.

journal_id = fields.Char(string="journals",compute='get_journals', store=True)


@api.depends('journals_id')
def get_journals(self):
for rec in self:
    journal_id = ','.join(journal.type for journal in rec.journals_id)
    rec.journal_id = journal_id