Python 如果在向导-Odoo v8上选中布尔值,则从第行加载字段
我有以下向导代码:Python 如果在向导-Odoo v8上选中布尔值,则从第行加载字段,python,openerp,odoo-8,Python,Openerp,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.m
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")
我感到困惑的是,只有当是\u book\u block、是\u binding和是\u edging
三者都处于True
状态时,我才能启动此向导
我是否应该像在TransientModel
上那样声明那些字段
像这样:
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中实现这一点的唯一方法是使用按钮打开向导,但 我对订单行中的字段有点困惑 不是顺序,因此当您说要打开此向导时,如果此字段全部为真 你的确切意思是什么:
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.
对于bouth案例,您可以这样做:
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)
订购表格:
在奥莱德:
#注意更改方法的名称,以便下次可以理解您的代码^^
@api.multi
def open_向导(自我):
“”“为……打开向导”“”
返回{
#传递相同的上下文以访问活动的\u id
“上下文”:self.env.context,
'姓名':'您的头衔在这里',
“视图类型”:“表单”,
“查看模式”:“表单”,
'res_model':'generate.print.order',
'type':'ir.actions.act_window',
}
至于外地:
new_field=fields.Boolean('check…',compute='check_fields',store=True)
取决于('line_id',
“行ID.is_binding”,
“生产线标识为边缘”,
'行ID.is\u book\u block',)
def检查_字段(自身):
“检查字段”
对于rec in self:
如果有(记录订单行中的行的line.is_装订和line.is_封边和line.is_书块):
rec.new_字段=真
其他:
rec.new_字段=False
你是我的英雄,哈哈,我肯定从你身上学到了很多:)非常感谢