Hi All,
I have problem as follows,
I Add a computed field and it was working fine
and suddenly it gives me error
My .py Code
from datetime import timedeltafrom odoo import models, fields, api, exceptionsclass Session(models.Model): _name = "openacademy.session" name = fields.Char(string="Session Name", required=True) start_date = fields.Date(default=fields.Date.today) duration = fields.Float(digits=(6,2), help="Duration in days") seats = fields.Integer(string="No Of Seats") active = fields.Boolean(default=True) instructor_id = fields.Many2one('res.partner', ondelete='set null', string='Instructor', domain=['|', ('instructor', '=', True), ('category_id.name', 'ilike', 'teacher')]) course_id = fields.Many2one('openacademy.course', string='Course', ondelete='cascade', required=True) attendee_ids = fields.Many2many("res.partner", string="Attendees") end_date = fields.Date(string="End Date", store=True, compute='_get_end_date', inverse="_set_end_date") taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')@api.depends('seats', 'attendee_ids')def _taken_seats(self): for r in self: r.taken_seats = 100.0 * len(r.attendee_ids) / r.seats
and my XML Code
<odoo> <!-- Create Form View --> <record model="ir.ui.view" id="session_form_view"> <field name="name">Session.Form</field> <field name="model">openacademy.session</field> <field name="arch" type="xml"> <form string="Session Form"> <sheet> <group string="General"> <field name="course_id"/> <field name="name"/> <field name="instructor_id"/> <field name="active"/> </group> <group string="Schedule"> <field name="start_date"/> <field name="duration"/> <field name="end_date"/> <field name="seats"/> <field name="taken_seats" widget="progressbar"/> </group> <label for="attendee_ids"/> <field name="attendee_ids"/> </sheet> </form> </field> </record> <!-- Create Tree View --> <record model="ir.ui.view" id="session_tree_view"> <field name="name">Session.Tree</field> <field name="model">openacademy.session</field> <field name="arch" type="xml"> <tree string="Session Tree"> <field name="course_id"/> <field name="name"/> <field name="instructor_id"/> <field name="start_date"/> <field name="end_date"/> <field name="duration"/> <field name="active"/> <field name="seats"/> <field name="taken_seats" widget="progressbar"/> </tree> </field> </record> <!-- calendar view --> <record model="ir.ui.view" id="session_calendar_view"> <field name="name">session.calendar</field> <field name="model">openacademy.session</field> <field name="arch" type="xml"> <calendar string="Session Calendar" date_start="start_date" date_stop="end_date" color="instructor_id"> <field name="name"/> </calendar> </field> </record> <!-- Create Action--> <record model="ir.actions.act_window" id="session_list_action"> <field name="name">Sessions</field> <field name="res_model">openacademy.session</field> <field name="view_type">form</field> <field name="view_mode">tree,form,calendar</field> </record> <!-- Create Menu Item --> <menuitem id="session_menu" parent="Setting_menu" name="Sessions" action="session_list_action"/></odoo>
and this is the error
File "E:\odoo-11.0\odoo\fields.py", line 1081, in determine_inverse getattr(records, self.inverse)() AttributeError: 'openacademy.session' object has no attribute '_set_end_date'
Niyas Raphy Thanks for your Answer and your advice about the code
I see the problem
python require indentation
all functions must be under the class
simply when I Make correct indentation every thing comes ok