Browse Source

[IMP] doc: recommend not using @api.one

* alter docstring of @api.one to mark it as deprecated for 9.0,
  recommend using @api.multi instead
  - deprecation notes were not correctly styled, add styling
    matching "warning" alerts
* move @api.one down the doc page to deemphasize it
* fix "backend" tutorial to remove all instances of ``@api.one``

closes #8527
master
Xavier Morel 6 years ago
parent
commit
2474a91bc9
  1. 142
      doc/_extensions/odoo/static/style.css
  2. 58
      doc/_extensions/odoo/static/style.less
  3. 11
      doc/howtos/backend.rst
  4. 59
      doc/howtos/backend/exercise-calendar
  5. 27
      doc/howtos/backend/exercise-computed
  6. 16
      doc/howtos/backend/exercise-constraint-python
  7. 12
      doc/howtos/backend/exercise-copy-override
  8. 35
      doc/howtos/backend/exercise-gantt
  9. 33
      doc/howtos/backend/exercise-graph
  10. 16
      doc/howtos/backend/exercise-onchange
  11. 31
      doc/howtos/backend/exercise-state-basic
  12. 40
      doc/howtos/backend/exercise-state-workflow
  13. 24
      doc/howtos/backend/exercise-translations
  14. 4
      doc/reference/orm.rst
  15. 9
      openerp/api.py

142
doc/_extensions/odoo/static/style.css

@ -9098,7 +9098,8 @@ hr.divider {
width: 900%;
margin-left: -13px;
}
main .alert {
main .alert,
main .deprecated {
padding: 15px;
border-radius: 0;
border-width: 0 0 0 3px;
@ -9110,25 +9111,35 @@ main .alert {
color: #173038;
}
@media (min-width: 480px) {
main .alert {
main .alert,
main .deprecated {
padding-left: 5.5em;
}
}
main .alert > p,
main .alert > ul {
main .deprecated > p,
main .alert > ul,
main .deprecated > ul {
margin: .5em 0;
}
main .alert > .alert-title,
main .alert > h3 {
main .deprecated > .alert-title,
main .alert > h3,
main .deprecated > h3 {
color: #4b9eb6;
}
main .alert > .alert-title:before,
main .alert > h3:before {
main .deprecated > .alert-title:before,
main .alert > h3:before,
main .deprecated > h3:before {
content: "\e639";
}
main .alert > h3,
main .alert > .alert-title {
font-size: 1.642857143em;
main .deprecated > h3,
main .alert > .alert-title,
main .deprecated > .alert-title,
main .alert > p > .versionmodified,
main .deprecated > p > .versionmodified {
line-height: 1em;
margin: 0 0 10px 0;
font-size: 14px;
@ -9136,12 +9147,15 @@ main .alert > .alert-title {
font-family: Lato, sans-serif;
}
main .alert > h3:before,
main .alert > .alert-title:before {
main .deprecated > h3:before,
main .alert > .alert-title:before,
main .deprecated > .alert-title:before,
main .alert > p > .versionmodified:before,
main .deprecated > p > .versionmodified:before {
font-family: 'Material-Design-Icons';
content: "\e639";
display: inline-block;
text-rendering: geometricPrecision;
font-size: 1.6em;
transform: translate(0, -0.15em);
position: absolute;
top: 50%;
@ -9152,83 +9166,144 @@ main .alert > .alert-title:before {
}
@media (max-width: 480px) {
main .alert > h3:before,
main .alert > .alert-title:before {
main .deprecated > h3:before,
main .alert > .alert-title:before,
main .deprecated > .alert-title:before,
main .alert > p > .versionmodified:before,
main .deprecated > p > .versionmodified:before {
display: none;
}
}
main .alert.alert-success {
main .alert.alert-success,
main .deprecated.alert-success {
border-color: #b9dfb9;
background-color: #eef7ee;
color: #183518;
}
main .alert.alert-success > .alert-title,
main .alert.alert-success > h3 {
main .deprecated.alert-success > .alert-title,
main .alert.alert-success > h3,
main .deprecated.alert-success > h3 {
color: #50af51;
}
main .alert.alert-success > .alert-title:before,
main .alert.alert-success > h3:before {
main .deprecated.alert-success > .alert-title:before,
main .alert.alert-success > h3:before,
main .deprecated.alert-success > h3:before {
content: "\e625";
}
main .alert.alert-info,
main .alert.tip {
main .deprecated.alert-info,
main .alert.tip,
main .deprecated.tip {
border-color: #b8d9e2;
background-color: #eef6f8;
color: #173038;
}
main .alert.alert-info > .alert-title,
main .deprecated.alert-info > .alert-title,
main .alert.tip > .alert-title,
main .deprecated.tip > .alert-title,
main .alert.alert-info > h3,
main .alert.tip > h3 {
main .deprecated.alert-info > h3,
main .alert.tip > h3,
main .deprecated.tip > h3 {
color: #4b9eb6;
}
main .alert.alert-info > .alert-title:before,
main .deprecated.alert-info > .alert-title:before,
main .alert.tip > .alert-title:before,
main .deprecated.tip > .alert-title:before,
main .alert.alert-info > h3:before,
main .alert.tip > h3:before {
main .deprecated.alert-info > h3:before,
main .alert.tip > h3:before,
main .deprecated.tip > h3:before {
content: "\e639";
}
main .alert.alert-warning,
main .alert.warning {
main .deprecated.alert-warning,
main .alert.warning,
main .deprecated.warning,
main .alert.deprecated,
main .deprecated.deprecated {
border-color: #fceedb;
background-color: #fef9f3;
color: #81500b;
}
main .alert.alert-warning > .alert-title,
main .deprecated.alert-warning > .alert-title,
main .alert.warning > .alert-title,
main .deprecated.warning > .alert-title,
main .alert.deprecated > .alert-title,
main .deprecated.deprecated > .alert-title,
main .alert.alert-warning > h3,
main .alert.warning > h3 {
main .deprecated.alert-warning > h3,
main .alert.warning > h3,
main .deprecated.warning > h3,
main .alert.deprecated > h3,
main .deprecated.deprecated > h3,
main .alert.alert-warning > p > .versionmodified,
main .deprecated.alert-warning > p > .versionmodified,
main .alert.warning > p > .versionmodified,
main .deprecated.warning > p > .versionmodified,
main .alert.deprecated > p > .versionmodified,
main .deprecated.deprecated > p > .versionmodified {
color: #f0ad4e;
}
main .alert.alert-warning > .alert-title:before,
main .deprecated.alert-warning > .alert-title:before,
main .alert.warning > .alert-title:before,
main .deprecated.warning > .alert-title:before,
main .alert.deprecated > .alert-title:before,
main .deprecated.deprecated > .alert-title:before,
main .alert.alert-warning > h3:before,
main .alert.warning > h3:before {
main .deprecated.alert-warning > h3:before,
main .alert.warning > h3:before,
main .deprecated.warning > h3:before,
main .alert.deprecated > h3:before,
main .deprecated.deprecated > h3:before,
main .alert.alert-warning > p > .versionmodified:before,
main .deprecated.alert-warning > p > .versionmodified:before,
main .alert.warning > p > .versionmodified:before,
main .deprecated.warning > p > .versionmodified:before,
main .alert.deprecated > p > .versionmodified:before,
main .deprecated.deprecated > p > .versionmodified:before {
content: "\e6a4";
}
main .alert.alert-danger {
main .alert.alert-danger,
main .deprecated.alert-danger {
border-color: #f4cecd;
background-color: #fdf7f7;
color: #611715;
}
main .alert.alert-danger > .alert-title,
main .alert.alert-danger > h3 {
main .deprecated.alert-danger > .alert-title,
main .alert.alert-danger > h3,
main .deprecated.alert-danger > h3 {
color: #d9534f;
}
main .alert.alert-danger > .alert-title:before,
main .alert.alert-danger > h3:before {
main .deprecated.alert-danger > .alert-title:before,
main .alert.alert-danger > h3:before,
main .deprecated.alert-danger > h3:before {
content: "\e6a4";
}
main .alert.alert-exercise {
main .alert.alert-exercise,
main .deprecated.alert-exercise {
border-color: #deddde;
background-color: #f7f7f7;
color: #393639;
}
main .alert.alert-exercise > .alert-title,
main .alert.alert-exercise > h3 {
main .deprecated.alert-exercise > .alert-title,
main .alert.alert-exercise > h3,
main .deprecated.alert-exercise > h3 {
color: #938e94;
}
main .alert.alert-exercise > .alert-title:before,
main .alert.alert-exercise > h3:before {
main .deprecated.alert-exercise > .alert-title:before,
main .alert.alert-exercise > h3:before,
main .deprecated.alert-exercise > h3:before {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
-o-transform: translate(0, 0);
@ -9237,10 +9312,14 @@ main .alert.alert-exercise > h3:before {
content: "\e709";
}
@media (min-width: 1170px) {
main .alert.doc-content {
main .alert.doc-content,
main .deprecated.doc-content {
max-width: 55%;
}
}
main .deprecated .versionmodified {
display: block;
}
.pq-patch {
background: #c2c2c2;
}
@ -9508,7 +9587,7 @@ aside {
#navClone ul li {
padding: 0;
position: relative;
border-radius: none;
border-radius: 0;
border-bottom: 1px solid rgba(35, 43, 65, 0.1);
}
.navbar-aside ul li > a,
@ -9520,7 +9599,7 @@ aside {
color: #393f4f;
font-weight: bold;
display: block;
border-radius: none;
border-radius: 0;
line-height: 1.2;
background: #dbdbdb;
border-bottom: none;
@ -9531,9 +9610,8 @@ aside {
#navClone ul li > a:active,
.navbar-aside ul li > a:focus,
#navClone ul li > a:focus {
background-color: transparent;
text-decoration: none;
border-radius: none;
border-radius: 0;
background: #cecece;
border-left: 5px solid rgba(33, 183, 153, 0.5);
}
@ -9617,7 +9695,6 @@ aside {
height: 56px;
display: inline-block;
z-index: 0;
background-color: transparent;
border-radius: 50%;
padding: 16px;
box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.1), 0 6px 20px 0 rgba(0, 0, 0, 0.05);
@ -9636,7 +9713,7 @@ aside {
position: absolute;
z-index: 1;
overflow: hidden;
right: 0%;
right: 0;
width: 380px;
bottom: 0;
padding: 0;
@ -9650,7 +9727,6 @@ aside {
box-shadow: 0 0 0 transparent;
}
#floating_action_menu .content {
margin-bottom: 0;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);

58
doc/_extensions/odoo/static/style.less

@ -353,7 +353,7 @@ hr.divider {
margin-left: -13px;
}
main .alert {
main .alert, main .deprecated {
padding: 15px;
border-radius: 0;
border-width: 0 0 0 3px;
@ -368,8 +368,7 @@ main .alert {
}
.alert-info; // 'INFO' is the default style
> h3, > .alert-title {
font-size: 1.642857143em;
> h3, > .alert-title, > p > .versionmodified {
line-height: 1em;
margin: 0 0 10px 0;
font-size: 14px;
@ -381,7 +380,6 @@ main .alert {
content: "\e639";
display: inline-block;
text-rendering: geometricPrecision;
font-size: 1.6em;
transform: translate(0, -0.15em);
position: absolute;
top: 50%;
@ -412,22 +410,22 @@ main .alert {
color: darken(@doc_info, 35%);
> .alert-title, > h3 {
color: @doc_info
}
> .alert-title:before, > h3:before {
content: "\e639";
color: @doc_info;
&:before {
content: "\e639";
}
}
}
&.alert-warning, &.warning {
&.alert-warning, &.warning, &.deprecated {
border-color: lighten(@doc_warning, 30%);
background-color: lighten(@doc_warning, 35%);
color: darken(@doc_warning, 35%);
> .alert-title, > h3 {
color: @doc_warning
}
> .alert-title:before, > h3:before {
content: "\e6a4";
> .alert-title, > h3, > p > .versionmodified {
color: @doc_warning;
&:before {
content: "\e6a4";
}
}
}
&.alert-danger {
@ -436,10 +434,10 @@ main .alert {
color: darken(@doc_danger, 35%);
> .alert-title, > h3 {
color: @doc_danger
}
> .alert-title:before, > h3:before {
content: "\e6a4";
color: @doc_danger;
&:before {
content: "\e6a4";
}
}
}
&.alert-exercise {
@ -449,11 +447,11 @@ main .alert {
> .alert-title, > h3 {
color: @doc_exercise;
}
> .alert-title:before, > h3:before {
.translate(0;0);
top: 28px;
content: "\e709";
&:before {
.translate(0;0);
top: 28px;
content: "\e709";
}
}
}
@ -463,6 +461,9 @@ main .alert {
}
}
}
main .deprecated .versionmodified {
display: block;
}
.pq-patch{
background: rgb(194, 194, 194);
@ -688,7 +689,7 @@ aside{
li {
padding: 0;
position:relative;
border-radius: none;
border-radius: 0;
border-bottom: 1px solid fadeout(@doc_text, 90%);
> a {
font-size: 0.7em;
@ -698,15 +699,14 @@ aside{
color: @doc_heading;
font-weight: bold;
display: block;
border-radius: none;
border-radius: 0;
line-height: 1.2;
background: darken(@doc_paper_dark, 10%);
border-bottom: none;
&:hover, &:active, &:focus {
background-color: transparent;
text-decoration: none;
border-radius: none;
border-radius: 0;
background: darken(@doc_paper_dark, 15%);
border-left: 5px solid fadeout(@doc_accent, 50%);
}
@ -788,7 +788,6 @@ aside{
height: 56px;
display: inline-block;
z-index: 0;
background-color: transparent;
border-radius: 50%;
padding: 16px;
box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.1), 0 6px 20px 0 rgba(0, 0, 0, 0.05);
@ -806,7 +805,7 @@ aside{
position: absolute;
z-index: 1;
overflow: hidden;
right: 0%;
right: 0;
width: 380px;
bottom: 0;
padding: 0;
@ -817,7 +816,6 @@ aside{
.box-shadow(0 0 0 transparent);
.content {
margin-bottom: 0;
margin:0;
li {
border: none;

11
doc/howtos/backend.rst

@ -787,13 +787,6 @@ method should simply set the value of the field to compute on every record in
for record in self:
record.name = str(random.randint(1, 1e6))
Our compute method is very simple: it loops over ``self`` and performs the same
operation on every record. We can make it slightly simpler by using the
decorator :func:`~openerp.api.one` to automatically loop on the collection::
@api.one
def _compute_name(self):
self.name = str(random.randint(1, 1e6))
Dependencies
------------
@ -812,10 +805,10 @@ field whenever some of its dependencies have been modified::
name = fields.Char(compute='_compute_name')
value = fields.Integer()
@api.one
@api.depends('value')
def _compute_name(self):
self.name = "Record with value %s" % self.value
for record in self:
self.name = "Record with value %s" % self.value
.. exercise:: Computed fields

59
doc/howtos/backend/exercise-calendar

@ -1,10 +1,10 @@
# HG changeset patch
# Parent 85a8d7317b9e13480f39ad739955442d15144451
# Parent 16fcdc4c6462a7872636f3c19550c16879af5281
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 13:45:01.987048512 +0200
+++ addons/openacademy/models.py 2014-08-28 13:59:30.387035620 +0200
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
@ -12,50 +12,49 @@ Index: addons/openacademy/models.py
from openerp import models, fields, api, exceptions
class Course(models.Model):
@@ -55,6 +56,8 @@
@@ -55,6 +56,8 @@ class Session(models.Model):
attendee_ids = fields.Many2many('res.partner', string="Attendees")
taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')
+ end_date = fields.Date(string="End Date", store=True,
+ compute='_get_end_date', inverse='_set_end_date')
@api.one
@api.depends('seats', 'attendee_ids')
@@ -82,6 +85,30 @@
def _taken_seats(self):
@@ -81,6 +84,30 @@ class Session(models.Model):
},
}
@api.one
+ @api.depends('start_date', 'duration')
+ def _get_end_date(self):
+ if not (self.start_date and self.duration):
+ self.end_date = self.start_date
+ return
+ for r in self:
+ if not (r.start_date and r.duration):
+ r.end_date = r.start_date
+ continue
+
+ # Add duration to start_date, but: Monday + 5 days = Saturday, so
+ # subtract one second to get on Friday instead
+ start = fields.Datetime.from_string(self.start_date)
+ duration = timedelta(days=self.duration, seconds=-1)
+ self.end_date = start + duration
+ # Add duration to start_date, but: Monday + 5 days = Saturday, so
+ # subtract one second to get on Friday instead
+ start = fields.Datetime.from_string(r.start_date)
+ duration = timedelta(days=r.duration, seconds=-1)
+ r.end_date = start + duration
+
+ @api.one
+ def _set_end_date(self):
+ if not (self.start_date and self.end_date):
+ return
+ for r in self:
+ if not (r.start_date and r.end_date):
+ continue
+
+ # Compute the difference between dates, but: Friday - Monday = 4 days,
+ # so add one day to get 5 days instead
+ start_date = fields.Datetime.from_string(self.start_date)
+ end_date = fields.Datetime.from_string(self.end_date)
+ self.duration = (end_date - start_date).days + 1
+ # Compute the difference between dates, but: Friday - Monday = 4 days,
+ # so add one day to get 5 days instead
+ start_date = fields.Datetime.from_string(r.start_date)
+ end_date = fields.Datetime.from_string(r.end_date)
+ r.duration = (end_date - start_date).days + 1
+
+ @api.one
@api.constrains('instructor_id', 'attendee_ids')
def _check_instructor_not_in_attendees(self):
if self.instructor_id and self.instructor_id in self.attendee_ids:
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-28 13:45:01.987048512 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-28 13:54:02.000000000 +0200
for r in self:
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -125,11 +125,24 @@
</field>
</record>

27
doc/howtos/backend/exercise-computed

@ -1,28 +1,27 @@
# HG changeset patch
# Parent a358be0a577b0569831958a8ec1302825c645dee
# Parent 59107edbe5f81bab5e7db172bf2bffa504ce399a
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-26 17:26:03.795783315 +0200
+++ addons/openacademy/models.py 2014-08-26 17:26:03.791783315 +0200
@@ -28,3 +28,13 @@
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -28,3 +28,13 @@ class Session(models.Model):
course_id = fields.Many2one('openacademy.course',
ondelete='cascade', string="Course", required=True)
attendee_ids = fields.Many2many('res.partner', string="Attendees")
+
+ taken_seats = fields.Float(string="Taken seats", compute='_taken_seats')
+
+ @api.one
+ @api.depends('seats', 'attendee_ids')
+ def _taken_seats(self):
+ if not self.seats:
+ self.taken_seats = 0.0
+ else:
+ self.taken_seats = 100.0 * len(self.attendee_ids) / self.seats
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-26 17:26:03.795783315 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-26 17:26:03.791783315 +0200
+ for r in self:
+ if not r.seats:
+ r.taken_seats = 0.0
+ else:
+ r.taken_seats = 100.0 * len(r.attendee_ids) / r.seats
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -100,6 +100,7 @@
<field name="start_date"/>
<field name="duration"/>

16
doc/howtos/backend/exercise-constraint-python

@ -1,10 +1,10 @@
# HG changeset patch
# Parent 7a7d003fe38426a405ce0657a627a139133ec4dd
# Parent 52f54b46487c8224a5aade4b921be77360ed3eae
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-26 17:26:06.591783274 +0200
+++ addons/openacademy/models.py 2014-08-26 17:26:06.587783274 +0200
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
@ -13,13 +13,13 @@ Index: addons/openacademy/models.py
class Course(models.Model):
_name = 'openacademy.course'
@@ -56,3 +56,9 @@
@@ -56,3 +56,9 @@ class Session(models.Model):
'message': "Increase seats or remove excess attendees",
},
}
+
+ @api.one
+ @api.constrains('instructor_id', 'attendee_ids')
+ def _check_instructor_not_in_attendees(self):
+ if self.instructor_id and self.instructor_id in self.attendee_ids:
+ raise exceptions.ValidationError("A session's instructor can't be an attendee")
+ for r in self:
+ if r.instructor_id and r.instructor_id in r.attendee_ids:
+ raise exceptions.ValidationError("A session's instructor can't be an attendee")

12
doc/howtos/backend/exercise-copy-override

@ -1,15 +1,15 @@
# HG changeset patch
# Parent 7d14b75cdfd4c7a272a13572947de5d47f3e851f
# Parent f400352a70963801f0b4732d33a0183e4f6800ff
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 11:00:44.343194847 +0200
+++ addons/openacademy/models.py 2014-08-28 13:44:32.143048955 +0200
@@ -13,6 +13,20 @@
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -13,6 +13,20 @@ class Course(models.Model):
session_ids = fields.One2many(
'openacademy.session', 'course_id', string="Sessions")
+ @api.one
+ @api.multi
+ def copy(self, default=None):
+ default = dict(default or {})
+

35
doc/howtos/backend/exercise-gantt

@ -1,40 +1,39 @@
# HG changeset patch
# Parent dba00a105dd2a82490394b8dec5fea5f1d8847e1
# Parent f4374b6e2e661e0782e396b24c57c1eb97d13288
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 14:21:46.543015785 +0200
+++ addons/openacademy/models.py 2014-08-28 14:21:46.539015785 +0200
@@ -59,6 +59,9 @@
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -59,6 +59,9 @@ class Session(models.Model):
end_date = fields.Date(string="End Date", store=True,
compute='_get_end_date', inverse='_set_end_date')
+ hours = fields.Float(string="Duration in hours",
+ compute='_get_hours', inverse='_set_hours')
+
@api.one
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
@@ -109,6 +112,15 @@
self.duration = (end_date - start_date).days + 1
for r in self:
@@ -108,6 +111,15 @@ class Session(models.Model):
end_date = fields.Datetime.from_string(r.end_date)
r.duration = (end_date - start_date).days + 1
@api.one
+ @api.depends('duration')
+ def _get_hours(self):
+ self.hours = self.duration * 24
+ for r in self:
+ r.hours = r.duration * 24
+
+ @api.one
+ def _set_hours(self):
+ self.duration = self.hours / 24
+ for r in self:
+ r.duration = r.hours / 24
+
+ @api.one
@api.constrains('instructor_id', 'attendee_ids')
def _check_instructor_not_in_attendees(self):
if self.instructor_id and self.instructor_id in self.attendee_ids:
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-28 14:21:46.543015785 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-28 14:21:46.539015785 +0200
for r in self:
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -145,11 +145,23 @@
</field>
</record>

33
doc/howtos/backend/exercise-graph

@ -1,37 +1,36 @@
# HG changeset patch
# Parent a6fe4d3923db1f8f5dff2c39a711a814b0a0f549
# Parent 0687e07f570f363bf5005c6337e0c565a63a6bac
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 14:21:55.039015659 +0200
+++ addons/openacademy/models.py 2014-08-28 14:21:55.031015659 +0200
@@ -62,6 +62,9 @@
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -62,6 +62,9 @@ class Session(models.Model):
hours = fields.Float(string="Duration in hours",
compute='_get_hours', inverse='_set_hours')
+ attendees_count = fields.Integer(
+ string="Attendees count", compute='_get_attendees_count', store=True)
+
@api.one
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
@@ -121,6 +124,11 @@
self.duration = self.hours / 24
for r in self:
@@ -120,6 +123,11 @@ class Session(models.Model):
for r in self:
r.duration = r.hours / 24
@api.one
+ @api.depends('attendee_ids')
+ def _get_attendees_count(self):
+ self.attendees_count = len(self.attendee_ids)
+ for r in self:
+ r.attendees_count = len(r.attendee_ids)
+
+ @api.one
@api.constrains('instructor_id', 'attendee_ids')
def _check_instructor_not_in_attendees(self):
if self.instructor_id and self.instructor_id in self.attendee_ids:
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-28 14:21:55.039015659 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-28 14:21:55.031015659 +0200
@@ -158,11 +158,22 @@
for r in self:
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -157,11 +157,22 @@
</field>
</record>

16
doc/howtos/backend/exercise-onchange

@ -1,14 +1,14 @@
# HG changeset patch
# Parent 8d5573b704b2867788dd6895503f1871c2976a29
# Parent 9eb163e5da677a0d09e01a354ba56697b576a4bc
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-26 17:26:05.687783287 +0200
+++ addons/openacademy/models.py 2014-08-26 17:26:05.679783287 +0200
@@ -39,3 +39,20 @@
self.taken_seats = 0.0
else:
self.taken_seats = 100.0 * len(self.attendee_ids) / self.seats
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -39,3 +39,20 @@ class Session(models.Model):
r.taken_seats = 0.0
else:
r.taken_seats = 100.0 * len(r.attendee_ids) / r.seats
+
+ @api.onchange('seats', 'attendee_ids')
+ def _verify_valid_seats(self):

31
doc/howtos/backend/exercise-state-basic

@ -1,39 +1,38 @@
# HG changeset patch
# Parent 8c721171aa16a41e94059f53d6780c67b5ef2dfc
# Parent 8d2ca42b5be2031ea9624896df53f09f7ca131be
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 14:22:01.371015565 +0200
+++ addons/openacademy/models.py 2014-08-28 14:22:01.367015565 +0200
@@ -66,6 +66,24 @@
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -66,6 +66,24 @@ class Session(models.Model):
attendees_count = fields.Integer(
string="Attendees count", compute='_get_attendees_count', store=True)
+ state = fields.Selection([
+ ('draft', "Draft"),
+ ('confirmed', "Confirmed"),
+ ('done', "Done"),
+ ('draft', "Draft"),
+ ('confirmed', "Confirmed"),
+ ('done', "Done"),
+ ], default='draft')
+
+ @api.one
+ @api.multi
+ def action_draft(self):
+ self.state = 'draft'
+
+ @api.one
+ @api.multi
+ def action_confirm(self):
+ self.state = 'confirmed'
+
+ @api.one
+ @api.multi
+ def action_done(self):
+ self.state = 'done'
+
@api.one
@api.depends('seats', 'attendee_ids')
def _taken_seats(self):
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-28 14:22:01.371015565 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-28 14:22:01.367015565 +0200
for r in self:
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -96,6 +96,19 @@
<field name="model">openacademy.session</field>
<field name="arch" type="xml">

40
doc/howtos/backend/exercise-state-workflow

@ -1,10 +1,10 @@
# HG changeset patch
# Parent c72382bf0c5794135fa318f6ba59899b2277d8c5
# Parent 82f902dbb7aab4d3ddd9caaa9170536afa9d274d
Index: addons/openacademy/__openerp__.py
===================================================================
--- addons.orig/openacademy/__openerp__.py 2014-08-28 14:22:04.135015524 +0200
+++ addons/openacademy/__openerp__.py 2014-08-28 14:22:04.131015524 +0200
diff --git a/openacademy/__openerp__.py b/openacademy/__openerp__.py
--- a/openacademy/__openerp__.py
+++ b/openacademy/__openerp__.py
@@ -29,6 +29,7 @@
'templates.xml',
'views/openacademy.xml',
@ -13,23 +13,21 @@ Index: addons/openacademy/__openerp__.py
],
# only loaded in demonstration mode
'demo': [
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 14:22:04.135015524 +0200
+++ addons/openacademy/models.py 2014-08-28 14:22:04.131015524 +0200
@@ -70,7 +70,7 @@
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -70,7 +70,7 @@ class Session(models.Model):
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
- ], default='draft')
+ ])
@api.one
@api.multi
def action_draft(self):
Index: addons/openacademy/views/openacademy.xml
===================================================================
--- addons.orig/openacademy/views/openacademy.xml 2014-08-28 14:22:04.135015524 +0200
+++ addons/openacademy/views/openacademy.xml 2014-08-28 14:22:04.131015524 +0200
diff --git a/openacademy/views/openacademy.xml b/openacademy/views/openacademy.xml
--- a/openacademy/views/openacademy.xml
+++ b/openacademy/views/openacademy.xml
@@ -97,13 +97,13 @@
<field name="arch" type="xml">
<form string="Session Form">
@ -47,10 +45,10 @@ Index: addons/openacademy/views/openacademy.xml
string="Mark as done" states="confirmed"
class="oe_highlight"/>
<field name="state" widget="statusbar"/>
Index: addons/openacademy/views/session_workflow.xml
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ addons/openacademy/views/session_workflow.xml 2014-08-28 14:22:04.131015524 +0200
diff --git a/openacademy/views/session_workflow.xml b/openacademy/views/session_workflow.xml
new file mode 100644
--- /dev/null
+++ b/openacademy/views/session_workflow.xml
@@ -0,0 +1,50 @@
+<openerp>
+ <data>

24
doc/howtos/backend/exercise-translations

@ -1,7 +1,9 @@
Index: addons/openacademy/models.py
===================================================================
--- addons.orig/openacademy/models.py 2014-08-28 14:02:42.203032773 +0200
+++ addons/openacademy/models.py 2014-08-28 14:06:54.871029022 +0200
# HG changeset patch
# Parent 7c95aad3b60e4c2006c5f706bd157e8e05318bfa
diff --git a/openacademy/models.py b/openacademy/models.py
--- a/openacademy/models.py
+++ b/openacademy/models.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
@ -11,7 +13,7 @@ Index: addons/openacademy/models.py
class Course(models.Model):
_name = 'openacademy.course'
@@ -19,11 +19,11 @@
@@ -19,11 +19,11 @@ class Course(models.Model):
default = dict(default or {})
copied_count = self.search_count(
@ -26,7 +28,7 @@ Index: addons/openacademy/models.py
default['name'] = new_name
return super(Course, self).copy(default)
@@ -97,15 +97,15 @@
@@ -97,15 +97,15 @@ class Session(models.Model):
if self.seats < 0:
return {
'warning': {
@ -46,9 +48,9 @@ Index: addons/openacademy/models.py
},
}
@@ -151,4 +151,4 @@
@api.constrains('instructor_id', 'attendee_ids')
@@ -151,4 +151,4 @@ class Session(models.Model):
def _check_instructor_not_in_attendees(self):
if self.instructor_id and self.instructor_id in self.attendee_ids:
- raise exceptions.ValidationError("A session's instructor can't be an attendee")
+ raise exceptions.ValidationError(_("A session's instructor can't be an attendee"))
for r in self:
if r.instructor_id and r.instructor_id in r.attendee_ids:
- raise exceptions.ValidationError("A session's instructor can't be an attendee")
+ raise exceptions.ValidationError(_("A session's instructor can't be an attendee"))

4
doc/reference/orm.rst

@ -766,8 +766,8 @@ Method decorators
=================
.. automodule:: openerp.api
:members: one, multi, model, depends, constrains, onchange, returns,
v7, v8
:members: multi, model, depends, constrains, onchange, returns,
one, v7, v8
.. _reference/orm/fields:

9
openerp/api.py

@ -383,6 +383,15 @@ def one(method):
names = recs.method(args)
names = model.method(cr, uid, ids, args, context=context)
.. deprecated:: 9.0
:func:`~.one` often makes the code less clear and behaves in ways
developers and readers may not expect.
It is strongly recommended to use :func:`~.multi` and either
iterate on the ``self`` recordset or ensure that the recordset
is a single record with :meth:`~openerp.models.Model.ensure_one`.
"""
split = get_context_split(method)
downgrade = get_downgrade(method)

Loading…
Cancel
Save