Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
8590 มุมมอง

Hi, I try to get a self.id by a simple "for rec in self:"

but I get a full object any idea why?


class Partner(models.Model):

    _inherit = 'res.partner'


    rappel = fields.Float(string='Rappel')


    @api.onchange('rappel')

    def compute_rappel_invoice_line(self):

        _logger.info('self : %s' % self)     # res.partner(<odoo.models.NewId object at 0x7f35a7b0ea98>,)

        _logger.info('self.ids : %s' % self.ids) # []

        _logger.info('self.id : %s' % self.id)  # <odoo.models.NewId object at 0x7f35a7b0ea98>

        for rec in self:

            _logger.info('rec : %s' % rec)      # res.partner(<odoo.models.NewId object at 0x7f35a7b0ea98>,)

            _logger.info('rec.id : %s' % rec.id)   # <odoo.models.NewId object at 0x7f35a7b0ea98>



            invoices = self.env["account.invoice"].search([("partner_id", "=", self.id),("state", "=", 'draft')])

            if invoices:

                for invoice in invoices:

                    lines = self.env["account.invoice.line"].search([("invoice_id", "=", invoice.id)])

                    for line in lines:

                        line.write({'rappel': self.rappel})

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

As it is onchange function try self._origin, it will return the id.


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

it works! How did you know this solution? It is not in Odoo docs.

Related Posts ตอบกลับ มุมมอง กิจกรรม
Difference in Record and Recordsets? แก้ไขแล้ว
5
ก.พ. 19
10054
1
ก.พ. 24
2482
1
ธ.ค. 22
6932
1
มิ.ย. 22
6178
How do I count all rooms in this model? แก้ไขแล้ว
1
ก.พ. 23
2038