我正在運行一個簡單的代碼來打開generate_invoice視圖,如果我縮進它下和for語句它不工作。有誰知道我錯過了什麼?代碼沒有效果for循環python odoo 8
這裏是我的代碼
目的:代碼工作是打開,如果在支付結構具有的任何條目,for循環檢查generate_invoice看法,如果有任何帳戶,如果是,那麼返回的觀點,如果不提高驗證錯誤。
class res_student(models.Model):
_name = 'res.student'
此代碼不工作沒有錯誤。
@api.multi
@api.depends('payment_structure')
def generate_invoice(self):
for x in self:
for rec in x.payment_structure:
if rec.account == False:
raise ValidationError("Please define a payment structure to Generate Invoice")
else:
form = self.env['generate.invoice']
id = self.id
record = form.create({'student_id': id,
'journal': x.journal.id,
'payment_type': x.payment_account.id})
return {'name': "Generate Invoice",
'type': 'ir.actions.act_window',
'res_model': 'generate.invoice',
'view_id': False,
'view_type': 'form',
'view_mode': 'form',
'res_id' : record.id,
'target': 'new',
'domain': '[]'}
如果我刪除for和if語句,然後工作。
@api.multi
@api.depends('payment_structure')
def generate_invoice(self):
form = self.env['generate.invoice']
id = self.id
record = form.create({'student_id': id,
'journal': x.journal.id,
'payment_type': x.payment_account.id})
return {'name': "Generate Invoice",
'type': 'ir.actions.act_window',
'res_model': 'generate.invoice',
'view_id': False,
'view_type': 'form',
'view_mode': 'form',
'res_id' : record.id,
'target': 'new',
'domain': '[]'}
#accounting
journal = fields.Many2one('account.journal')
payment_account = fields.Many2one('nominal.account')
payed = fields.Float(compute="get_payment")
discount = fields.Float(compute="get_discount")
payments = fields.One2many('invoice.line','student_id')
payment_structure = fields.One2many('payment.structure','student_id')
class payment_structure(models.Model):
_name = "payment.structure"
student_id = fields.Many2one('res.student')
account = fields.Many2one('nominal.account')
qty = fields.Integer()
unit = fields.Selection([('once','Once'),('month','Month')])
price = fields.Float()
class generate_invoice(models.TransientModel):
_name = 'generate.invoice'
student_id = fields.Many2one('res.student')
month = fields.Integer(string="Months")
payment_type = fields.Many2one('nominal.account', related="student_id.payment_account",)
payment_structure = fields.One2many(related="student_id.payment_structure")
journal = fields.Many2one('account.journal')
請編輯您的代碼,它看起來不正確。另外,描述「它不工作」。你有錯誤嗎?沒有輸出?與預期不同的輸出? – Gabriel