Commit 7c35c0a4 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_accounting: Use getInventoryList list to fetch unpaid invoices

    The implementation shouldn't rely on the existence of Payment Transaction for knowing if the Sale Invoice Transaction is payed or not.
parent df92f04d
...@@ -3,16 +3,10 @@ portal_membership=portal.portal_membership ...@@ -3,16 +3,10 @@ portal_membership=portal.portal_membership
user = portal_membership.getAuthenticatedMember().getUserValue() user = portal_membership.getAuthenticatedMember().getUserValue()
def wrapWithShadow(): def wrapWithShadow(user):
return [i.getCausalityValue(portal_type="Sale Invoice Transaction") for i in context.getPortalObject().portal_catalog( return user.Entity_getOutstandingAmountList()
portal_type="Payment Transaction",
simulation_state="started",
destination_section_uid=user.getUid(),
default_causality_portal_type="Sale Invoice Transaction",
default_causality_simulation_state=("stopped", "delivered"),
)]
return user.Person_restrictMethodAsShadowUser( return user.Person_restrictMethodAsShadowUser(
shadow_document=user, shadow_document=user,
callable_object=wrapWithShadow, callable_object=wrapWithShadow,
argument_list=[]) argument_list=[user])
# Note: can be cached for 24h if needed: the list is not expected to change often, nor to ever reach even 10 entries.
portal = context.getPortalObject()
return portal.account_module.searchFolder(
strict_account_type_uid=portal.portal_categories.account_type.asset.receivable.getUid(),
validation_state='validated',
)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getReceivableAccountList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""return a list of invoices with the following attributes:
- payment_request_uid: the uid of the invoice, we consider that payment request is the invoice.
- total_price: the amount left to pay for this invoice
- getTotalPrice: the original amount of this invoice.
Arguments:
- at_date (default None)
"""
portal = context.getPortalObject()
params = dict()
if at_date:
params['at_date'] = at_date
params['grouping_reference'] = None
object_list = []
for (idx, brain) in enumerate(portal.portal_simulation.getInventoryList(
mirror_section_uid=context.getUid(),
simulation_state=('stopped', 'delivered'),
node_uid=[x.uid for x in context.Base_getReceivableAccountList()] or -1,
**params )):
# XXX rewrap inventory list brain because they don't have a valid "uid" and cannot be used
# directly in listbox. We should probably add support for this in getInventoryList instead
# of this hack
# XXX In our case, this hould be always None.
payment_request_uid = brain.payment_request_uid
if not payment_request_uid:
payment_request_uid = brain.getObject().getExplanationUid()
payment_request = portal.portal_catalog.getObject(uid=payment_request_uid)
object_list.append(payment_request.asContext(
section_uid=brain.section_uid,
payment_request_uid=payment_request_uid,
node_uid=brain.node_uid,
node_relative_url=brain.node_relative_url,
total_price=brain.total_price,
uid='new_%s' % idx,))
return object_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>at_date=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Entity_getOutstandingAmountList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -290,19 +290,6 @@ return context.getParentValue()""") ...@@ -290,19 +290,6 @@ return context.getParentValue()""")
def test_AccountingTransactionModule_getUnpaidInvoiceList(self): def test_AccountingTransactionModule_getUnpaidInvoiceList(self):
person = self.makePerson(user=1) person = self.makePerson(user=1)
payment_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
payment = payment_template.Base_createCloneDocument(batch_mode=1)
for line in payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
line.setQuantity(-1)
elif line.getSource() == "account_module/receivable":
line.setQuantity(1)
payment.confirm()
payment.start()
template = self.portal.restrictedTraverse( template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate()) self.portal.portal_preferences.getPreferredDefaultPrePaymentSubscriptionInvoiceTemplate())
current_invoice = template.Base_createCloneDocument(batch_mode=1) current_invoice = template.Base_createCloneDocument(batch_mode=1)
...@@ -321,26 +308,63 @@ return context.getParentValue()""") ...@@ -321,26 +308,63 @@ return context.getParentValue()""")
cell.edit(quantity=1) cell.edit(quantity=1)
cell.setPrice(1) cell.setPrice(1)
payment.setCausalityValue(current_invoice)
payment.setDestinationSectionValue(person)
current_invoice.plan() current_invoice.plan()
current_invoice.confirm() current_invoice.confirm()
current_invoice.startBuilding() current_invoice.startBuilding()
current_invoice.reindexObject() current_invoice.reindexObject()
current_invoice.stop() current_invoice.stop()
self.tic()
current_invoice.Delivery_manageBuildingCalculatingDelivery()
self.tic()
current_invoice.SaleInvoiceTransaction_forceBuildSlapOSAccountingLineList()
self.tic() self.tic()
self.login(person.getUserId()) self.login(person.getUserId())
unpaid_invoice_list = self.portal.accounting_module.AccountingTransactionModule_getUnpaidInvoiceList()
self.assertEqual( self.assertEqual(
self.portal.accounting_module.AccountingTransactionModule_getUnpaidInvoiceList(), [i.getRelativeUrl() for i in unpaid_invoice_list],
[current_invoice]) [current_invoice.getRelativeUrl()])
self.login() self.login()
payment_template = self.portal.restrictedTraverse(
self.portal.portal_preferences.getPreferredDefaultPrePaymentTemplate())
payment = payment_template.Base_createCloneDocument(batch_mode=1)
for line in payment.contentValues():
if line.getSource() == "account_module/payment_to_encash":
line.setQuantity(-1)
elif line.getSource() == "account_module/receivable":
line.setQuantity(1)
payment.confirm()
payment.start()
payment.setCausalityValue(current_invoice)
payment.setDestinationSectionValue(person)
payment.stop() payment.stop()
self.tic() self.tic()
is_lettered = False
letter = None
for line in current_invoice.contentValues():
if line.getSource() == "account_module/receivable":
is_lettered = True
letter = line.getGroupingReference()
self.assertTrue(is_lettered)
# is it groupped?
is_lettered = False
for line in payment.contentValues():
if line.getSource() == "account_module/receivable":
is_lettered = True
self.assertEqual(letter, line.getGroupingReference())
self.assertTrue(is_lettered)
self.login(person.getUserId()) self.login(person.getUserId())
unpaid_invoice_list = self.portal.accounting_module.AccountingTransactionModule_getUnpaidInvoiceList()
self.assertEqual( self.assertEqual(
self.portal.accounting_module.AccountingTransactionModule_getUnpaidInvoiceList(), [i.getRelativeUrl() for i in unpaid_invoice_list],
[]) [])
\ No newline at end of file
portal = context.getPortalObject() portal = context.getPortalObject()
person_uid_list = []
for (_, brain) in enumerate(portal.portal_simulation.getInventoryList(
simulation_state=('stopped', 'delivered'),
parent_payment_mode_uid = [
portal.portal_categories.payment_mode.payzen.getUid(),
portal.portal_categories.payment_mode.wechat.getUid()],
group_by_mirror_section=True,
portal_type=portal.getPortalAccountingMovementTypeList(),
node_uid=[x.uid for x in context.Base_getReceivableAccountList()],
grouping_reference=None)):
payment_request_uid = brain.payment_request_uid
if not payment_request_uid:
payment_request_uid = brain.getObject().getExplanationUid()
payment_request = portal.portal_catalog.getObject(uid=payment_request_uid)
section_uid = payment_request.getDestinationSectionUid(portal_type="Person")
if section_uid is not None:
person_uid_list.append(section_uid)
portal.portal_catalog.searchAndActivate( portal.portal_catalog.searchAndActivate(
portal_type="Person", portal_type="Person",
validation_state="validated", validation_state="validated",
destination_section_related__portal_type="Payment Transaction", uid=person_uid_list,
destination_section_related__simulation_state="started",
method_id='Person_checkToCreateRegularisationRequest', method_id='Person_checkToCreateRegularisationRequest',
activate_kw={'tag': tag} activate_kw={'tag': tag}
) )
......
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