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

I have an Integer field in my account.move.line model and I want this field to display the number of the products. For e.g. for the first product, it will be 1, the second product will be 2, the tenth product will be 10 and so on (basically increment of 1) How can I achieve this using odoo studio?


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

So you basically want to create serial number for the line items right?

Edited:

This can be done by an onchange function on account move. assuming your field on account move line is 'serial_number ', 
class AccountMoveLine(models.Model):

 _inherit = 'account.move.line' 

serial_number = fields.Integer(string='Serial Number', compute='_compute_serial_number', store=True) 

@api.depends('move_id') 

def _compute_serial_number(self): 

for line in self: 

if line.move_id: 

lines = line.move_id.line_ids.sorted(key=lambda r: r.create_date)

line.serial_number = lines.ids.index(line.id) + 1

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

Hello,
Yes.