diff --git a/account_spread_cost_revenue/models/account_spread.py b/account_spread_cost_revenue/models/account_spread.py index 87d0184b..05d0df57 100644 --- a/account_spread_cost_revenue/models/account_spread.py +++ b/account_spread_cost_revenue/models/account_spread.py @@ -120,6 +120,9 @@ class AccountSpread(models.Model): display_recompute_buttons = fields.Boolean( compute='_compute_display_recompute_buttons', string='Display Buttons Recompute') + display_move_line_auto_post = fields.Boolean( + compute='_compute_display_move_line_auto_post', + string='Display Button Auto-post lines') @api.model def default_get(self, fields): @@ -195,6 +198,13 @@ class AccountSpread(models.Model): if spread.invoice_id.state == 'draft': spread.display_recompute_buttons = False + @api.multi + def _compute_display_move_line_auto_post(self): + for spread in self: + spread.display_move_line_auto_post = True + if spread.company_id.force_move_auto_post: + spread.display_move_line_auto_post = False + @api.multi def _get_spread_entry_name(self, seq): """Use this method to customise the name of the accounting entry.""" diff --git a/account_spread_cost_revenue/models/account_spread_line.py b/account_spread_cost_revenue/models/account_spread_line.py index 5e683c51..f3a7650d 100644 --- a/account_spread_cost_revenue/models/account_spread_line.py +++ b/account_spread_cost_revenue/models/account_spread_line.py @@ -41,8 +41,16 @@ class AccountInvoiceSpreadLine(models.Model): spread.message_post(body=post_msg) spread._reconcile_spread_moves(created_moves) - if created_moves and spread.move_line_auto_post: - created_moves.post() + self._post_spread_moves(spread, created_moves) + + @api.model + def _post_spread_moves(self, spread, moves): + if not moves: + return + if spread.company_id.force_move_auto_post: + moves.post() + elif spread.move_line_auto_post: + moves.post() @api.multi def create_move(self): @@ -151,3 +159,8 @@ class AccountInvoiceSpreadLine(models.Model): ('move_id', '=', False) ]) lines.create_and_reconcile_moves() + + unposted_moves = self.search([('move_id', '!=', False)]).mapped( + 'move_id').filtered(lambda m: m.state != 'posted') + unposted_moves.filtered( + lambda m: m.company_id.force_move_auto_post).post() diff --git a/account_spread_cost_revenue/models/res_company.py b/account_spread_cost_revenue/models/res_company.py index 6efd3cbe..8f5239e1 100644 --- a/account_spread_cost_revenue/models/res_company.py +++ b/account_spread_cost_revenue/models/res_company.py @@ -22,5 +22,8 @@ class ResCompany(models.Model): allow_spread_planning = fields.Boolean( default=True, help="Disable this option if you do not want to allow the " - "spreading before the invoice is validated.", - ) + "spreading before the invoice is validated.") + force_move_auto_post = fields.Boolean( + 'Auto-post spread lines', + help="Enable this option if you want to post automatically the " + "accounting moves of all the spreads.") diff --git a/account_spread_cost_revenue/readme/CONFIGURE.rst b/account_spread_cost_revenue/readme/CONFIGURE.rst index 4c61e939..d216dc31 100644 --- a/account_spread_cost_revenue/readme/CONFIGURE.rst +++ b/account_spread_cost_revenue/readme/CONFIGURE.rst @@ -11,7 +11,10 @@ In the same *Account Spread* tab, you can also configure the Spread Balance Shee * the *Default Spread Account for Revenues*, * the *Default Spread Account for Expenses*. - This module by default allows the spreading even before the receipt of the invoice or when the invoice is still draft, so that it is possible to work on the plan of the cost/revenue spreading. To disable this feature, on the form view of 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. diff --git a/account_spread_cost_revenue/readme/USAGE.rst b/account_spread_cost_revenue/readme/USAGE.rst index 916c299f..da01e39e 100644 --- a/account_spread_cost_revenue/readme/USAGE.rst +++ b/account_spread_cost_revenue/readme/USAGE.rst @@ -28,6 +28,7 @@ A cron job will automatically create the accounting moves for all the lines havi By default, the status of the created accounting moves is posted. To disable the automatic posting of the accounting moves, set the flag *Auto-post lines* to False. +This flag is only available when the *Auto-post spread lines* option, present on the form view of the company, is disabled. Click on button *Recalculate entire spread* button in the spread board to force the recalculation of the spread lines: this will also reset all the journal entries previously created. diff --git a/account_spread_cost_revenue/views/account_spread.xml b/account_spread_cost_revenue/views/account_spread.xml index f7c96366..fd283b9d 100644 --- a/account_spread_cost_revenue/views/account_spread.xml +++ b/account_spread_cost_revenue/views/account_spread.xml @@ -29,6 +29,7 @@ + @@ -79,7 +80,7 @@ - + diff --git a/account_spread_cost_revenue/views/res_company.xml b/account_spread_cost_revenue/views/res_company.xml index a93f40c1..83307b91 100644 --- a/account_spread_cost_revenue/views/res_company.xml +++ b/account_spread_cost_revenue/views/res_company.xml @@ -18,9 +18,12 @@ - + + + +