From 513b180a5f0cbdfe50fca453d2bff6d0c2a88b3d Mon Sep 17 00:00:00 2001 From: Jean-Paul Smets <jp@nexedi.com> Date: Mon, 18 Sep 2006 12:32:39 +0000 Subject: [PATCH] First generic implementation of precision handling git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10091 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../ERP5/Document/InvoiceTransactionRule.py | 5 +++-- product/ERP5Type/Base.py | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/product/ERP5/Document/InvoiceTransactionRule.py b/product/ERP5/Document/InvoiceTransactionRule.py index b73e387650..68821fc86b 100644 --- a/product/ERP5/Document/InvoiceTransactionRule.py +++ b/product/ERP5/Document/InvoiceTransactionRule.py @@ -263,6 +263,7 @@ class InvoiceTransactionRule(Rule, PredicateMatrix): # XXX this happen in many order, so this log is probably useless LOG("InvoiceTransactionRule", PROBLEM, "expanding %s: without resource" % applied_rule.getPath()) + quantity_precision = self.getQuantityPrecisionFromResource(resource) my_simulation_movement._edit( source = transaction_line.getSource() , destination = transaction_line.getDestination() @@ -271,9 +272,9 @@ class InvoiceTransactionRule(Rule, PredicateMatrix): .getDestinationSection() , resource = resource # calculate (quantity * price) * cell_quantity - , quantity = (my_invoice_line_simulation.getQuantity() + , quantity = round((my_invoice_line_simulation.getQuantity() * my_invoice_line_simulation.getPrice()) - * transaction_line.getQuantity() + * transaction_line.getQuantity(), quantity_precision) , start_date = my_invoice_line_simulation.getStartDate() , stop_date = my_invoice_line_simulation.getStopDate() , force_update = 1 diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index 70818e5ab4..220fedfac3 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -2335,12 +2335,33 @@ class Base( CopyContainer, PortalContent, ActiveObject, Historical, ERP5Property # Add to catalog self.reindexObject() + # ZODB Transaction Management security.declarePublic('serialize') def serialize(self): """Make the transaction accessing to this object atomic """ self.id = self.id + # Helpers + def getQuantityPrecisionFromResource(self, resource): + """ + Provides a quick access to precision without accessing the resource + value in ZODB + """ + def cashed_getQuantityPrecisionFromResource(resource): + resource_value = self.portal_categories.resolveCategory(resource) + if resource_value is not None: + return resource_value.getQuantityPrecision() + else: + return 0 + + cashed_getQuantityPrecisionFromResource = CachingMethod(cashed_getQuantityPrecisionFromResource, + id='Base_getQuantityPrecisionFromResource') + + return cashed_getResourceQuantityPrecision(resource) + + + # Documentation Helpers security.declareProtected( Permissions.ManagePortal, 'asDocumentationHelper' ) def asDocumentationHelper(self, item_id=None): """ -- 2.30.9