{"action":"created","comment":{"url":"https://api.github.com/repos/odoo/odoo/pulls/comments/26552935","id":26552935,"diff_hunk":"@@ -1,818 +1,731 @@\n # -*- coding: utf-8 -*-\n-##############################################################################\n-#\n-#    OpenERP, Open Source Management Solution\n-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).\n-#\n-#    This program is free software: you can redistribute it and/or modify\n-#    it under the terms of the GNU Affero General Public License as\n-#    published by the Free Software Foundation, either version 3 of the\n-#    License, or (at your option) any later version.\n-#\n-#    This program is distributed in the hope that it will be useful,\n-#    but WITHOUT ANY WARRANTY; without even the implied warranty of\n-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n-#    GNU Affero General Public License for more details.\n-#\n-#    You should have received a copy of the GNU Affero General Public License\n-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n-#\n-##############################################################################\n-\n-from openerp.osv import fields, osv\n-import time\n import datetime\n-from openerp import tools\n-from openerp.exceptions import UserError\n-from openerp.tools.translate import _\n+import time\n from dateutil.relativedelta import relativedelta\n \n-def str_to_datetime(strdate):\n-    return datetime.datetime.strptime(strdate, tools.DEFAULT_SERVER_DATE_FORMAT)\n+from openerp import _, api, fields, models, tools\n+from openerp.exceptions import UserError\n \n-class fleet_vehicle_cost(osv.Model):\n+\n+class FleetVehicleCost(models.Model):\n     _name = 'fleet.vehicle.cost'\n     _description = 'Cost related to a vehicle'\n-    _order = 'date desc, vehicle_id asc'\n+    _order = 'date desc, vehicle_id asc, id desc'\n \n-    def _get_odometer(self, cr, uid, ids, odometer_id, arg, context):\n-        res = dict.fromkeys(ids, False)\n-        for record in self.browse(cr,uid,ids,context=context):\n-            if record.odometer_id:\n-                res[record.id] = record.odometer_id.value\n-        return res\n+    @api.one\n+    @api.depends('odometer_id')\n+    def _compute_get_odometer(self):\n+        self.odometer = self.odometer_id and self.odometer_id.value\n \n-    def _set_odometer(self, cr, uid, id, name, value, args=None, context=None):\n-        if not value:\n+    @api.one\n+    def _compute_set_odometer(self):\n+        if not self.odometer:\n             raise UserError(_('Emptying the odometer value of a vehicle is not allowed.'))\n-        date = self.browse(cr, uid, id, context=context).date\n-        if not(date):\n-            date = fields.date.context_today(self, cr, uid, context=context)\n-        vehicle_id = self.browse(cr, uid, id, context=context).vehicle_id\n-        data = {'value': value, 'date': date, 'vehicle_id': vehicle_id.id}\n-        odometer_id = self.pool.get('fleet.vehicle.odometer').create(cr, uid, data, context=context)\n-        return self.write(cr, uid, id, {'odometer_id': odometer_id}, context=context)\n-\n-    _columns = {\n-        'name': fields.related('vehicle_id', 'name', type=\"char\", string='Name', store=True),\n-        'vehicle_id': fields.many2one('fleet.vehicle', 'Vehicle', required=True, help='Vehicle concerned by this log'),\n-        'cost_subtype_id': fields.many2one('fleet.service.type', 'Type', help='Cost type purchased with this cost'),\n-        'amount': fields.float('Total Price'),\n-        'cost_type': fields.selection([('contract', 'Contract'), ('services','Services'), ('fuel','Fuel'), ('other','Other')], 'Category of the cost', help='For internal purpose only', required=True),\n-        'parent_id': fields.many2one('fleet.vehicle.cost', 'Parent', help='Parent cost to this current cost'),\n-        'cost_ids': fields.one2many('fleet.vehicle.cost', 'parent_id', 'Included Services'),\n-        'odometer_id': fields.many2one('fleet.vehicle.odometer', 'Odometer', help='Odometer measure of the vehicle at the moment of this log'),\n-        'odometer': fields.function(_get_odometer, fnct_inv=_set_odometer, type='float', string='Odometer Value', help='Odometer measure of the vehicle at the moment of this log'),\n-        'odometer_unit': fields.related('vehicle_id', 'odometer_unit', type=\"char\", string=\"Unit\", readonly=True),\n-        'date' :fields.date('Date',help='Date when the cost has been executed'),\n-        'contract_id': fields.many2one('fleet.vehicle.log.contract', 'Contract', help='Contract attached to this cost'),\n-        'auto_generated': fields.boolean('Automatically Generated', readonly=True, required=True),\n-    }\n+        odometer = self.env['fleet.vehicle.odometer'].create({\n+            'value': self.odometer,\n+            'date': self.date or fields.Date.today(),\n+            'vehicle_id': self.vehicle_id.id})\n+        self.odometer_id = odometer.id\n+\n+    name = fields.Char(related='vehicle_id.name', store=True)\n+    vehicle_id = fields.Many2one('fleet.vehicle', string='Vehicle', required=True,\n+                                 help='Vehicle concerned by this log')\n+    cost_subtype_id = fields.Many2one('fleet.service.type', string='Type',\n+                                      help='Cost type purchased with this cost')\n+    amount = fields.Float(string='Total Price')\n+    cost_type = fields.Selection(selection=[('contract', 'Contract'), ('services', 'Services'),\n+                                            ('fuel', 'Fuel'), ('other', 'Other')],\n+                                 string='Category of the cost', help='For internal purpose only',\n+                                 required=True, default='other')\n+    parent_id = fields.Many2one('fleet.vehicle.cost', string='Parent', help='Parent cost to this current cost')\n+    cost_ids = fields.One2many('fleet.vehicle.cost', 'parent_id', string='Included Services')\n+    odometer_id = fields.Many2one('fleet.vehicle.odometer', string='Odometer',\n+                                  help='Odometer measure of the vehicle at the moment of this log')\n+    odometer = fields.Float(compute='_compute_get_odometer', inverse='_compute_set_odometer', string='Odometer Value',\n+                            help='Odometer measure of the vehicle at the moment of this log', store=True)\n+    odometer_unit = fields.Selection(related='vehicle_id.odometer_unit', string=\"Unit\", readonly=True)\n+    date = fields.Date(help='Date when the cost has been executed')\n+    contract_id = fields.Many2one('fleet.vehicle.log.contract', string='Contract',\n+                                  help='Contract attached to this cost')\n+    auto_generated = fields.Boolean('Automatically Generated', readonly=True, required=True)\n+\n+    @api.model\n+    def create(self, values):\n+        # make sure that the data are consistent with values of parent and contract records given\n+        if 'parent_id' in values and values['parent_id']:","path":"addons/fleet/fleet.py","position":115,"original_position":115,"commit_id":"5717a8897fdd22914c9a7e366361a87c30a01366","original_commit_id":"5717a8897fdd22914c9a7e366361a87c30a01366","user":{"login":"ara-odoo","id":7600008,"avatar_url":"https://avatars.githubusercontent.com/u/7600008?v=3","gravatar_id":"","url":"https://api.github.com/users/ara-odoo","html_url":"https://github.com/ara-odoo","followers_url":"https://api.github.com/users/ara-odoo/followers","following_url":"https://api.github.com/users/ara-odoo/following{/other_user}","gists_url":"https://api.github.com/users/ara-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/ara-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ara-odoo/subscriptions","organizations_url":"https://api.github.com/users/ara-odoo/orgs","repos_url":"https://api.github.com/users/ara-odoo/repos","events_url":"https://api.github.com/users/ara-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/ara-odoo/received_events","type":"User","site_admin":false},"body":"why you check parent_id in values two times?","created_at":"2015-03-17T07:07:03Z","updated_at":"2015-03-17T07:07:03Z","html_url":"https://github.com/odoo/odoo/pull/3086#discussion_r26552935","pull_request_url":"https://api.github.com/repos/odoo/odoo/pulls/3086","_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments/26552935"},"html":{"href":"https://github.com/odoo/odoo/pull/3086#discussion_r26552935"},"pull_request":{"href":"https://api.github.com/repos/odoo/odoo/pulls/3086"}}},"pull_request":{"url":"https://api.github.com/repos/odoo/odoo/pulls/3086","id":22766528,"html_url":"https://github.com/odoo/odoo/pull/3086","diff_url":"https://github.com/odoo/odoo/pull/3086.diff","patch_url":"https://github.com/odoo/odoo/pull/3086.patch","issue_url":"https://api.github.com/repos/odoo/odoo/issues/3086","number":3086,"state":"open","locked":false,"title":"[fleet] New API migration","user":{"login":"rim-odoo","id":7300760,"avatar_url":"https://avatars.githubusercontent.com/u/7300760?v=3","gravatar_id":"","url":"https://api.github.com/users/rim-odoo","html_url":"https://github.com/rim-odoo","followers_url":"https://api.github.com/users/rim-odoo/followers","following_url":"https://api.github.com/users/rim-odoo/following{/other_user}","gists_url":"https://api.github.com/users/rim-odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/rim-odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rim-odoo/subscriptions","organizations_url":"https://api.github.com/users/rim-odoo/orgs","repos_url":"https://api.github.com/users/rim-odoo/repos","events_url":"https://api.github.com/users/rim-odoo/events{/privacy}","received_events_url":"https://api.github.com/users/rim-odoo/received_events","type":"User","site_admin":false},"body":"- Task: https://www.odoo.com/web#id=10075&view_type=form&model=project.task&action=333&active_id=131\r\n- Pad: https://pad.odoo.com/p/r.xFp6558VZvondGaA","created_at":"2014-10-15T08:02:17Z","updated_at":"2015-03-17T07:07:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f39ceae7132bf95e60440aba1a2005ccfdea7b57","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/odoo/odoo/pulls/3086/commits","review_comments_url":"https://api.github.com/repos/odoo/odoo/pulls/3086/comments","review_comment_url":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/odoo/odoo/issues/3086/comments","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/5717a8897fdd22914c9a7e366361a87c30a01366","head":{"label":"odoo-dev:master-fleet_new_api-sha","ref":"master-fleet_new_api-sha","sha":"5717a8897fdd22914c9a7e366361a87c30a01366","user":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"repo":{"id":19853934,"name":"odoo","full_name":"odoo-dev/odoo","owner":{"login":"odoo-dev","id":7466976,"avatar_url":"https://avatars.githubusercontent.com/u/7466976?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo-dev","html_url":"https://github.com/odoo-dev","followers_url":"https://api.github.com/users/odoo-dev/followers","following_url":"https://api.github.com/users/odoo-dev/following{/other_user}","gists_url":"https://api.github.com/users/odoo-dev/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo-dev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo-dev/subscriptions","organizations_url":"https://api.github.com/users/odoo-dev/orgs","repos_url":"https://api.github.com/users/odoo-dev/repos","events_url":"https://api.github.com/users/odoo-dev/events{/privacy}","received_events_url":"https://api.github.com/users/odoo-dev/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo-dev/odoo","description":"RD Dev Repository","fork":true,"url":"https://api.github.com/repos/odoo-dev/odoo","forks_url":"https://api.github.com/repos/odoo-dev/odoo/forks","keys_url":"https://api.github.com/repos/odoo-dev/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo-dev/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo-dev/odoo/teams","hooks_url":"https://api.github.com/repos/odoo-dev/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo-dev/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo-dev/odoo/events","assignees_url":"https://api.github.com/repos/odoo-dev/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo-dev/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo-dev/odoo/tags","blobs_url":"https://api.github.com/repos/odoo-dev/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo-dev/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo-dev/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo-dev/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo-dev/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo-dev/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo-dev/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo-dev/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo-dev/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo-dev/odoo/subscription","commits_url":"https://api.github.com/repos/odoo-dev/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo-dev/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo-dev/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo-dev/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo-dev/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo-dev/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo-dev/odoo/merges","archive_url":"https://api.github.com/repos/odoo-dev/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo-dev/odoo/downloads","issues_url":"https://api.github.com/repos/odoo-dev/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo-dev/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo-dev/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo-dev/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo-dev/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo-dev/odoo/releases{/id}","created_at":"2014-05-16T11:16:19Z","updated_at":"2015-03-13T12:02:04Z","pushed_at":"2015-03-17T06:56:37Z","git_url":"git://github.com/odoo-dev/odoo.git","ssh_url":"git@github.com:odoo-dev/odoo.git","clone_url":"https://github.com/odoo-dev/odoo.git","svn_url":"https://github.com/odoo-dev/odoo","homepage":"https://www.odoo.com","size":1079887,"stargazers_count":44,"watchers_count":44,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":12,"forks":18,"open_issues":12,"watchers":44,"default_branch":"master"}},"base":{"label":"odoo:master","ref":"master","sha":"d4990c1b4cd8a68cbeecb6a757933ed1f70f8c39","user":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"repo":{"id":19745004,"name":"odoo","full_name":"odoo/odoo","owner":{"login":"odoo","id":6368483,"avatar_url":"https://avatars.githubusercontent.com/u/6368483?v=3","gravatar_id":"","url":"https://api.github.com/users/odoo","html_url":"https://github.com/odoo","followers_url":"https://api.github.com/users/odoo/followers","following_url":"https://api.github.com/users/odoo/following{/other_user}","gists_url":"https://api.github.com/users/odoo/gists{/gist_id}","starred_url":"https://api.github.com/users/odoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/odoo/subscriptions","organizations_url":"https://api.github.com/users/odoo/orgs","repos_url":"https://api.github.com/users/odoo/repos","events_url":"https://api.github.com/users/odoo/events{/privacy}","received_events_url":"https://api.github.com/users/odoo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/odoo/odoo","description":"Odoo (formerly OpenERP). Open Source Apps To Grow Your Business.","fork":false,"url":"https://api.github.com/repos/odoo/odoo","forks_url":"https://api.github.com/repos/odoo/odoo/forks","keys_url":"https://api.github.com/repos/odoo/odoo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/odoo/odoo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/odoo/odoo/teams","hooks_url":"https://api.github.com/repos/odoo/odoo/hooks","issue_events_url":"https://api.github.com/repos/odoo/odoo/issues/events{/number}","events_url":"https://api.github.com/repos/odoo/odoo/events","assignees_url":"https://api.github.com/repos/odoo/odoo/assignees{/user}","branches_url":"https://api.github.com/repos/odoo/odoo/branches{/branch}","tags_url":"https://api.github.com/repos/odoo/odoo/tags","blobs_url":"https://api.github.com/repos/odoo/odoo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/odoo/odoo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/odoo/odoo/git/refs{/sha}","trees_url":"https://api.github.com/repos/odoo/odoo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/odoo/odoo/statuses/{sha}","languages_url":"https://api.github.com/repos/odoo/odoo/languages","stargazers_url":"https://api.github.com/repos/odoo/odoo/stargazers","contributors_url":"https://api.github.com/repos/odoo/odoo/contributors","subscribers_url":"https://api.github.com/repos/odoo/odoo/subscribers","subscription_url":"https://api.github.com/repos/odoo/odoo/subscription","commits_url":"https://api.github.com/repos/odoo/odoo/commits{/sha}","git_commits_url":"https://api.github.com/repos/odoo/odoo/git/commits{/sha}","comments_url":"https://api.github.com/repos/odoo/odoo/comments{/number}","issue_comment_url":"https://api.github.com/repos/odoo/odoo/issues/comments{/number}","contents_url":"https://api.github.com/repos/odoo/odoo/contents/{+path}","compare_url":"https://api.github.com/repos/odoo/odoo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/odoo/odoo/merges","archive_url":"https://api.github.com/repos/odoo/odoo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/odoo/odoo/downloads","issues_url":"https://api.github.com/repos/odoo/odoo/issues{/number}","pulls_url":"https://api.github.com/repos/odoo/odoo/pulls{/number}","milestones_url":"https://api.github.com/repos/odoo/odoo/milestones{/number}","notifications_url":"https://api.github.com/repos/odoo/odoo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/odoo/odoo/labels{/name}","releases_url":"https://api.github.com/repos/odoo/odoo/releases{/id}","created_at":"2014-05-13T15:38:58Z","updated_at":"2015-03-17T03:22:33Z","pushed_at":"2015-03-16T22:32:28Z","git_url":"git://github.com/odoo/odoo.git","ssh_url":"git@github.com:odoo/odoo.git","clone_url":"https://github.com/odoo/odoo.git","svn_url":"https://github.com/odoo/odoo","homepage":"https://www.odoo.com","size":1112148,"stargazers_count":2265,"watchers_count":2265,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1749,"mirror_url":null,"open_issues_count":2037,"forks":1749,"open_issues":2037,"watchers":2265,"default_branch":"8.0"}},"_links":{"self":{"href":"https://api.github.com/repos/odoo/odoo/pulls/3086"},"html":{"href":"https://github.com/odoo/odoo/pull/3086"},"issue":{"href":"https://api.github.com/repos/odoo/odoo/issues/3086"},"comments":{"href":"https://api.github.com/repos/odoo/odoo/issues/3086/comments"},"review_comments":{"href":"https://api.github.com/repos/odoo/odoo/pulls/3086/comments"},"review_comment":{"href":"https://api.github.com/repos/odoo/odoo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/odoo/odoo/pulls/3086/commits"},"statuses":{"href":"https://api.github.com/repos/odoo/odoo/statuses/5717a8897fdd22914c9a7e366361a87c30a01366"}}}}