Skip to content

Commit

Permalink
cash register
Browse files Browse the repository at this point in the history
  • Loading branch information
dhongu committed Oct 20, 2024
1 parent 644518e commit dfee586
Show file tree
Hide file tree
Showing 18 changed files with 1,046 additions and 14 deletions.
67 changes: 67 additions & 0 deletions l10n_ro_cash_register/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
=======================
Romania - Cash Register
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:bd84ef5da0acda74f54ced4b755ef26bb3ac3d7f2779067283750d99f95e396b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-dhongu%2Fl10n--romania-lightgray.png?logo=github
:target: https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_cash_register
:alt: dhongu/l10n-romania

|badge1| |badge2| |badge3|

Functionalitati

- Registrul de casa

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/dhongu/l10n-romania/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/dhongu/l10n-romania/issues/new?body=module:%20l10n_ro_cash_register%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Terrabit

Contributors
------------

- `Terrabit <https://www.terrabit.ro>`__:

- Dorin Hongu <[email protected]>

Do not contact contributors directly about support or help with
technical issues.

Maintainers
-----------

This module is part of the `dhongu/l10n-romania <https://github.com/dhongu/l10n-romania/tree/15.0/l10n_ro_cash_register>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions l10n_ro_cash_register/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
17 changes: 17 additions & 0 deletions l10n_ro_cash_register/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Romania - Cash Register",
"version": "15.0.1.0.0",
"author": "Terrabit," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-romania",
"category": "Romania Adaptation",
"depends": ["account"],
"countries": ["ro"],
"data": [
"views/cash_register_views.xml",
"security/ir.model.access.csv",
"security/cash_register_security.xml",
"views/report_cash_register.xml",
],
"license": "AGPL-3",
}
5 changes: 5 additions & 0 deletions l10n_ro_cash_register/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import cash_register
from . import account_move_line
from . import account_journal_dashboard
18 changes: 18 additions & 0 deletions l10n_ro_cash_register/models/account_journal_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import models


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(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
return super().open_action()
8 changes: 8 additions & 0 deletions l10n_ro_cash_register/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def print_cash_operation(self):
pass
193 changes: 193 additions & 0 deletions l10n_ro_cash_register/models/cash_register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
from odoo import api, fields, models


class CashRegister(models.Model):
_name = "l10n.ro.cash.register"
_description = "Cash Register"
_inherit = ["mail.thread", "mail.activity.mixin", "sequence.mixin"]

def _get_default_journal_id(self):
return self.env["account.journal"].search([("type", "=", "cash")], limit=1)

name = fields.Char(
string="Number",
compute="_compute_name",
readonly=False,
store=True,
copy=False,
tracking=True,
index="trigram",
)

company_id = fields.Many2one(
"res.company",
string="Company",
required=True,
default=lambda self: self.env.company,
)
currency_id = fields.Many2one(
"res.currency",
string="Currency",
default=lambda self: self.env.company.currency_id,
)
journal_id = fields.Many2one(
"account.journal",
string="Journal",
required=True,
domain=[("type", "=", "cash")],
default=_get_default_journal_id,
)
date = fields.Date(required=True, default=fields.Date.context_today)

balance_start = fields.Monetary(string="Starting Balance", compute="_compute_balance_start", store=True)

# Balance end is calculated based on the statement line amounts and real starting balance.
balance_end = fields.Monetary(
string="Computed Balance",
compute="_compute_balance_end",
store=True,
)

move_ids = fields.Many2many("account.move", string="Journal Items", compute="_compute_move_ids")
move_line_ids = fields.Many2many("account.move.line", string="Journal Items", compute="_compute_move_ids")

_sql_constraints = [("unique_date_journal", "unique(date, journal_id)", "Duplicate date")]

@api.depends("journal_id", "date")
def _compute_name(self):
for item in self.sorted(lambda m: m.date):
move_has_name = item.name and item.name != "/"
if move_has_name:
if not item._sequence_matches_date():
if item._get_last_sequence():
# The name does not match the date and the move is not the first in the period:
# Reset to draft
item.name = False
continue
else:
if move_has_name or not move_has_name and item._get_last_sequence():
# The move either
# - has a name and was posted before, or
# - doesn't have a name, but is not the first in the period
# so we don't recompute the name
continue
if item.date and (not move_has_name or not item._sequence_matches_date()):
item._set_next_sequence()

def _get_last_sequence_domain(self, relaxed=False):
# pylint: disable=sql-injection
# EXTENDS account sequence.mixin
self.ensure_one()
if not self.date or not self.journal_id:
return "WHERE FALSE", {}
where_string = "WHERE journal_id = %(journal_id)s AND name != '/'"
param = {"journal_id": self.journal_id.id}
return where_string, param

@api.onchange("journal_id")
def _onchange_journal_id(self):
if self.journal_id:
self.currency_id = self.journal_id.currency_id or self.env.company.currency_id

def generate_missing_cash_register(self):
"""Generate missing cash registers for all cash journals and for all moves"""
domain = [("type", "=", "cash")]
journals = self.env["account.journal"].search(domain)
for journal in journals:
account = journal.default_account_id
# cautam toate miscari pentru contul de casa grupate dupa data
sql = """
SELECT date, SUM(debit-credit) as amount
FROM account_move_line
WHERE account_id = %s and state = 'posted'
GROUP BY date
"""
self.env.cr.execute(sql, (account.id,))
for row in self.env.cr.dictfetchall():
date = row["date"]
row["amount"]
# verificam daca exista deja un registru de casa pentru aceasta data
cash_register = self.env["cash.register"].search([("journal_id", "=", journal.id), ("date", "=", date)])
if not cash_register:
cash_register.create(
{
"name": f"{journal.name} - {date}",
"company_id": journal.company_id.id,
"currency_id": journal.currency_id.id,
"journal_id": journal.id,
"date": date,
}
)

@api.depends("date", "journal_id")
def _compute_move_ids(self):
for record in self:
move_lines = self.env["account.move.line"].search(
[
("date", "=", record.date),
("account_id", "=", record.journal_id.default_account_id.id),
("move_id.state", "=", "posted"),
]
)
record.move_line_ids = move_lines
record.move_ids = move_lines.mapped("move_id")

def _compute_balance_start(self):
for record in self:
param = {
"account_id": record.journal_id.default_account_id.id,
"date": record.date,
"company_id": record.company_id.id,
}
sql = """
SELECT SUM(debit-credit) as amount
FROM account_move_line join account_move on account_move_line.move_id = account_move.id
WHERE account_id = %(account_id)s
AND account_move_line.date < %(date)s
AND account_move_line.company_id = %(company_id)s
AND account_move.state = 'posted'
"""
self.env.cr.execute(sql, param)
row = self.env.cr.dictfetchone()
record.balance_start = row["amount"] or 0.0

@api.depends("date", "journal_id", "move_ids")
def _compute_balance_end(self):
for record in self:
if not record.journal_id:
record.balance_end = 0.0
continue
param = {
"account_id": record.journal_id.default_account_id.id,
"date": record.date,
"company_id": record.company_id.id,
}
sql = """
SELECT SUM(debit-credit) as amount
FROM account_move_line join account_move on account_move_line.move_id = account_move.id
WHERE account_id = %(account_id)s
AND account_move_line.date <= %(date)s
AND account_move_line.company_id = %(company_id)s
AND account_move.state = 'posted'
"""
self.env.cr.execute(sql, param)
row = self.env.cr.dictfetchone()
record.balance_end = row["amount"] or 0.0

def action_refresh(self):
self._compute_balance_start()
self._compute_balance_end()
self._compute_move_ids()
return True

def action_receipt(self):
action = self.journal_id.open_payments_action("inbound", "form")
action["context"].update({"default_journal_id": self.journal_id.id})
action["target"] = "new"
return action

def action_payment(self):
action = self.journal_id.open_payments_action("outbound", "form")
action["context"].update({"default_journal_id": self.journal_id.id})
action["target"] = "new"
return action
4 changes: 4 additions & 0 deletions l10n_ro_cash_register/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Terrabit](https://www.terrabit.ro):
- Dorin Hongu \<<[email protected]>\>

Do not contact contributors directly about support or help with technical issues.
3 changes: 3 additions & 0 deletions l10n_ro_cash_register/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Functionalitati

- Registrul de casa
7 changes: 7 additions & 0 deletions l10n_ro_cash_register/security/cash_register_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo>
<record model="ir.rule" id="cash_register_account_rule">
<field name="name">Cash register multi-company</field>
<field name="model_id" ref="model_l10n_ro_cash_register" />
<field name="domain_force">['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions l10n_ro_cash_register/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_l10n_ro_cash_register_user,cash_register user,model_l10n_ro_cash_register,account.group_account_manager,1,1,1,1
Binary file added l10n_ro_cash_register/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dfee586

Please sign in to comment.