In odoo 10, I'd like to have a computed field that calculate every day difference between current date and other date: This is my code:
Python :
days_number = fields.Integer('Days remaining', compute='_compute_remaining_days', store=True)
@api.depends('maturity_date')
def _compute_remaining_days(self):
current_date = datetime.datetime.now().date()
date1 = False
if self.maturity_date:
date1 = datetime.datetime.strptime(self.maturity_date, "%Y-%m-%d")
date2 = datetime.datetime.strptime(str(current_date), "%Y-%m-%d")
date3 = date1 - date2
date = int(date3.days)
self.days_number = date
XML:
<record id="ir_cron_remain_days" model="ir.cron">
<field name="name">Remaining Days</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field name="model">tresorerie_test.account.payment.maturity</field>
<field name="function">_compute_remaining_days</field>
<field name="args">()</field>
</record>
The problem that the field doesn't get the value automatically.
Can you help me to solve this ?
Kind regards