forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsale_order.py
64 lines (58 loc) · 2.51 KB
/
sale_order.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
# -*- coding: utf-8 -*-
#
#
# Copyright 2013 Camptocamp SA
#
# 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 dateutil.relativedelta import relativedelta
from openerp import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
date_validity = fields.Date(
string='Valid Until', readonly=True, copy=False,
help="Define date until when quotation is valid",
states={
'draft': [('readonly', False)],
'sent': [('readonly', True)],
},
track_visibility='onchange',
default=lambda rec: rec._default_date_validity())
@api.model
def _default_date_validity(self):
date_validity_str = False
company_pool = self.env['res.company']
company_id = company_pool._company_default_get('sale.order')
company = company_pool.browse(company_id)
if company.default_sale_order_validity_days:
today_str = fields.Date.context_today(self)
today = fields.Date.from_string(today_str)
date_validity = today + relativedelta(
days=company.default_sale_order_validity_days)
date_validity_str = fields.Date.to_string(date_validity)
return date_validity_str
@api.onchange('date_order')
def _onchange_date_order(self):
company_pool = self.env['res.company']
if self.date_order:
company = self.company_id
if not company:
company_id = company_pool._company_default_get('sale.order')
company = company_pool.browse(company_id)
if company.default_sale_order_validity_days:
date_order = fields.Datetime.from_string(self.date_order)
date_validity = date_order + relativedelta(
days=company.default_sale_order_validity_days)
self.date_validity = fields.Date.to_string(date_validity)