From e6ac08561e6b8eeb507887c10e0be1d44a913022 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Fri, 17 May 2019 14:43:59 -0500 Subject: [PATCH] [FIX] Issue #331 --- agreement_legal/__init__.py | 8 ++++++++ agreement_legal/__manifest__.py | 6 +++++- agreement_legal/models/agreement.py | 7 +++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/agreement_legal/__init__.py b/agreement_legal/__init__.py index 073035d1..c8c5c214 100644 --- a/agreement_legal/__init__.py +++ b/agreement_legal/__init__.py @@ -1,4 +1,12 @@ # Copyright (C) 2018 - TODAY, Pavlov Media # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, SUPERUSER_ID from . import models + + +def post_init_agreement_legal(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, dict()) + cr.execute('UPDATE agreement SET stage_id = %s WHERE stage_id IS NULL;', + (env.ref('agreement_legal.agreement_stage_new').id,)) + return True diff --git a/agreement_legal/__manifest__.py b/agreement_legal/__manifest__.py index d519218a..aae585b4 100644 --- a/agreement_legal/__manifest__.py +++ b/agreement_legal/__manifest__.py @@ -35,7 +35,11 @@ "views/agreement.xml", "views/menu.xml", ], + "post_init_hook": "post_init_agreement_legal", "application": True, "development_status": "Beta", - "maintainers": ["max3903", "ygol"], + "maintainers": [ + "max3903", + "ygol" + ], } diff --git a/agreement_legal/models/agreement.py b/agreement_legal/models/agreement.py index 0f784976..65683254 100644 --- a/agreement_legal/models/agreement.py +++ b/agreement_legal/models/agreement.py @@ -8,9 +8,6 @@ class Agreement(models.Model): _name = "agreement" _inherit = ["agreement", "mail.thread"] - def _default_stage_id(self): - return self.env.ref("agreement_legal.agreement_stage_new") - # General name = fields.Char(string="Title", required=True) is_template = fields.Boolean( @@ -339,7 +336,6 @@ class Agreement(models.Model): "agreement.stage", string="Stage", group_expand="_read_group_stage_ids", - default=lambda self: self._default_stage_id(), help="Select the current stage of the agreement.", track_visibility="onchange", index=True) @@ -389,6 +385,9 @@ class Agreement(models.Model): vals["code"] = self.env["ir.sequence"].next_by_code( "agreement" ) or _("New") + if not vals.get('stage_id'): + vals["stage_id"] = \ + self.env.ref("agreement_legal.agreement_stage_new").id return super(Agreement, self).create(vals) # Increments the revision on each save action