Skip to content

Commit

Permalink
Merge e953984 into 350f5f4
Browse files Browse the repository at this point in the history
  • Loading branch information
lepistone committed Oct 31, 2014
2 parents 350f5f4 + e953984 commit f00cc73
Show file tree
Hide file tree
Showing 19 changed files with 339 additions and 296 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
##############################################################################
{'name': 'Framework agreement integration in sourcing',
'version': '0.1',
'version': '1.0',
'author': 'Camptocamp',
'maintainer': 'Camptocamp',
'category': 'NGO',
Expand All @@ -34,15 +34,15 @@
agreement will be used as source for the concerned source lines
of your request.
In this case tender flow is byassed and confirmed PO will be generated
when logistic requisition is confirmed.
In this case the tender flow is bypassed and confirmed PO will be generated
when the logistic requisition is confirmed.
When confirming Logistic request sourcing lines are generating.
When confirming Logistic request sourcing lines are generated.
Generation process will look up all agreements with remaining quantity
and use them one after the other.
We will first choose cheapest agreements with price in negociated currency even
if they are cheaper in other currences.
if they are cheaper in other currencies.
Then we will choose remaining agreements ordered
by price converted in company currency.
Expand All @@ -53,13 +53,13 @@
""",
'website': 'http://www.camptocamp.com',
'data': [
'view/requisition_view.xml',
'wizard/logistic_requisition_source_create_po_view.xml',
'security/ir.model.access.csv'
'view/requisition_view.xml',
'wizard/logistic_requisition_source_create_po_view.xml',
'security/ir.model.access.csv'
],
'demo': [],
'test': [],
'installable': False,
'installable': True,
'auto_install': False,
'license': 'AGPL-3',
'application': False,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@
from . import logistic_requisition_source
from . import purchase
from . import sale_order
from . import logistic_requisition_cost_estimate
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
#
##############################################################################
from collections import namedtuple
from openerp.tools.translate import _
from openerp.osv import orm
from .logistic_requisition_source import AGR_PROC


class logistic_requisition_line(orm.Model):

"""Override to enable generation of source line"""

_inherit = "logistic.requisition.line"

def _prepare_line_source(self, cr, uid, line,
qty=None, agreement=None,
context=None):
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 @@ -55,12 +54,13 @@ def _prepare_line_source(self, cr, uid, line,
res['framework_agreement_id'] = False
if agreement:
if not agreement.product_id.id == line.product_id.id:
raise ValueError("Product mismatch for agreement and requisition 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'
res['procurement_method'] = 'procurement'
else:
res['procurement_method'] = 'other'
return res
Expand Down Expand Up @@ -114,7 +114,8 @@ def _best_company_price(cr, uid, agreement, qty):
return agreements

def _generate_lines_from_agreements(self, cr, uid, container, line,
agreements, qty, currency=None, context=None):
agreements, qty, currency=None,
context=None):
"""Generate 1/n source line(s) for one requisition line.
This is done using available agreements.
Expand Down Expand Up @@ -145,23 +146,27 @@ def _generate_lines_from_agreements(self, cr, uid, container, line,
to_consume = qty if avail_sold >= 0 else avail

source_id = self.make_source_line(cr, uid, line, force_qty=to_consume,
agreement=current_agr, context=context)
agreement=current_agr,
context=context)
container.append(source_id)
difference = qty - to_consume
if difference:
return self._generate_lines_from_agreements(cr, uid, container, line,
agreements, difference,
return self._generate_lines_from_agreements(cr, uid, container,
line, agreements,
difference,
context=context)
else:
return 0

def _source_lines_for_agreements(self, cr, uid, line, agreements, currency=None, context=None):
def _source_lines_for_agreements(self, cr, uid, line, agreements,
currency=None, context=None):
"""Generate 1/n source line(s) for one requisition line
This is done using available agreements.
We first look for cheapeast agreement.
Then if no more quantity are available and there is still remaining needs
we look for next cheapest agreement or we create a tender source line
Then if no more quantity are available and there is still remaining
needs we look for next cheapest agreement or we create a tender source
line
:param line: requisition line browse record
:returns: (generated line ids, remaining qty not covered by agreement)
Expand All @@ -170,12 +175,15 @@ def _source_lines_for_agreements(self, cr, uid, line, agreements, currency=None,
Sourced = namedtuple('Sourced', ['generated', 'remaining'])
qty = line.requested_qty
generated = []
remaining_qty = self._generate_lines_from_agreements(cr, uid, generated,
line, agreements, qty,
currency=currency, context=context)
remaining_qty = self._generate_lines_from_agreements(cr, uid,
generated, line,
agreements, qty,
currency=currency,
context=context)
return Sourced(generated, remaining_qty)

def make_source_line(self, cr, uid, line, force_qty=None, agreement=None, context=None):
def make_source_line(self, cr, uid, line, force_qty=None, agreement=None,
context=None):
"""Generate a source line from a requisition line, see
_prepare_line_source for details.
Expand All @@ -188,17 +196,17 @@ def make_source_line(self, cr, uid, line, force_qty=None, agreement=None, contex
qty = force_qty if force_qty else line.requested_qty
src_obj = self.pool['logistic.requisition.source']
vals = self._prepare_line_source(cr, uid, line,
qty=qty,
agreement=agreement,
context=None)
qty=qty,
agreement=agreement,
context=None)
return src_obj.create(cr, uid, vals, context=context)

def _generate_source_line(self, cr, uid, line, context=None):
"""Generate one or n source line(s) per requisition line.
Depending on the available resources. If there is framework agreement(s)
running we generate one or n source line using agreements otherwise we generate one
source line using tender process
Depending on the available resources. If there is framework
agreement(s) running we generate one or n source line using agreements
otherwise we generate one source line using tender process
:param line: browse record of origin logistic.request
Expand All @@ -211,16 +219,17 @@ def _generate_source_line(self, cr, uid, line, context=None):
date = line.requisition_id.date
currency = line.currency_id
product_id = line.product_id.id
agreements = agr_obj.get_all_product_agreements(cr, uid, product_id, date,
agreements = agr_obj.get_all_product_agreements(cr, uid, product_id,
date,
context=context)
generated_lines = []
if agreements:
line_ids, missing_qty = self._source_lines_for_agreements(cr, uid, line,
agreements, currency=currency)
line_ids, missing_qty = self._source_lines_for_agreements(
cr, uid, line, agreements, currency=currency)
generated_lines.extend(line_ids)
if missing_qty:
generated_lines.append(self.make_source_line(cr, uid, line,
force_qty=missing_qty))
generated_lines.append(self.make_source_line(
cr, uid, line, force_qty=missing_qty))
else:
generated_lines.append(self.make_source_line(cr, uid, line))

Expand All @@ -236,8 +245,8 @@ def _do_confirm(self, cr, uid, ids, context=None):
# this should probably be in logistic_requisition module
# providing a mechanism to allow each type of sourcing method
# to generate source line
res = super(logistic_requisition_line, self)._do_confirm(cr, uid, ids,
context=context)
res = super(logistic_requisition_line, self)._do_confirm(
cr, uid, ids, context=context)
for line_br in self.browse(cr, uid, ids, context=context):
self._generate_source_line(cr, uid, line_br, context=context)
return res

0 comments on commit f00cc73

Please sign in to comment.