Skip to Content
Menu
This question has been flagged
2 Replies
3071 Views

I'm still confuse, is many2one field always return a boolean value False


Like when u inherit a field from another model

field_id = fields.Many2one('model.name','Field String')

if I print field_id.field_name, it always return false even though the field_name type is integer.

Avatar
Discard

The field "field_name" have value?

Also, please ensure you restart your Odoo service and upgrade the module.

Author

Yes sir, there's a value 100 then I want to fetch it but it returns a false value.

I tried to restart it many times,still the same

You can provide me the entire code?

Author

Yes sir

from odoo import models,fields,api

from docutils.nodes import field

from datetime import datetime,date,time

from odoo.addons.base import res

class AccountInvoice(models.Model):

_inherit = 'account.invoice'

owner_id = fields.Many2one(

'res.partner', 'Owner')

partner_id = fields.Many2one(

'res.partner', 'Partner')

company_id = fields.Many2one(

'res.company', 'Company',

default=lambda self: self.env['res.company']._company_default_get('stock.picking'))

backorder_id = fields.Many2one('stock.picking','Back Order of')

date_invoice = fields.Date("Invoice: ")

@api.multi

def _write(self, vals):

res = super(AccountInvoice,self)._write(vals)

print("Owner ID: " + str(self.owner_id.min_date)) #false

print("Partner ID: " + str(self.partner_id.name))

print("Company ID: " + str(self.company_id.name))

print("Backorder ID: " + str(self.backorder_id.min_date)) #false

print('=============================')

print("Invoice: " + self.date_invoice)

return res

i tried every id that is m2o, to know which id have access of min_date

What is this? --> from odoo.addons.base import res?

why you need the following import?

from docutils.nodes import field

you are not using the following import. so avoid the imports that you are not using

from datetime import datetime, date, time

min_date field is a customized field in stock.picking?

Author

Some of my imports were automatically imported, my bad, I will remove it.

No, The min_field is declared inside the stock.picking class ,

I'm sorry, I'm still exploring the flow of odoo and I find it confusing on some part of it especially the relation model

I can't get your exact problem.

Anyway, try the write method instead of _write.

let me know the results.

Author

It still the same sir, the _write method is inherited from account.invoice ,

The goal of the code is to inherit also the min_date field value from stock.picking inside the inherited class account.invoice and initialize it on the date_invoice field.

How could I do it? They told me to get the id from the stock,picking but when i used the backorder_id.min_date, it returns false

Try related field concept

Author

Ok sir Avinash. Thank u for helping me :)

Related Posts Replies Views Activity
2
Oct 19
2691
0
Jun 22
1378
1
Aug 24
430
2
Nov 24
764
3
Oct 23
13197