Skip to content

Commit

Permalink
Merge 524f168 into 2fe8d86
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed Jan 26, 2015
2 parents 2fe8d86 + 524f168 commit d8af12c
Show file tree
Hide file tree
Showing 42 changed files with 456 additions and 176 deletions.
4 changes: 2 additions & 2 deletions framework_agreement_sourcing/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2013 Camptocamp SA
# Copyright 2013-2015 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 @@ -19,7 +19,7 @@
#
##############################################################################
{'name': 'Framework agreement integration in sourcing',
'version': '1.2',
'version': '1.3',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'category': 'NGO',
Expand Down
16 changes: 8 additions & 8 deletions framework_agreement_sourcing/i18n/en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ msgstr "Logistics Requisition Line"

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "{'invisible': [('procurement_method', '=', 'fw_agreement')]}"
msgstr "{'invisible': [('procurement_method', '=', 'fw_agreement')]}"
msgid "{'invisible': [('sourcing_method', '=', 'fw_agreement')]}"
msgstr "{'invisible': [('sourcing_method', '=', 'fw_agreement')]}"

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_sourcing_method(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr "onchange_sourcing_method(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgid "onchange_sourcing_method(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr "onchange_sourcing_method(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"

#. module: framework_agreement_sourcing
#: model:ir.model,name:framework_agreement_sourcing.model_logistic_requisition_cost_estimate
Expand Down Expand Up @@ -174,8 +174,8 @@ msgstr "You can only chose a pricelist with a currency that is included

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_quantity(procurement_method, requisition_line_id, proposed_qty, proposed_product_id)"
msgstr "onchange_quantity(procurement_method, requisition_line_id, proposed_qty, proposed_product_id)"
msgid "onchange_quantity(sourcing_method, requisition_line_id, proposed_qty, proposed_product_id)"
msgstr "onchange_quantity(sourcing_method, requisition_line_id, proposed_qty, proposed_product_id)"

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source.create.agr.po:0
Expand All @@ -200,8 +200,8 @@ msgstr "Cancel"

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_product_id(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr "onchange_product_id(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgid "onchange_product_id(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr "onchange_product_id(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source.create.agr.po:0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ msgstr ""

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "{'invisible': [('procurement_method', '=', 'fw_agreement')]}"
msgid "{'invisible': [('sourcing_method', '=', 'fw_agreement')]}"
msgstr ""

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_sourcing_method(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgid "onchange_sourcing_method(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr ""

#. module: framework_agreement_sourcing
Expand Down Expand Up @@ -164,7 +164,7 @@ msgstr ""

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_quantity(procurement_method, requisition_line_id, proposed_qty, proposed_product_id)"
msgid "onchange_quantity(sourcing_method, requisition_line_id, proposed_qty, proposed_product_id)"
msgstr ""

#. module: framework_agreement_sourcing
Expand All @@ -190,7 +190,7 @@ msgstr ""

#. module: framework_agreement_sourcing
#: view:logistic.requisition.source:0
msgid "onchange_product_id(procurement_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgid "onchange_product_id(sourcing_method, requisition_line_id, proposed_product_id, proposed_qty)"
msgstr ""

#. module: framework_agreement_sourcing
Expand Down
8 changes: 4 additions & 4 deletions framework_agreement_sourcing/model/logistic_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2013 Camptocamp SA
# Copyright 2013-2015 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 Down Expand Up @@ -30,9 +30,9 @@ class LogisticsRequisitionLine(models.Model):
@api.multi
def _prepare_agreement_source(self, agreement, qty=None):
"""Prepare data dict for source line creation. If an agreement
is given, the procurement_method will be an LTA ('fw_agreement').
is given, the sourcing_method will be an LTA ('fw_agreement').
Otherwise, if it's a stockable product we'll go to tender
by setting procurement_method as 'procurement'. Finally marke the
by setting sourcing_method as 'procurement'. Finally marke the
rest as 'other'. Those are default value that can be changed afterward
by the user.
Expand All @@ -49,7 +49,7 @@ def _prepare_agreement_source(self, agreement, qty=None):
values = self._prepare_source(qty)
values.update(
framework_agreement_id=agreement.id,
procurement_method='fw_agreement',
sourcing_method='fw_agreement',
unit_cost=agreement.get_price(qty, self.currency_id),
)
return values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2013-2014 Camptocamp SA
# Copyright 2013-2015 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 Down Expand Up @@ -242,9 +242,9 @@ def make_purchase_order(self, cr, uid, ids, pricelist, context=None):
# LRS of type other
other_sources = []
for source in sources:
if source.procurement_method == 'fw_agreement':
if source.sourcing_method == 'fw_agreement':
agreement_sources.append(source)
elif source.procurement_method == 'other':
elif source.sourcing_method == 'other':
other_sources.append(source)
else:
raise orm.except_orm(
Expand Down Expand Up @@ -368,7 +368,7 @@ def _onchange_base_agreement_method(self):
self.price_is = 'fixed'
return self._check_enought_qty(agreement)

@api.onchange('procurement_method')
@api.onchange('sourcing_method')
def onchange_sourcing_method(self):
"""
Called when source method is set on a source line.
Expand All @@ -378,7 +378,7 @@ def onchange_sourcing_method(self):
and raise quantity warning.
"""
if (self.procurement_method != 'fw_agreement'
if (self.sourcing_method != 'fw_agreement'
or not self.proposed_product_id):
self.framework_agreement_id = False
return
Expand All @@ -387,7 +387,7 @@ def onchange_sourcing_method(self):
@api.onchange('proposed_qty')
def onchange_quantity(self):
"""Raise a warning if agreed qty is not sufficient"""
if (self.procurement_method != 'fw_agreement'
if (self.sourcing_method != 'fw_agreement'
or not self.proposed_product_id):
return
agreement = self._get_best_agreement()
Expand All @@ -404,7 +404,7 @@ def onchange_product_id(self):
and raise quantity warning.
"""
if self.procurement_method != 'fw_agreement':
if self.sourcing_method != 'fw_agreement':
if self.proposed_product_id:
self.proposed_uom_id = self.proposed_product_id.uom_id or False
return
Expand Down
58 changes: 54 additions & 4 deletions framework_agreement_sourcing/model/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2013 Camptocamp SA
# Authors: Nicolas Bessi, Yannick Vaucher
# Copyright 2013-2015 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 @@ -18,16 +18,66 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import netsvc
from openerp import models, api, exceptions, _, netsvc
from openerp.osv import orm


class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.multi
def action_accepted(self):
""" On acceptation of Cost Estimate, we generate PO
for all line sourced by a framework agreement
Framework agreement currency is selected this way:
- Currency matching with Cost Estimate currency.
- Or first currency found on framework agreement.
"""
res = super(SaleOrder, self).action_accepted()
fa_so_lines = self.mapped('order_line').filtered(
lambda rec: (rec.sourcing_method == 'fw_agreement'
and not rec.sourced_by))
for line in fa_so_lines:
source = line.lr_source_id
# If no po has been generated yet
if not source.purchase_line_id:
line._make_source_fa_purchase_order()
line.sourced_by = source.purchase_line_id
return res


class sale_order_line(orm.Model):

"""Pass agreement PO into state confirmed when SO is confirmed"""

_inherit = "sale.order.line"

@api.multi
def _make_source_fa_purchase_order(self):
source = self.lr_source_id
pricelist = self.order_id.pricelist_id
order_currency = pricelist.currency_id
fa_currencies = (source
.framework_agreement_id
.framework_agreement_pricelist_ids
.mapped('currency_id'))
if not fa_currencies:
raise exceptions.Warning(
_('No currency found for Framework agreement %s')
% source.framework_agreement_id)
if order_currency not in fa_currencies:
currency = fa_currencies[0]

pricelist = self.env['product.pricelist'].search(
[('currency_id', '=', currency.id),
('type', '=', 'purchase')],
limit=1)

source.make_purchase_order(pricelist)

def button_confirm(self, cr, uid, ids, context=None):
"""Override confirmation of request of quotation to support LTA
Expand All @@ -40,7 +90,7 @@ def button_confirm(self, cr, uid, ids, context=None):
wf_service = netsvc.LocalService("workflow")

def source_valid(source):
if source and source.procurement_method == 'fw_agreement':
if source and source.sourcing_method == 'fw_agreement':
return True
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##############################################################################
#
# Author: Nicolas Bessi
# Copyright 2013 Camptocamp SA
# Copyright 2013-2015 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 Down Expand Up @@ -44,9 +44,9 @@ def setUp(self):
self.assertEqual(len(sources), 2)
self.source_lines = sources
self.lta_source = next(x for x in self.source_lines
if x.procurement_method == 'fw_agreement')
if x.sourcing_method == 'fw_agreement')
self.other_source = next(x for x in self.source_lines
if x.procurement_method == 'other')
if x.sourcing_method == 'other')

def test_01_transform_source_to_agreement_wh_dest(self):
"""Test transformation of an agreement source line into PO"""
Expand Down
8 changes: 4 additions & 4 deletions framework_agreement_sourcing/tests/test_check_sourcing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Author: Leonardo Pistone
# Copyright 2014 Camptocamp SA
# Copyright 2014-2015 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 @@ -20,20 +20,20 @@ class TestCheckSourcing(TransactionCase):
"""Check the _check_sourcing method of the source. """

def test_agreement_sourcing_without_agreement_is_not_sourced(self):
self.source.procurement_method = 'fw_agreement'
self.source.sourcing_method = 'fw_agreement'
errors = self.source._check_sourcing()
self.assertEquals(1, len(errors))
self.assertIn('No Framework Agreement', errors[0])

def test_agreement_sourcing_with_running_agreement_is_sourced(self):
self.source.procurement_method = 'fw_agreement'
self.source.sourcing_method = 'fw_agreement'
self.source.framework_agreement_id = self.Agreement.new({
'state': 'running'
})
self.assertEquals([], self.source._check_sourcing())

def test_other_sourcing_is_always_sourced(self):
self.source.procurement_method = 'other'
self.source.sourcing_method = 'other'
self.assertEquals([], self.source._check_sourcing())

def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_01_enough_qty_on_first_agr(self):
self.assertEqual(len(agr_line.source_ids), 1,
'wrong number of source line to validate')
to_validate = agr_line.source_ids
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertEqual(to_validate.sourcing_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 50.0)
self.assertEqual(to_validate.proposed_qty, 400)

Expand All @@ -56,7 +56,7 @@ def test_02_enough_qty_on_high_agr(self):
self.assertEqual(len(agr_line.source_ids), 1,
'wrong number of source line to validate')
to_validate = agr_line.source_ids
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertEqual(to_validate.sourcing_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 30.0)
self.assertEqual(to_validate.proposed_qty, 1500)

Expand All @@ -81,7 +81,7 @@ def test_03_not_enough_qty_on_high_agreement(self):
if x.framework_agreement_id ==
self.cheap_on_high_agreement), None)
self.assertTrue(high_line, msg="High agreement was not used")
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.sourcing_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 30.0)

Expand All @@ -90,7 +90,7 @@ def test_03_not_enough_qty_on_high_agreement(self):
if x.framework_agreement_id ==
self.cheap_on_low_agreement), None)
self.assertTrue(low_line, msg="Low agreement was not used")
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.sourcing_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 400)
self.assertAlmostEqual(low_line.unit_cost, 50.0)

Expand Down Expand Up @@ -119,7 +119,7 @@ def test_04_not_enough_qty_on_all_agreements(self):
if x.framework_agreement_id ==
self.cheap_on_high_agreement), None)
self.assertTrue(high_line, msg="High agreement was not used")
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.sourcing_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 30.0)

Expand All @@ -128,12 +128,12 @@ def test_04_not_enough_qty_on_all_agreements(self):
if x.framework_agreement_id ==
self.cheap_on_low_agreement), None)
self.assertTrue(low_line, msg="Low agreement was not used")
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.sourcing_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 1200)
self.assertAlmostEqual(low_line.unit_cost, 45.0)

# Tender line
tender_line = next((x for x in to_validates
if not x.framework_agreement_id), None)
self.assertTrue(tender_line, msg="Tender line was not generated")
self.assertNotEqual(tender_line.procurement_method, 'fw_agreement')
self.assertNotEqual(tender_line.sourcing_method, 'fw_agreement')
Loading

0 comments on commit d8af12c

Please sign in to comment.