Commit 4a15ec3d authored by Lucas Ficheux's avatar Lucas Ficheux Committed by ntome

[cragr] Fix DateGuesser for some savings

Somme savings Accounts have Transactions with a date without a year,
we use a DateGuesser to guess that year. The DateGuesser wasn't
properly handed to the method, that is what this patch fixes.

For DateGuesser to fulfill it's purpose the same instance needs
to be shared between all Transaction objects, or the default behaviour of
*Element is to make a copy of the parent's env variable (the dictionnary
used by the filter Env) so each Transaction would have a new instance
of DateGuesser.

Here we create a child class of DateGuesser
with it's __deepcopy__ method overridden so that a call of deepcopy on it will
return the object itself instead of a copy, this counteracts the
behaviour of *Element and allows all Transaction objects to share the
same instance of DateGuesser.

This may break again.
parent 49c4c7ec
......@@ -619,7 +619,13 @@ class CragrRegion(LoginBrowser):
):
self.unhandled_method(account.id)
date_guesser = LinearDateGuesser(date_max_bump=timedelta(30))
class NoCopyLinearDateGuesser(LinearDateGuesser):
# params passed to a @method are deepcopied, in each iteration of ItemElement
# so we want to avoid repeatedly copying objects since we wan't to keep using the same object
def __deepcopy__(self, memo):
return self
date_guesser = NoCopyLinearDateGuesser(date_max_bump=timedelta(30))
for tr in self.page.iter_history(date_guesser=date_guesser):
yield tr
......
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