Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dhongu committed Oct 21, 2024
1 parent dbf228a commit 3b4e3b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
33 changes: 28 additions & 5 deletions l10n_ro_cash_register/models/account_journal_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
class account_journal(models.Model):
_inherit = "account.journal"

def open_action_with_context(self):
if self.type == "cash" and self.company_id.country_id.code == "RO":
action = self.env["ir.actions.actions"]._for_xml_id("l10n_ro_cash_register.action_cash_register")
action["context"] = {"default_journal_id": self.id}
return action
# def open_action_with_context(self):
# if self.type == "cash" and self.company_id.country_id.code == "RO":
# action = self.env["ir.actions.actions"]._for_xml_id("l10n_ro_cash_register.action_cash_register")
# action["context"] = {"default_journal_id": self.id}
# return action

def open_action(self):
if self.type == "cash" and self.company_id.country_id.code == "RO":
Expand Down Expand Up @@ -56,3 +56,26 @@ def generate_missing_cash_register(self):
}
)
return True

def remove_outstanding_accounts(self):
for journal in self:
if journal.type != "cash":
continue
lines = self.outbound_payment_method_line_ids + self.inbound_payment_method_line_ids
for line in lines:
account_id = line.payment_account_id.id or self.company_id.account_journal_payment_debit_account_id.id
if account_id == journal.default_account_id.id:
continue
journal._remove_outstanding_account(account_id)
line.write({"payment_account_id": journal.default_account_id.id})

def _remove_outstanding_account(self, account_id):
param = {'old_account': account_id, 'journal_id': self.id, 'new_account': self.default_account_id.id}
sql = """
UPDATE account_move_line
SET account_id = %(new_account)s
WHERE account_id = %(old_account)s
AND journal_id = %(journal_id)s
"""""
self.env.cr.execute(sql, param)

7 changes: 7 additions & 0 deletions l10n_ro_cash_register/views/cash_register_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,12 @@
<field name="code">record.generate_missing_cash_register()</field>
</record>

<record id="action_remove_outstanding_accounts" model="ir.actions.server">
<field name="name">Remove Outstanding Accounts</field>
<field name="model_id" ref="account.model_account_journal"/>
<field name="binding_model_id" ref="account.model_account_journal"/>
<field name="state">code</field>
<field name="code">record.remove_outstanding_accounts()</field>
</record>

</odoo>

0 comments on commit 3b4e3b2

Please sign in to comment.