Commit b6d3499d authored by Jérome Perrin's avatar Jérome Perrin

base/invoicing: special case currency exchange for invoice price lookup

When an invoice has a resource set, newly added invoice lines and cells
will lookup prices using currency exchange lines (and might even find
a price).
parent 2d814f2a
Pipeline #39611 passed with stage
in 0 seconds
......@@ -652,9 +652,7 @@ class TestCurrencyExchangeCell(CurrencyExchangeTestCase):
self.tic()
# we need a base for asContext, we use the currency, but in real code you
# might want to use a more meaningful context.
context = euro.asContext(
context = self._getPriceContext(
categories=['resource/%s' % euro.getRelativeUrl(),
'price_currency/%s' % usd.getRelativeUrl(),
'currency_exchange_type/type_a'])
......
......@@ -23,6 +23,12 @@ def sort_key(exchange_line):
if movement is None:
return context.Resource_getPriceCalculationOperandDict(**kw)
else:
portal = context.getPortalObject()
if (not movement.hasResource()
and movement.getPortalType() in portal.getPortalInvoiceMovementTypeList()):
# XXX Invoice have a currency as resource and this resource is acquired on lines, but we don't want
# to lookup a price using the currency exchange line for such lines.
return None
if validation_state is None:
validation_state = 'validated'
kw.setdefault('portal_type', 'Currency Exchange Line')
......@@ -31,7 +37,7 @@ else:
# and that searchPredicateList does not accept.
kw.pop('categories', None)
predicate_list = context.portal_domains.searchPredicateList(
predicate_list = portal.portal_domains.searchPredicateList(
context=movement,
validation_state=validation_state,
test=True,
......
......@@ -1499,6 +1499,51 @@ self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
sale_invoice_brain, = self.portal.portal_catalog(uid=sale_invoice.getUid(), select_list=["specialise_trade_condition_title"], limit=1)
self.assertEqual(sale_invoice_brain.specialise_trade_condition_title, trade_condition_title)
def test_invoice_movement_getPrice(self):
resource = self.portal.product_module.newContent(
portal_type='Product',
title='Resource %s' % self.id(),
)
resource.setSaleSupplyLineBasePrice(123)
resource.setPurchaseSupplyLineBasePrice(123)
currency = self.portal.currency_module.newContent(
portal_type='Currency', title='Currency %s' % self.id())
currency.newContent(
portal_type='Currency Exchange Line',
price_currency_value=currency,
base_price=1,
).validate()
client = self.portal.organisation_module.newContent(
portal_type='Organisation', title='Client')
vendor = self.portal.organisation_module.newContent(
portal_type='Organisation', title='Vendor')
self.tic()
invoice = self.portal.accounting_module.newContent(
portal_type=self.invoice_portal_type,
source_value=vendor,
source_section_value=vendor,
destination_value=client,
destination_section_value=client,
start_date=DateTime(2008, 10, 21),
price_currency_value=currency,
resource_value=currency,
)
invoice_line = invoice.newContent(
portal_type=self.invoice_line_portal_type,
resource_value=resource,
quantity=1)
self.assertEqual(invoice_line.getPrice(), 123)
invoice_line_without_resource = invoice.newContent(
portal_type=self.invoice_line_portal_type, quantity=1)
self.assertIsNone(invoice_line_without_resource.getPrice())
invoice_cell_without_resource = invoice_line_without_resource.newContent(
portal_type=self.invoice_line_portal_type, quantity=1)
self.assertIsNone(invoice_cell_without_resource.getPrice())
class TestSaleInvoice(TestSaleInvoiceMixin, TestInvoice, ERP5TypeTestCase):
"""Tests for sale invoice.
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment