跳至内容
菜单
此问题已终结
3 回复
4413 查看

I have value error in my classname here, what should I do?

from odoo import models,fields,api
from docutils.nodes import field

class AccountInvoices(models.Model):
_inherits = {'stock.picking':'backorder_id','account.invoice':'refund_invoice_id'}

backorder_id = fields.Many2one('stock.picking','Back Order of')
refund_invoice_id = fields.Many2one('account.invoice',string="Invoice for which this invoice is the refund")


@api.depends('backorder_id','refund_invoice_id')
def _write(self, vals):
print(self.backorder_id.min_date)
print('=============================')
print(self.refund_invoice_id.date_invoice)
return super(AccountInvoice,self)._write(vals)


I create a new classname but it doesn't accept it, what will I do to call the two models, I'm trying to fetch the field min_date from stock.picking and field date_invoice from account_invoice,

I tried to use this:


from odoo import models,fields,api
from docutils.nodes import field

class AccountInvoice(models.Model):
_inherit = 'account.invoice'

backorder_id = fields.Many2one('stock.picking','Back Order of')
date_invoice = fields.Date("This is invoices")


@api.depends('backorder_id')
def _write(self, vals):
print(self.backorder_id.min_date)
print('=============================')
print(self.date_invoice)
return super(AccountInvoice,self)._write(vals)


But the value of backorder_id.min_date is False when the actual value is 2019-08-01


形象
丢弃

Hi Sudhir

Sorry, I dunno when to use each of the decorator and I tried to use the code u gave to me but the self.backorder_id.min_date still returns the False value. Why it still return a bool value? Thank u for correcting me sir :) and thank u again in advance

最佳答案

How can you use api.depends on _write method? From where did you get this?

_write method must have api.multi and you should call super method first and then check the value of backorder_id.min_date

Try following code:

@api.multi
def _write(self, vals):
res = super(your_class_name, self)._write(vals)
print ("........ ", self.backorder_id.min_date)
return res


形象
丢弃
编写者 最佳答案

Hi Sudhir

Sorry, I dunno when to use each of the decorator and I tried to use the code to give me the self.backorder_id.min_date still returns the False value. Why does it still return a bool value? Thank u for correcting me sir :) and thank u again in advance


形象
丢弃
相关帖文 回复 查看 活动
5
6月 21
17631
1
11月 19
3529
2
11月 19
10361
4
9月 19
4789
3
7月 18
3690