Search code examples
pythonpython-3.xxmlodooodoo-12

Why am I getting "Error while validating constraint None"?


I'm developing a new module to Odoo 12. I made the respective wizard and I know it's fine because I've install the module with no problems until here.

But, now I made the view for this model (it's a wizard form), but when I try to update the model, my computer gets slower, the odoo service shuts down (by itself) and after some minutes it shows me the following:

odoo.tools.convert.ParseError: "Error mientras se validaban las restricciones

None" while parsing /opt/odoo/odoo12-custom-addons/opens_annual_opening_seat/wizards/wizard_opening_seat.xml:3, near create.openning.seat.wizard wizard.openning.seat

If I comment the line where I import this xml in the manifest, and try to update again, it works. So the problem is in this xml.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="generate_openning_seat_form" model="ir.ui.view">
        <field name="name">create.openning.seat.wizard</field>
        <field name="model">wizard.openning.seat</field>
        <field name="arch" type="xml">
            <form string="Close period">
                <group>
                    <field name="year" required="1"/>
                </group>
                <footer>
                    <button name="generate_seat" string="Create seat" type="object" class="btn-primary"/>
                </footer>
            </form>
        </field>
    </record>

    <record id="closing_periods_form" model="ir.actions.act_window">
        <field name="name">Period closing</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">wizard.openning.seat</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="generate_openning_seat_form"/>
        <field name="target">new</field>
    </record>

    <menuitem id="menu_closing_period" name="Consultor" parent="account.menu_finance" sequence="35"/>

    <menuitem id="close_period" name="Closing period" parent="menu_closing_period"
              action="closing_periods_form" sequence="40"/>

</odoo>

My model is defined in this way:

# -*- coding: utf-8 -*-
from odoo import api, fields, models
from datetime import date, datetime, time, timedelta

class OpenAnnualSeatWizard(models.Model):
    _name = 'wizard.openning.seat'

    @api.model
    def year_selection(self):
        date = datetime.now().strftime("%Y")
        year = int(date) - 1
        year_list = []
        while year != year+1:
            year_list.append((str(year), str(year)))
            year += 1
        return year_list

    year = fields.Selection(year_selection, string='Año', default='2020')

    @api.multi
    def generate_seat(self):
        # code

Extra info:

  • Yes, I've import account module in the manifest file.
  • Yes, I've checked that the model was created.
  • Yes, I've checked that the model's name is properly written in the file.

Solution

  • You have an infinite loop in the function that is supposed to compute the selection.

    The expression:

    year != year+1
    

    will be always True and Odoo will get in an infinite while loop without a break condition.

    Use the year attribute to get the date year as an integer.

    current_year = datetime.now().year