Skip to Content
Menu
This question has been flagged
3 Replies
3498 Views

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
Discard

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

Best Answer

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
Discard
Author Best Answer

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
Discard
Related Posts Replies Views Activity
5
Jun 21
15729
1
Nov 19
2613
2
Nov 19
9310
4
Sep 19
3769
3
Jul 18
2602