2
0

Add option to force the posting of accounting move

This commit is contained in:
Andrea 2019-04-05 14:40:52 +02:00 committed by Andrea Stirpe
parent b60c1ab8e4
commit 1e66c61563
7 changed files with 41 additions and 7 deletions

View File

@ -120,6 +120,9 @@ class AccountSpread(models.Model):
display_recompute_buttons = fields.Boolean( display_recompute_buttons = fields.Boolean(
compute='_compute_display_recompute_buttons', compute='_compute_display_recompute_buttons',
string='Display Buttons Recompute') 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 @api.model
def default_get(self, fields): def default_get(self, fields):
@ -195,6 +198,13 @@ class AccountSpread(models.Model):
if spread.invoice_id.state == 'draft': if spread.invoice_id.state == 'draft':
spread.display_recompute_buttons = False 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 @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."""

View File

@ -41,8 +41,16 @@ class AccountInvoiceSpreadLine(models.Model):
spread.message_post(body=post_msg) spread.message_post(body=post_msg)
spread._reconcile_spread_moves(created_moves) spread._reconcile_spread_moves(created_moves)
if created_moves and spread.move_line_auto_post: self._post_spread_moves(spread, created_moves)
created_moves.post()
@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 @api.multi
def create_move(self): def create_move(self):
@ -151,3 +159,8 @@ class AccountInvoiceSpreadLine(models.Model):
('move_id', '=', False) ('move_id', '=', False)
]) ])
lines.create_and_reconcile_moves() 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()

View File

@ -22,5 +22,8 @@ class ResCompany(models.Model):
allow_spread_planning = fields.Boolean( allow_spread_planning = fields.Boolean(
default=True, default=True,
help="Disable this option if you do not want to allow the " 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.")

View File

@ -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 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, 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 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. 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.

View File

@ -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. 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. 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: 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. this will also reset all the journal entries previously created.

View File

@ -29,6 +29,7 @@
<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"/> <field name="display_recompute_buttons" invisible="1"/>
<field name="display_move_line_auto_post" invisible="1"/>
</group> </group>
</group> </group>
<group name="accounts"> <group name="accounts">
@ -79,7 +80,7 @@
<field name="invoice_line_id" readonly="1" attrs="{'invisible':[('invoice_line_id','=',False)]}"/> <field name="invoice_line_id" readonly="1" attrs="{'invisible':[('invoice_line_id','=',False)]}"/>
<field name="estimated_amount" attrs="{'readonly':[('invoice_line_id','!=',False)],'invisible':[('estimated_amount','=',0.0),('invoice_line_id','!=',False)]}"/> <field name="estimated_amount" attrs="{'readonly':[('invoice_line_id','!=',False)],'invisible':[('estimated_amount','=',0.0),('invoice_line_id','!=',False)]}"/>
<field name="total_amount" attrs="{'invisible':[('invoice_line_id','=',False)]}"/> <field name="total_amount" attrs="{'invisible':[('invoice_line_id','=',False)]}"/>
<field name="move_line_auto_post" /> <field name="move_line_auto_post" attrs="{'invisible':[('display_move_line_auto_post','=',False)]}"/>
</group> </group>
<group> <group>
<field name="period_number"/> <field name="period_number"/>

View File

@ -18,9 +18,12 @@
</group> </group>
</group> </group>
<group name="spreading_options"> <group name="spreading_options">
<group> <group name="spreading_options_left">
<field name="allow_spread_planning"/> <field name="allow_spread_planning"/>
</group> </group>
<group name="spreading_options_right">
<field name="force_move_auto_post"/>
</group>
</group> </group>
</page> </page>
</xpath> </xpath>