From cd6670ab5dbd96240d666bfa87de93c57b27d1b3 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Tue, 6 Jun 2017 13:30:39 +0200 Subject: [PATCH] Remove qty_delivered constraint --- .../README.md | 8 +++---- .../models/project_task.py | 10 +------- .../models/sale_order.py | 23 +++++++++++-------- .../models/sale_order_line.py | 19 ++++----------- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/sale_project_fixed_price_task_completed_invoicing/README.md b/sale_project_fixed_price_task_completed_invoicing/README.md index 176d13c06c40..fc49df47fb58 100644 --- a/sale_project_fixed_price_task_completed_invoicing/README.md +++ b/sale_project_fixed_price_task_completed_invoicing/README.md @@ -7,9 +7,9 @@ Sale Project Fixed Price Task Completed Invoicing The main goal of this module is to add the possibility to link a sale.order.line to a project.task considering the delivery. -Unless sale_timesheet, the quantity shipped won't be linked to a Timesheet nor -to the time spent on the task. The price is fixed on the sale.order.line and it -will be considered as shipped once the task is accomplished. +The difference with sale_timesheet is that the quantity shipped won't be linked +to a Timesheet nor to the time spent on the task. The price is fixed on the +sale.order.line and it will be considered as shipped once the task is accomplished. Usage ===== @@ -19,7 +19,7 @@ Create a product with product.type 'Service' and track_service 'Completed Task'. Use it in a Sale Order. Once you validate the Sale Order, it will create a linked project and task. -Once the task is finished, on the form view of the corrisponding task click on the +Once the task is finished, on the form view of the corresponding task click on the button 'Invoiceable'. The linked sale.order.line will be considered as shipped. 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 index 507bb047d6da..6274f4cb526a 100644 --- a/sale_project_fixed_price_task_completed_invoicing/models/project_task.py +++ b/sale_project_fixed_price_task_completed_invoicing/models/project_task.py @@ -22,8 +22,7 @@ def toggle_invoiceable(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', 'cancel') or - task.sale_line_id.invoice_status in ('to invoice', - 'invoiced')): + task.sale_line_id.invoice_status in ('invoiced',)): raise UserError(_("You cannot modify the status if there is " "no Sale Order Line or if it has been " "invoiced.")) @@ -49,10 +48,3 @@ def create(self, vals): raise ValidationError(_('You cannot add a task to and invoiced ' 'Sale Order Line')) return super(ProjectTask, self).create(vals) - - @api.onchange('invoiceable') - def _onchange_invoiceable(self): - for task in self: - if not task.invoiceable: - continue - task.sale_line_id._check_delivered_qty() diff --git a/sale_project_fixed_price_task_completed_invoicing/models/sale_order.py b/sale_project_fixed_price_task_completed_invoicing/models/sale_order.py index f1fa88ce18b7..20b171863c08 100644 --- a/sale_project_fixed_price_task_completed_invoicing/models/sale_order.py +++ b/sale_project_fixed_price_task_completed_invoicing/models/sale_order.py @@ -13,13 +13,18 @@ def action_confirm(self): res = super(SaleOrder, self).action_confirm() for order in self: if not order.project_project_id: - for line in order.order_line: - if (line.product_id.track_service in ('completed_task', - 'timesheet')): - if not order.project_id: - order._create_analytic_account( - prefix=line.product_id.default_code or None) - order.project_id.project_create( - {'name': order.project_id.name, - 'use_tasks': True}) + order._create_analytic_account(self) return res + + @api.multi + def _create_analytic_and_tasks(self): + for order in self: + for line in ord.order_line: + if (line.product_id.track_service in ('completed_task', + 'timesheet')): + if not order.project_id: + order._create_analytic_account( + prefix=line.product_id.default_code or None) + order.project_id.project_create( + {'name': order.project_id.name, + 'use_tasks': True}) 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 index bc57524fc254..2f434c29d146 100644 --- 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 @@ -2,8 +2,7 @@ # 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 +from odoo import api, models class SaleOrderLine(models.Model): @@ -17,20 +16,10 @@ def create(self, vals): line.order_id._create_analytic_account() return line - @api.constrains('product_id') - def _onchange_product_id(self): - for line in self: - if ('completed_task' == line.product_id.track_service and - line.product_uom_qty != 1.0): - raise ValidationError(_("The quantity for 'Complete Task' " - "products must be exactly one")) - @api.multi def _check_delivered_qty(self): for line in self: - tasks_count = self.env['project.task'].search_count( + tasks = self.env['project.task'].search( [('sale_line_id', '=', line.id)]) - task_invoiced_count = self.env['project.task'].search_count( - [('sale_line_id', '=', line.id), ('invoiceable', '=', True)]) - if tasks_count == task_invoiced_count: - line.qty_delivered = 1.0 + if len(tasks) == len(tasks.filtered('invoiceable')): + line.qty_delivered = line.product_uom_qty