Add option to disable spread planning + code review
This commit is contained in:
parent
5d7390183d
commit
b60c1ab8e4
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2016-2018 Onestein (<https://www.onestein.eu>)
|
# Copyright 2016-2019 Onestein (<https://www.onestein.eu>)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -49,10 +49,12 @@ class AccountInvoiceLine(models.Model):
|
|||||||
|
|
||||||
# In case no spread board is linked to the invoice line
|
# In case no spread board is linked to the invoice line
|
||||||
# open the wizard to link them
|
# open the wizard to link them
|
||||||
|
company = self.invoice_id.company_id
|
||||||
ctx = dict(
|
ctx = dict(
|
||||||
self.env.context,
|
self.env.context,
|
||||||
default_invoice_line_id=self.id,
|
default_invoice_line_id=self.id,
|
||||||
default_company_id=self.invoice_id.company_id.id,
|
default_company_id=company.id,
|
||||||
|
allow_spread_planning=company.allow_spread_planning,
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
'name': _('Link Invoice Line with Spread Board'),
|
'name': _('Link Invoice Line with Spread Board'),
|
||||||
|
@ -117,6 +117,9 @@ class AccountSpread(models.Model):
|
|||||||
display_create_all_moves = fields.Boolean(
|
display_create_all_moves = fields.Boolean(
|
||||||
compute='_compute_display_create_all_moves',
|
compute='_compute_display_create_all_moves',
|
||||||
string='Display Button All Moves')
|
string='Display Button All Moves')
|
||||||
|
display_recompute_buttons = fields.Boolean(
|
||||||
|
compute='_compute_display_recompute_buttons',
|
||||||
|
string='Display Buttons Recompute')
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields):
|
def default_get(self, fields):
|
||||||
@ -184,6 +187,14 @@ class AccountSpread(models.Model):
|
|||||||
else:
|
else:
|
||||||
spread.display_create_all_moves = False
|
spread.display_create_all_moves = False
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def _compute_display_recompute_buttons(self):
|
||||||
|
for spread in self:
|
||||||
|
spread.display_recompute_buttons = True
|
||||||
|
if not spread.company_id.allow_spread_planning:
|
||||||
|
if spread.invoice_id.state == 'draft':
|
||||||
|
spread.display_recompute_buttons = False
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _get_spread_entry_name(self, seq):
|
def _get_spread_entry_name(self, seq):
|
||||||
"""Use this method to customise the name of the accounting entry."""
|
"""Use this method to customise the name of the accounting entry."""
|
||||||
@ -258,7 +269,7 @@ class AccountSpread(models.Model):
|
|||||||
'with selected invoice type'))
|
'with selected invoice type'))
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_spread_period_duration(self):
|
def _get_spread_period_duration(self):
|
||||||
"""Converts the selected period_type to number of months."""
|
"""Converts the selected period_type to number of months."""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
if self.period_type == 'year':
|
if self.period_type == 'year':
|
||||||
@ -277,7 +288,7 @@ class AccountSpread(models.Model):
|
|||||||
# if we already have some previous validated entries,
|
# if we already have some previous validated entries,
|
||||||
# starting date is last entry + method period
|
# starting date is last entry + method period
|
||||||
last_date = posted_line_ids[-1].date
|
last_date = posted_line_ids[-1].date
|
||||||
months = self._compute_spread_period_duration()
|
months = self._get_spread_period_duration()
|
||||||
spread_date = last_date + relativedelta(months=months)
|
spread_date = last_date + relativedelta(months=months)
|
||||||
else:
|
else:
|
||||||
spread_date = self.spread_date
|
spread_date = self.spread_date
|
||||||
@ -289,7 +300,7 @@ class AccountSpread(models.Model):
|
|||||||
is used by "def _compute_spread_board()" method.
|
is used by "def _compute_spread_board()" method.
|
||||||
"""
|
"""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
months = self._compute_spread_period_duration()
|
months = self._get_spread_period_duration()
|
||||||
date = date + relativedelta(months=months)
|
date = date + relativedelta(months=months)
|
||||||
# get the last day of the month
|
# get the last day of the month
|
||||||
if month_day > 28:
|
if month_day > 28:
|
||||||
@ -512,7 +523,8 @@ class AccountSpread(models.Model):
|
|||||||
if not line.move_id:
|
if not line.move_id:
|
||||||
line.create_move()
|
line.create_move()
|
||||||
|
|
||||||
@api.multi
|
@api.depends(
|
||||||
|
'debit_account_id.deprecated', 'credit_account_id.deprecated')
|
||||||
def _compute_deprecated_accounts(self):
|
def _compute_deprecated_accounts(self):
|
||||||
for spread in self:
|
for spread in self:
|
||||||
debit_deprecated = bool(spread.debit_account_id.deprecated)
|
debit_deprecated = bool(spread.debit_account_id.deprecated)
|
||||||
|
@ -18,3 +18,9 @@ class ResCompany(models.Model):
|
|||||||
|
|
||||||
default_spread_expense_journal_id = fields.Many2one(
|
default_spread_expense_journal_id = fields.Many2one(
|
||||||
'account.journal', string='Expense Spread Journal')
|
'account.journal', string='Expense Spread Journal')
|
||||||
|
|
||||||
|
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.",
|
||||||
|
)
|
||||||
|
@ -10,3 +10,8 @@ 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 Revenues*,
|
||||||
* the *Default Spread Account for Expenses*.
|
* 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.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2018 Onestein (<https://www.onestein.eu>)
|
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -123,6 +123,7 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
wizard1 = Wizard.with_context(
|
wizard1 = Wizard.with_context(
|
||||||
default_invoice_line_id=self.invoice_line.id,
|
default_invoice_line_id=self.invoice_line.id,
|
||||||
default_company_id=my_company.id,
|
default_company_id=my_company.id,
|
||||||
|
allow_spread_planning=True,
|
||||||
).create({})
|
).create({})
|
||||||
|
|
||||||
self.assertEqual(wizard1.invoice_line_id, self.invoice_line)
|
self.assertEqual(wizard1.invoice_line_id, self.invoice_line)
|
||||||
@ -144,7 +145,7 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
self.assertEqual(wizard2.invoice_type, 'out_invoice')
|
self.assertEqual(wizard2.invoice_type, 'out_invoice')
|
||||||
self.assertFalse(wizard2.spread_id)
|
self.assertFalse(wizard2.spread_id)
|
||||||
self.assertEqual(wizard2.company_id, my_company)
|
self.assertEqual(wizard2.company_id, my_company)
|
||||||
self.assertEqual(wizard2.spread_action_type, 'link')
|
self.assertEqual(wizard2.spread_action_type, 'template')
|
||||||
self.assertFalse(wizard2.spread_account_id)
|
self.assertFalse(wizard2.spread_account_id)
|
||||||
self.assertFalse(wizard2.spread_journal_id)
|
self.assertFalse(wizard2.spread_journal_id)
|
||||||
|
|
||||||
@ -169,6 +170,7 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
wizard1 = Wizard.with_context(
|
wizard1 = Wizard.with_context(
|
||||||
default_invoice_line_id=self.invoice_line.id,
|
default_invoice_line_id=self.invoice_line.id,
|
||||||
default_company_id=my_company.id,
|
default_company_id=my_company.id,
|
||||||
|
allow_spread_planning=True,
|
||||||
).create({})
|
).create({})
|
||||||
|
|
||||||
self.assertEqual(wizard1.invoice_line_id, self.invoice_line)
|
self.assertEqual(wizard1.invoice_line_id, self.invoice_line)
|
||||||
@ -200,7 +202,7 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
self.assertEqual(wizard2.invoice_type, 'out_invoice')
|
self.assertEqual(wizard2.invoice_type, 'out_invoice')
|
||||||
self.assertFalse(wizard2.spread_id)
|
self.assertFalse(wizard2.spread_id)
|
||||||
self.assertEqual(wizard2.company_id, my_company)
|
self.assertEqual(wizard2.company_id, my_company)
|
||||||
self.assertEqual(wizard2.spread_action_type, 'link')
|
self.assertEqual(wizard2.spread_action_type, 'template')
|
||||||
self.assertFalse(wizard2.spread_account_id)
|
self.assertFalse(wizard2.spread_account_id)
|
||||||
self.assertFalse(wizard2.spread_journal_id)
|
self.assertFalse(wizard2.spread_journal_id)
|
||||||
|
|
||||||
@ -221,6 +223,7 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
wizard1 = Wizard.with_context(
|
wizard1 = Wizard.with_context(
|
||||||
default_invoice_line_id=self.invoice_line.id,
|
default_invoice_line_id=self.invoice_line.id,
|
||||||
default_company_id=my_company.id,
|
default_company_id=my_company.id,
|
||||||
|
allow_spread_planning=True,
|
||||||
).create({})
|
).create({})
|
||||||
self.assertEqual(wizard1.spread_action_type, 'link')
|
self.assertEqual(wizard1.spread_action_type, 'link')
|
||||||
|
|
||||||
@ -717,7 +720,6 @@ class TestAccountInvoiceSpread(common.TransactionCase):
|
|||||||
|
|
||||||
other_journal = self.env['account.journal'].create({
|
other_journal = self.env['account.journal'].create({
|
||||||
'name': 'Other Journal', 'type': 'general', 'code': 'test2'})
|
'name': 'Other Journal', 'type': 'general', 'code': 'test2'})
|
||||||
self.assertTrue(other_journal)
|
|
||||||
with self.assertRaises(ValidationError):
|
with self.assertRaises(ValidationError):
|
||||||
self.spread2.journal_id = other_journal
|
self.spread2.journal_id = other_journal
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright 2018 Onestein (<https://www.onestein.eu>)
|
# Copyright 2018-2019 Onestein (<https://www.onestein.eu>)
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
<header>
|
<header>
|
||||||
<button name="compute_spread_board" type="object" string="Recalculate unposted lines" class="oe_highlight" attrs="{'invisible': [('debit_account_id', '=', False)]}" />
|
<button name="compute_spread_board" type="object" string="Recalculate unposted lines" class="oe_highlight" attrs="{'invisible': ['|',('debit_account_id', '=', False),('display_recompute_buttons', '=', False)]}" />
|
||||||
<button name="action_recalculate_spread" type="object" string="Recalculate entire spread" attrs="{'invisible': [('debit_account_id', '=', False)]}" groups="account.group_account_manager" />
|
<button name="action_recalculate_spread" type="object" string="Recalculate entire spread" attrs="{'invisible': ['|',('debit_account_id', '=', False),('display_recompute_buttons', '=', False)]}" groups="account.group_account_manager" />
|
||||||
<button name="action_undo_spread" type="object" string="Undo spread" attrs="{'invisible': [('line_ids', '=', [])]}" groups="account.group_account_manager" />
|
<button name="action_undo_spread" type="object" string="Undo spread" attrs="{'invisible': [('line_ids', '=', [])]}" groups="account.group_account_manager" />
|
||||||
<button name="action_unlink_invoice_line" type="object" string="Unlink Invoice Line" attrs="{'invisible': [('invoice_line_id', '=', False)]}" groups="account.group_account_manager" />
|
<button name="action_unlink_invoice_line" type="object" string="Unlink Invoice Line" attrs="{'invisible': [('invoice_line_id', '=', False)]}" groups="account.group_account_manager" />
|
||||||
</header>
|
</header>
|
||||||
@ -28,6 +28,7 @@
|
|||||||
<group name="spread_definitions">
|
<group name="spread_definitions">
|
||||||
<field name="template_id"/>
|
<field name="template_id"/>
|
||||||
<field name="invoice_type" attrs="{'readonly':[('invoice_line_id','!=',False)]}"/>
|
<field name="invoice_type" attrs="{'readonly':[('invoice_line_id','!=',False)]}"/>
|
||||||
|
<field name="display_recompute_buttons" invisible="1"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group name="accounts">
|
<group name="accounts">
|
||||||
|
@ -8,15 +8,20 @@
|
|||||||
<xpath expr="//notebook">
|
<xpath expr="//notebook">
|
||||||
<page name="account_spread_cost_revenue" string="Account Spread" groups="account.group_account_manager">
|
<page name="account_spread_cost_revenue" string="Account Spread" groups="account.group_account_manager">
|
||||||
<group>
|
<group>
|
||||||
<group string="Default Spread Accounts">
|
<group string="Default Spread Accounts" name="default_spread_accounts">
|
||||||
<field name="default_spread_revenue_account_id" />
|
<field name="default_spread_revenue_account_id" />
|
||||||
<field name="default_spread_expense_account_id" />
|
<field name="default_spread_expense_account_id" />
|
||||||
</group>
|
</group>
|
||||||
<group string="Default Spread Journals">
|
<group string="Default Spread Journals" name="default_spread_journals">
|
||||||
<field name="default_spread_revenue_journal_id" />
|
<field name="default_spread_revenue_journal_id" />
|
||||||
<field name="default_spread_expense_journal_id" />
|
<field name="default_spread_expense_journal_id" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
<group name="spreading_options">
|
||||||
|
<group>
|
||||||
|
<field name="allow_spread_planning"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
@ -8,6 +8,24 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
|||||||
_name = 'account.spread.invoice.line.link.wizard'
|
_name = 'account.spread.invoice.line.link.wizard'
|
||||||
_description = 'Account Spread Invoice Line Link Wizard'
|
_description = 'Account Spread Invoice Line Link Wizard'
|
||||||
|
|
||||||
|
def _selection_spread_action_type(self):
|
||||||
|
base_selection = [
|
||||||
|
('template', 'Create from spread template'),
|
||||||
|
('new', 'Create new spread board')
|
||||||
|
]
|
||||||
|
if not self.env.context.get('allow_spread_planning'):
|
||||||
|
return base_selection
|
||||||
|
|
||||||
|
link_selection = [
|
||||||
|
('link', 'Link to existing spread board'),
|
||||||
|
]
|
||||||
|
return link_selection + base_selection
|
||||||
|
|
||||||
|
def _selection_default_spread_action_type(self):
|
||||||
|
if not self.env.context.get('allow_spread_planning'):
|
||||||
|
return 'template'
|
||||||
|
return 'link'
|
||||||
|
|
||||||
invoice_line_id = fields.Many2one(
|
invoice_line_id = fields.Many2one(
|
||||||
'account.invoice.line',
|
'account.invoice.line',
|
||||||
string='Invoice Line',
|
string='Invoice Line',
|
||||||
@ -36,11 +54,9 @@ class AccountSpreadInvoiceLineLinkWizard(models.TransientModel):
|
|||||||
'res.company',
|
'res.company',
|
||||||
string='Company',
|
string='Company',
|
||||||
required=True)
|
required=True)
|
||||||
spread_action_type = fields.Selection([
|
spread_action_type = fields.Selection(
|
||||||
('link', 'Link to existing spread board'),
|
selection=_selection_spread_action_type,
|
||||||
('template', 'Create from spread template'),
|
default=_selection_default_spread_action_type)
|
||||||
('new', 'Create new spread board')],
|
|
||||||
default='link')
|
|
||||||
template_id = fields.Many2one(
|
template_id = fields.Many2one(
|
||||||
'account.spread.template',
|
'account.spread.template',
|
||||||
string='Spread Template')
|
string='Spread Template')
|
||||||
|
Loading…
Reference in New Issue
Block a user