Programmer LiLi
Programmer LiLi

Reputation: 157

How to print records number in form view in odoo?

I have in my python file this function to count number of records in (Order Lines):

class Class_sale_order(models.Model):
    _inherit = 'sale.order'

    caseacocher_sale_order = fields.Boolean(string='Print customized')

    new_field2 = fields.Integer(compute='function_count_saleorderlines')

    @api.depends('order_line')

    def function_count_saleorderlines(self):
        for rec in self:
            rec.new_field2 = len('order_line')

But when i see the form view i find that the value of filed is 10, the problem that i have only 5 records.

Upvotes: 1

Views: 67

Answers (1)

arryph
arryph

Reputation: 2825

len('order_line') returns the size of the string 'order_line' which is 10 that's why you are getting the value 10. Set like following:

rec.new_field2 = len(rec.order_line)

Upvotes: 2

Related Questions