From f051ee785ae485a5fdd7ad86eeae08deae7e5b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com> Date: Sun, 14 May 2006 22:38:13 +0000 Subject: [PATCH] refactor SimulationMovement.isAccountable to call isAccountable on the rule git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7260 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/AppliedRule.py | 6 ++++ product/ERP5/Document/InvoiceRule.py | 11 ++++++- product/ERP5/Document/InvoicingRule.py | 24 +++++++++----- product/ERP5/Document/Rule.py | 35 ++++++++++----------- product/ERP5/Document/SimulationMovement.py | 7 +++-- 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/product/ERP5/Document/AppliedRule.py b/product/ERP5/Document/AppliedRule.py index 02bed149fb..d444b2aea2 100644 --- a/product/ERP5/Document/AppliedRule.py +++ b/product/ERP5/Document/AppliedRule.py @@ -100,6 +100,12 @@ class AppliedRule(XMLObject): if rule is not None: rule.reset(self) + security.declareProtected(Permissions.AccessContentsInformation, + 'isAccountable') + def isAccountable(self, movement): + """Tells wether generated movement needs to be accounted or not.""" + return self.getSpecialiseValue().isAccountable(movement) + security.declareProtected(Permissions.ModifyPortalContent, 'expand') def expand(self, **kw): """ diff --git a/product/ERP5/Document/InvoiceRule.py b/product/ERP5/Document/InvoiceRule.py index 8b7267c5e0..7a56b30c55 100644 --- a/product/ERP5/Document/InvoiceRule.py +++ b/product/ERP5/Document/InvoiceRule.py @@ -60,8 +60,17 @@ class InvoiceRule(DeliveryRule): , PropertySheet.CategoryCore , PropertySheet.DublinCore ) + + security.declareProtected(Permissions.AccessContentsInformation, + 'isAccountable') + def isAccountable(self, movement): + """Tells wether generated movement needs to be accounted or not. + + Invoice movement are never accountable, so simulation movement for + invoice movements should not be accountable either. + """ + return 0 - # Simulation workflow security.declareProtected(Permissions.ModifyPortalContent, 'expand') def expand(self, applied_rule, movement_type_method='getPortalInvoiceMovementTypeList', **kw): diff --git a/product/ERP5/Document/InvoicingRule.py b/product/ERP5/Document/InvoicingRule.py index 3bd26f7459..ea18411d01 100644 --- a/product/ERP5/Document/InvoicingRule.py +++ b/product/ERP5/Document/InvoicingRule.py @@ -62,6 +62,16 @@ class InvoicingRule(Rule): , PropertySheet.DublinCore ) + security.declareProtected(Permissions.AccessContentsInformation, + 'isAccountable') + def isAccountable(self, movement): + """Tells wether generated movement needs to be accounted or not. + + Invoice movement are never accountable, so simulation movement for + invoice movements should not be accountable either. + """ + return 0 + security.declareProtected(Permissions.AccessContentsInformation, 'test') def test(self, movement): """ @@ -126,18 +136,16 @@ class InvoicingRule(Rule): start_date = my_context_movement.getStartDate(), stop_date = my_context_movement.getStopDate(), source = my_context_movement.getSource(), - source_section = my_context_movement.getSourceSection(), + source_section = source_section, destination = my_context_movement.getDestination(), - destination_section = my_context_movement.getDestinationSection(), + destination_section = destination_section, # We do need to collect invoice lines to build invoices - deliverable = 1 + deliverable = 1, ) + # Create one submovement which sources the transformation Rule.expand(self, applied_rule, **kw) def isDeliverable(self, m): - resource = m.getResource() - if m.getResource() is None: - return 0 - else: - return 1 + return m.getResource() is not None + diff --git a/product/ERP5/Document/Rule.py b/product/ERP5/Document/Rule.py index cdaf8a5b79..ddfa4ab329 100644 --- a/product/ERP5/Document/Rule.py +++ b/product/ERP5/Document/Rule.py @@ -81,9 +81,19 @@ class Rule(XMLObject, Predicate): , PropertySheet.CategoryCore , PropertySheet.DublinCore ) - - # Instanciation as an appl - security.declareProtected(Permissions.ModifyPortalContent, 'constructNewAppliedRule') + + security.declareProtected(Permissions.AccessContentsInformation, + 'isAccountable') + def isAccountable(self, movement): + """Tells wether generated movement needs to be accounted or not. + + Only account movements which are not associated to a delivery; + Whenever delivery is there, delivery has priority + """ + return movement.getDeliveryValue() is None + + security.declareProtected(Permissions.ModifyPortalContent, + 'constructNewAppliedRule') def constructNewAppliedRule(self, context, id=None,**kw): """ Creates a new applied rule which points to self @@ -92,29 +102,18 @@ class Rule(XMLObject, Predicate): if id is None: id = context.generateNewId() if getattr(aq_base(context), id, None) is None: - context.newContent(id=id, portal_type='Applied Rule', specialise_value=self,**kw) + context.newContent(id=id, + portal_type='Applied Rule', + specialise_value=self, + **kw) return context.get(id) # Simulation workflow - security.declareProtected(Permissions.ModifyPortalContent, 'reset') - def reset(self, applied_rule): - """ - DO WE NEED IT ? - - -> this does either a diverge or a reset depending - on the position in the tree - - if it is in root position, it is a solve - if it is in non root position, it is a diverse - """ - security.declareProtected(Permissions.ModifyPortalContent, 'expand') def expand(self, applied_rule, **kw): """ Expands the current movement downward. - -> new status -> expanded - An applied rule can be expanded only if its parent movement is expanded. """ diff --git a/product/ERP5/Document/SimulationMovement.py b/product/ERP5/Document/SimulationMovement.py index d436b129c9..45f47a5779 100644 --- a/product/ERP5/Document/SimulationMovement.py +++ b/product/ERP5/Document/SimulationMovement.py @@ -173,10 +173,11 @@ class SimulationMovement(Movement): def isAccountable(self): """ Returns 1 if this needs to be accounted - Only account movements which are not associated to a delivery - Whenever delivery is there, delivery has priority + Some Simulation movement corresponds to non accountable movements, + the parent applied rule decide wether this movement is accountable + or not. """ - return (self.getDeliveryValue() is None) + return self.getParentValue().isAccountable(self) # Ordering / Delivering security.declareProtected( Permissions.AccessContentsInformation, -- 2.30.9