-
-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_move_default_journal: A module to have more meaningful …
…journals defaults in forms.
- Loading branch information
1 parent
2975fdc
commit 96cd47b
Showing
8 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2021 Therp BV <https://therp.nl> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Default Journal", | ||
"version": "14.0.1.0.0", | ||
"author": "Therp BV,Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"category": "Accounting & Finance", | ||
"summary": "Configure a default journal for new account moves", | ||
"depends": [ | ||
'account', | ||
], | ||
"data": [ | ||
'views/account_config_settings.xml' | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_config_settings | ||
from . import account_move |
74 changes: 74 additions & 0 deletions
74
account_move_default_journal/models/account_config_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2021 Therp BV <https://therp.nl> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
account_move_default_general_journal_id = fields.Many2one( | ||
'account.journal', string='Default journal for new general bookings' | ||
) | ||
account_move_default_sale_journal_id = fields.Many2one( | ||
'account.journal', string='Default journal for new sale bookings' | ||
) | ||
account_move_default_purchase_journal_id = fields.Many2one( | ||
'account.journal', string='Default journal for new purchase bookings' | ||
) | ||
|
||
def set_values(self): | ||
super(ResConfigSettings, self).set_values() | ||
|
||
if self.account_move_default_general_journal_id: | ||
self.env['ir.config_parameter'].set_param( | ||
'account_move_default_journal.general_journal_id', | ||
self.account_move_default_general_journal_id.id) | ||
if self.account_move_default_sale_journal_id: | ||
self.env['ir.config_parameter'].set_param( | ||
'account_move_default_journal.sale_journal_id', | ||
self.account_move_default_sale_journal_id.id) | ||
if self.account_move_default_purchase_journal_id: | ||
self.env['ir.config_parameter'].set_param( | ||
'account_move_default_journal.purchase_journal_id', | ||
self.account_move_default_purchase_journal_id.id) | ||
|
||
@api.model | ||
def get_values(self): | ||
res = super(ResConfigSettings, self).get_values() | ||
|
||
# General | ||
journal_id = self._get_value( | ||
'account_move_default_journal.general_journal_id' | ||
) | ||
if journal_id: | ||
res.update( | ||
account_move_default_general_journal_id=journal_id | ||
) | ||
|
||
# Sale | ||
journal_id = self._get_value( | ||
'account_move_default_journal.sale_journal_id' | ||
) | ||
if journal_id: | ||
res.update( | ||
account_move_default_sale_journal_id=journal_id | ||
) | ||
|
||
# Purchase | ||
journal_id = self._get_value( | ||
'account_move_default_journal.purchase_journal_id' | ||
) | ||
if journal_id: | ||
res.update( | ||
account_move_default_purchase_journal_id=journal_id | ||
) | ||
|
||
return res | ||
|
||
def _get_value(self, config_key): | ||
journal_id = self.env['ir.config_parameter'].get_param(config_key) | ||
if journal_id: | ||
journal_id = int(journal_id) | ||
return self.env['account.journal'].browse(journal_id) | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2021 Therp BV <https://therp.nl> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = 'account.move' | ||
|
||
@api.model | ||
def _search_default_journal(self, journal_types): | ||
company_id = self._context.get('default_company_id', | ||
self.env.company.id) | ||
domain = [ | ||
('company_id', '=', company_id), | ||
('type', 'in', journal_types), | ||
] | ||
if self._context.get('default_currency_id'): | ||
domain.push( | ||
('currency_id', '=', self._context['default_currency_id']) | ||
) | ||
|
||
# Use the appropriate config parameter for the journal type | ||
journal_id = None | ||
if 'sale' in journal_types: | ||
journal_id = self.env['ir.config_parameter'].get_param( | ||
'account_move_default_journal.sale_journal_id') | ||
elif 'purchase' in journal_types: | ||
journal_id = self.env['ir.config_parameter'].get_param( | ||
'account_move_default_journal.purchase_journal_id') | ||
elif 'general' in journal_types: | ||
journal_id = self.env['ir.config_parameter'].get_param( | ||
'account_move_default_journal.general_journal_id') | ||
|
||
# Try to get the journal, or default back to normal behavior | ||
if journal_id: | ||
journal_id = int(journal_id) | ||
journal = self.env['account.journal'].search([ | ||
'&', | ||
('id', '=', journal_id), | ||
'&', | ||
*domain | ||
]) | ||
else: | ||
journal = super()._search_default_journal(journal_types) | ||
|
||
return journal | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Danny de Jong <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This module allows you to set defaults for journals, so that default values for | ||
the journal field in forms can be configured. For one, this prevents users from | ||
accidentally picking an old journal that gets usually offered as a default. |
49 changes: 49 additions & 0 deletions
49
account_move_default_journal/views/account_config_settings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
<record id="res_config_settings_view_form" model="ir.ui.view"> | ||
<field name="name">res.config.settings.view.form.inherit.journals</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="account.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div[@data-key='account']" position="inside"> | ||
<h2>Journals</h2> | ||
<div class="row mt16 o_settings_container" | ||
id="journals_setting_container"> | ||
<div class="col-12 col-lg-6 o_setting_box"> | ||
<div class="o_setting_left_pane"/> | ||
<div class="o_setting_left_pane" /> | ||
<div class="o_setting_right_pane"> | ||
<span class="o_form_label">Default Journals</span> | ||
<div class="text-muted"> | ||
Default journals for new bookings and invoices. | ||
</div> | ||
<div class="content-group"> | ||
<div class="row mt16"> | ||
<label string="General Journal" | ||
for="account_move_default_general_journal_id" | ||
class="col-lg-3 o_light_label" /> | ||
<field name="account_move_default_general_journal_id" | ||
domain="[('type', '=', 'general')]" /> | ||
</div> | ||
<div class="row mt16"> | ||
<label string="Sale Journal" | ||
for="account_move_default_sale_journal_id" | ||
class="col-lg-3 o_light_label" /> | ||
<field name="account_move_default_sale_journal_id" | ||
domain="[('type', '=', 'sale')]" /> | ||
</div> | ||
<div class="row mt16"> | ||
<label string="Purchase Journal" | ||
for="account_move_default_purchase_journal_id" | ||
class="col-lg-3 o_light_label" /> | ||
<field name="account_move_default_purchase_journal_id" | ||
domain="[('type', '=', 'purchase')]" /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |