I am follow odoo document and in chapter 9 I want to use Automatic field ( create_date) to compute value of another field this is my model.
_name = "estate.offer"
_description = "this is work as a offer offered to our real estate model"
_log_access = True
price = fields.Float()
status = fields.Selection(selection=[('accepted', 'Accepted'), ('refused', 'Refused')], copy=False)
partner_id = fields.Many2one("res.partner", string="Partner", required=True)
property_id = fields.Many2one("estate.model", 'offer_id', required=True)
validity = fields.Integer(compute="_inverse_date_deadline", inverse="_compute_date_deadline")
date_deadline = fields.Date(string="Date Deadline", compute="_compute_date_deadline",
inverse="_inverse_date_deadline")
api.depends('create_date', 'validity')
def _compute_date_deadline(self):
for record in self:
record.date_deadline = record.create_date + datetime.timedelta(days=record.validity)
# problem in this function
api.depends('create_date', 'date_deadline')
def _inverse_date_deadline(self):
#print('f ddd {5} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzxxxxxxxxx')
for record in self:
record.validity = (record.date_deadline - record.create_date).days
in the odoo document they give this tip:
Tip: the create_date is only filled in when the record is created, therefore you will need a fallback to prevent crashing at time of creation.
source https://stackoverflow.com/questions/74185814/using-create-date-automatic-fields-in-odoo
Comments
Post a Comment