python - 如果在向导中检查了 bool 值,则从行加载字段 - Odoo v8

标签 python odoo odoo-8

我有这个向导代码:

class generate_print_order(models.TransientModel):
    _name = 'generate.print.order'

    isbns = fields.One2many('order.lines', 'order_id', 'ISBN')
    production_order = fields.Many2one('bsi.production.order', 'Production Order')

@api.model
def default_get(self, fields):
    res = super(generate_print_order, self).default_get(fields)
    isbns = []
    if self.env.context.has_key('active_id'):
        production_order = self.env.context['active_id']
        order = self.env['bsi.production.order'].browse(production_order)
        for line in order.order_lines:
            if line.remaining_qty > 0:
                val = {
                    'name': 'name',
                    'isbn':line.isbn.id,
                    'qty': line.remaining_qty}
                isbns.append([0,0,val])
        res.update({'isbns':isbns,'production_order':production_order})
    return res

@api.multi    
def generate(self):
    if self.isbns:
        order_lines = []
        print_order = self.env['bsi.print.order'].create({
            'state': 'draft',
            'production_orders':self.production_order.id,
            })
        for line in self.isbns:
            order_lines.append(self.env['bsi.print.order.lines'].create({
                'print_order':print_order.id,
                'isbn':line.isbn.id,
                'qty':line.qty}))
            prod_isbn = self.env['bsi.production.order.lines'].search([('production_order','=',self.production_order.id),
                                                           ('isbn','=',line.isbn.id)])
            prod_isbn.consumed_qty = line.qty
        print_order.write({'order_lines':[(6,0,map(lambda x:x.id,order_lines))]})
        tree_view_id = self.env.ref('bsi.bsi_print_orders_view_tree').id
        form_view_id = self.env.ref('bsi.view_print_order_form').id
        self.production_order.state = 'print_order_inprogress'
        return {
            'name': _('Print Order'),
            'type': 'ir.actions.act_window',
            'res_model': 'bsi.print.order',
            'view_mode': 'tree,form',
            'view_type': 'form',
            'views': [(tree_view_id, 'tree'),(form_view_id, 'form')],
            'view_id':tree_view_id,
            'res_id': [print_order.id],
            'domain': [('id', 'in', [print_order.id])]
             }

class order_lines(models.TransientModel):
    _name = 'order.lines'

    order_id = fields.Many2one('generate.print.order', 'Order')
    isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
    qty = fields.Float(string="Quantity")

这是bsi.print.order.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") #, compute="_remaining_func"
    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")

我感到困惑的是,只有当 is_book_block、is_binding 和 is_edging 全部三个都处于 True 状态时,我如何才能启动此向导。

我应该像在 TransientModel 上使用 order.lines 那样声明这些字段吗?

像这样:

class order_lines(models.TransientModel):
    _name = 'order.lines'

    order_id = fields.Many2one('generate.print.order', 'Order')
    isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
    qty = fields.Float(string="Quantity")
    is_binding = fields.Boolean(string="Is Binding Done", default=True)
    is_edging = fields.Boolean(string="Is Edging Done", default=True)
    is_book_block = fields.Boolean(string="Is Book Block Done", default=True)

但我不知道如何实现

有什么想法吗?

最佳答案

在 odoo 中执行此操作的唯一方法是使用按钮打开向导,但是 我在这里有点困惑,您条件所在的字段位于订单行中 不是顺序,所以当您说要打开此向导时,如果此字段全部为 true 你到底是什么意思:

  1 - if there is only one line that all the three field are true, you can open the wizard
  2 - all the line in the order must have this three field then you can open the wizard.

对于两种情况,你可以做类似的事情:

 1 - create a boolean field in the order witch is compute field 
 2 - compute the value of the field based on condition 1 or 2
 3 - add a button the the form of the order and show it only if the field is true.
 4- don't forget to add this field too to the form so you can use it in attrs   
 5- in order define a method to open the wizard and pass the same context to wizard (active_id)  

按订单形式:

<field name="new_field" invisible="1"/>
<button name="open_wizard" type="object" 
           class="oe_highlight"
           attrs="{'readonly':[('new_field','=',True)]}"
           />

按顺序:

# note change the name of the method so you can understand you code next time ^^
@api.multi
def open_wizard(self):
    """ open wizard for ....  """
    return {
        # pass the same context to access active_id 
        'context': self.env.context,        
        'name': 'Your title Here',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'generate.print.order',
        'type': 'ir.actions.act_window',
    }

对于该字段:

new_field = fields.Boolean('check ...' , compute='check_fields', store=True)

depends('line_ids', 
    'line_ids.is_binding',
    'line_ids.is_edging',
    'line_ids.is_book_block',)
def check_fields(self):
    """ check fields"""
    for rec in self:
        if any( line.is_binding and line.is_edging and line.is_book_block               for line in rec.order_lines):
            rec.new_field = True

        else:
            rec.new_field = False

关于python - 如果在向导中检查了 bool 值,则从行加载字段 - Odoo v8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47363393/

相关文章:

python - 如何构建带有 @> 运算符过滤器的 sqlalchemy 查询?

python - celery 节拍在同一时间间隔组下安排多个任务

odoo - 预期单例 odoo 9

python-3.x - 我可以从odoo 10,11中的location_id获取warehouse_id吗

postgresql - 如何解决此错误 - "One of the documents you are trying to access has been deleted, please try refreshing"?在 Odoo v8 中?

python - 如何允许群组用户修改 Odoo 中表单的特定部分?

javascript - 使用 django 模板引用外部文件

Python + Qt : pyqtProperty, 样式表和事件处理程序

xml - 如何在odoo 14的打印菜单中隐藏报告?

odoo - 如何标准化 Odoo 8 中创建或写入时的字段值?