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

feat: init the module, define models and views #4

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
674 changes: 674 additions & 0 deletions account_oss_report/LICENSE

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions account_oss_report/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. image:: https://img.shields.io/badge/licence-GPL--3-blue.svg
:target: http://www.gnu.org/licenses/gpl-3.0-standalone.html
:alt: License: GPL-3

==================
Account Oss Report
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is "OSS"

==================

Module summary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary is missing.


For a detailed documentation have a look at https://www.odoo-wiki.org/account-oss-report.html

Configuration
~~~~~~~~~~~~~

* No additional configurations needed

Maintainer
~~~~~~~~~~

.. image:: https://raw.githubusercontent.com/Mint-System/Wiki/master/assets/mint-system-logo.png
:target: https://www.mint-system.ch

This module is maintained by Mint System GmbH.

For support and more information, please visit `our Website <https://www.mint-system.ch>`__.
1 change: 1 addition & 0 deletions account_oss_report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models, wizard
22 changes: 22 additions & 0 deletions account_oss_report/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "Account OSS Report",
"summary": """
Create OSS tax report for CH.
""",
"author": "Mint System GmbH, Odoo Community Association (OCA)",
"website": "https://www.mint-system.ch",
"category": "Accounting",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": ["account", "l10n_eu_oss"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not depend on l10n_eu_oss

"data": [
"views/account_oss_report.xml",
"wizard/oss_report_recalculate.xml",
"security/ir.model.access.csv",
"views/menu.xml",
],
"installable": True,
"application": False,
"auto_install": False,
"images": ["images/screen.png"],
}
Binary file added account_oss_report/images/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions account_oss_report/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_oss_report
75 changes: 75 additions & 0 deletions account_oss_report/models/account_oss_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from odoo import api, fields, models

class AccountOssReport(models.Model):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"OSS"

_name = "account.oss.report"
_description = "OSS Tax Report"

country_code = fields.Char()
tax_rate = fields.Float()
base_amount = fields.Float()
tax_amount = fields.Float()
net_amount = fields.Float()
# tax_type = fields.Selection()

@api.model
def _get_account_move_data(self, data=None, start_date=False, end_date=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why account_move ?

"""
Fetch data from account.move.line with the appropriate domain and calculations.
"""
if data is None:
data = []

# Fetch the tag for "OSS" to use in the domain
oss_tag = self.env['account.account.tag'].search([('name', '=', 'OSS')], limit=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. The tag should be define as an XML ID.


# Build the domain to filter by date, tax, and tag "OSS"
domain = [
('move_id.invoice_date', '>=', start_date),
('move_id.invoice_date', '<=', end_date),
('tax_ids', '!=', False),
('tax_tag_ids', 'in', [oss_tag.id])
]

# Fetch move lines that match the criteria
move_lines = self.env['account.move.line'].search(domain)

for line in move_lines:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data should be grouped by country code!

And you have to distinct between tax included and excluded.

move = line.move_id
base_amount = move.amount_untaxed_signed
tax_amount = move.amount_tax_signed
net_amount = move.amount_total_signed

# Fetch the first tax's country code and tax rate if they exist
if line.tax_ids:
country_code = line.tax_ids[0].country_id.code
tax_rate = line.tax_ids[0].amount
else:
country_code = 'Unknown'
tax_rate = 0.0

data.append({
'country_code': country_code,
'tax_rate': tax_rate,
'base_amount': base_amount,
'tax_amount': tax_amount,
'net_amount': net_amount,
# 'tax_type': None,
})

return data

@api.model
def get_data(self, start_date=False, end_date=False):
"""
Generate OSS report data for the specified date range.
"""
data = []

# Fetch move line data
data = self._get_account_move_data(data, start_date, end_date)

# Clear existing data from the report
self.env.cr.execute("DELETE FROM account_oss_report")

# Insert new data into the report
self.create(data)
3 changes: 3 additions & 0 deletions account_oss_report/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_account_oss_report,access_account_oss_report,model_account_oss_report,base.group_user,1,1,1,1
access_oss_report_recalculate,access_oss_report_recalculate,model_oss_report_recalculate,base.group_user,1,1,1,1
Binary file added account_oss_report/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.
27 changes: 27 additions & 0 deletions account_oss_report/views/account_oss_report.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<odoo>
<record id="view_account_oss_report_tree" model="ir.ui.view">
<field name="name">account.oss.report.tree</field>
<field name="model">account.oss.report</field>
<field name="arch" type="xml">
<tree>
<field name="country_code"/>
<field name="tax_rate"/>
<field name="base_amount"/>
<field name="tax_amount"/>
<field name="net_amount"/>
</tree>
</field>
</record>

<record id="action_account_oss_report" model="ir.actions.act_window">
<field name="name">OSS Tax Report</field>
<field name="res_model">account.oss.report</field>
<field name="view_mode">tree</field>
</record>

<!-- <menuitem id="menu_account_oss_report" -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove comment code.

<!-- name="OSS Tax Report" -->
<!-- parent="account.menu_finance_reports" -->
<!-- action="action_account_oss_report"/> -->

</odoo>
21 changes: 21 additions & 0 deletions account_oss_report/views/menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<menuitem id="menu_oss_tax_reporting"
name="OSS Tax Reporting"
parent="account.menu_finance_reports"
sequence="100"/>

<menuitem id="menu_oss_report_recalculate_wizard"
name="Recalculate OSS Report"
parent="menu_oss_tax_reporting"
action="account_oss_report.action_recalculate_oss_report"
sequence="200"/>

<menuitem id="menu_account_oss_report"
name="OSS Tax Report"
parent="menu_oss_tax_reporting"
action="account_oss_report.action_account_oss_report"
sequence="300"/>

</odoo>
1 change: 1 addition & 0 deletions account_oss_report/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import oss_report_recalculate
28 changes: 28 additions & 0 deletions account_oss_report/wizard/oss_report_recalculate.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of the wizard.

The calculation should be pretty fast, so not wizard might be required.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo import fields, models


class OssReportRecalculate(models.TransientModel):
_name = "oss.report.recalculate"
_description = "Recalculate OSS report"

start_date = fields.Date(required=True)
end_date = fields.Date(required=True)

def recalculate_oss_report(self):
self.env["account.oss.report"].get_data(self.start_date, self.end_date)

tree_view_id = self.env.ref(
"account_oss_report.view_account_oss_report_tree"
).id

return {
"type": "ir.actions.act_window",
"views": [(tree_view_id, "tree")],
"view_mode": "tree",
"name": "OSS Tax Report",
"res_model": "account.oss.report",
"domain": [],
"context": dict(
self.env.context, start_date=self.start_date, end_date=self.end_date
),
}
37 changes: 37 additions & 0 deletions account_oss_report/wizard/oss_report_recalculate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_oss_report_recalculate_wizard" model="ir.ui.view">
<field name="name">Recalculate OSS Report</field>
<field name="model">oss.report.recalculate</field>
<field name="arch" type="xml">
<form string="Recalculate OSS Report">
<group>
<field name="start_date"/>
<field name="end_date"/>
</group>
<group>
<p>The recalculation of the OSS report may take a few minutes depending on the data.</p>
</group>
<footer>
<button name="recalculate_oss_report" string="Recalculate" type="object" class="btn-primary" />
<button string="Cancel" class="btn-secondary" special="cancel" />
</footer>
</form>
</field>
</record>

<record id="action_recalculate_oss_report" model="ir.actions.act_window">
<field name="name">Recalculate OSS Report</field>
<field name="res_model">oss.report.recalculate</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<!-- <menuitem id="menu_oss_report_recalculate_wizard" -->
<!-- name="Recalculate OSS Report" -->
<!-- parent="account.menu_finance_reports" -->
<!-- action="account_oss_report.action_recalculate_oss_report" -->
<!-- sequence="200"/> -->

</odoo>