I want to copy all the information stored in the one2many relation when I double the entry to the view. All values except for the on2many relation are copied. I have even tried to overwrite the copy function to do it by hand but there is something I must be doing wrong or that I have not come to understand.
Here its the code of the class
class EmpleadosProductos(models.Model):
_name = "employee.as.product"
collection_lines = {}
employee_line = fields.One2many(
'employee.line',
'order_id',
string='Employee Lines'
)
state = fields.Selection([('creado', 'Creado'),
('confirmado', 'Confirmado'),
('cancelado', 'Cancelado'),
('validado', 'Validado'),
('pagado', 'Pagado')
], string='Status', index=True, readonly=True, track_visibility='onchange', copy=False, default='creado', required=True, help='Estado del parte de empleado')
companyias = fields.Many2one('res.partner', 'Obra', domain=[('is_company', '=', True)])
amount_total = fields.Monetary(string='Total', store=True, readonly=True, compute='_calcularTotal')
journal_entry = fields.Many2one('account.move')
currency_id = fields.Many2one('res.currency', 'Currency', required=True, default=lambda self: self.env.user.company_id.currency_id.id)
fecha = fields.Date('Fecha')
referencia = fields.Char(string='Ref', required=True)
# referencia = fields.Char(string='Ref', required=True)
journal_id = fields.Many2one('account.journal', 'Journal')
_sql_constraints = [
('refererecia_constraint', 'unique(referencia)', 'La referencia debe de ser Ășnica!'),
]
@api.multi
def action_confirmar(self):
self.write({'state': 'confirmado'})
@api.multi
def action_cancelar(self):
self.write({'state': 'cancelado'})
@api.multi
def action_validar(self):
self.write({'state': 'validado'})
@api.multi
def action_pagar(self):
self.write({'state': 'pagado'})
@api.multi
def copy(self, default):
_logger.info("DEBBUG:" + " default " + str(default))
_logger.info("DEBBUG:" + " self.employee_line " + str(self.employee_line.name_get()))
for line in self.employee_line:
_logger.info("DEBBUG:" + " self.employee_line " + str(line.name_get()))
default = dict(default or {})
default.update({
'employee_line' : self.employee_line,
'referencia': '',
})
# _logger.info("DEBBUG:" + str(vals))
return super(EmpleadosProductos, self).copy(default)