3

In odoo every model will be having a write_date column which will store the last edited time and date of the record.I want to take the value of that field to a variable/ field. But when I print this , it is printing False . What to do.?

code

variable = self.write_date

Thanks in Advance..

vbt
  • 795
  • 7
  • 31
  • Which recordset do you have in `self`? – forvas May 07 '18 at 13:47
  • you mean model right ? Iam using a custom module and a custom model is used .. @forvas – vbt May 07 '18 at 15:58
  • Just before your line (`variable = self.write_date`), add this: `_logger.info(self)`, and write me the result of this line in the log file. – forvas May 07 '18 at 16:22
  • ocean_5_may odoo.addons.orchid_travels_v10.models.orchid_inbound: orchid.inbound(,) @forvas – vbt May 08 '18 at 04:09

2 Answers2

5

The problem is that you're getting in self a new recordset (odoo.models.NewId object at 0x7fe0c05717d0). Therefore, you're trying to get the write_date of a record which has not been created yet. If the record has never been updated (even not created), it's not going to have a value in write_date.

Remember that write_date stores the latest date in which the record was updated.

So, first, at least, you must create the record, and then, you will be able to apply this: variable = self.write_date.

But take a look at this:

What's happening with these transient models' IDs?

May be you get the write_date without creating the record, give a try to this: variable = self._origin.write_date.

forvas
  • 9,801
  • 7
  • 62
  • 158
1

Even though we can see a field named write_date in the table, First of all, what we have to do is that you have to add a field named write_date into your model and then try the same.

write_date = fields.Datetime(string='Write Date') solved my problem.Thanks everyone for helping.

vbt
  • 795
  • 7
  • 31