Skip to content

Commit

Permalink
Merge da169b8 into 495fe1a
Browse files Browse the repository at this point in the history
  • Loading branch information
lepistone committed Nov 21, 2014
2 parents 495fe1a + da169b8 commit 7a11d62
Show file tree
Hide file tree
Showing 14 changed files with 288 additions and 387 deletions.
11 changes: 11 additions & 0 deletions logistic_budget/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Logisitic budget
================

This module adds a notion of budget on logistic requests and cost estimates.

A line of a logistic request can have a budget and a pre-approval by a budget
holder and a finance officer.

The creation of a cost estimate can be done without approval or with a budget
overrun. On the other hand, approving a cost estimate into a logistic order
requires approval by the budget holder, and the limit must be respected.
23 changes: 5 additions & 18 deletions logistic_budget/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Author: Joël Grand-Guillaume, Jacques-Etienne Baudoux, Guewen Baconnier
# Leonardo Pistone
# Copyright 2013-2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -18,37 +19,23 @@
#
#
{"name": "Logistics Budget",
"version": "0.3",
"version": "1.0",
"author": "Camptocamp",
"license": "AGPL-3",
"category": "Purchase Management",
'complexity': "normal",
"images": [],
"website": "http://www.camptocamp.com",
"description": """
Logisitic budget
================
This module adds a notion of budget on logistic requisition.
Each requisition lines have now a budget holder and a budget Value.
Requisiton must be approves by budget manager.
If budget is exceeded requisition flow is block unitl adaptation of price
or budget.
""",
"depends": ["logistic_requisition",
"sale_exceptions",
"sale_stock",
],
"demo": [],
"data": ["view/logistic_requisition.xml",
"view/sale_order.xml",
"view/report_logistic_requisition.xml",
"data/exceptions.xml",
],
"auto_install": False,
# TODO one test is disabled due to a bug with field functions odoo#3422
# to reactivate once fixed
"test": ['test/requisition_create_cost_estimate.yml',
],
'installable': True,
}
26 changes: 26 additions & 0 deletions logistic_budget/data/exceptions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">

<record id="insufficient_budget" model="sale.exception">
<field name="name">Insufficient budget</field>
<field name="description">The total amount of this cost estimate is over the total budget of all lines. Please review your price or ask the budget holder to increase the budget.</field>
<field name="sequence">10</field>
<field name="model">sale.order</field>
<field name="code">if object.over_budget():
failed = True</field>
<field name="active" eval="True"/>
</record>

<record id="no_budget_holder" model="sale.exception">
<field name="name">No Budget Holder</field>
<field name="description">The Budget Holder has not validated the cost estimate, please ask for confirmation</field>
<field name="sequence">20</field>
<field name="model">sale.order</field>
<field name="code">if not object.has_budget_holder():
failed = True</field>
<field name="active" eval="True"/>
</record>

</data>
</openerp>
30 changes: 25 additions & 5 deletions logistic_budget/model/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2013-2014 Camptocamp SA
# Copyright 2014 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -15,8 +13,6 @@
#
# 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/>.
#
##############################################################################
from openerp import models, fields, api


Expand All @@ -37,6 +33,14 @@ class SaleOrder(models.Model):
'Finance Officer Validation Date')
finance_officer_remark = fields.Text(
'Finance Officer Remark')
total_budget = fields.Float("Total Budget", compute='_total_budget',
store=True)
budget_holder_id = fields.Many2one('res.users', 'Budget Holder')

@api.one
@api.depends('order_line.budget_tot_price')
def _total_budget(self):
self.total_budget = sum([l.budget_tot_price for l in self.order_line])

@api.onchange('budget_holder_id')
def onchange_set_date_budget_holder(self):
Expand All @@ -45,3 +49,19 @@ def onchange_set_date_budget_holder(self):
@api.onchange('finance_officer_id')
def onchange_set_date_finance_officer(self):
self.date_finance_officer = fields.Datetime.now()

@api.multi
def over_budget(self):
self.ensure_one()
return self.amount_total > self.total_budget

@api.multi
def has_budget_holder(self):
self.ensure_one()
return bool(self.budget_holder_id)


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

budget_tot_price = fields.Float("Budget Amount")
173 changes: 0 additions & 173 deletions logistic_budget/test/requisition_create_cost_estimate.yml

This file was deleted.

32 changes: 3 additions & 29 deletions logistic_budget/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Romain Deheele
# Copyright 2014 Camptocamp SA
#
# 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/>.
#
##############################################################################
from . import test_purchase_split_requisition


fast_suite = [
]

checks = [
test_purchase_split_requisition,
]
from . import test_propagate_budget
from . import test_unit_check
from . import test_it_blocks
Loading

0 comments on commit 7a11d62

Please sign in to comment.