Skip to content

Commit

Permalink
Add sale_project_fixed_price_task_completed_invoicing
Browse files Browse the repository at this point in the history
  • Loading branch information
leemannd committed May 30, 2017
1 parent c446efc commit 3b5488e
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sale_project_fixed_price_task_completed_invoicing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
20 changes: 20 additions & 0 deletions sale_project_fixed_price_task_completed_invoicing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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')]
)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="edit_project_task_track" model="ir.ui.view">
<field name="name">project.task.form.track</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">

<xpath expr="//field[@name='planned_hours']" position="after">
<field name='invoiceable'/>
<field name="fixed_price"/>
</xpath>

<div name="button_box" position="inside">
<button class="oe_stat_button" name="toggle_invoiceable" type="object" icon="fa-file" attrs="{'invisible': [('fixed_price', '=', False)]}">
<p>Invoiceable</p>
</button>
</div>

</field>
</record>

</odoo>

0 comments on commit 3b5488e

Please sign in to comment.