Skip to content

Commit

Permalink
ADD account_receipt_journal: Define and use journals dedicated to rec…
Browse files Browse the repository at this point in the history
…eipts
  • Loading branch information
eLBati committed Oct 17, 2022
1 parent 4f11bfb commit 651cd5d
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 0 deletions.
18 changes: 18 additions & 0 deletions account_receipt_journal/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from . import models
from openupgradelib import openupgrade


def rename_old_italian_data(cr):

if not openupgrade.is_module_installed(cr, "l10n_it_corrispettivi"):
return

openupgrade.rename_xmlids(
cr,
[
(
"l10n_it_corrispettivi.corrispettivi_journal",
"account_receipt_journal.sale_receipts_journal",
),
],
)
29 changes: 29 additions & 0 deletions account_receipt_journal/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2022 Lorenzo Battistini - TAKOBI
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Receipts Journals",
"summary": "Define and use journals dedicated to receipts",
"version": "14.0.1.0.0",
"development_status": "Beta",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoicing",
"author": "TAKOBI, Odoo Community Association (OCA)",
"maintainers": ["eLBati"],
"license": "LGPL-3",
"application": False,
"installable": True,
"preloadable": True,
"depends": [
"account",
],
"data": [
"views/account_journal_views.xml",
"data/account_journal_data.xml",
],
"pre_init_hook": "rename_old_italian_data",
"external_dependencies": {
"python": [
"openupgradelib",
],
},
}
18 changes: 18 additions & 0 deletions account_receipt_journal/data/account_journal_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="sale_receipts_journal" model="account.journal">
<field name="name">Sale Receipts Journal</field>
<field name="code">S-REC</field>
<field name="type">sale</field>
<field name="receipts" eval="True" />
<!-- Avoid being selected as default journal -->
<field name="sequence">99</field>
</record>
<record id="purchase_receipts_journal" model="account.journal">
<field name="name">Purchase Receipts Journal</field>
<field name="code">P-REC</field>
<field name="type">purchase</field>
<field name="receipts" eval="True" />
<field name="sequence">99</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions account_receipt_journal/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import account_journal
from . import account_move
6 changes: 6 additions & 0 deletions account_receipt_journal/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from odoo import fields, models


class Journal(models.Model):
_inherit = "account.journal"
receipts = fields.Boolean(string="Receipts")
33 changes: 33 additions & 0 deletions account_receipt_journal/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from odoo import api, models


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

@api.model
def _search_default_receipt_journal(self, journal_types):
company_id = self._context.get("default_company_id", self.env.company.id)
domain = [
("company_id", "=", company_id),
("type", "in", journal_types),
("receipts", "=", True),
]
journal = None
if self._context.get("default_currency_id"):
currency_domain = domain + [
("currency_id", "=", self._context["default_currency_id"])
]
journal = self.env["account.journal"].search(currency_domain, limit=1)
if not journal:
journal = self.env["account.journal"].search(domain, limit=1)
return journal

@api.model
def _search_default_journal(self, journal_types):
journal = super(Move, self)._search_default_journal(journal_types)
default_move_type = self.env.context.get("default_move_type")
if not journal.receipts and default_move_type in ("in_receipt", "out_receipt"):
receipt_journal = self._search_default_receipt_journal(journal_types)
if receipt_journal:
journal = receipt_journal
return journal
3 changes: 3 additions & 0 deletions account_receipt_journal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `TAKOBI <https://takobi.online>`_:

* Lorenzo Battistini
1 change: 1 addition & 0 deletions account_receipt_journal/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Define journals dedicated to receipts and automatically use them in sale and purchase receipts
1 change: 1 addition & 0 deletions account_receipt_journal/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_receipts
67 changes: 67 additions & 0 deletions account_receipt_journal/tests/test_receipts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from odoo.tests import tagged

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestReceipts(AccountTestInvoicingCommon):
def setUp(self):
super(TestReceipts, self).setUp()
self.move_model = self.env["account.move"]
self.tax_model = self.env["account.tax"]
self.journal_model = self.env["account.journal"]
self.a_sale = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_account_type_revenue").id,
)
],
limit=1,
)
self.tax22inc = self.tax_model.create(
{
"name": "Tax 22 INC",
"amount": 22,
"price_include": True,
}
)
self.receipt_journal = self.create_receipt_journal()

def create_receipt_journal(self):
return self.journal_model.create(
{
"name": "Sale Receipts Journal",
"code": "S-REC",
"type": "sale",
"receipts": True,
"sequence": 99,
}
)

def create_receipt(self):
receipt = self.move_model.with_context(default_move_type="out_receipt").create(
{
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.a_sale.id,
"product_id": self.env.ref("product.product_product_5").id,
"name": "Receipt",
"quantity": 1,
"price_unit": 10,
"tax_ids": [(6, 0, {self.tax22inc.id})],
},
),
]
}
)
return receipt

def test_receipt_journal_default(self):
"""Test default values for receipt."""
receipt = self.create_receipt()
self.assertEqual(receipt.journal_id.id, self.receipt_journal.id)
20 changes: 20 additions & 0 deletions account_receipt_journal/views/account_journal_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_account_journal_form_receipts" model="ir.ui.view">
<field name="name">account.journal.form.receipts</field>
<field name="model">account.journal</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.view_account_journal_form" />
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']/group" position="inside">
<group
name="receipts"
string="Receipts"
attrs="{'invisible': [('type', 'not in', ('sale', 'purchase'))]}"
>
<field name="receipts" />
</group>
</xpath>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# generated from manifests external_dependencies
openupgradelib
6 changes: 6 additions & 0 deletions setup/account_receipt_journal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 651cd5d

Please sign in to comment.