2
0

Add button to post all spread lines

This commit is contained in:
Andrea 2018-12-21 09:17:51 +01:00 committed by Andrea Stirpe
parent 3fbfa32f73
commit 85584004f0
4 changed files with 35 additions and 3 deletions

View File

@ -114,6 +114,9 @@ class AccountSpread(models.Model):
'account.analytic.tag',
string='Analytic Tags')
move_line_auto_post = fields.Boolean('Auto-post lines', default=True)
display_create_all_moves = fields.Boolean(
compute='_compute_display_create_all_moves',
string='Display Button All Moves')
@api.model
def default_get(self, fields):
@ -173,6 +176,14 @@ class AccountSpread(models.Model):
spread.posted_amount = posted_amount
spread.total_amount = total_amount
@api.multi
def _compute_display_create_all_moves(self):
for spread in self:
if any(not line.move_id for line in spread.line_ids):
spread.display_create_all_moves = True
else:
spread.display_create_all_moves = False
@api.multi
def _get_spread_entry_name(self, seq):
"""Use this method to customise the name of the accounting entry."""
@ -409,8 +420,7 @@ class AccountSpread(models.Model):
spread_mls = spread.line_ids.mapped('move_id.line_ids')
spread_mls.remove_move_reconcile()
inv_link = '<a href=# data-oe-model=account.invoice ' \
'data-oe-id=%d>%s</a>' % (
spread.invoice_id.id, _("Invoice"))
'data-oe-id=%d>%s</a>' % (spread.invoice_id.id, _("Invoice"))
msg_body = _("Unlinked invoice line '%s' (view %s).") % (
spread.invoice_line_id.name, inv_link)
spread.message_post(body=msg_body)
@ -477,6 +487,13 @@ class AccountSpread(models.Model):
do_reconcile.remove_move_reconcile()
do_reconcile.reconcile()
@api.multi
def create_all_moves(self):
for spread in self:
for line in spread.line_ids:
if not line.move_id:
line.create_move()
@api.multi
def _compute_deprecated_accounts(self):
for spread in self:

View File

@ -1 +0,0 @@
* Add option to post all spread lines in one click

View File

@ -724,3 +724,16 @@ class TestAccountInvoiceSpread(common.TransactionCase):
self.assertTrue(other_journal)
with self.assertRaises(ValidationError):
self.spread2.journal_id = other_journal
def test_14_create_all_moves(self):
self.spread.compute_spread_board()
spread_lines = self.spread.line_ids
self.assertEqual(len(spread_lines), 12)
for line in spread_lines:
self.assertFalse(line.move_id)
# create moves for all the spread lines
self.spread.create_all_moves()
spread_lines = self.spread.line_ids
for line in spread_lines:
self.assertTrue(line.move_id)

View File

@ -107,6 +107,9 @@
<group name="extension_left">
</group>
<group name="extension_right">
<field name="display_create_all_moves" invisible="1"/>
<button name="create_all_moves" string="Create All Moves" type="object"
icon="fa-play" attrs="{'invisible':[('display_create_all_moves','!=',True)]}"/>
<field name="unspread_amount" attrs="{'invisible': [('unspread_amount', '=', 0)]}" />
<field name="unposted_amount" attrs="{'invisible': [('unposted_amount', '=', 0)]}" />
<field name="posted_amount" attrs="{'invisible': [('posted_amount', '=', 0)]}" />