通过具体的状态'从一个对象到另一个对象的选择 - Odoo v8

时间:2017-11-04 03:56:50

标签: python openerp odoo-8

我有这些模特:

class bsi_production_order(models.Model):
    _name = 'bsi.production.order'

    @api.model
    def create(self, vals):
        if vals.get('name', 'New') == 'New':
            if vals.get('production_type') == 'budgeted':
                vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.budgeted') or '/'
            elif vals.get('production_type') == 'nonbudgeted':
                vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.non_budgeted') or '/'
            elif vals.get('production_type') == 'direct':
                vals['name'] = self.env['ir.sequence'].next_by_code('bsi.production.direct') or '/'
        return super(bsi_production_order, self).create(vals)

    name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
    date = fields.Date(string="Production Date")
    production_type = fields.Selection([
        ('budgeted','Budgeted'),
        ('nonbudgeted','Non Budgeted'),
        ('direct','Direct Order'),
    ], string='Type of Order', index=True,  
    track_visibility='onchange', copy=False,
    help=" ")
    notes = fields.Text(string="Notes")
    order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="Order lines", copy=True)
print_orders = fields.One2many('bsi.print.order', 'production_orders', string="Print Orders")
state = fields.Selection([
        ('draft','Draft'),
        ('start','Started'),
        ('inprogress','In progress'),
        ('print_order_inprogress','Print Order In Progress'),
        ('finished','Finished'),
        ('cancel','Cancel'),
    ], string='State', index=True,  
    track_visibility='onchange', copy=False,
    help=" ")

class bsi_print_order(models.Model):
    _name = 'bsi.print.order'

    @api.model
    def create(self, vals):
        if vals.get('name', 'New') == 'New':
            vals['name'] = self.env['ir.sequence'].next_by_code('bsi.print.order') or '/'
        return super(bsi_print_order, self).create(vals)

    name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
    date = fields.Date(string="Print Date")
    origin = fields.Char(string="Origin")
    production_orders = fields.Many2one('bsi.production.order', ondelete='cascade', string="Production Order")
    order_lines = fields.One2many('bsi.print.order.lines', 'print_order', string="Order lines")
    book_block = fields.Boolean(string="Book Block")
    binding = fields.Boolean(string="Binding")
    edging = fields.Boolean(string="Edging")
    contract_worksheet = fields.One2many('mrp.worksheet.contract', 'printer_order', string="Worksheet calculation")
    state = fields.Selection([
        ('draft','Draft'),
        ('awaitingraw','Awaiting raw materials'),
        ('wip','Work in Progress'),
        ('delivered','Delivered'),
        ('cancel','Cancel'),
    ], string="State")
    notes = fields.Text(string="Notes")

此方法属于bsi.production.order,必须从中创建bsi.print.order

@api.multi
def create_printy(self):
    copy_record = self.env['bsi.print.order'] 
    for record in self:

        order_lines = []
        for rec in record.order_lines:
            order_lines.append(
            (0,0,
            {
                'isbn': rec.isbn.id,
                'consumed_qty': rec.qty,
                }
            ))

        copy_record.create({
            'state' : 'draft', 
            'order_lines': order_lines, 
        })

有什么问题?问题是,在bsi.production.order此功能可见的状态(按钮)为inprogress,现在,此状态在bsi.print.order上不存在,但是,您可以在copy_record.create上看到,我已经过了“状态”状态'作为'草稿',但它不起作用,它引发了我:

ValidateError

Error while validating constraint

Wrong value for bsi.print.order.state: 'inprogress'

我的意思是,这很明显,但不是很多,因为bsi.print.order应该在draft州创建。

我做错了什么?

0 个答案:

没有答案