Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
9018 Lượt xem

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})

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

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


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 10 25
10654
1
thg 2 24
3084
1
thg 12 22
7391
1
thg 6 22
6844
1
thg 2 23
2420