Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UPD] ssi_financial_accounting #30

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ssi_financial_accounting/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [],
Expand Down
6 changes: 6 additions & 0 deletions ssi_financial_accounting/data/account_journal_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<field name="type">general</field>
</record>

<record id="journal_opening" model="account.journal">
<field name="name">Opening</field>
<field name="code">OPEN</field>
<field name="type">general</field>
</record>

<record id="journal_adj" model="account.journal">
<field name="name">Adjustment</field>
<field name="code">ADJ</field>
Expand Down
21 changes: 21 additions & 0 deletions ssi_financial_accounting/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions ssi_financial_accounting/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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_line_selector_all,account_move_line_selector - all user,model_account_move_line_selector,,1,1,1,1
1 change: 1 addition & 0 deletions ssi_financial_accounting/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

from . import (
aged_partner_balance_report_wizard,
account_move_line_selector,
)
106 changes: 106 additions & 0 deletions ssi_financial_accounting/wizards/account_move_line_selector.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 OpenSynergy Indonesia
Copyright 2022 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="account_move_line_selector_view_form" model="ir.ui.view">
<field name="name">account_move_line_selector form</field>
<field name="model">account_move_line_selector</field>
<field name="arch" type="xml">
<form>
<group name="group_1" colspan="4" col="2">
<field name="active_model" invisible="1" />
<field name="active_id" invisible="1" />
<field name="filter_account_ok" invisible="1" />
<field name="account_ids" widget="many2many_tags" invisible="1" />
<field name="filter_journal_ok" invisible="1" />
<field name="journal_ids" widget="many2many_tags" invisible="1" />
<field name="filter_partner_ok" invisible="1" />
<field name="partner_ids" widget="many2many_tags" invisible="1" />
<field name="direction" invisible="1" />
<field name="reconcile" invisible="1" />
<field
name="allowed_move_line_ids"
widget="many2many_tags"
invisible="1"
/>
<field name="field_mapping" widget="ace" invisible="1" />
</group>
<field
name="move_line_ids"
domain="[('id', 'in', allowed_move_line_ids)]"
/>
<footer>
<button
name="action_confirm"
type="object"
string="Confirm"
class="oe_highlight"
/>
or
<button special="cancel" string="Cancel" />
</footer>
</form>
</field>
</record>

<record id="account_move_line_selector_action" model="ir.actions.act_window">
<field name="name">Journal Items Selector</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account_move_line_selector</field>
<field name="view_mode">form</field>
<field name="view_id" ref="account_move_line_selector_view_form" />
<field name="target">new</field>
</record>


</odoo>
Loading