Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
4556 Tampilan

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


Avatar
Buang

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

Jawaban Terbai

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


Avatar
Buang
Penulis Jawaban Terbai

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


Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
5
Jun 21
17906
1
Nov 19
3696
2
Nov 19
10495
4
Sep 19
4947
3
Jul 18
3873