Here is my method:
def action_save(self):
for line in self.budget_investment_request_edit_division_line_ids:
if not line.is_save:
line.write({
'budget_investment_id': self.budget_investment_id.id,
'department_id': line.department_id.id,
'request_content': line.request_content,
'budget_investment_request_edit_division_id': self.id,
'is_save': True
})
When I created a record and enter button which is applied by above method, it ok. But when I started to create 2nd record, the 1st record duplicated. I had tried to debug for the first one and it was good, but when I started do the 2nd, it had already show 2 record that one of those was the duplicate one. Hope that someone can help me get through this.
p/s: I used an onchange method to show on the view, here it is:
@api.onchange('budget_investment_id')
def _onchange_budget_investment_id(self):
line_ids = self.env['hmv.budget.investment.division.request.edit.line'].search([('budget_investment_id', '=',
self.budget_investment_id.id)])
for line in line_ids:
self.budget_investment_request_edit_division_line_ids += self.budget_investment_request_edit_division_line_ids.new(
{
'budget_investment_id': line.budget_investment_id.id,
'department_id': line.department_id.id,
'request_content': line.request_content,
'is_save': True
})