From e933c5664c0905b6bbebe9d93b05ff7f55d9c86b Mon Sep 17 00:00:00 2001 From: Andhitia Rama Date: Sun, 24 Sep 2023 05:53:38 +0700 Subject: [PATCH 1/2] [UPD] ssi_financial_accounting * Change license on files to AGPL * Add resusable aml selector --- ssi_financial_accounting/__manifest__.py | 7 +- .../data/account_journal_data.xml | 6 + .../models/account_move_line.py | 21 ++++ .../security/ir.model.access.csv | 1 + ssi_financial_accounting/wizards/__init__.py | 1 + .../wizards/account_move_line_selector.py | 106 ++++++++++++++++++ .../account_move_line_selector_views.xml | 57 ++++++++++ 7 files changed, 196 insertions(+), 3 deletions(-) create mode 100644 ssi_financial_accounting/wizards/account_move_line_selector.py create mode 100644 ssi_financial_accounting/wizards/account_move_line_selector_views.xml diff --git a/ssi_financial_accounting/__manifest__.py b/ssi_financial_accounting/__manifest__.py index 3e6911d..8f8bdad 100644 --- a/ssi_financial_accounting/__manifest__.py +++ b/ssi_financial_accounting/__manifest__.py @@ -25,6 +25,10 @@ "security/ir.model.access.csv", "data/account_journal_data.xml", "menu.xml", + "wizards/general_ledger_wizard_views.xml", + "wizards/trial_balance_wizard_views.xml", + "wizards/aged_partner_balance_wizard_views.xml", + "wizards/account_move_line_selector_views.xml", "views/res_config_settings_views.xml", "views/mis_report_instance_views.xml", "views/mis_report_style_views.xml", @@ -34,9 +38,6 @@ "views/account_move_line_views.xml", "views/account_move_views.xml", "views/cash_flow_type_views.xml", - "wizards/general_ledger_wizard_views.xml", - "wizards/trial_balance_wizard_views.xml", - "wizards/aged_partner_balance_wizard_views.xml", "report/templates/aged_partner_balance.xml", ], "demo": [], diff --git a/ssi_financial_accounting/data/account_journal_data.xml b/ssi_financial_accounting/data/account_journal_data.xml index 4a44911..718837e 100644 --- a/ssi_financial_accounting/data/account_journal_data.xml +++ b/ssi_financial_accounting/data/account_journal_data.xml @@ -10,6 +10,12 @@ general + + Opening + OPEN + general + + Adjustment ADJ diff --git a/ssi_financial_accounting/models/account_move_line.py b/ssi_financial_accounting/models/account_move_line.py index 794029b..56f6937 100644 --- a/ssi_financial_accounting/models/account_move_line.py +++ b/ssi_financial_accounting/models/account_move_line.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models +from odoo.tools.safe_eval import safe_eval class AccountMoveLine(models.Model): @@ -57,3 +58,23 @@ def create(self, values_list): ) return results + + def _transform_to_other_data(self, aml_selector): + self.ensure_one() + dict_mappings = safe_eval(aml_selector.field_mapping) + record = self.read()[0] + + for dict_mapping in dict_mappings.items(): + if dict_mapping[1] == "active_id": + dict_mappings.update({dict_mapping[0]: aml_selector.active_id}) + else: + if type(record[dict_mapping[0]]) is tuple: + data = record[dict_mapping[1]][0] + else: + data = record[dict_mapping[1]] + dict_mappings.update( + { + dict_mapping[0]: data, + } + ) + self.env[aml_selector.active_model].create(dict_mappings) diff --git a/ssi_financial_accounting/security/ir.model.access.csv b/ssi_financial_accounting/security/ir.model.access.csv index e313f7f..45c8e7b 100644 --- a/ssi_financial_accounting/security/ir.model.access.csv +++ b/ssi_financial_accounting/security/ir.model.access.csv @@ -1,3 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_cash_flow_type_configurator,cash_flow_type - configurator,model_cash_flow_type,cash_flow_type_group,1,1,1,1 access_cash_flow_type_all,cash_flow_type - all user,model_cash_flow_type,,1,0,0,0 +access_account_move_selector_all,account_move_selector - all user,model_account_move_selector,,1,1,1,1 diff --git a/ssi_financial_accounting/wizards/__init__.py b/ssi_financial_accounting/wizards/__init__.py index 8fc67ba..c316bc2 100644 --- a/ssi_financial_accounting/wizards/__init__.py +++ b/ssi_financial_accounting/wizards/__init__.py @@ -4,4 +4,5 @@ from . import ( aged_partner_balance_report_wizard, + account_move_line_selector, ) diff --git a/ssi_financial_accounting/wizards/account_move_line_selector.py b/ssi_financial_accounting/wizards/account_move_line_selector.py new file mode 100644 index 0000000..08ca7a9 --- /dev/null +++ b/ssi_financial_accounting/wizards/account_move_line_selector.py @@ -0,0 +1,106 @@ +from odoo import api, fields, models + + +class AccountMoveLineSelector(models.TransientModel): + _name = "account_move_line_selector" + _description = "Journal Item Selector" + + active_model = fields.Char( + string="Active Model", + ) + active_id = fields.Integer( + string="Active ID", + ) + filter_account_ok = fields.Boolean( + string="Filter by Account", + default=False, + ) + account_ids = fields.Many2many( + string="Allowed Accounts", + comodel_name="account.account", + ) + filter_partner_ok = fields.Boolean( + string="Filter by Partner", + default=False, + ) + partner_ids = fields.Many2many( + string="Allowed Partners", + comodel_name="res.partner", + ) + filter_journal_ok = fields.Boolean( + string="Filter by Journal", + default=False, + ) + journal_ids = fields.Many2many( + string="Allowed Journals", + comodel_name="account.journal", + ) + direction = fields.Selection( + string="Direction", + selection=[ + ("dr", "Debit"), + ("cr", "Credit"), + ("both", "Both"), + ], + default="dr", + ) + reconcile = fields.Boolean( + string="Reconcile", + default=True, + ) + allowed_move_line_ids = fields.Many2many( + string="Allowed Move Lines", + comodel_name="account.move.line", + compute="_compute_allowed_move_line_ids", + store=False, + ) + move_line_ids = fields.Many2many( + string="Selected Move Lines", + comodel_name="account.move.line", + ) + field_mapping = fields.Text( + string="Field Mapping", + ) + + @api.depends( + "filter_account_ok", + "account_ids", + "filter_journal_ok", + "journal_ids", + "filter_partner_ok", + "partner_ids", + "direction", + "reconcile", + ) + def _compute_allowed_move_line_ids(self): + for record in self: + criteria = [ + ("reconciled", "=", record.reconcile), + ] + + if record.direction == "dr": + criteria.append(("debit", ">", 0.0)) + elif record.direction == "cr": + criteria.append(("credit", ">", 0.0)) + + if record.filter_account_ok: + criteria.append(("account_id", "in", record.account_ids.ids)) + + if record.filter_journal_ok: + criteria.append(("journal_id", "in", record.journal_ids.ids)) + + if record.filter_partner_ok: + criteria.append(("partner_id", "in", record.partner_ids.ids)) + + record.allowed_move_line_ids = self.env["account.move.line"].search( + criteria + ) + + def action_confirm(self): + for record in self.sudo(): + record._confirm() + + def _confirm(self): + self.ensure_one() + for aml in self.move_line_ids: + aml._transform_to_other_data(self) diff --git a/ssi_financial_accounting/wizards/account_move_line_selector_views.xml b/ssi_financial_accounting/wizards/account_move_line_selector_views.xml new file mode 100644 index 0000000..0ff9aac --- /dev/null +++ b/ssi_financial_accounting/wizards/account_move_line_selector_views.xml @@ -0,0 +1,57 @@ + + + + + account_move_line_selector form + account_move_line_selector + +
+ + + + + + + + + + + + + + + +
+
+ +
+
+ + + Journal Items Selector + ir.actions.act_window + account_move_line_selector + form + + new + + + +
From c515ca6d5cdbdbd78f05525370e1f4be2063679b Mon Sep 17 00:00:00 2001 From: Andhitia Rama Date: Sun, 24 Sep 2023 06:00:25 +0700 Subject: [PATCH 2/2] [UPD] ssi_financial_accounting * Change license on files to AGPL * Add resusable aml selector --- ssi_financial_accounting/security/ir.model.access.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssi_financial_accounting/security/ir.model.access.csv b/ssi_financial_accounting/security/ir.model.access.csv index 45c8e7b..777de5f 100644 --- a/ssi_financial_accounting/security/ir.model.access.csv +++ b/ssi_financial_accounting/security/ir.model.access.csv @@ -1,4 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_cash_flow_type_configurator,cash_flow_type - configurator,model_cash_flow_type,cash_flow_type_group,1,1,1,1 access_cash_flow_type_all,cash_flow_type - all user,model_cash_flow_type,,1,0,0,0 -access_account_move_selector_all,account_move_selector - all user,model_account_move_selector,,1,1,1,1 +access_account_move_line_selector_all,account_move_line_selector - all user,model_account_move_line_selector,,1,1,1,1