Skip to content

Commit

Permalink
Remove qty_delivered constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
leemannd committed Jun 6, 2017
1 parent 913010f commit cd6670a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 37 deletions.
8 changes: 4 additions & 4 deletions sale_project_fixed_price_task_completed_invoicing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand All @@ -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.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

0 comments on commit cd6670a

Please sign in to comment.