-
Notifications
You must be signed in to change notification settings - Fork 248
[IMP] l10n_ar_tax: add monthly cron to clean old padron files #1375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <odoo noupdate="1"> | ||
|
|
||
| <record id="cron_clean_old_padron_files" model="ir.cron"> | ||
| <field name="name">l10n_ar_tax: Clean old padron files</field> | ||
| <field name="model_id" ref="model_res_company_jurisdiction_padron"/> | ||
| <field name="state">code</field> | ||
| <field name="code">model._cron_clean_old_padron_files()</field> | ||
| <field name="interval_number">1</field> | ||
| <field name="interval_type">months</field> | ||
| </record> | ||
|
|
||
| </odoo> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from . import test_arba | ||
| from . import test_padron_cleanup_cron | ||
| from . import test_payment_receiptbook_and_withholding | ||
| from . import test_payment_withholding_validation | ||
| from . import test_withholding_thresholds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import base64 | ||
|
|
||
| from dateutil.relativedelta import relativedelta | ||
| from odoo import fields | ||
| from odoo.tests import common | ||
|
|
||
|
|
||
| class TestPadronCleanupCron(common.TransactionCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
| cls.padron_model = cls.env["res.company.jurisdiction.padron"] | ||
| cls.state_arba = cls.env.ref("base.state_ar_b") | ||
| cls.state_santa_fe = cls.env.ref("base.state_ar_s") | ||
| cls.company = cls.env.company | ||
| cls.dummy_file = base64.b64encode(b"dummy padron").decode() | ||
|
|
||
| def _create_padron(self, state, to_date): | ||
| return self.padron_model.create( | ||
| { | ||
| "company_id": self.company.id, | ||
| "state_id": state.id, | ||
| "file_padron": self.dummy_file, | ||
| "filename": "padron.txt", | ||
| "l10n_ar_padron_from_date": to_date + relativedelta(days=-30), | ||
| "l10n_ar_padron_to_date": to_date, | ||
| } | ||
| ) | ||
|
|
||
| def test_cron_deletes_only_old_padrons(self): | ||
| """Create 2 old and 2 new padrones, then verify the cron deletes only the 2 old ones.""" | ||
| threshold_date = fields.Date.start_of(fields.Date.context_today(self.padron_model), "month") + relativedelta( | ||
| years=-1 | ||
| ) | ||
|
|
||
| old_arba = self._create_padron(self.state_arba, threshold_date + relativedelta(days=-1)) | ||
| old_santa_fe = self._create_padron(self.state_santa_fe, threshold_date + relativedelta(days=-10)) | ||
| new_arba = self._create_padron(self.state_arba, threshold_date + relativedelta(days=1)) | ||
| new_santa_fe = self._create_padron(self.state_santa_fe, threshold_date + relativedelta(days=30)) | ||
|
|
||
| self.padron_model._cron_clean_old_padron_files() | ||
|
|
||
| self.assertFalse(old_arba.exists()) | ||
| self.assertFalse(old_santa_fe.exists()) | ||
| self.assertTrue(new_arba.exists()) | ||
| self.assertTrue(new_santa_fe.exists()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.