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

I´m having trouble trying to create a record from a wizard, I suspect that the problem is with one specifig model that is created with a sequence, because when I use a different model it works just fine. The model´s code is the next one:

# -*- coding: utf-8 -*-

from odoo import models, fields, api, exceptions


class SoapTransaction(models.Model):
    _name = 'soap.transaction'

    state = fields.Selection([('draft', 'Borrador'),
                              ('requested', 'Solicitado'),
                              ('answered', 'Respondido'),
                              ('registered', 'Registrado')],
                             string='Estado',
                             required=True,
                             default='draft')
    sequence_id = fields.Char(readonly=True, string='Transacción')
    transaction_type = fields.Selection([('request', 'Solicitud'),
                                         ('response', 'Respuesta')],
                                        string='Tipo de transacción',
                                        required=True,
                                        default='request')
    method_id = fields.Many2one('soap.method', string='Método')
    service_id = fields.Many2one(string='Servicio', related='method_id.service_id')
    request_line_ids = fields.One2many('soap.transaction.line', 'transaction_id', string='Líneas de transacción')

    @api.model
    def create(self, vals):
        seq = self.env['ir.sequence'].next_by_code('transaction.sequence') or '/'
        vals['sequence_id'] = seq
        return super(SoapTransaction, self).create(vals)

The wizard that is suposted to create the record is as simple as the next code:

# -*- coding: utf-8 -*-

from odoo import models, fields, api, exceptions


class SoapTransactionWizard(models.TransientModel):
    _name = 'soap.transaction.wizard'

    method_id = fields.Many2one('soap.method', string='Operación')

def create_request(self):
    transaction_record = self.env['soap.transaction']
    transaction_record.create = ({
            'state': 'draft',
            'transaction_type': 'request',
            'method_id': self.method_id,
        })
I thank you all for your time
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
for transaction_record insted of calling create method you are assingin it

transaction_record.create = ({  ==> transaction_record.create({


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

I think i´m tired for a mistake like that. Thank you so much!

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 24
1321
1
thg 7 24
2213
sequence prefix. Đã xử lý
3
thg 9 23
3650
1
thg 3 22
4967
1
thg 6 21
3313