forked from OCA/sale-workflow
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port sale_start_end_dates and sale_rental (OCA#353)
- Loading branch information
1 parent
2cc4c13
commit 54092c4
Showing
8 changed files
with
207 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,3 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Sale Start End Dates module for Odoo | ||
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com) | ||
# @author Alexis de Lattre <alexis.delattre@akretion.com> | ||
# | ||
# 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/>. | ||
# | ||
############################################################################## | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import sale | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,18 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# Sale Start End Dates module for Odoo | ||
# Copyright (C) 2014-2015 Akretion (http://www.akretion.com) | ||
# @author Alexis de Lattre <alexis.delattre@akretion.com> | ||
# | ||
# 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/>. | ||
# | ||
############################################################################## | ||
|
||
# -*- coding: utf-8 -*- | ||
# © 2014-2016 Akretion (http://www.akretion.com) | ||
# @author Alexis de Lattre <alexis.delattre@akretion.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Sale Start End Dates', | ||
'version': '8.0.0.1.0', | ||
'version': '9.0.1.0.0', | ||
'category': 'Sales Management', | ||
'license': 'AGPL-3', | ||
'summary': 'Adds start date and end date on sale order lines', | ||
'author': 'Akretion,Odoo Community Association (OCA)', | ||
'website': 'http://www.akretion.com', | ||
'depends': ['account_cutoff_prepaid', 'sale', 'web_context_tunnel'], | ||
'data': ['sale_view.xml'], | ||
'demo': ['sale_demo.xml'], | ||
'depends': ['account_invoice_start_end_dates', 'sale'], | ||
'data': ['views/sale_order.xml'], | ||
'demo': ['demo/sale_demo.xml'], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import sale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2014-2016 Akretion (http://www.akretion.com) | ||
# @author Alexis de Lattre <alexis.delattre@akretion.com> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, fields, api, _ | ||
from openerp.exceptions import ValidationError | ||
from dateutil.relativedelta import relativedelta | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
default_start_date = fields.Date(string='Default Start Date') | ||
default_end_date = fields.Date(string='Default End Date') | ||
|
||
@api.one | ||
@api.constrains('default_start_date', 'default_end_date') | ||
def _check_default_start_end_dates(self): | ||
if ( | ||
self.default_start_date and | ||
self.default_end_date and | ||
self.default_start_date > self.default_end_date): | ||
raise ValidationError( | ||
_("Default Start Date should be before or be the " | ||
"same as Default End Date for sale order %s") | ||
% self.name) | ||
|
||
@api.onchange('default_start_date') | ||
def default_start_date_change(self): | ||
if ( | ||
self.default_start_date and | ||
self.default_end_date and | ||
self.default_start_date > self.default_end_date): | ||
self.default_end_date = self.default_start_date | ||
|
||
@api.onchange('default_end_date') | ||
def default_end_date_change(self): | ||
if ( | ||
self.default_start_date and | ||
self.default_end_date and | ||
self.default_start_date > self.default_end_date): | ||
self.default_start_date = self.default_end_date | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
start_date = fields.Date( | ||
string='Start Date', readonly=True, | ||
states={'draft': [('readonly', False)]}) | ||
end_date = fields.Date( | ||
string='End Date', readonly=True, | ||
states={'draft': [('readonly', False)]}) | ||
number_of_days = fields.Integer(string='Number of Days') | ||
must_have_dates = fields.Boolean( | ||
related='product_id.must_have_dates', readonly=True) | ||
|
||
@api.one | ||
@api.constrains('start_date', 'end_date', 'number_of_days') | ||
def _check_start_end_dates(self): | ||
if self.product_id and self.must_have_dates: | ||
if not self.end_date: | ||
raise ValidationError(_( | ||
"Missing End Date for sale order line with " | ||
"Product '%s'.") % (self.product_id.name)) | ||
if not self.start_date: | ||
raise ValidationError(_( | ||
"Missing Start Date for sale order line with " | ||
"Product '%s'.") % (self.product_id.name)) | ||
if not self.number_of_days: | ||
raise ValidationError(_( | ||
"Missing number of days for sale order line with " | ||
"Product '%s'.") % (self.product_id.name)) | ||
if self.start_date > self.end_date: | ||
raise ValidationError(_( | ||
"Start Date should be before or be the same as " | ||
"End Date for sale order line with Product '%s'.") | ||
% (self.product_id.name)) | ||
if self.number_of_days < 0: | ||
raise ValidationError(_( | ||
"On sale order line with Product '%s', the " | ||
"number of days is negative ; this is not allowed.") | ||
% (self.product_id.name)) | ||
days_delta = ( | ||
fields.Date.from_string(self.end_date) - | ||
fields.Date.from_string(self.start_date)).days + 1 | ||
if self.number_of_days != days_delta: | ||
raise ValidationError(_( | ||
"On the sale order line with Product '%s', " | ||
"there are %d days between the Start Date (%s) and " | ||
"the End Date (%s), but the number of days field " | ||
"has a value of %d days.") | ||
% (self.product_id.name, days_delta, self.start_date, | ||
self.end_date, self.number_of_days)) | ||
|
||
@api.multi | ||
def _prepare_invoice_line(self, qty): | ||
self.ensure_one() | ||
res = super(SaleOrderLine, self)._prepare_invoice_line(qty) | ||
if self.must_have_dates: | ||
res.update({ | ||
'start_date': self.start_date, | ||
'end_date': self.end_date, | ||
}) | ||
return res | ||
|
||
@api.onchange('end_date') | ||
def end_date_change(self): | ||
if self.end_date: | ||
if self.start_date and self.start_date > self.end_date: | ||
self.start_date = self.end_date | ||
if self.start_date: | ||
number_of_days = ( | ||
fields.Date.from_string(self.end_date) - | ||
fields.Date.from_string(self.start_date)).days + 1 | ||
if self.number_of_days != number_of_days: | ||
self.number_of_days = number_of_days | ||
|
||
@api.onchange('start_date') | ||
def start_date_change(self): | ||
if self.start_date: | ||
if self.end_date and self.start_date > self.end_date: | ||
self.end_date = self.start_date | ||
if self.end_date: | ||
number_of_days = ( | ||
fields.Date.from_string(self.end_date) - | ||
fields.Date.from_string(self.start_date)).days + 1 | ||
if self.number_of_days != number_of_days: | ||
self.number_of_days = number_of_days | ||
|
||
@api.onchange('number_of_days') | ||
def number_of_days_change(self): | ||
if self.number_of_days: | ||
if self.start_date: | ||
end_date_dt = fields.Date.from_string(self.start_date) +\ | ||
relativedelta(days=self.number_of_days - 1) | ||
end_date = fields.Date.to_string(end_date_dt) | ||
if self.end_date != end_date: | ||
self.end_date = end_date | ||
elif self.end_date: | ||
self.start_date = fields.Date.from_string(self.end_date) -\ | ||
relativedelta(days=self.number_of_days - 1) | ||
|
||
@api.onchange('product_id') | ||
def start_end_dates_product_id_change(self): | ||
if self.product_id: | ||
if self.order_id.default_start_date: | ||
self.start_date = self.order_id.default_start_date | ||
else: | ||
self.start_date = False | ||
if self.order_id.default_end_date: | ||
self.end_date = self.order_id.default_end_date | ||
else: | ||
self.end_date = False | ||
else: | ||
self.start_date = False | ||
self.end_date = False |
Oops, something went wrong.