当我将视图的条目加倍时,我想复制存储在one2many关系中的所有信息。除了on2many关系之外的所有值都被复制。我甚至试图用手写覆盖复制功能,但有些事情我一定做错了或者我还没有理解。
这是它的代码
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)
答案 0 :(得分:1)
尝试将copy=True
添加到employee_line
定义:
class EmpleadosProductos(models.Model):
_name = 'employee.as.product'
employee_line = fields.One2many(
'employee.line',
'order_id',
string='Employee Lines',
copy=True,
)
执行此操作后,您不需要扩展/覆盖copy()
方法。