try to compute the days differance
error:
raise exception.with_traceback(None) from new_cause AttributeError: 'test.testing' object has no attribute '_compute_p_days'
py:
from datetime import date, timedelta
from odoo.exceptions import ValidationError
from odoo import api, fields, models
class test_testing(models.Model):
_name = 'test.testing'
_description = 'test code'
start_date = fields.Date(string = 'Start Date',
required = True)
end_date = fields.Date(string = 'End Date',
required = True)
p_days = fields.Float(string = 'Plan Days',
compute = '_compute_p_days',
default = lambda self: self._compute_p_days)
g_days = fields.Float(string = 'Days Gone',
compute = '_compute_g_days',
default = lambda self: self._compute_g_days)
@api.depends('start_date')
def _compute_g_days(self):
self.g_days = 0
for record in self:
if record.start_date > date.today():
raise ValidationError('Start date should not greater than end date.')
else:
record.g_days = (date.today() - record.start_date).days
@api.depends('start_date', 'end_date')
def _compute_p_days(self):
self.p_days = 0
for record in self:
if record.start_date > record.end_date:
raise ValidationError('Start date should not greater than end date.')
else:
record.p_days = (record.end_date - record.start_date).days
XML:
xml version="1.0" encoding="utf-8"?>
id="test_testing_view_form" model="ir.ui.view">
name="name">test.testing.form
name="model">test.testing
name="arch" type="xml">
string="Testing Code">
string="Information">
name="start_date" type="date"/>
name="end_date" type="date"/>
name="p_days"/>
name="g_days"/>
id="test_testing_tree" model="ir.ui.view">
name="name">test.testing.tree
name="model">test.testing
name="arch" type="xml">
string="Testing">
name="start_date" type="date"/>
name="end_date" type="date"/>
name="p_days"/>
name="g_days"/>
id="test_testing_action" model="ir.actions.act_window">
name="name">testing Code
name="type">ir.actions.act_window
name="res_model">test.testing
name="view_mode">tree,form
name="context">{}
name="domain">[]
name="help" type="html">
class="o_view_nocontent_smiling_face">
Create your first project!
id="menu_test"
name="test"
parent="test_root"
action="test_testing_action"
sequence="20"
/>