Skip to content

Commit

Permalink
factor out a constant that is just a little string
Browse files Browse the repository at this point in the history
  • Loading branch information
lepistone committed Oct 31, 2014
1 parent 9cb731c commit c78e9e1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
5 changes: 2 additions & 3 deletions framework_agreement_sourcing/model/logistic_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
##############################################################################
from collections import namedtuple
from openerp.osv import orm
from .logistic_requisition_source import AGR_PROC


class logistic_requisition_line(orm.Model):
Expand All @@ -33,7 +32,7 @@ def _prepare_line_source(self, cr, uid, line,
qty=None, agreement=None,
context=None):
"""Prepare data dict for source line creation. If an agreement
is given, the procurement_method will be an LTA (AGR_PROC).
is given, the procurement_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
rest as 'other'. Those are default value that can be changed afterward
Expand All @@ -58,7 +57,7 @@ def _prepare_line_source(self, cr, uid, line,
raise ValueError(
"Product mismatch for agreement and requisition line")
res['framework_agreement_id'] = agreement.id
res['procurement_method'] = AGR_PROC
res['procurement_method'] = 'fw_agreement'
else:
if line.product_id.type == 'product':
res['procurement_method'] = 'procurement'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
from openerp.tools.translate import _
from openerp.addons.framework_agreement.utils import id_boilerplate

AGR_PROC = 'fw_agreement'


class logistic_requisition_source(orm.Model):

Expand All @@ -47,7 +45,7 @@ def _get_procur_method_hook(self, cr, uid, context=None):
field"""
res = super(logistic_requisition_source, self)._get_procur_method_hook(
cr, uid, context=context)
res.append((AGR_PROC, 'Framework agreement'))
res.append(('fw_agreement', 'Framework agreement'))
return res

# ----------------- adapting source line to po --------------------------
Expand Down Expand Up @@ -214,7 +212,7 @@ 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 == AGR_PROC:
if source.procurement_method == 'fw_agreement':
agreement_sources.append(source)
elif source.procurement_method == 'other':
other_sources.append(source)
Expand Down Expand Up @@ -293,7 +291,7 @@ def onchange_sourcing_method(self, cr, uid, ids, method, req_line_id,
"""
line_source = self.browse(cr, uid, ids, context=context)
res = {'value': {'framework_agreement_id': False}}
if (method != AGR_PROC or not proposed_product_id):
if (method != 'fw_agreement' or not proposed_product_id):
return res
currency = line_source.currency_id
agreement_obj = self.pool['framework.agreement']
Expand Down Expand Up @@ -321,7 +319,7 @@ def onchange_quantity(self, cr, uid, ids, method, req_line_id, qty,
proposed_product_id, context=None):
"""Raise a warning if agreed qty is not sufficient"""
line_source = self.browse(cr, uid, ids, context=context)
if (method != AGR_PROC or not proposed_product_id):
if (method != 'fw_agreement' or not proposed_product_id):
return {}
currency = line_source.currency_id
date = self._get_date(cr, uid, req_line_id, context=context)
Expand All @@ -342,7 +340,7 @@ def onchange_product_id(self, cr, uid, ids, method, req_line_id,
and raise quantity warning.
"""
if method != AGR_PROC:
if method != 'fw_agreement':
if proposed_product_id:
value = {'proposed_uom_id': ''}
if proposed_product_id:
Expand Down
3 changes: 1 addition & 2 deletions framework_agreement_sourcing/model/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
##############################################################################
from openerp import netsvc
from openerp.osv import orm
from .logistic_requisition_source import AGR_PROC


class sale_order_line(orm.Model):
Expand All @@ -41,7 +40,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 == AGR_PROC:
if source and source.procurement_method == 'fw_agreement':
return True
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from ..model.logistic_requisition_source import AGR_PROC
from .common import CommonSourcingSetUp


Expand All @@ -41,7 +40,7 @@ def test_01_enough_qty_on_first_agr(self):
self.assertTrue(len(to_validate_ids) == 1)
to_validate = self.source_line_model.browse(
cr, uid, to_validate_ids[0])
self.assertEqual(to_validate.procurement_method, AGR_PROC)
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 0.0)
self.assertEqual(to_validate.proposed_qty, 400)

Expand All @@ -62,7 +61,7 @@ def test_02_enough_qty_on_high_agr(self):
self.assertTrue(len(to_validate_ids) == 1)
to_validate = self.source_line_model.browse(
cr, uid, to_validate_ids[0])
self.assertEqual(to_validate.procurement_method, AGR_PROC)
self.assertEqual(to_validate.procurement_method, 'fw_agreement')
self.assertAlmostEqual(to_validate.unit_cost, 0.0)
self.assertEqual(to_validate.proposed_qty, 1500)

Expand All @@ -89,7 +88,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, AGR_PROC)
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 0.0)

Expand All @@ -98,7 +97,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, AGR_PROC)
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 400)
self.assertAlmostEqual(low_line.unit_cost, 0.0)

Expand Down Expand Up @@ -129,7 +128,7 @@ def test_03_not_enough_qty_on_all_agreemenst(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, AGR_PROC)
self.assertEqual(high_line.procurement_method, 'fw_agreement')
self.assertEqual(high_line.proposed_qty, 2000)
self.assertAlmostEqual(high_line.unit_cost, 0.0)

Expand All @@ -138,12 +137,12 @@ def test_03_not_enough_qty_on_all_agreemenst(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, AGR_PROC)
self.assertEqual(low_line.procurement_method, 'fw_agreement')
self.assertEqual(low_line.proposed_qty, 1200)
self.assertAlmostEqual(low_line.unit_cost, 0.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, AGR_PROC)
self.assertNotEqual(tender_line.procurement_method, 'fw_agreement')
5 changes: 2 additions & 3 deletions framework_agreement_sourcing/wizard/cost_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
##############################################################################
from openerp.osv import orm
from openerp.tools.translate import _
from .logistic_requisition_source import AGR_PROC


class logistic_requisition_cost_estimate(orm.TransientModel):
Expand All @@ -37,7 +36,7 @@ def _prepare_cost_estimate_line(self, cr, uid, sourcing, context=None):
self)._prepare_cost_estimate_line(cr, uid, sourcing,
context=context)

if sourcing.procurement_method == AGR_PROC:
if sourcing.procurement_method == 'fw_agreement':
res['type'] = 'make_to_order'
res['sale_flow'] = 'direct_delivery'
return res
Expand Down Expand Up @@ -96,7 +95,7 @@ def cost_estimate(self, cr, uid, ids, context=None):

for lrl in wizard.line_ids:
for source in lrl.source_ids:
if source.procurement_method == AGR_PROC:
if source.procurement_method == 'fw_agreement':
sources.append(source)

po_ids = set(x.purchase_line_id.order_id.id for x in sources
Expand Down

0 comments on commit c78e9e1

Please sign in to comment.