mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Improvements as per feedback
This commit is contained in:
@@ -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."""
|
||||
@@ -188,6 +199,12 @@ class AccountSpread(models.Model):
|
||||
else:
|
||||
if self.invoice_type in ['out_invoice', 'out_refund']:
|
||||
self.invoice_type = 'in_invoice'
|
||||
if self.template_id.period_number:
|
||||
self.period_number = self.template_id.period_number
|
||||
if self.template_id.period_type:
|
||||
self.period_type = self.template_id.period_type
|
||||
if self.template_id.start_date:
|
||||
self.spread_date = self.template_id.start_date
|
||||
|
||||
@api.onchange('invoice_type', 'company_id')
|
||||
def onchange_invoice_type(self):
|
||||
@@ -326,7 +343,11 @@ class AccountSpread(models.Model):
|
||||
spread_date = self._next_line_date(month_day, spread_date)
|
||||
|
||||
self.write({'line_ids': commands})
|
||||
self.message_post(body=_("Spread table created."))
|
||||
invoice_type_selection = dict(self.fields_get(
|
||||
allfields=['invoice_type']
|
||||
)['invoice_type']['selection'])[self.invoice_type]
|
||||
msg_body = _("Spread table '%s' created.") % invoice_type_selection
|
||||
self.message_post(body=msg_body)
|
||||
|
||||
@api.multi
|
||||
def _get_number_of_periods(self, month_day):
|
||||
@@ -398,8 +419,28 @@ class AccountSpread(models.Model):
|
||||
for spread in self:
|
||||
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"))
|
||||
msg_body = _("Unlinked invoice line '%s' (view %s).") % (
|
||||
spread.invoice_line_id.name, inv_link)
|
||||
spread.message_post(body=msg_body)
|
||||
spread.write({'invoice_line_ids': [(5, 0, 0)]})
|
||||
|
||||
@api.multi
|
||||
def unlink(self):
|
||||
for spread in self:
|
||||
if spread.invoice_line_id:
|
||||
raise UserError(
|
||||
_('Cannot delete spread(s) that are linked '
|
||||
'to an invoice line.'))
|
||||
posted_line_ids = self.line_ids.filtered(
|
||||
lambda x: x.move_id.state == 'posted')
|
||||
if posted_line_ids:
|
||||
raise ValidationError(
|
||||
_('Cannot delete spread(s): there are some '
|
||||
'posted Journal Entries.'))
|
||||
return super().unlink()
|
||||
|
||||
@api.multi
|
||||
def reconcile_spread_moves(self):
|
||||
for spread in self:
|
||||
@@ -446,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:
|
||||
|
||||
@@ -34,7 +34,10 @@ class AccountInvoiceSpreadLine(models.Model):
|
||||
|
||||
if created_moves:
|
||||
post_msg = _("Created move(s) ")
|
||||
post_msg += ", ".join(str(id) for id in created_moves.ids)
|
||||
post_msg += ", ".join(
|
||||
'<a href=# data-oe-model=account.move data-oe-id=%d'
|
||||
'>%s</a>' % (move.id, move.name)
|
||||
for move in created_moves)
|
||||
spread.message_post(body=post_msg)
|
||||
|
||||
spread._reconcile_spread_moves(created_moves)
|
||||
|
||||
@@ -27,6 +27,15 @@ class AccountSpreadTemplate(models.Model):
|
||||
'account.account',
|
||||
string='Spread Balance Sheet Account',
|
||||
required=True)
|
||||
period_number = fields.Integer(
|
||||
string='Number of Repetitions',
|
||||
help="Define the number of spread lines")
|
||||
period_type = fields.Selection([
|
||||
('month', 'Month'),
|
||||
('quarter', 'Quarter'),
|
||||
('year', 'Year')],
|
||||
help="Period length for the entries")
|
||||
start_date = fields.Date()
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
@@ -74,5 +83,12 @@ class AccountSpreadTemplate(models.Model):
|
||||
invoice_type = 'in_invoice'
|
||||
spread_vals['credit_account_id'] = self.spread_account_id.id
|
||||
|
||||
if self.period_number:
|
||||
spread_vals['period_number'] = self.period_number
|
||||
if self.period_type:
|
||||
spread_vals['period_type'] = self.period_type
|
||||
if self.start_date:
|
||||
spread_vals['spread_date'] = self.start_date
|
||||
|
||||
spread_vals['invoice_type'] = invoice_type
|
||||
return spread_vals
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
from odoo.tools import convert_file
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
class TestAccountInvoiceSpread(common.TransactionCase):
|
||||
|
||||
def _load(self, module, *args):
|
||||
convert_file(
|
||||
@@ -724,3 +724,16 @@ class TestAccountInvoiceSpread(AccountingTestCase):
|
||||
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)
|
||||
|
||||
@@ -8,10 +8,10 @@ from psycopg2 import IntegrityError
|
||||
from odoo.tools import convert_file, mute_logger
|
||||
from odoo.modules.module import get_module_resource
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAccountSpreadCostRevenue(AccountingTestCase):
|
||||
class TestAccountSpreadCostRevenue(common.TransactionCase):
|
||||
|
||||
def _load(self, module, *args):
|
||||
convert_file(
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# Copyright 2017-2018 Onestein (<https://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
|
||||
from odoo.tests import common
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class TestComputeSpreadBoard(AccountingTestCase):
|
||||
class TestComputeSpreadBoard(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
@@ -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)]}" />
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
<group>
|
||||
<field name="spread_type"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="period_number"/>
|
||||
<field name="period_type"/>
|
||||
<field name="start_date"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="spread_account_id" domain="[('company_id', '=', company_id), ('deprecated', '=', False)]" options="{'no_create': True}"/>
|
||||
|
||||
@@ -147,6 +147,7 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
||||
spread_vals = self.template_id._prepare_spread_from_template()
|
||||
|
||||
date_invoice = self.invoice_id.date_invoice
|
||||
date_invoice = date_invoice or self.template_id.start_date
|
||||
date_invoice = date_invoice or fields.Date.today()
|
||||
spread_vals['spread_date'] = date_invoice
|
||||
|
||||
|
||||
Reference in New Issue
Block a user