1
我有此嚮導代碼:負載領域,如果布爾值是在嚮導檢查 - Odoo V8
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 and is_edging
都是True
這三個狀態。
我是否應該像order.lines
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)
但我不知道如何去實現它
任何想法?
你是我的英雄,哈哈,我當然學到了很多與你:)非常感謝你 – NeoVe
很高興知道你問一個好問題^^。 – Cherif