From 3b5488e00ab4f1f926b4a83dac172f96aa47dc42 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Tue, 30 May 2017 14:25:37 +0200 Subject: [PATCH] Add sale_project_fixed_price_task_completed_invoicing --- .../__init__.py | 4 ++ .../__manifest__.py | 20 +++++++++ .../models/__init__.py | 6 +++ .../models/product_template.py | 13 ++++++ .../models/project_task.py | 43 +++++++++++++++++++ .../models/sale_order_line.py | 19 ++++++++ .../views/project_views.xml | 24 +++++++++++ 7 files changed, 129 insertions(+) create mode 100644 sale_project_fixed_price_task_completed_invoicing/__init__.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/__manifest__.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/models/__init__.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/models/product_template.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/models/project_task.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/models/sale_order_line.py create mode 100644 sale_project_fixed_price_task_completed_invoicing/views/project_views.xml diff --git a/sale_project_fixed_price_task_completed_invoicing/__init__.py b/sale_project_fixed_price_task_completed_invoicing/__init__.py new file mode 100644 index 000000000000..a77a6fcbc5d3 --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/sale_project_fixed_price_task_completed_invoicing/__manifest__.py b/sale_project_fixed_price_task_completed_invoicing/__manifest__.py new file mode 100644 index 000000000000..9a6101e681fe --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/__manifest__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Sale project fixed price task completed invoicing", + "version": "10.0.1.0.0", + "depends": [ + 'sale', + 'product', + 'project', + ], + "author": "Camptocamp,Odoo Community Association (OCA)", + "website": "http://www.camptocamp.com", + "license": "AGPL-3", + "category": "Sale", + "data": [ + 'views/project_views.xml', + ], + 'installable': True, +} diff --git a/sale_project_fixed_price_task_completed_invoicing/models/__init__.py b/sale_project_fixed_price_task_completed_invoicing/models/__init__.py new file mode 100644 index 000000000000..ea9c7dbd318f --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import product_template +from . import project_task +from . import sale_order_line diff --git a/sale_project_fixed_price_task_completed_invoicing/models/product_template.py b/sale_project_fixed_price_task_completed_invoicing/models/product_template.py new file mode 100644 index 000000000000..94851e7224e4 --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/models/product_template.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + track_service = fields.Selection(selection_add=[ + ('completed_task', 'Completed Task')] + ) diff --git a/sale_project_fixed_price_task_completed_invoicing/models/project_task.py b/sale_project_fixed_price_task_completed_invoicing/models/project_task.py new file mode 100644 index 000000000000..2f20556be806 --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/models/project_task.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError + + +class ProjectTask(models.Model): + _inherit = 'project.task' + + invoiceable = fields.Boolean( + string='Invoiceable', + ) + fixed_price = fields.Boolean( + string='Fixed Price', + ) + + @api.multi + def toggle_invoiceable(self): + for task in self: + # We dont' want to modify when the related SOLine is invoiced + if not task.sale_line_id or task.sale_line_id.state in ('done'): + continue + task.invoiceable = not task.invoiceable + + @api.multi + def write(self, vals): + for task in self: + if (vals.get('sale_line_id') and + task.sale_line_id.state in ('done')): + raise ValidationError(_('You cannot modify the Sale Order ' + 'Line of the task once it is invoiced') + ) + + def create(self, vals): + SOLine = self.env['sale.order.line'] + + so_line = SOLine.browse(vals.get('sale_line_id')) + if so_line.state in ('done'): + raise ValidationError(_('You cannot add a task to and invoiced ' + 'Sale Order Line')) + return super(ProjectTask, self).create(vals) diff --git a/sale_project_fixed_price_task_completed_invoicing/models/sale_order_line.py b/sale_project_fixed_price_task_completed_invoicing/models/sale_order_line.py new file mode 100644 index 000000000000..376c5dd19075 --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/models/sale_order_line.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models +from odoo.exceptions import ValidationError + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + @api.constrains('product_id') + def _onchange_product_id(self): + for line in self: + if ('track_service' == line.product_id.track_service and + line.product_uom_qty != 1.0): + raise ValidationError('Error! You cannot have more than one ' + '"track_service" sold in one Sale Order ' + 'Line') diff --git a/sale_project_fixed_price_task_completed_invoicing/views/project_views.xml b/sale_project_fixed_price_task_completed_invoicing/views/project_views.xml new file mode 100644 index 000000000000..b642b78b5b85 --- /dev/null +++ b/sale_project_fixed_price_task_completed_invoicing/views/project_views.xml @@ -0,0 +1,24 @@ + + + + + project.task.form.track + project.task + + + + + + + + +
+ +
+ +
+
+ +