mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Add option to auto-archive spreads
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user