Python 将布尔字段从父类更改为子类-Odoo v8

Python 将布尔字段从父类更改为子类-Odoo v8,python,openerp,odoo-8,Python,Openerp,Odoo 8,考虑这一点: @api.multi @api.onchange('order_lines', 'order_lines.is_book_block', '') @api.constrains('order_lines', 'order_lines.isbn') def check_quantity(self): location = self.printer_book_block.property_stock_supplier.id for rec in self:

考虑这一点:

@api.multi
@api.onchange('order_lines', 'order_lines.is_book_block', '')
@api.constrains('order_lines', 'order_lines.isbn')
def check_quantity(self):
    location = self.printer_book_block.property_stock_supplier.id
    for rec in self:
        if rec.order_lines:
            for line in rec.order_lines:
                if line.qty > line.isbn.with_context({ 'location': location, }).qty_available >= 0:#line.isbn.qty_available in location:
                    rec.write({'state': 'awaitingraw'})
                else:
                    rec.write({'state': 'work_in_progress', 'is_book_block': True})
当指定位置上有足够的产品数量(isbn)时,将文档状态更改为
work\u in\u progress
,并将布尔字段
is\u book\u block
更改为
True

状态
字段位于父模型上:

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')
order_lines = fields.One2many('bsi.print.order.lines', 'print_order', string="Order lines")
book_block = fields.Boolean(string="Book Block", default=True)
binding = fields.Boolean(string="Binding")
edging = fields.Boolean(string="Edging")
state = fields.Selection([
        ('draft','Draft'),
        ('awaitingraw','Awaiting raw materials'),
        ('work_in_progress','Print in Progress'),
        ('delivered','Delivered'),
        ('cancel','Cancel'),
    ], string="State")
is\u book\u block
字段位于子类
One2many order\u line字段上:

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

    print_order = fields.Many2one('bsi.print.order', string="Print Order")
    isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
    qty = fields.Integer(string="Quantity")
    consumed_qty = fields.Integer(string="Quantity consumed")
    remaining_qty = fields.Float(string="Remaining quantity")
is_book_block = fields.Boolean(string="Is Book Block Done")
is_binding = fields.Boolean(string="Is Binding Done")
is_edging = fields.Boolean(string="Is Edging Done")
isbns = fields.Many2one('worksheets.isbns', string="Worksheet ISBNS")
还有另外两个字段
为绑定
为边缘

无论如何,知道其中一个就足以理解另外两个(我猜,lol),因此,由于
state
在父类上,它工作得很好,记录的状态实际上发生了变化,然而,
is\u book\u block
没有语法错误,它应该变为
True
,但是它没有,所以,我认为这是因为该方法在
order\u行上循环,但它只在父类(bsi.production.order)上更改内容


有什么想法吗?

据我所知,当你循环行时,
是一本书,块
在行中,每行都是一条记录,如果你想设置多个字段或只是更改该字段,你可以自己调用write:

  # when you change just one field no need for write just 
  rec.state = 'work_in_progress' # is enough
  # because rec.state will trigger write method
  # but for more than one field use write to trigger it only one time
  # line is a record too you can call write also if you want
  line.is_book_block = True
从onchange decorator中删除
订单行的一件事是\u book\u block
,因为您将触发对该方法的不定式调用:

  @api.onchange('order_lines')