From c8c7431ed71792689335a10a17dc27e5e2079b44 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 21 Aug 2019 13:18:42 +0200 Subject: [PATCH] Add option to auto-archive spreads --- .../models/account_spread.py | 5 +++++ .../models/account_spread_line.py | 5 +++++ .../models/res_company.py | 4 ++++ account_spread_cost_revenue/readme/CONFIGURE.rst | 3 +++ .../views/account_spread.xml | 16 ++++++++++++++++ .../views/res_company.xml | 1 + 6 files changed, 34 insertions(+) diff --git a/account_spread_cost_revenue/models/account_spread.py b/account_spread_cost_revenue/models/account_spread.py index 7bb8b94cc..1cfbc979a 100644 --- a/account_spread_cost_revenue/models/account_spread.py +++ b/account_spread_cost_revenue/models/account_spread.py @@ -68,6 +68,9 @@ class AccountSpread(models.Model): total_amount = fields.Float( digits=dp.get_precision('Account'), compute='_compute_amounts') + all_posted = fields.Boolean( + compute='_compute_amounts', + store=True) line_ids = fields.One2many( 'account.spread.line', 'spread_id', @@ -123,6 +126,7 @@ class AccountSpread(models.Model): display_move_line_auto_post = fields.Boolean( compute='_compute_display_move_line_auto_post', string='Display Button Auto-post lines') + active = fields.Boolean(default=True) @api.model def default_get(self, fields): @@ -181,6 +185,7 @@ class AccountSpread(models.Model): spread.unposted_amount = total_amount - posted_amount spread.posted_amount = posted_amount spread.total_amount = total_amount + spread.all_posted = spread.unposted_amount == 0.0 @api.multi def _compute_display_create_all_moves(self): diff --git a/account_spread_cost_revenue/models/account_spread_line.py b/account_spread_cost_revenue/models/account_spread_line.py index b6b04ad8e..48a39c933 100644 --- a/account_spread_cost_revenue/models/account_spread_line.py +++ b/account_spread_cost_revenue/models/account_spread_line.py @@ -166,3 +166,8 @@ class AccountInvoiceSpreadLine(models.Model): 'move_id').filtered(lambda m: m.state != 'posted') unposted_moves.filtered( lambda m: m.company_id.force_move_auto_post).post() + + spreads_to_archive = self.env['account.spread'].search([ + ('all_posted', '=', True) + ]).filtered(lambda s: s.company_id.auto_archive) + spreads_to_archive.write({'active': False}) diff --git a/account_spread_cost_revenue/models/res_company.py b/account_spread_cost_revenue/models/res_company.py index 8f5239e1a..8b5d17eba 100644 --- a/account_spread_cost_revenue/models/res_company.py +++ b/account_spread_cost_revenue/models/res_company.py @@ -27,3 +27,7 @@ class ResCompany(models.Model): 'Auto-post spread lines', help="Enable this option if you want to post automatically the " "accounting moves of all the spreads.") + auto_archive = fields.Boolean( + 'Auto-archive spread', + help="Enable this option if you want the cron job to automatically " + "archive the spreads when all lines are posted.") diff --git a/account_spread_cost_revenue/readme/CONFIGURE.rst b/account_spread_cost_revenue/readme/CONFIGURE.rst index d216dc31f..594bb201d 100644 --- a/account_spread_cost_revenue/readme/CONFIGURE.rst +++ b/account_spread_cost_revenue/readme/CONFIGURE.rst @@ -18,3 +18,6 @@ the company disable the *Allow Spread Planning* option. On the form view of the company, the *Auto-post spread lines* option forces the account moves created during the cost/revenue spreading to be automatically posted. When this option is false, the user can enable/disable the automatic posting by the flag *Auto-post lines* present in the spread board. + +On the form view of the company, enable the *Auto-archive spread* option if you want the +cron job to automatically archive the spreads when all lines are posted. diff --git a/account_spread_cost_revenue/views/account_spread.xml b/account_spread_cost_revenue/views/account_spread.xml index fd283b9d8..a2de275e9 100644 --- a/account_spread_cost_revenue/views/account_spread.xml +++ b/account_spread_cost_revenue/views/account_spread.xml @@ -19,6 +19,12 @@ type="object" string="Reconciled entries"> +