-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD account_receipt_journal: Define and use journals dedicated to rec…
…eipts
- Loading branch information
Showing
14 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_journal | ||
from . import account_move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `TAKOBI <https://takobi.online>`_: | ||
|
||
* Lorenzo Battistini |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_receipts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
# generated from manifests external_dependencies | ||
openupgradelib |
1 change: 1 addition & 0 deletions
1
setup/account_receipt_journal/odoo/addons/account_receipt_journal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_receipt_journal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |