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

trade: Display tax lines in order printout

So far, simulated tax is not included in printed Orders. This allow to include expected tax in vat_list for printout.

This is done using `getPreferredTaxUseList` which is probably wrong and will hopefully be rewritten using more modern technologies (html not odt) and to use base amount, but this allows to make order printout show tax lines again.

See merge request nexedi/erp5!1168
parents a39b74c2 91f543a1
Pipeline #10200 failed with stage
in 0 seconds
# coding: utf-8
translateString = context.Base_translateString
portal = context.getPortalObject()
translateString = portal.Base_translateString
request = context.REQUEST
tax_use_list = portal.portal_preferences.getPreferredTaxUseList() or ["use/trade/tax"]
# display only title line instead of description
use_line_title = request.get('use_line_title', 0)
......@@ -62,8 +65,7 @@ def getSocialCapital(reg_cap):
s += '%s: %s€' % (translateString('Social Capital'), reg_cap)
return s
preferred_date_order = context.getPortalObject().portal_preferences\
.getPreferredDateOrder() or 'ymd'
preferred_date_order = portal.portal_preferences.getPreferredDateOrder() or 'ymd'
def getOrderedDate(date):
if date is None:
return ''
......@@ -91,6 +93,9 @@ def getTaxLineList(order):
tax_line_list = [line for line in
order.contentValues(portal_type=order.getPortalTaxMovementTypeList())
if line.getTotalPrice()]
for line in order.Base_getSpecialisedAggregatedAmountList():
if any(line.isMemberOf(tax_use) for tax_use in tax_use_list):
tax_line_list.append(line)
tax_line_list.sort(key=lambda line:line.getTitle())
return tax_line_list
......@@ -147,11 +152,7 @@ for line in getSubLineList(context):
display_id = 'title'
variation_description = ', '.join([x[0] for x in line.getVariationCategoryItemList(display_id=display_id)])
desc = ('%s %s' % (desc[0], variation_description), )
is_tax = 0
for tax_use in (context.getPortalObject().portal_preferences.getPreferredTaxUseList() or ["use/trade/tax"]):
if line.isMemberOf(tax_use):
is_tax = 1
break
is_tax = any(line.isMemberOf(tax_use) for tax_use in tax_use_list)
#set the not_tax_line with the tax_number and the tax_line with the tax_name
tax_number=''
......@@ -285,7 +286,7 @@ destination_decision = context.getDestinationDecisionValue()
if destination_decision is None:
destination_decision = EmptyOrganisation()
if context.getPortalType() in context.getPortalObject().getPortalOrderTypeList():
if context.getPortalType() in portal.getPortalOrderTypeList():
report_title = context.getSimulationState() == "draft" and "Draft Order" or "Order"
else:
report_title = context.getSimulationState() == "draft" and "Draft Packing List" or "Packing List"
......
......@@ -38,6 +38,7 @@ from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import simple_decorator
from DateTime import DateTime
from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5OOo.tests.utils import Validator
def save_result_as(name):
......@@ -92,6 +93,8 @@ class TestTradeModelLineMixin(TestBPMMixin, UserDict):
def afterSetUp(self):
UserDict.__init__(self)
self.portal.portal_preferences.getActiveSystemPreference().setPreferredTaxUseList(['use/tax'])
self.tic()
return super(TestTradeModelLineMixin, self).afterSetUp()
def beforeTearDown(self):
......@@ -963,6 +966,7 @@ return lambda *args, **kw: 1""")
price=.15,
resource_value=tax,
trade_phase='default/tax',
use='tax',
base_application='base_amount/tax'),
))
source = self.createNode()
......@@ -976,10 +980,50 @@ return lambda *args, **kw: 1""")
source_section_value=source,
destination_section_value=destination)
def checkVATOnOrderPrintout(order):
# BBB invoice printout has been improved to display
# tax in a table grouping each tax togetherr, but order printout
# not yet and uses a sligthly different data model
data_dict = order._getTypeBasedMethod('getODTDataDict')()
self.assertEqual(data_dict['total_price'], 1000.0)
self.assertEqual(data_dict['total_price_novat'], 1000.0)
self.assertEqual(
[vat.getTotalPrice() for vat in data_dict['vat_list']], [150.0])
# rendering template does not fail and is valid ODF
self.assertFalse(
Validator().validate(order._getTypeBasedMethod('viewAsODT')()))
def checkVATOnInvoicePrintout(invoice):
data_dict = invoice._getTypeBasedMethod('getODTDataDict')()
self.assertEqual(data_dict['total_price_exclude_tax'], 1000.0)
self.assertEqual(data_dict['total_tax_price'], 150.0)
self.assertEqual(data_dict['total_price'], 1150.0)
self.assertEqual(
[
(
line_tax['total_quantity'],
line_tax['base_price'],
line_tax['total_price'],
) for line_tax in data_dict['line_not_tax']
], [(10.0, 100.0, 1000.0)])
self.assertEqual(
[
(
line_tax['total_quantity'],
line_tax['base_price'],
line_tax['total_price'],
) for line_tax in data_dict['line_tax']
], [(1000.0, 0.15, 150.0)])
# rendering template does not fail and is valid ODF
self.assertFalse(
Validator().validate(order._getTypeBasedMethod('viewAsODT')()))
checkVATOnOrderPrintout(order)
order.plan()
order.confirm()
self.tic()
self.buildPackingLists()
checkVATOnOrderPrintout(order)
packing_list = order.getCausalityRelatedValue(
portal_type=self.packing_list_portal_type)
......@@ -999,9 +1043,10 @@ return lambda *args, **kw: 1""")
self.assertEqual(1150, invoice.getTotalPrice())
self.assertEqual([], invoice.getDivergenceList())
checkVATOnInvoicePrintout(invoice)
invoice.start()
self.tic()
checkVATOnInvoicePrintout(invoice)
self.assertEqual([], invoice.getDivergenceList())
accounting_line_list = invoice.getMovementList(
portal_type=self.invoice_transaction_line_portal_type)
......
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