forked from OCA/project
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsale.py
66 lines (59 loc) · 2.34 KB
/
sale.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
###############################################################################
#
# Module for OpenERP
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# Copyright (C) 2010-2013 Akretion LDTA (<http://www.akretion.com>)
# @author Sébastien BEAU <[email protected]>
# @author Benoît GUILLOT <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from openerp import api, fields, models
from datetime import date
class SaleOrder(models.Model):
_inherit = "sale.order"
@api.one
@api.depends('project_id')
def _compute_related_project_id(self):
self.related_project_id = (
self.project_id.use_tasks and
self.env['project.project'].search(
[('analytic_account_id', '=', self.project_id.id)],
limit=1)[:1])
related_project_id = fields.Many2one(
comodel_name='project.project', string='Project',
compute='_compute_related_project_id')
@api.model
def _prepare_project_vals(self, order):
name = u" %s - %s - %s" % (
order.partner_id.name,
date.today().year,
order.name)
return {
'user_id': order.user_id.id,
'name': name,
'partner_id': order.partner_id.id,
}
@api.multi
def action_create_project(self):
project_obj = self.env['project.project']
for order in self:
vals = self._prepare_project_vals(order)
project = project_obj.create(vals)
order.write({
'project_id': project.analytic_account_id.id
})
return True