콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
14642 화면

Hi. 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):
default.update({
'employee_line' : self.employee_line,
'referencia': '',
})
return super(EmpleadosProductos, self).copy(default)
아바타
취소
베스트 답변

Hello Carlos,

add below attribute in One2many line and upgrade your module.

copy=True

Example with your source ==>
employee_line = fields.One2many(
                         'employee.line',
                         'order_id',
string='Employee Lines',
                         copy=True)

아바타
취소
베스트 답변

Hello Carlos, please try this, If you have any problem, let me know:

@api.multi
def copy(self, default=None):
default = default or {}
ids = self.one2many_ids.ids
    default['one2many_ids'] = [(6, False, ids)]
    return super(ClasName, self).copy(default)
아바타
취소
관련 게시물 답글 화면 활동
1
1월 21
3692
2
2월 25
6007
1
12월 24
1528
1
11월 22
16090
3
8월 22
13174