在开始状态表单上写入名称序列 - Odoo v8

Write name sequence on start state form - Odoo v8

我有这个方法:

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, copy=False,
        help=" ")

这会根据 production_type 选择创建一条新记录。

现在,这个一保存就写文件名,状态我有这个方法:

    state = fields.Selection([
        ('draft','Draft'),
        ('confirm','Confirmed'),
        ('inprogress','In progress'),
        ('print_order_inprogress','Print In Progress'),
        ('finished','Finished'),
        ('cancel','Cancel'),
    ], string='State', index=True, copy=False,
    help=" ")
    @api.one
    def prod_start_func(self):
        self.write({'state': 'confirm',})

我保存文件的时候,保存的时候写的是文件名,所以默认是draft状态。

我需要的是实际使用prod_start_func方法将statedraft改为confirm

时要写的名字

有什么想法吗?

只需删除从 create 到函数的代码:

  @api.model
    def create(self, vals):
        if vals.get('name', 'New') == 'New':
            # if you don't want name to equal New.
            vals['name'] = '/'

在你的函数中:

    @api.one
    def prod_start_func(self):
        name = '/'
        if self.production_type == 'budgeted':
                name = self.env['ir.sequence'].next_by_code('bsi.production.budgeted') or '/'
        elif self.production_type == 'nonbudgeted':
                name = self.env['ir.sequence'].next_by_code('bsi.production.non_budgeted') or '/'
        elif self.production_type == 'direct':
                name = self.env['ir.sequence'].next_by_code('bsi.production.direct') or '/'

        self.write({
                'state': 'confirm',
                'name' : name,
                })